This commit is contained in:
kotyaralih 2021-12-05 05:30:13 -08:00
parent d5a6be70ac
commit 1e29cbbbeb
20 changed files with 98 additions and 96 deletions

View file

@ -146,9 +146,9 @@ class BanAPI{
case "op":
$user = strtolower($params[0]);
if($user == NULL){
$output .= "Usage: /op <player>\n";
break;
}
$output .= "Usage: /op <player>\n";
break;
}
$player = $this->server->api->player->get($user);
if(!($player instanceof Player)){
$this->ops->set($user);

View file

@ -120,9 +120,21 @@ class EntityAPI{
if($item->getID() === AIR or $item->count <= 0){
return;
}
$i = 0;
do { // drop the block to the first supporting block
$i++;
$v = new Vector3($pos->x, $pos->y - $i, $pos->z);
$b = $pos->level->getBlock($v);
if($b->isSolid === true) break;
if(($b instanceof LiquidBlock) or $b->getID() === COBWEB or $b->getID() === LADDER or $b->getID() === FENCE or $b->getID() === STONE_WALL)
break;
}
while ($i<200);
if ($i==200) $i=0;
$data = array(
"x" => $pos->x + mt_rand(-10, 10) / 50,
"y" => $pos->y + 0.19,
"y" => $pos->y + 0.19 - $i + 1,
"z" => $pos->z + mt_rand(-10, 10) / 50,
"level" => $pos->level,
//"speedX" => mt_rand(-3, 3) / 8,
@ -130,6 +142,7 @@ class EntityAPI{
//"speedZ" => mt_rand(-3, 3) / 8,
"item" => $item,
);
if($this->server->api->handle("item.drop", $data) !== false){
for($count = $item->count; $count > 0; ){
$item->count = min($item->getMaxStackSize(), $count);

View file

@ -196,7 +196,7 @@ class LevelAPI{
$timeu = microtime(true);
foreach($blockUpdates->getAll() as $bupdate){
$this->server->api->block->scheduleBlockUpdate(new Position((int) $bupdate["x"],(int) $bupdate["y"],(int) $bupdate["z"], $this->levels[$name]), (float) $bupdate["delay"], (int) $bupdate["type"]);
$this->server->api->block->scheduleBlockUpdate(new Position((int) $bupdate["x"],(int) $bupdate["y"],(int) $bupdate["z"], $this->levels["name"]), (float) $bupdate["delay"], (int) $bupdate["type"]);
}
return true;
}

View file

@ -28,13 +28,6 @@ class PluginAPI extends stdClass{
$this->randomNonce = Utils::getRandomBytes(16, false);
}
public function __destruct(){
foreach($this->plugins as $p){
$p[0]->__destruct();
}
unset($plugins);
}
public function getList(){
$list = array();
foreach($this->plugins as $p){

View file

@ -146,7 +146,7 @@ class ServerAPI{
self::$serverRequest = $this->server;
console("[INFO] This server is running PocketMine-MP version ".($version->isDev() ? FORMAT_YELLOW:"").MAJOR_VERSION.FORMAT_RESET." \"".CODENAME."\" (MCPE: ".CURRENT_MINECRAFT_VERSION.") (API ".CURRENT_API_VERSION.")", true, true, 0);
console("[INFO] PocketMine-MP is distibuted under the LGPL License", true, true, 0);
if(ADVANCED_CACHE == true){
console("[INFO] Advanced cache enabled");
}

View file

@ -1285,8 +1285,6 @@ class Player{
$this->username = $data["username"];
$this->iusername = strtolower($this->username);
}else{
$this->username = $data["username"];
$this->iusername = strtolower($this->username);
$this->close("Bad username", false);
break;
}
@ -1309,6 +1307,11 @@ class Player{
$u->close("logged in from another location");
}
if(!isset($this->CID) or $this->CID == null){
console("[DEBUG] Player ".$this->username." does not have a CID", true, true, 2);
$this->CID = Utils::readLong(Utils::getRandomBytes(8, false));
}
$this->server->api->player->add($this->CID);
if($this->server->api->handle("player.join", $this) === false){
$this->close("join cancelled", false);
@ -1370,7 +1373,7 @@ class Player{
));
if(($this->gamemode & 0x01) === 0x01){
$this->slot = 0;
$this->hotbar = array();
$this->hotbar = array();
}elseif($this->data->exists("hotbar")){
$this->hotbar = $this->data->get("hotbar");
$this->slot = $this->hotbar[0];
@ -2218,6 +2221,7 @@ class Player{
foreach($this->hotbar as $slot){
$hotbar[] = $slot <= -1 ? -1 : $slot + 9;
}
$this->dataPacket(MC_CONTAINER_SET_CONTENT, array(
"windowid" => 0,
"count" => count($this->inventory),

View file

@ -413,7 +413,6 @@ class PocketMinecraftServer{
if(stripos($er["file"], "plugin") !== false){
$dump .= "THIS ERROR WAS CAUSED BY A PLUGIN. REPORT IT TO THE PLUGIN DEVELOPER.\r\n";
}
$dump .= "Code: \r\n";
$file = @file($er["file"], FILE_IGNORE_NEW_LINES);
for($l = max(0, $er["line"] - 10); $l < $er["line"] + 10; ++$l){
@ -444,7 +443,6 @@ class PocketMinecraftServer{
}
$dump .= "\r\n\r\n";
}
$extensions = array();
foreach(get_loaded_extensions() as $ext){
$extensions[$ext] = phpversion($ext);

View file

@ -21,23 +21,36 @@
set_time_limit(0);
date_default_timezone_set("GMT");
if(strpos(" ".strtoupper(php_uname("s")), " WIN") !== false){
$time = time();
$time -= $time % 60;
exec("time.exe /T", $hour);
$i = array_map("intval", explode(":", trim($hour[0])));
exec("date.exe /T", $date);
$j = array_map("intval", explode(substr($date[0], 2, 1), trim($date[0])));
$offset = round((mktime($i[0], $i[1], 0, $j[1], $j[0], $j[2]) - $time) / 60) * 60;
}else{
exec("date +%s", $t);
$offset = round((intval(trim($t[0])) - time()) / 60) * 60;
}
if(ini_get("date.timezone") == ""){ //No Timezone set
date_default_timezone_set("GMT");
if(strpos(" ".strtoupper(php_uname("s")), " WIN") !== false){
$time = time();
$time -= $time % 60;
//TODO: Parse different time & date formats by region. ¬¬ world
//Example: USA
exec("time.exe /T", $hour);
$i = array_map("intval", explode(":", trim($hour[0])));
exec("date.exe /T", $date);
$j = array_map("intval", explode(substr($date[0], 2, 1), trim($date[0])));
$offset = round((mktime($i[0], $i[1], 0, $j[1], $j[0], $j[2]) - $time) / 60) * 60;
}else{
exec("date +%s", $t);
$offset = round((intval(trim($t[0])) - time()) / 60) * 60;
}
$daylight = (int) date("I");
date_default_timezone_set(timezone_name_from_abbr("", $offset, $daylight));
$d = timezone_name_from_abbr("", $offset, $daylight);
ini_set("date.timezone", $d);
date_default_timezone_set($d);
}else{
$d = @date_default_timezone_get();
if(strpos($d, "/") === false){
$d = timezone_name_from_abbr($d);
ini_set("date.timezone", $d);
date_default_timezone_set($d);
}
}
gc_enable();
error_reporting(E_ALL | E_STRICT);
@ -65,4 +78,4 @@ if(file_exists(FILE_PATH.".git/refs/heads/master")){ //Found Git information!
define("GIT_COMMIT", strtolower(trim(file_get_contents(FILE_PATH.".git/refs/heads/master"))));
}else{ //Unknown :(
define("GIT_COMMIT", str_repeat("00", 20));
}
}

View file

@ -192,7 +192,7 @@ function console($message, $EOL = true, $log = true, $level = 1){
if(preg_match("/\[([a-zA-Z0-9]*)\]/", $message, $matches) > 0){
switch($matches[1]){
case "ERROR":
case "SEVERE":
case "SEVERE":
$add .= FORMAT_RED;
break;
case "INTERNAL":

View file

@ -29,6 +29,4 @@ class Window{
public function __construct(){
$this->server = ServerAPI::request();
}
}
?>
}

View file

@ -37,12 +37,12 @@ class SugarcaneBlock extends FlowableBlock{
for($y = 1; $y < 3; ++$y){
$b = $this->level->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
if($b->getID() === AIR){
$this->level->setBlock($b, new SugarcaneBlock(), true, false, true);
//$this->level->setBlock($b, new SugarcaneBlock(), true, false, true);
break;
}
}
$this->meta = 0;
$this->level->setBlock($this, $this, true, false, true);
//$this->level->setBlock($this, $this, true, false, true);
}
if(($player->gamemode & 0x01) === 0){
$item->count--;
@ -56,25 +56,25 @@ class SugarcaneBlock extends FlowableBlock{
if($type === BLOCK_UPDATE_NORMAL){
$down = $this->getSide(0);
if($down->isTransparent === true and $down->getID() !== SUGARCANE_BLOCK){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SUGARCANE));
//ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SUGARCANE));
$this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
}elseif($type === BLOCK_UPDATE_RANDOM){
if($this->getSide(0)->getID() !== SUGARCANE_BLOCK){
if($this->meta === 0x0F){
for($y = 1; $y < 3; ++$y){
$b = $this->level->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
if($b->getID() === AIR){
$this->level->setBlock($b, new SugarcaneBlock(), true, false, true);
break;
}
}
//for($y = 1; $y < 3; ++$y){
//$b = $this->level->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
//if($b->getID() === AIR){
// $this->level->setBlock($b, new SugarcaneBlock(), true, false, true);
//break;
//}
//}
$this->meta = 0;
$this->level->setBlock($this, $this, true, false, true);
//$this->level->setBlock($this, $this, true, false, true);
}else{
++$this->meta;
$this->level->setBlock($this, $this, true, false, true);
//$this->level->setBlock($this, $this, true, false, true);
}
return BLOCK_UPDATE_RANDOM;
}
@ -85,7 +85,7 @@ class SugarcaneBlock extends FlowableBlock{
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === SUGARCANE_BLOCK){
$this->level->setBlock($block, new SugarcaneBlock(), true, false, true);
//$this->level->setBlock($block, new SugarcaneBlock(), true, false, true);
return true;
}elseif($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === SAND){
$block0 = $down->getSide(2);
@ -93,8 +93,8 @@ class SugarcaneBlock extends FlowableBlock{
$block2 = $down->getSide(4);
$block3 = $down->getSide(5);
if(($block0 instanceof WaterBlock) or ($block1 instanceof WaterBlock) or ($block2 instanceof WaterBlock) or ($block3 instanceof WaterBlock)){
$this->level->setBlock($block, new SugarcaneBlock(), true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
// $this->level->setBlock($block, new SugarcaneBlock(), true, false, true);
// $this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
}

View file

@ -142,7 +142,7 @@ class LeavesBlock extends TransparentBlock{
if(mt_rand(1,20) === 1){ //Saplings
$drops[] = array(SAPLING, $this->meta & 0x03, 1);
}
if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1,200) === 1){ //Apples
if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1,100) === 1){ //Apples
$drops[] = array(APPLE, 0, 1);
}
}

View file

@ -28,24 +28,9 @@ class BucketItem extends Item{
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($this->meta === AIR){
if($target instanceof LiquidBlock){
$level->setBlock($target, new AirBlock(), true, false, true);
if(($player->gamemode & 0x01) === 0){
$this->meta = ($target instanceof WaterBlock) ? WATER:LAVA;
}
return true;
}
//Nope
}elseif($this->meta === WATER){
//Support Make Non-Support Water to Support Water
if($block->getID() === AIR || ( $block instanceof WaterBlock && ($block->getMetadata() & 0x07) != 0x00 ) ){
$water = new WaterBlock();
$level->setBlock($block, $water, true, false, true);
$water->place(clone $this, $player, $block, $target, $face, $fx, $fy, $fz);
if(($player->gamemode & 0x01) === 0){
$this->meta = 0;
}
return true;
}
//Nope
}elseif($this->meta === LAVA){
if($block->getID() === AIR){
$level->setBlock($block, new LavaBlock(), true, false, true);

View file

@ -23,12 +23,11 @@ class Cache{
public static $cached = array();
public static function add($identifier, $blob, $minTTL = 30){
self::$cached[$identifier] = array($blob, microtime(true) + $minTTL, $minTTL);
self::$cached[$identifier] = array($blob, microtime(true) + $minTTL);
}
public static function get($identifier){
if(isset(self::$cached[$identifier])){
self::$cached[$identifier][1] += $minTTL;
return self::$cached[$identifier][0];
}
return false;

View file

@ -256,13 +256,13 @@ class Config{
* @return boolean
*/
public function exists($k, $lowercase = false){
if($lowercase === true){
if($lowercase === true){
$k = strtolower($k);//Convert requested key to lower
$array = array_change_key_case($this->config, CASE_LOWER);//Change all keys in array to lower
return isset($array[$k]);//Find $k in modified array
}else{
return isset($this->config[$k]);
}
}
}
/**

View file

@ -30,7 +30,7 @@ class Utils{
public static function isOnline(){
return ((@fsockopen("google.com", 80, $e = null, $n = null, 2) !== false or @fsockopen("www.linux.org", 80, $e = null, $n = null, 2) !== false or @fsockopen("www.php.net", 80, $e = null, $n = null, 2) !== false) ? true:false);
}
public static function getUniqueID($raw = false, $extra = ""){
$machine = php_uname("a");
$machine .= file_exists("/proc/cpuinfo") ? file_get_contents("/proc/cpuinfo") : "";
@ -121,7 +121,7 @@ class Utils{
}
public static function readTriad($str){
list(,$unpacked) = unpack("N", "\x00".$str);
list(,$unpacked) = @unpack("N", "\x00".$str);
return $unpacked;
}
@ -457,7 +457,7 @@ class Utils{
}
public static function readShort($str, $signed = true){
list(,$unpacked) = unpack("n", $str);
list(,$unpacked) = @unpack("n", $str);
if($unpacked > 0x7fff and $signed === true){
$unpacked -= 0x10000; // Convert unsigned short to signed short
}
@ -472,7 +472,7 @@ class Utils{
}
public static function readLShort($str, $signed = true){
list(,$unpacked) = unpack("v", $str);
list(,$unpacked) = @unpack("v", $str);
if($unpacked > 0x7fff and $signed === true){
$unpacked -= 0x10000; // Convert unsigned short to signed short
}
@ -487,7 +487,7 @@ class Utils{
}
public static function readInt($str){
list(,$unpacked) = unpack("N", $str);
list(,$unpacked) = @unpack("N", $str);
if($unpacked >= 2147483648){
$unpacked -= 4294967296;
}
@ -502,7 +502,7 @@ class Utils{
}
public static function readLInt($str){
list(,$unpacked) = unpack("V", $str);
list(,$unpacked) = @unpack("V", $str);
if($unpacked >= 2147483648){
$unpacked -= 4294967296;
}
@ -517,7 +517,7 @@ class Utils{
}
public static function readFloat($str){
list(,$value) = ENDIANNESS === BIG_ENDIAN ? unpack("f", $str):unpack("f", strrev($str));
list(,$value) = ENDIANNESS === BIG_ENDIAN ? @unpack("f", $str):@unpack("f", strrev($str));
return $value;
}
@ -526,7 +526,7 @@ class Utils{
}
public static function readLFloat($str){
list(,$value) = ENDIANNESS === BIG_ENDIAN ? unpack("f", strrev($str)):unpack("f", $str);
list(,$value) = ENDIANNESS === BIG_ENDIAN ? @unpack("f", strrev($str)):@unpack("f", $str);
return $value;
}
@ -539,7 +539,7 @@ class Utils{
}
public static function readDouble($str){
list(,$value) = ENDIANNESS === BIG_ENDIAN ? unpack("d", $str):unpack("d", strrev($str));
list(,$value) = ENDIANNESS === BIG_ENDIAN ? @unpack("d", $str):@unpack("d", strrev($str));
return $value;
}
@ -548,7 +548,7 @@ class Utils{
}
public static function readLDouble($str){
list(,$value) = ENDIANNESS === BIG_ENDIAN ? unpack("d", strrev($str)):unpack("d", $str);
list(,$value) = ENDIANNESS === BIG_ENDIAN ? @unpack("d", strrev($str)):@unpack("d", $str);
return $value;
}
@ -569,7 +569,7 @@ class Utils{
for($i = 0; $i < 8; $i += 4){
$value = bcmul($value, "4294967296", 0); //4294967296 == 2^32
$value = bcadd($value, 0x1000000 * ord($x{$i}) + ((ord($x{$i + 1}) << 16) | (ord($x{$i + 2}) << 8) | ord($x{$i + 3})), 0);
$value = bcadd($value, 0x1000000 * ord(@$x{$i}) + ((ord(@$x{$i + 1}) << 16) | (ord(@$x{$i + 2}) << 8) | ord(@$x{$i + 3})), 0);
}
return ($negative === true ? "-".$value:$value);
}

View file

@ -201,6 +201,7 @@ class Entity extends Position{
case MOB_PIGMAN:
return array(
array(COOKED_PORKCHOP, 0, mt_rand(0,2)),
array(GOLD_INGOT, 0, mt_rand(0,2)),
);
case MOB_CREEPER:
return array(
@ -367,10 +368,7 @@ class Entity extends Position{
break;
case FIRE: //Fire block damage
if($this->inBlock(new Vector3($x, $y, $z))){
$this->harm(1, "fire");
$this->fire = 300;
$this->updateMetadata();
$hasUpdate = true;
//patched
}
break;
case CACTUS: //Cactus damage

View file

@ -106,9 +106,11 @@ class Explosion{
$server->api->entity->spawnToAll($e);
}elseif(mt_rand(0, 10000) < ((1/$this->size) * 10000)){
if(isset(self::$specialDrops[$block->getID()])){
$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem(self::$specialDrops[$block->getID()], 0));
//$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem(self::$specialDrops[$block->getID()], 0));
return;
}else{
$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem($block->getID(), $this->level->level->getBlockDamage($block->x, $block->y, $block->z)));
//$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem($block->getID(), $this->level->level->getBlockDamage($block->x, $block->y, $block->z)));
return;
}
}
$this->level->level->setBlockID($block->x, $block->y, $block->z, 0);

View file

@ -389,7 +389,7 @@ class Level{
return false;
}
Cache::remove("world:{$this->name}:$X:$Z");
return $this->level->unloadChunk($X, $Z);
return $this->level->unloadChunk($X, $Z, $this->server->saveEnabled);
}
public function getOrderedChunk($X, $Z, $Yndex){
@ -402,9 +402,8 @@ class Level{
return $cache;
}
}
$raw = array();
for($Y = 0; $Y < 8; ++$Y){
if(($Yndex & (1 << $Y)) > 0){

View file

@ -28,7 +28,7 @@ class MineshaftPopulator extends Populator{
public function populate(Level $level, $chunkX, $chunkZ, Random $random){
if($random->nextRange(0, MineshaftPopulator::$ODD) === 0){
//$mineshaft = new Mineshaft($random);
$mineshaft = new Mineshaft($random);
}
}