diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 6b4ac7a0e..03c14c760 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1694,7 +1694,10 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ if($this->spawned){ $this->processMovement($tickDiff); + + Timings::$timerEntityBaseTick->startTiming(); $this->entityBaseTick($tickDiff); + Timings::$timerEntityBaseTick->stopTiming(); if(!$this->isSpectator() and $this->isAlive()){ $this->checkNearEntities($tickDiff); diff --git a/src/pocketmine/block/BlockFactory.php b/src/pocketmine/block/BlockFactory.php index 6f41575d6..ec785a99d 100644 --- a/src/pocketmine/block/BlockFactory.php +++ b/src/pocketmine/block/BlockFactory.php @@ -375,7 +375,11 @@ class BlockFactory{ } try{ - $block = clone self::$fullList[($id << 4) | $meta]; + if(self::$fullList !== null){ + $block = clone self::$fullList[($id << 4) | $meta]; + }else{ + $block = new UnknownBlock($id, $meta); + } }catch(\RuntimeException $e){ throw new \InvalidArgumentException("Block ID $id is out of bounds"); } diff --git a/src/pocketmine/block/Dandelion.php b/src/pocketmine/block/Dandelion.php index 640748a57..dd9e8b58a 100644 --- a/src/pocketmine/block/Dandelion.php +++ b/src/pocketmine/block/Dandelion.php @@ -43,7 +43,7 @@ class Dandelion extends Flowable{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); - if($down->getId() === 2 or $down->getId() === 3 or $down->getId() === 60){ + if($down->getId() === Block::GRASS or $down->getId() === Block::DIRT or $down->getId() === Block::FARMLAND){ $this->getLevel()->setBlock($blockReplace, $this, true, true); return true; diff --git a/src/pocketmine/command/defaults/VersionCommand.php b/src/pocketmine/command/defaults/VersionCommand.php index 257651765..7854c2eb2 100644 --- a/src/pocketmine/command/defaults/VersionCommand.php +++ b/src/pocketmine/command/defaults/VersionCommand.php @@ -86,11 +86,11 @@ class VersionCommand extends VanillaCommand{ $desc = $plugin->getDescription(); $sender->sendMessage(TextFormat::DARK_GREEN . $desc->getName() . TextFormat::WHITE . " version " . TextFormat::DARK_GREEN . $desc->getVersion()); - if($desc->getDescription() != null){ + if($desc->getDescription() !== ""){ $sender->sendMessage($desc->getDescription()); } - if($desc->getWebsite() != null){ + if($desc->getWebsite() !== ""){ $sender->sendMessage("Website: " . $desc->getWebsite()); } diff --git a/src/pocketmine/item/Armor.php b/src/pocketmine/item/Armor.php index 27f442706..340f647be 100644 --- a/src/pocketmine/item/Armor.php +++ b/src/pocketmine/item/Armor.php @@ -26,7 +26,7 @@ namespace pocketmine\item; abstract class Armor extends Item{ - public function getMaxStackSize(){ + public function getMaxStackSize() : int{ return 1; } } \ No newline at end of file diff --git a/src/pocketmine/item/Bed.php b/src/pocketmine/item/Bed.php index fece690a3..1d6b1487b 100644 --- a/src/pocketmine/item/Bed.php +++ b/src/pocketmine/item/Bed.php @@ -32,7 +32,7 @@ class Bed extends Item{ parent::__construct(self::BED, $meta, "Bed"); } - public function getMaxStackSize(){ + public function getMaxStackSize() : int{ return 1; } } \ No newline at end of file diff --git a/src/pocketmine/item/BeetrootSoup.php b/src/pocketmine/item/BeetrootSoup.php index 011846038..041841e03 100644 --- a/src/pocketmine/item/BeetrootSoup.php +++ b/src/pocketmine/item/BeetrootSoup.php @@ -29,7 +29,7 @@ class BeetrootSoup extends Food{ parent::__construct(self::BEETROOT_SOUP, $meta, "Beetroot Soup"); } - public function getMaxStackSize(){ + public function getMaxStackSize() : int{ return 1; } diff --git a/src/pocketmine/item/Bow.php b/src/pocketmine/item/Bow.php index 41e019eb5..08313b9c2 100644 --- a/src/pocketmine/item/Bow.php +++ b/src/pocketmine/item/Bow.php @@ -51,6 +51,7 @@ class Bow extends Tool{ public function onReleaseUsing(Player $player) : bool{ if($player->isSurvival() and !$player->getInventory()->contains(ItemFactory::get(Item::ARROW, 0, 1))){ $player->getInventory()->sendContents($player); + return false; } $nbt = new CompoundTag("", [ diff --git a/src/pocketmine/item/Bucket.php b/src/pocketmine/item/Bucket.php index 86c470453..b906575de 100644 --- a/src/pocketmine/item/Bucket.php +++ b/src/pocketmine/item/Bucket.php @@ -37,7 +37,7 @@ class Bucket extends Item{ parent::__construct(self::BUCKET, $meta, "Bucket"); } - public function getMaxStackSize(){ + public function getMaxStackSize() : int{ return 1; } diff --git a/src/pocketmine/item/Cake.php b/src/pocketmine/item/Cake.php index 4ac6544c1..a8ccc8120 100644 --- a/src/pocketmine/item/Cake.php +++ b/src/pocketmine/item/Cake.php @@ -32,7 +32,7 @@ class Cake extends Item{ parent::__construct(self::CAKE, $meta, "Cake"); } - public function getMaxStackSize(){ + public function getMaxStackSize() : int{ return 1; } } \ No newline at end of file diff --git a/src/pocketmine/item/IronDoor.php b/src/pocketmine/item/IronDoor.php index 8fbce996b..518f14c20 100644 --- a/src/pocketmine/item/IronDoor.php +++ b/src/pocketmine/item/IronDoor.php @@ -32,7 +32,7 @@ class IronDoor extends Item{ parent::__construct(self::IRON_DOOR, $meta, "Iron Door"); } - public function getMaxStackSize(){ + public function getMaxStackSize() : int{ return 1; } } \ No newline at end of file diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index 9f4676fa5..1319721a3 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -738,7 +738,7 @@ class Item implements ItemIds, \JsonSerializable{ * Returns the highest amount of this item which will fit into one inventory slot. * @return int */ - public function getMaxStackSize(){ + public function getMaxStackSize() : int{ return 64; } diff --git a/src/pocketmine/item/MushroomStew.php b/src/pocketmine/item/MushroomStew.php index 8a2db5d08..a3776393d 100644 --- a/src/pocketmine/item/MushroomStew.php +++ b/src/pocketmine/item/MushroomStew.php @@ -28,7 +28,7 @@ class MushroomStew extends Food{ parent::__construct(self::MUSHROOM_STEW, $meta, "Mushroom Stew"); } - public function getMaxStackSize(){ + public function getMaxStackSize() : int{ return 1; } diff --git a/src/pocketmine/item/Sign.php b/src/pocketmine/item/Sign.php index 834be4e9a..b8a6e5c77 100644 --- a/src/pocketmine/item/Sign.php +++ b/src/pocketmine/item/Sign.php @@ -32,7 +32,7 @@ class Sign extends Item{ parent::__construct(self::SIGN, $meta, "Sign"); } - public function getMaxStackSize(){ + public function getMaxStackSize() : int{ return 16; } } \ No newline at end of file diff --git a/src/pocketmine/item/Snowball.php b/src/pocketmine/item/Snowball.php index 4a378d947..cd5abcbe4 100644 --- a/src/pocketmine/item/Snowball.php +++ b/src/pocketmine/item/Snowball.php @@ -29,7 +29,7 @@ class Snowball extends Item{ parent::__construct(self::SNOWBALL, $meta, "Snowball"); } - public function getMaxStackSize(){ + public function getMaxStackSize() : int{ return 16; } diff --git a/src/pocketmine/item/Tool.php b/src/pocketmine/item/Tool.php index b2b612f30..fe6376f1d 100644 --- a/src/pocketmine/item/Tool.php +++ b/src/pocketmine/item/Tool.php @@ -40,7 +40,7 @@ abstract class Tool extends Item{ const TYPE_AXE = 4; const TYPE_SHEARS = 5; - public function getMaxStackSize(){ + public function getMaxStackSize() : int{ return 1; } diff --git a/src/pocketmine/item/WoodenDoor.php b/src/pocketmine/item/WoodenDoor.php index 3ea688ad3..4402967ab 100644 --- a/src/pocketmine/item/WoodenDoor.php +++ b/src/pocketmine/item/WoodenDoor.php @@ -32,7 +32,7 @@ class WoodenDoor extends Item{ parent::__construct(self::WOODEN_DOOR, $meta, "Wooden Door"); } - public function getMaxStackSize(){ + public function getMaxStackSize() : int{ return 1; } } \ No newline at end of file diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index fdac6aa92..2a411ede3 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -407,49 +407,31 @@ class Level implements ChunkManager, Metadatable{ public function addSound(Sound $sound, array $players = null){ $pk = $sound->encode(); + if(!is_array($pk)){ + $pk = [$pk]; + } if($players === null){ - if($pk !== null){ - if(!is_array($pk)){ - $this->addChunkPacket($sound->x >> 4, $sound->z >> 4, $pk); - }else{ - foreach($pk as $e){ - $this->addChunkPacket($sound->x >> 4, $sound->z >> 4, $e); - } - } + foreach($pk as $e){ + $this->addChunkPacket($sound->x >> 4, $sound->z >> 4, $e); } }else{ - if($pk !== null){ - if(!is_array($pk)){ - $this->server->broadcastPacket($players, $pk); - }else{ - $this->server->batchPackets($players, $pk, false); - } - } + $this->server->batchPackets($players, $pk, false); } } public function addParticle(Particle $particle, array $players = null){ $pk = $particle->encode(); + if(!is_array($pk)){ + $pk = [$pk]; + } if($players === null){ - if($pk !== null){ - if(!is_array($pk)){ - $this->addChunkPacket($particle->x >> 4, $particle->z >> 4, $pk); - }else{ - foreach($pk as $e){ - $this->addChunkPacket($particle->x >> 4, $particle->z >> 4, $e); - } - } + foreach($pk as $e){ + $this->addChunkPacket($particle->x >> 4, $particle->z >> 4, $e); } }else{ - if($pk !== null){ - if(!is_array($pk)){ - $this->server->broadcastPacket($players, $pk); - }else{ - $this->server->batchPackets($players, $pk, false); - } - } + $this->server->batchPackets($players, $pk, false); } } @@ -1637,10 +1619,8 @@ class Level implements ChunkManager, Metadatable{ } $above = $this->getBlock(new Vector3($target->x, $target->y + 1, $target->z)); - if($above !== null){ - if($above->getId() === Item::FIRE){ - $this->setBlock($above, BlockFactory::get(Block::AIR), true); - } + if($above->getId() === Item::FIRE){ + $this->setBlock($above, BlockFactory::get(Block::AIR), true); } if($createParticles){ diff --git a/src/pocketmine/permission/BanList.php b/src/pocketmine/permission/BanList.php index bbbc45134..ab0a12a27 100644 --- a/src/pocketmine/permission/BanList.php +++ b/src/pocketmine/permission/BanList.php @@ -101,9 +101,9 @@ class BanList{ */ public function addBan(string $target, string $reason = null, \DateTime $expires = null, string $source = null) : BanEntry{ $entry = new BanEntry($target); - $entry->setSource($source != null ? $source : $entry->getSource()); + $entry->setSource($source ?? $entry->getSource()); $entry->setExpires($expires); - $entry->setReason($reason != null ? $reason : $entry->getReason()); + $entry->setReason($reason ?? $entry->getReason()); $this->list[$entry->getName()] = $entry; $this->save(); diff --git a/src/pocketmine/tile/Spawnable.php b/src/pocketmine/tile/Spawnable.php index f77e81d71..6a49b642b 100644 --- a/src/pocketmine/tile/Spawnable.php +++ b/src/pocketmine/tile/Spawnable.php @@ -31,11 +31,7 @@ use pocketmine\Player; abstract class Spawnable extends Tile{ - public function spawnTo(Player $player){ - if($this->closed){ - return false; - } - + public function createSpawnPacket() : BlockEntityDataPacket{ $nbt = new NBT(NBT::LITTLE_ENDIAN); $nbt->setData($this->getSpawnCompound()); $pk = new BlockEntityDataPacket(); @@ -43,7 +39,16 @@ abstract class Spawnable extends Tile{ $pk->y = $this->y; $pk->z = $this->z; $pk->namedtag = $nbt->write(true); - $player->dataPacket($pk); + + return $pk; + } + + public function spawnTo(Player $player){ + if($this->closed){ + return false; + } + + $player->dataPacket($this->createSpawnPacket()); return true; } @@ -58,11 +63,8 @@ abstract class Spawnable extends Tile{ return; } - foreach($this->getLevel()->getChunkPlayers($this->chunk->getX(), $this->chunk->getZ()) as $player){ - if($player->spawned === true){ - $this->spawnTo($player); - } - } + $pk = $this->createSpawnPacket(); + $this->level->addChunkPacket($this->chunk->getX(), $this->chunk->getZ(), $pk); } protected function onChanged(){