diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index ebb7663e3..554b929fa 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -1397,7 +1397,7 @@ class Server{ Network::$BATCH_THRESHOLD = -1; } - $this->networkCompressionLevel = $this->getProperty("network.compression-level", 7); + $this->networkCompressionLevel = (int) $this->getProperty("network.compression-level", 7); if($this->networkCompressionLevel < 1 or $this->networkCompressionLevel > 9){ $this->logger->warning("Invalid network compression level $this->networkCompressionLevel set, setting to default 7"); $this->networkCompressionLevel = 7; diff --git a/src/pocketmine/block/CocoaBlock.php b/src/pocketmine/block/CocoaBlock.php index fca535a99..e345bb45b 100644 --- a/src/pocketmine/block/CocoaBlock.php +++ b/src/pocketmine/block/CocoaBlock.php @@ -23,6 +23,11 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\item\Item; +use pocketmine\item\ItemFactory; +use pocketmine\item\ItemIds; +use function mt_rand; + class CocoaBlock extends Transparent{ protected $id = self::COCOA_BLOCK; @@ -48,4 +53,14 @@ class CocoaBlock extends Transparent{ public function isAffectedBySilkTouch() : bool{ return false; } + + public function getDropsForCompatibleTool(Item $item) : array{ + return [ + ItemFactory::get(ItemIds::DYE, 3, ($this->meta >> 2) === 2 ? mt_rand(2, 3) : 1) + ]; + } + + public function getPickedItem() : Item{ + return ItemFactory::get(ItemIds::DYE, 3); + } } diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 8beceae0e..c858b663b 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -1931,7 +1931,12 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ } public function spawnTo(Player $player) : void{ - if(!isset($this->hasSpawned[$player->getLoaderId()]) and $this->chunk !== null and isset($player->usedChunks[Level::chunkHash($this->chunk->getX(), $this->chunk->getZ())])){ + if( + !isset($this->hasSpawned[$player->getLoaderId()]) and + $this->chunk !== null and + isset($player->usedChunks[$chunkHash = Level::chunkHash($this->chunk->getX(), $this->chunk->getZ())]) and + $player->usedChunks[$chunkHash] === true + ){ $this->hasSpawned[$player->getLoaderId()] = $player; $this->sendSpawnPacket($player); diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 57ef67567..d732c531b 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1909,7 +1909,7 @@ class Level implements ChunkManager, Metadatable{ if($player !== null){ $ev = new BlockPlaceEvent($player, $hand, $blockReplace, $blockClicked, $item); - if($this->checkSpawnProtection($player, $blockClicked)){ + if($this->checkSpawnProtection($player, $blockReplace)){ $ev->setCancelled(); } diff --git a/src/pocketmine/level/light/LightUpdate.php b/src/pocketmine/level/light/LightUpdate.php index 80bf4689a..e4fa7cf03 100644 --- a/src/pocketmine/level/light/LightUpdate.php +++ b/src/pocketmine/level/light/LightUpdate.php @@ -34,17 +34,26 @@ abstract class LightUpdate{ /** @var ChunkManager */ protected $level; - /** @var int[][] blockhash => [x, y, z, new light level] */ + /** + * @var int[][] blockhash => [x, y, z, new light level] + * @phpstan-var array + */ protected $updateNodes = []; /** @var \SplQueue */ protected $spreadQueue; - /** @var bool[] */ + /** + * @var true[] + * @phpstan-var array + */ protected $spreadVisited = []; /** @var \SplQueue */ protected $removalQueue; - /** @var bool[] */ + /** + * @var true[] + * @phpstan-var array + */ protected $removalVisited = []; /** @var SubChunkIteratorManager */ protected $subChunkHandler; diff --git a/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php b/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php index fa4fbf64f..2e249a265 100644 --- a/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php @@ -28,6 +28,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\item\Item; use pocketmine\math\Vector3; use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\protocol\types\DeviceOS; use pocketmine\network\mcpe\protocol\types\EntityLink; use pocketmine\utils\UUID; use function count; @@ -84,7 +85,7 @@ class AddPlayerPacket extends DataPacket{ /** @var string */ public $deviceId = ""; //TODO: fill player's device ID (???) /** @var int */ - public $buildPlatform = -1; + public $buildPlatform = DeviceOS::UNKNOWN; protected function decodePayload(){ $this->uuid = $this->getUUID(); diff --git a/src/pocketmine/network/mcpe/protocol/types/DeviceOS.php b/src/pocketmine/network/mcpe/protocol/types/DeviceOS.php new file mode 100644 index 000000000..97a6fe5eb --- /dev/null +++ b/src/pocketmine/network/mcpe/protocol/types/DeviceOS.php @@ -0,0 +1,44 @@ +defaultPerms[$permission->getName()] = $permission; $this->dirtyPermissibles(false); } - Timings::$permissionDefaultTimer->startTiming(); + Timings::$permissionDefaultTimer->stopTiming(); } private function dirtyPermissibles(bool $op) : void{ diff --git a/src/pocketmine/resourcepacks/ZippedResourcePack.php b/src/pocketmine/resourcepacks/ZippedResourcePack.php index 3a4ba556a..89b9a97a7 100644 --- a/src/pocketmine/resourcepacks/ZippedResourcePack.php +++ b/src/pocketmine/resourcepacks/ZippedResourcePack.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\resourcepacks; use Ahc\Json\Comment as CommentedJsonDecoder; +use function assert; use function count; use function fclose; use function feof; @@ -35,6 +36,8 @@ use function fseek; use function gettype; use function hash_file; use function implode; +use function preg_match; +use function strlen; class ZippedResourcePack implements ResourcePack{ @@ -85,7 +88,22 @@ class ZippedResourcePack implements ResourcePack{ } if(($manifestData = $archive->getFromName("manifest.json")) === false){ - if($archive->locateName("pack_manifest.json") !== false){ + $manifestPath = null; + $manifestIdx = null; + for($i = 0; $i < $archive->numFiles; ++$i){ + $name = $archive->getNameIndex($i); + if( + ($manifestPath === null or strlen($name) < strlen($manifestPath)) and + preg_match('#.*/manifest.json$#', $name) === 1 + ){ + $manifestPath = $name; + $manifestIdx = $i; + } + } + if($manifestIdx !== null){ + $manifestData = $archive->getFromIndex($manifestIdx); + assert($manifestData !== false); + }elseif($archive->locateName("pack_manifest.json") !== false){ throw new ResourcePackException("Unsupported old pack format"); }else{ throw new ResourcePackException("manifest.json not found in the archive root"); diff --git a/src/pocketmine/scheduler/TaskScheduler.php b/src/pocketmine/scheduler/TaskScheduler.php index 60e4b1b60..31621a89c 100644 --- a/src/pocketmine/scheduler/TaskScheduler.php +++ b/src/pocketmine/scheduler/TaskScheduler.php @@ -36,7 +36,7 @@ class TaskScheduler{ /** @var bool */ private $enabled = true; - /** @var ReversePriorityQueue */ + /** @var ReversePriorityQueue */ protected $queue; /** @var TaskHandler[] */