From 4f4a6e7446df08be7f77735fd77a2d28821002f4 Mon Sep 17 00:00:00 2001 From: Falkirks Date: Fri, 24 Oct 2014 17:11:59 -0700 Subject: [PATCH 01/61] Fixes get and set armour --- src/pocketmine/inventory/PlayerInventory.php | 32 ++++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/pocketmine/inventory/PlayerInventory.php b/src/pocketmine/inventory/PlayerInventory.php index ec1ee6be7..8c5cd325e 100644 --- a/src/pocketmine/inventory/PlayerInventory.php +++ b/src/pocketmine/inventory/PlayerInventory.php @@ -166,35 +166,35 @@ class PlayerInventory extends BaseInventory{ } public function getHelmet(){ - return $this->getItem($this->getSize() + 3); - } - - public function getChestplate(){ - return $this->getItem($this->getSize() + 2); - } - - public function getLeggings(){ - return $this->getItem($this->getSize() + 1); - } - - public function getBoots(){ return $this->getItem($this->getSize()); } + public function getChestplate(){ + return $this->getItem($this->getSize() + 1); + } + + public function getLeggings(){ + return $this->getItem($this->getSize() + 2); + } + + public function getBoots(){ + return $this->getItem($this->getSize() + 3); + } + public function setHelmet(Item $helmet){ - return $this->setItem($this->getSize() + 3, $helmet); + return $this->setItem($this->getSize(), $helmet); } public function setChestplate(Item $chestplate){ - return $this->setItem($this->getSize() + 2, $chestplate); + return $this->setItem($this->getSize() + 1, $chestplate); } public function setLeggings(Item $leggings){ - return $this->setItem($this->getSize() + 1, $leggings); + return $this->setItem($this->getSize() + 2, $leggings); } public function setBoots(Item $boots){ - return $this->setItem($this->getSize(), $boots); + return $this->setItem($this->getSize() + 3, $boots); } public function setItem($index, Item $item, $source = null){ From 8e7077ff4bbb8452291ecb468ad2d1d3dab8ee3e Mon Sep 17 00:00:00 2001 From: PEMapModder Date: Sat, 25 Oct 2014 12:26:57 +0800 Subject: [PATCH 02/61] Update FallingBlock to new Anvil formats, possible fix for #2189 I don't have time to test yet, so I am not sure if it does fix it. --- src/pocketmine/block/Fallable.php | 4 +++- src/pocketmine/entity/FallingBlock.php | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/pocketmine/block/Fallable.php b/src/pocketmine/block/Fallable.php index fdf5126ff..8faf46acf 100644 --- a/src/pocketmine/block/Fallable.php +++ b/src/pocketmine/block/Fallable.php @@ -29,6 +29,7 @@ use pocketmine\nbt\tag\Compound; use pocketmine\nbt\tag\Double; use pocketmine\nbt\tag\Enum; use pocketmine\nbt\tag\Float; +use pocketmine\nbt\tag\Int; use pocketmine\Player; abstract class Fallable extends Solid{ @@ -60,7 +61,8 @@ abstract class Fallable extends Solid{ new Float("", 0), new Float("", 0) ]), - "Tile" => new Byte("Tile", $this->getID()) + "TileID" => new Int("TileID", $this->getID()), + "Data" => new Byte("Data", $this->getDamage()), ])); $fall->spawnToAll(); diff --git a/src/pocketmine/entity/FallingBlock.php b/src/pocketmine/entity/FallingBlock.php index ac83fe800..d28955294 100644 --- a/src/pocketmine/entity/FallingBlock.php +++ b/src/pocketmine/entity/FallingBlock.php @@ -28,6 +28,7 @@ use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityRegainHealthEvent; use pocketmine\item\Item; use pocketmine\nbt\tag\Byte; +use pocketmine\nbt\tag\Int; use pocketmine\nbt\tag\String; use pocketmine\network\protocol\AddEntityPacket; use pocketmine\network\protocol\SetEntityMotionPacket; @@ -44,13 +45,18 @@ class FallingBlock extends Entity{ protected $gravity = 0.04; protected $drag = 0.02; protected $blockId = 0; + protected $damage; public $canCollide = false; protected function initEntity(){ $this->namedtag->id = new String("id", "FallingSand"); - if(isset($this->namedtag->Tile)){ + if(isset($this->namedtag->TileID)){ + $this->blockId = $this->namedtag["TileID"]; + } + elseif(isset($this->namedtag->Tile)){ $this->blockId = $this->namedtag["Tile"]; + $this->namedtag["TileID"] = $this->blockId; } if($this->blockId === 0){ @@ -106,9 +112,9 @@ class FallingBlock extends Entity{ $this->kill(); $block = $this->level->getBlock($pos); if(!$block->isFullBlock){ - $this->getLevel()->dropItem($this, Item::get($this->getBlock(), 0, 1)); + $this->getLevel()->dropItem($this, Item::get($this->getBlock(), $this->getDamage(), 1)); }else{ - $this->server->getPluginManager()->callEvent($ev = new EntityBlockChangeEvent($this, $block, Block::get($this->getBlock(), 0))); + $this->server->getPluginManager()->callEvent($ev = new EntityBlockChangeEvent($this, $block, Block::get($this->getBlock(), $this->getDamage()))); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($pos, $ev->getTo(), true); } @@ -125,9 +131,13 @@ class FallingBlock extends Entity{ public function getBlock(){ return $this->blockId; } + public function getDamage(){ + return $this->damage; + } public function saveNBT(){ - $this->namedtag->Tile = new Byte("Tile", $this->blockId); + $this->namedtag->TileID = new Int("TileID", $this->blockId); + $this->namedtag->Data = new Byte("Data", $this->damage); } public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){ From ee4f416d93b842934a56b77e9317bc58b565a17e Mon Sep 17 00:00:00 2001 From: PEMapModder Date: Sat, 25 Oct 2014 18:15:47 +0800 Subject: [PATCH 03/61] Fix FallingBlock.php --- src/pocketmine/entity/FallingBlock.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/entity/FallingBlock.php b/src/pocketmine/entity/FallingBlock.php index d28955294..43fea4900 100644 --- a/src/pocketmine/entity/FallingBlock.php +++ b/src/pocketmine/entity/FallingBlock.php @@ -56,7 +56,7 @@ class FallingBlock extends Entity{ } elseif(isset($this->namedtag->Tile)){ $this->blockId = $this->namedtag["Tile"]; - $this->namedtag["TileID"] = $this->blockId; + $this->namedtag["TileID"] = new Int("TileID", $this->blockId); } if($this->blockId === 0){ @@ -166,4 +166,4 @@ class FallingBlock extends Entity{ parent::spawnTo($player); } -} \ No newline at end of file +} From df81b365e56ecf5ea7b598bd1c8d777876d15c10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=82=A4=EB=A6=AC=ED=86=A0?= Date: Sun, 26 Oct 2014 22:21:21 +0900 Subject: [PATCH 04/61] Update BaseInventory.php --- src/pocketmine/inventory/BaseInventory.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index e9e6dd7e3..6353e2ca3 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -126,6 +126,7 @@ abstract class BaseInventory implements Inventory{ return false; }elseif($item->getID() === 0 or $item->getCount() <= 0){ $this->clear($index, $source); + return true; } $holder = $this->getHolder(); @@ -426,4 +427,4 @@ abstract class BaseInventory implements Inventory{ return $this->type; } -} \ No newline at end of file +} From 7abf52e6158049e075b02403e3debf4592fedad2 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 27 Oct 2014 15:39:20 +0100 Subject: [PATCH 05/61] Implemented Vector3 List and AxisAlignedBB Pool to decrease object allocation --- src/pocketmine/Player.php | 11 ++- src/pocketmine/Server.php | 11 +++ src/pocketmine/block/Bed.php | 6 +- src/pocketmine/block/Block.php | 8 +- src/pocketmine/block/Cactus.php | 7 +- src/pocketmine/block/Cake.php | 5 +- src/pocketmine/block/Carpet.php | 5 +- src/pocketmine/block/Chest.php | 5 +- src/pocketmine/block/Door.php | 31 ++++--- src/pocketmine/block/EndPortal.php | 5 +- src/pocketmine/block/Farmland.php | 5 +- src/pocketmine/block/Fence.php | 5 +- src/pocketmine/block/FenceGate.php | 7 +- src/pocketmine/block/Ladder.php | 11 +-- src/pocketmine/block/Liquid.php | 8 +- src/pocketmine/block/Slab.php | 7 +- src/pocketmine/block/SoulSand.php | 5 +- src/pocketmine/block/Stair.php | 17 ++-- src/pocketmine/block/StoneWall.php | 5 +- src/pocketmine/block/Sugarcane.php | 4 +- src/pocketmine/block/Thin.php | 5 +- src/pocketmine/block/Trapdoor.php | 17 ++-- src/pocketmine/block/Vine.php | 5 +- src/pocketmine/block/WoodSlab.php | 7 +- .../command/defaults/TeleportCommand.php | 2 +- src/pocketmine/entity/Arrow.php | 2 +- src/pocketmine/entity/DroppedItem.php | 2 +- src/pocketmine/entity/Entity.php | 49 +++++------ src/pocketmine/entity/FallingBlock.php | 7 +- src/pocketmine/entity/Living.php | 4 +- .../inventory/InventoryTransactionEvent.php | 3 + .../inventory/SimpleTransactionGroup.php | 3 +- src/pocketmine/level/Explosion.php | 26 +++--- src/pocketmine/level/Level.php | 46 ++++++----- src/pocketmine/level/MovingObjectPosition.php | 4 +- src/pocketmine/math/AxisAlignedBB.php | 58 +++++++++++-- src/pocketmine/math/Vector3.php | 82 +++++++++++++++---- src/pocketmine/tile/Chest.php | 2 +- src/pocketmine/utils/BlockIterator.php | 4 +- 39 files changed, 273 insertions(+), 223 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index b6e91472c..bb2ad190d 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1057,8 +1057,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ return; } - $oldPos = new Vector3($this->x, $this->y, $this->z); - $distanceSquared = $oldPos->distanceSquared($this->newPosition); + $distanceSquared = $this->newPosition->distanceSquared($this); $revert = false; @@ -1558,7 +1557,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } break; case ProtocolInfo::USE_ITEM_PACKET: - $blockVector = new Vector3($packet->x, $packet->y, $packet->z); + $blockVector = Vector3::createVector($packet->x, $packet->y, $packet->z); $this->craftingType = 0; @@ -1718,7 +1717,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } $this->craftingType = 0; - $vector = new Vector3($packet->x, $packet->y, $packet->z); + $vector = Vector3::createVector($packet->x, $packet->y, $packet->z); if($this->isCreative()){ @@ -2185,7 +2184,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } $this->craftingType = 0; - $t = $this->level->getTile($v = new Vector3($packet->x, $packet->y, $packet->z)); + $t = $this->level->getTile(Vector3::createVector($packet->x, $packet->y, $packet->z)); if($t instanceof Sign){ $nbt = new NBT(NBT::LITTLE_ENDIAN); $nbt->read($packet->namedtag); @@ -2193,7 +2192,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ if($nbt["id"] !== Tile::SIGN){ $t->spawnTo($this); }else{ - $ev = new SignChangeEvent($this->level->getBlock($v), $this, [ + $ev = new SignChangeEvent($t->getBlock(), $this, [ $nbt["Text1"], $nbt["Text2"], $nbt["Text3"], $nbt["Text4"] ]); diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index b4700540b..18b76853b 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -50,6 +50,8 @@ use pocketmine\level\generator\GenerationRequestManager; use pocketmine\level\generator\Generator; use pocketmine\level\generator\Normal; use pocketmine\level\Level; +use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Vector3; use pocketmine\metadata\EntityMetadataStore; use pocketmine\metadata\LevelMetadataStore; use pocketmine\metadata\PlayerMetadataStore; @@ -2111,6 +2113,15 @@ class Server{ $this->generationManager->process(); + + if(($this->tickCounter % 600) === 0){ + Vector3::clearVectors(); + AxisAlignedBB::clearBoundingBoxes(); + }else{ + Vector3::clearVectorList(); + AxisAlignedBB::clearBoundingBoxPool(); + } + Timings::$serverTickTimer->stopTiming(); TimingsHandler::tick(); diff --git a/src/pocketmine/block/Bed.php b/src/pocketmine/block/Bed.php index fccd98fcc..e012b867f 100644 --- a/src/pocketmine/block/Bed.php +++ b/src/pocketmine/block/Bed.php @@ -36,11 +36,7 @@ class Bed extends Transparent{ } public function getBoundingBox(){ - if($this->boundingBox !== null){ - return $this->boundingBox; - } - - return $this->boundingBox = new AxisAlignedBB( + return AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z, diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index ea28c66e3..6374fa73a 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -512,7 +512,6 @@ class Block extends Position implements Metadatable{ protected $name = "Unknown"; protected $breakTime = 0.20; protected $hardness = 10; - protected $boundingBox = null; public $hasEntityCollision = false; public $isActivable = false; public $breakable = true; @@ -820,7 +819,6 @@ class Block extends Position implements Metadatable{ $this->y = (int) $v->y; $this->z = (int) $v->z; $this->level = $v->level; - $this->boundingBox = null; } /** @@ -899,11 +897,7 @@ class Block extends Position implements Metadatable{ * @return AxisAlignedBB */ public function getBoundingBox(){ - if($this->boundingBox !== null){ - return $this->boundingBox; - } - - return $this->boundingBox = new AxisAlignedBB( + return AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z, diff --git a/src/pocketmine/block/Cactus.php b/src/pocketmine/block/Cactus.php index e2eaa2d06..29110b7da 100644 --- a/src/pocketmine/block/Cactus.php +++ b/src/pocketmine/block/Cactus.php @@ -43,11 +43,8 @@ class Cactus extends Transparent{ } public function getBoundingBox(){ - if($this->boundingBox !== null){ - return $this->boundingBox; - } - return $this->boundingBox = new AxisAlignedBB( + return AxisAlignedBB::getBoundingBoxFromPool( $this->x + 0.0625, $this->y, $this->z + 0.0625, @@ -82,7 +79,7 @@ class Cactus extends Transparent{ if($this->getSide(0)->getID() !== self::CACTUS){ if($this->meta == 0x0F){ for($y = 1; $y < 3; ++$y){ - $b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z)); + $b = $this->getLevel()->getBlock(Vector3::createVector($this->x, $this->y + $y, $this->z)); if($b->getID() === self::AIR){ Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, new Cactus())); if(!$ev->isCancelled()){ diff --git a/src/pocketmine/block/Cake.php b/src/pocketmine/block/Cake.php index 0f98dc373..7cff10727 100644 --- a/src/pocketmine/block/Cake.php +++ b/src/pocketmine/block/Cake.php @@ -38,13 +38,10 @@ class Cake extends Transparent{ } public function getBoundingBox(){ - if($this->boundingBox !== null){ - return $this->boundingBox; - } $f = (1 + $this->getDamage() * 2) / 16; - return $this->boundingBox = new AxisAlignedBB( + return AxisAlignedBB::getBoundingBoxFromPool( $this->x + $f, $this->y, $this->z + 0.0625, diff --git a/src/pocketmine/block/Carpet.php b/src/pocketmine/block/Carpet.php index 91269b9b0..d7b315072 100644 --- a/src/pocketmine/block/Carpet.php +++ b/src/pocketmine/block/Carpet.php @@ -54,11 +54,8 @@ class Carpet extends Flowable{ } public function getBoundingBox(){ - if($this->boundingBox !== null){ - return $this->boundingBox; - } - return $this->boundingBox = new AxisAlignedBB( + return AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z, diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index ad24a0316..9242b4a99 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -43,11 +43,8 @@ class Chest extends Transparent{ } public function getBoundingBox(){ - if($this->boundingBox !== null){ - return $this->boundingBox; - } - return $this->boundingBox = new AxisAlignedBB( + return AxisAlignedBB::getBoundingBoxFromPool( $this->x + 0.0625, $this->y, $this->z + 0.0625, diff --git a/src/pocketmine/block/Door.php b/src/pocketmine/block/Door.php index a28598740..04506d99b 100644 --- a/src/pocketmine/block/Door.php +++ b/src/pocketmine/block/Door.php @@ -53,14 +53,11 @@ abstract class Door extends Transparent{ } public function getBoundingBox(){ - if($this->boundingBox !== null){ - return $this->boundingBox; - } $f = 0.1875; $damage = $this->getFullDamage(); - $bb = new AxisAlignedBB( + $bb = AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z, @@ -76,7 +73,7 @@ abstract class Door extends Transparent{ if($j === 0){ if($flag){ if(!$flag1){ - $bb = new AxisAlignedBB( + $bb = AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z, @@ -85,7 +82,7 @@ abstract class Door extends Transparent{ $this->z + $f ); }else{ - $bb = new AxisAlignedBB( + $bb = AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z + 1 - $f, @@ -95,7 +92,7 @@ abstract class Door extends Transparent{ ); } }else{ - $bb = new AxisAlignedBB( + $bb = AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z, @@ -107,7 +104,7 @@ abstract class Door extends Transparent{ }elseif($j === 1){ if($flag){ if(!$flag1){ - $bb = new AxisAlignedBB( + $bb = AxisAlignedBB::getBoundingBoxFromPool( $this->x + 1 - $f, $this->y, $this->z, @@ -116,7 +113,7 @@ abstract class Door extends Transparent{ $this->z + 1 ); }else{ - $bb = new AxisAlignedBB( + $bb = AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z, @@ -126,7 +123,7 @@ abstract class Door extends Transparent{ ); } }else{ - $bb = new AxisAlignedBB( + $bb = AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z, @@ -138,7 +135,7 @@ abstract class Door extends Transparent{ }elseif($j === 2){ if($flag){ if(!$flag1){ - $bb = new AxisAlignedBB( + $bb = AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z + 1 - $f, @@ -147,7 +144,7 @@ abstract class Door extends Transparent{ $this->z + 1 ); }else{ - $bb = new AxisAlignedBB( + $bb = AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z, @@ -157,7 +154,7 @@ abstract class Door extends Transparent{ ); } }else{ - $bb = new AxisAlignedBB( + $bb = AxisAlignedBB::getBoundingBoxFromPool( $this->x + 1 - $f, $this->y, $this->z, @@ -169,7 +166,7 @@ abstract class Door extends Transparent{ }elseif($j === 3){ if($flag){ if(!$flag1){ - $bb = new AxisAlignedBB( + $bb = AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z, @@ -178,7 +175,7 @@ abstract class Door extends Transparent{ $this->z + 1 ); }else{ - $bb = new AxisAlignedBB( + $bb = AxisAlignedBB::getBoundingBoxFromPool( $this->x + 1 - $f, $this->y, $this->z, @@ -188,7 +185,7 @@ abstract class Door extends Transparent{ ); } }else{ - $bb = new AxisAlignedBB( + $bb = AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z + 1 - $f, @@ -199,7 +196,7 @@ abstract class Door extends Transparent{ } } - return $this->boundingBox = $bb; + return $bb; } public function onUpdate($type){ diff --git a/src/pocketmine/block/EndPortal.php b/src/pocketmine/block/EndPortal.php index 46eaefeb6..af4ef3132 100644 --- a/src/pocketmine/block/EndPortal.php +++ b/src/pocketmine/block/EndPortal.php @@ -30,11 +30,8 @@ class EndPortal extends Solid{ } public function getBoundingBox(){ - if($this->boundingBox !== null){ - return $this->boundingBox; - } - return $this->boundingBox = new AxisAlignedBB( + return AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z, diff --git a/src/pocketmine/block/Farmland.php b/src/pocketmine/block/Farmland.php index ec170171a..004f7f8f8 100644 --- a/src/pocketmine/block/Farmland.php +++ b/src/pocketmine/block/Farmland.php @@ -31,11 +31,8 @@ class Farmland extends Solid{ } public function getBoundingBox(){ - if($this->boundingBox !== null){ - return $this->boundingBox; - } - return $this->boundingBox = new AxisAlignedBB( + return AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z, diff --git a/src/pocketmine/block/Fence.php b/src/pocketmine/block/Fence.php index 5ff6694b0..35bd7c246 100644 --- a/src/pocketmine/block/Fence.php +++ b/src/pocketmine/block/Fence.php @@ -32,9 +32,6 @@ class Fence extends Transparent{ } public function getBoundingBox(){ - if($this->boundingBox !== null){ - return $this->boundingBox; - } $flag = $this->canConnect($this->getSide(2)); $flag1 = $this->canConnect($this->getSide(3)); @@ -46,7 +43,7 @@ class Fence extends Transparent{ $f2 = $flag ? 0 : 0.375; $f3 = $flag1 ? 1 : 0.625; - return $this->boundingBox = new AxisAlignedBB( + return AxisAlignedBB::getBoundingBoxFromPool( $this->x + $f, $this->y, $this->z + $f2, diff --git a/src/pocketmine/block/FenceGate.php b/src/pocketmine/block/FenceGate.php index 2d8f6a235..9195347aa 100644 --- a/src/pocketmine/block/FenceGate.php +++ b/src/pocketmine/block/FenceGate.php @@ -39,9 +39,6 @@ class FenceGate extends Transparent{ public function getBoundingBox(){ - if($this->boundingBox !== null){ - return $this->boundingBox; - } if(($this->getDamage() & 0x04) > 0){ return null; @@ -49,7 +46,7 @@ class FenceGate extends Transparent{ $i = ($this->getDamage() & 0x03); if($i === 2 and $i === 0){ - return $this->boundingBox = new AxisAlignedBB( + return AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z + 0.375, @@ -58,7 +55,7 @@ class FenceGate extends Transparent{ $this->z + 0.625 ); }else{ - return $this->boundingBox = new AxisAlignedBB( + return AxisAlignedBB::getBoundingBoxFromPool( $this->x + 0.375, $this->y, $this->z, diff --git a/src/pocketmine/block/Ladder.php b/src/pocketmine/block/Ladder.php index 3ce78534e..10b7c4fb8 100644 --- a/src/pocketmine/block/Ladder.php +++ b/src/pocketmine/block/Ladder.php @@ -44,14 +44,11 @@ class Ladder extends Transparent{ } public function getBoundingBox(){ - if($this->boundingBox !== null){ - return $this->boundingBox; - } $f = 0.125; if($this->meta === 2){ - return $this->boundingBox = new AxisAlignedBB( + return AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z + 1 - $f, @@ -60,7 +57,7 @@ class Ladder extends Transparent{ $this->z + 1 ); }elseif($this->meta === 3){ - return $this->boundingBox = new AxisAlignedBB( + return AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z, @@ -69,7 +66,7 @@ class Ladder extends Transparent{ $this->z + $f ); }elseif($this->meta === 4){ - return $this->boundingBox = new AxisAlignedBB( + return AxisAlignedBB::getBoundingBoxFromPool( $this->x + 1 - $f, $this->y, $this->z, @@ -78,7 +75,7 @@ class Ladder extends Transparent{ $this->z + 1 ); }elseif($this->meta === 5){ - return $this->boundingBox = new AxisAlignedBB( + return AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z, diff --git a/src/pocketmine/block/Liquid.php b/src/pocketmine/block/Liquid.php index 96c173939..20862628f 100644 --- a/src/pocketmine/block/Liquid.php +++ b/src/pocketmine/block/Liquid.php @@ -80,7 +80,7 @@ abstract class Liquid extends Transparent{ } public function getFlowVector(){ - $vector = new Vector3(0, 0, 0); + $vector = Vector3::createVector(0, 0, 0); $decay = $this->getEffectiveFlowDecay($this); @@ -99,7 +99,7 @@ abstract class Liquid extends Transparent{ }elseif($j === 3){ ++$z; } - $sideBlock = $this->getLevel()->getBlock(new Vector3($x, $y, $z)); + $sideBlock = $this->getLevel()->getBlock(Vector3::createVector($x, $y, $z)); $blockDecay = $this->getEffectiveFlowDecay($sideBlock); if($blockDecay < 0){ @@ -314,7 +314,7 @@ abstract class Liquid extends Transparent{ }elseif($j === 3){ ++$z; } - $blockSide = $this->getLevel()->getBlock(new Vector3($x, $y, $z)); + $blockSide = $this->getLevel()->getBlock(Vector3::createVector($x, $y, $z)); if(!$blockSide->isFlowable and !($blockSide instanceof Liquid)){ continue; @@ -356,7 +356,7 @@ abstract class Liquid extends Transparent{ }elseif($j === 3){ ++$z; } - $block = $this->getLevel()->getBlock(new Vector3($x, $y, $z)); + $block = $this->getLevel()->getBlock(Vector3::createVector($x, $y, $z)); if(!$block->isFlowable and !($block instanceof Liquid)){ continue; diff --git a/src/pocketmine/block/Slab.php b/src/pocketmine/block/Slab.php index 241f62d80..35bdcc09a 100644 --- a/src/pocketmine/block/Slab.php +++ b/src/pocketmine/block/Slab.php @@ -48,12 +48,9 @@ class Slab extends Transparent{ } public function getBoundingBox(){ - if($this->boundingBox !== null){ - return $this->boundingBox; - } if(($this->meta & 0x08) > 0){ - return $this->boundingBox = new AxisAlignedBB( + return AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y + 0.5, $this->z, @@ -62,7 +59,7 @@ class Slab extends Transparent{ $this->z + 1 ); }else{ - return $this->boundingBox = new AxisAlignedBB( + return AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z, diff --git a/src/pocketmine/block/SoulSand.php b/src/pocketmine/block/SoulSand.php index cde302304..3276c7613 100644 --- a/src/pocketmine/block/SoulSand.php +++ b/src/pocketmine/block/SoulSand.php @@ -31,11 +31,8 @@ class SoulSand extends Solid{ } public function getBoundingBox(){ - if($this->boundingBox !== null){ - return $this->boundingBox; - } - return $this->boundingBox = new AxisAlignedBB( + return AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z, diff --git a/src/pocketmine/block/Stair.php b/src/pocketmine/block/Stair.php index 74afea529..c88f5bafd 100644 --- a/src/pocketmine/block/Stair.php +++ b/src/pocketmine/block/Stair.php @@ -54,7 +54,7 @@ abstract class Stair extends Transparent{ $f3 = 0.5; } - if($bb->intersectsWith($bb2 = new AxisAlignedBB( + if($bb->intersectsWith($bb2 = AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y + $f, $this->z, @@ -66,7 +66,7 @@ abstract class Stair extends Transparent{ } if($j === 0){ - if($bb->intersectsWith($bb2 = new AxisAlignedBB( + if($bb->intersectsWith($bb2 = AxisAlignedBB::getBoundingBoxFromPool( $this->x + 0.5, $this->y + $f2, $this->z, @@ -77,7 +77,7 @@ abstract class Stair extends Transparent{ $list[] = $bb2; } }elseif($j === 1){ - if($bb->intersectsWith($bb2 = new AxisAlignedBB( + if($bb->intersectsWith($bb2 = AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y + $f2, $this->z, @@ -88,7 +88,7 @@ abstract class Stair extends Transparent{ $list[] = $bb2; } }elseif($j === 2){ - if($bb->intersectsWith($bb2 = new AxisAlignedBB( + if($bb->intersectsWith($bb2 = AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y + $f2, $this->z + 0.5, @@ -99,7 +99,7 @@ abstract class Stair extends Transparent{ $list[] = $bb2; } }elseif($j === 3){ - if($bb->intersectsWith($bb2 = new AxisAlignedBB( + if($bb->intersectsWith($bb2 = AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y + $f2, $this->z, @@ -114,12 +114,9 @@ abstract class Stair extends Transparent{ */ public function getBoundingBox(){ - if($this->boundingBox !== null){ - return $this->boundingBox; - } if(($this->getDamage() & 0x04) > 0){ - return $this->boundingBox = new AxisAlignedBB( + return AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y + 0.5, $this->z, @@ -128,7 +125,7 @@ abstract class Stair extends Transparent{ $this->z + 1 ); }else{ - return $this->boundingBox = new AxisAlignedBB( + return AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z, diff --git a/src/pocketmine/block/StoneWall.php b/src/pocketmine/block/StoneWall.php index 8abf9688a..a665e2bb8 100644 --- a/src/pocketmine/block/StoneWall.php +++ b/src/pocketmine/block/StoneWall.php @@ -37,9 +37,6 @@ class StoneWall extends Transparent{ } public function getBoundingBox(){ - if($this->boundingBox !== null){ - return $this->boundingBox; - } $flag = $this->canConnect($this->getSide(2)); $flag1 = $this->canConnect($this->getSide(3)); @@ -62,7 +59,7 @@ class StoneWall extends Transparent{ $f3 = 0.6875; } - return $this->boundingBox = new AxisAlignedBB( + return AxisAlignedBB::getBoundingBoxFromPool( $this->x + $f, $this->y, $this->z + $f2, diff --git a/src/pocketmine/block/Sugarcane.php b/src/pocketmine/block/Sugarcane.php index 262604a48..bf6cba252 100644 --- a/src/pocketmine/block/Sugarcane.php +++ b/src/pocketmine/block/Sugarcane.php @@ -49,7 +49,7 @@ class Sugarcane extends Flowable{ if($item->getID() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal if($this->getSide(0)->getID() !== self::SUGARCANE_BLOCK){ for($y = 1; $y < 3; ++$y){ - $b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z)); + $b = $this->getLevel()->getBlock(Vector3::createVector($this->x, $this->y + $y, $this->z)); if($b->getID() === self::AIR){ Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, new Sugarcane())); if(!$ev->isCancelled()){ @@ -83,7 +83,7 @@ class Sugarcane extends Flowable{ if($this->getSide(0)->getID() !== self::SUGARCANE_BLOCK){ if($this->meta === 0x0F){ for($y = 1; $y < 3; ++$y){ - $b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z)); + $b = $this->getLevel()->getBlock(Vector3::createVector($this->x, $this->y + $y, $this->z)); if($b->getID() === self::AIR){ $this->getLevel()->setBlock($b, new Sugarcane(), true); break; diff --git a/src/pocketmine/block/Thin.php b/src/pocketmine/block/Thin.php index dd621ec7a..59a0f6b50 100644 --- a/src/pocketmine/block/Thin.php +++ b/src/pocketmine/block/Thin.php @@ -30,9 +30,6 @@ abstract class Thin extends Transparent{ public $isSolid = false; public function getBoundingBox(){ - if($this->boundingBox !== null){ - return $this->boundingBox; - } $f = 0.4375; $f1 = 0.5625; @@ -66,7 +63,7 @@ abstract class Thin extends Transparent{ $f3 = 1; } - return $this->boundingBox = new AxisAlignedBB( + return AxisAlignedBB::getBoundingBoxFromPool( $this->x + $f, $this->y, $this->z + $f2, diff --git a/src/pocketmine/block/Trapdoor.php b/src/pocketmine/block/Trapdoor.php index d6093df8c..cceb46d11 100644 --- a/src/pocketmine/block/Trapdoor.php +++ b/src/pocketmine/block/Trapdoor.php @@ -38,9 +38,6 @@ class Trapdoor extends Transparent{ } public function getBoundingBox(){ - if($this->boundingBox !== null){ - return $this->boundingBox; - } $damage = $this->getDamage(); @@ -49,7 +46,7 @@ class Trapdoor extends Transparent{ $bb = null; if(($damage & 0x08) > 0){ - $bb = new AxisAlignedBB( + $bb = AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y + 1 - $f, $this->z, @@ -58,7 +55,7 @@ class Trapdoor extends Transparent{ $this->z + 1 ); }else{ - $bb = new AxisAlignedBB( + $bb = AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z, @@ -70,7 +67,7 @@ class Trapdoor extends Transparent{ if(($damage & 0x04) > 0){ if(($damage & 0x03) === 0){ - $bb = new AxisAlignedBB( + $bb = AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z + 1 - $f, @@ -79,7 +76,7 @@ class Trapdoor extends Transparent{ $this->z + 1 ); }elseif(($damage & 0x03) === 1){ - $bb = new AxisAlignedBB( + $bb = AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z, @@ -88,7 +85,7 @@ class Trapdoor extends Transparent{ $this->z + $f ); }if(($damage & 0x03) === 2){ - $bb = new AxisAlignedBB( + $bb = AxisAlignedBB::getBoundingBoxFromPool( $this->x + 1 - $f, $this->y, $this->z, @@ -97,7 +94,7 @@ class Trapdoor extends Transparent{ $this->z + 1 ); }if(($damage & 0x03) === 3){ - $bb = new AxisAlignedBB( + $bb = AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z, @@ -108,7 +105,7 @@ class Trapdoor extends Transparent{ } } - return $this->boundingBox = $bb; + return $bb; } public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ diff --git a/src/pocketmine/block/Vine.php b/src/pocketmine/block/Vine.php index f58196204..a1e63f3b0 100644 --- a/src/pocketmine/block/Vine.php +++ b/src/pocketmine/block/Vine.php @@ -44,9 +44,6 @@ class Vine extends Transparent{ } public function getBoundingBox(){ - if($this->boundingBox !== null){ - return $this->boundingBox; - } $f1 = 1; $f2 = 1; @@ -96,7 +93,7 @@ class Vine extends Transparent{ $f6 = 1; } - return $this->boundingBox = new AxisAlignedBB( + return AxisAlignedBB::getBoundingBoxFromPool( $this->x + $f1, $this->y + $f2, $this->z + $f3, diff --git a/src/pocketmine/block/WoodSlab.php b/src/pocketmine/block/WoodSlab.php index e3d38d964..804c3d68f 100644 --- a/src/pocketmine/block/WoodSlab.php +++ b/src/pocketmine/block/WoodSlab.php @@ -46,12 +46,9 @@ class WoodSlab extends Transparent{ } public function getBoundingBox(){ - if($this->boundingBox !== null){ - return $this->boundingBox; - } if(($this->meta & 0x08) > 0){ - return $this->boundingBox = new AxisAlignedBB( + return AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y + 0.5, $this->z, @@ -60,7 +57,7 @@ class WoodSlab extends Transparent{ $this->z + 1 ); }else{ - return $this->boundingBox = new AxisAlignedBB( + return AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z, diff --git a/src/pocketmine/command/defaults/TeleportCommand.php b/src/pocketmine/command/defaults/TeleportCommand.php index 797a2e177..fa6cf24e6 100644 --- a/src/pocketmine/command/defaults/TeleportCommand.php +++ b/src/pocketmine/command/defaults/TeleportCommand.php @@ -98,7 +98,7 @@ class TeleportCommand extends VanillaCommand{ $x = $this->getRelativeDouble($target->x, $sender, $args[$pos++]); $y = $this->getRelativeDouble($target->y, $sender, $args[$pos++], 0, 128); $z = $this->getRelativeDouble($target->z, $sender, $args[$pos]); - $target->teleport(new Vector3($x, $y, $z)); + $target->teleport(Vector3::createVector($x, $y, $z)); Command::broadcastCommandMessage($sender, "Teleported " . $target->getDisplayName() . " to " . round($x, 2) . ", " . round($y, 2) . ", " . round($z, 2)); return true; diff --git a/src/pocketmine/entity/Arrow.php b/src/pocketmine/entity/Arrow.php index 5a010f211..b24ad1116 100644 --- a/src/pocketmine/entity/Arrow.php +++ b/src/pocketmine/entity/Arrow.php @@ -87,7 +87,7 @@ class Arrow extends Projectile{ $this->keepMovement = $this->checkObstruction($this->x, ($this->boundingBox->minY + $this->boundingBox->maxY) / 2, $this->z); - $moveVector = new Vector3($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ); + $moveVector = Vector3::createVector($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ); $list = $this->getLevel()->getCollidingEntities($this->boundingBox->addCoord($this->motionX, $this->motionY, $this->motionZ)->expand(1, 1, 1), $this); diff --git a/src/pocketmine/entity/DroppedItem.php b/src/pocketmine/entity/DroppedItem.php index 79d5b5ae8..6d685134b 100644 --- a/src/pocketmine/entity/DroppedItem.php +++ b/src/pocketmine/entity/DroppedItem.php @@ -99,7 +99,7 @@ class DroppedItem extends Entity{ $friction = 1 - $this->drag; if($this->onGround and ($this->motionX != 0 or $this->motionZ != 0)){ - $friction = $this->getLevel()->getBlock(new Vector3($this->getFloorX(), $this->getFloorY() - 1, $this->getFloorZ()))->frictionFactor * $friction; + $friction = $this->getLevel()->getBlock(Vector3::createVector($this->getFloorX(), $this->getFloorY() - 1, $this->getFloorZ()))->frictionFactor * $friction; } $this->motionX *= $friction; diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 2ebce59fc..990142918 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -173,7 +173,7 @@ abstract class Entity extends Location implements Metadatable{ $this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0); $this->setPositionAndRotation( - new Vector3( + Vector3::createVector( $this->namedtag["Pos"][0], $this->namedtag["Pos"][1], $this->namedtag["Pos"][2] @@ -182,7 +182,7 @@ abstract class Entity extends Location implements Metadatable{ $this->namedtag->Rotation[1], true ); - $this->setMotion(new Vector3($this->namedtag["Motion"][0], $this->namedtag["Motion"][1], $this->namedtag["Motion"][2])); + $this->setMotion(Vector3::createVector($this->namedtag["Motion"][0], $this->namedtag["Motion"][1], $this->namedtag["Motion"][2])); if(!isset($this->namedtag->FallDistance)){ $this->namedtag->FallDistance = new Float("FallDistance", 0); @@ -387,15 +387,15 @@ abstract class Entity extends Location implements Metadatable{ $list = $this->level->getCollisionBlocks($this->boundingBox); - if(count($list) === 0 and !$this->level->isFullBlock(new Vector3($i, $j, $k))){ + if(count($list) === 0 and !$this->level->isFullBlock(Vector3::createVector($i, $j, $k))){ return false; }else{ - $flag = !$this->level->isFullBlock(new Vector3($i - 1, $j, $k)); - $flag1 = !$this->level->isFullBlock(new Vector3($i + 1, $j, $k)); - //$flag2 = !$this->level->isFullBlock(new Vector3($i, $j - 1, $k)); - $flag3 = !$this->level->isFullBlock(new Vector3($i, $j + 1, $k)); - $flag4 = !$this->level->isFullBlock(new Vector3($i, $j, $k - 1)); - $flag5 = !$this->level->isFullBlock(new Vector3($i, $j, $k + 1)); + $flag = !$this->level->isFullBlock(Vector3::createVector($i - 1, $j, $k)); + $flag1 = !$this->level->isFullBlock(Vector3::createVector($i + 1, $j, $k)); + //$flag2 = !$this->level->isFullBlock(Vector3::createVector($i, $j - 1, $k)); + $flag3 = !$this->level->isFullBlock(Vector3::createVector($i, $j + 1, $k)); + $flag4 = !$this->level->isFullBlock(Vector3::createVector($i, $j, $k - 1)); + $flag5 = !$this->level->isFullBlock(Vector3::createVector($i, $j, $k + 1)); $direction = 3; //UP! $limit = 9999; @@ -583,7 +583,7 @@ abstract class Entity extends Location implements Metadatable{ $x = -$xz * sin(deg2rad($this->yaw)); $z = $xz * cos(deg2rad($this->yaw)); - return new Vector3($x, $y, $z); + return Vector3::createVector($x, $y, $z); } public function onUpdate($currentTick){ @@ -745,7 +745,7 @@ abstract class Entity extends Location implements Metadatable{ } public function isInsideOfWater(){ - $block = $this->level->getBlock($pos = (new Vector3($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z))->floor()); + $block = $this->level->getBlock($pos = Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z)->floor()); if($block instanceof Water){ $f = ($pos->y + 1) - ($block->getFluidHeightPercent() - 0.1111111); @@ -756,7 +756,7 @@ abstract class Entity extends Location implements Metadatable{ } public function isInsideOfSolid(){ - $block = $this->level->getBlock($pos = (new Vector3($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z))->floor()); + $block = $this->level->getBlock($pos = Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z)->floor()); $bb = $block->getBoundingBox(); @@ -779,7 +779,7 @@ abstract class Entity extends Location implements Metadatable{ if($this->keepMovement){ $this->boundingBox->offset($dx, $dy, $dz); - $pos = new Vector3(($this->boundingBox->minX + $this->boundingBox->maxX) / 2, $this->boundingBox->minY - $this->ySize, ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2); + $pos = Vector3::createVector(($this->boundingBox->minX + $this->boundingBox->maxX) / 2, $this->boundingBox->minY - $this->ySize, ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2); $this->setPosition($pos); }else{ @@ -803,7 +803,7 @@ abstract class Entity extends Location implements Metadatable{ $movY = $dy; $movZ = $dz; - $axisalignedbb = clone $this->boundingBox; + $axisalignedbb = AxisAlignedBB::cloneBoundingBoxFromPool($this->boundingBox); /*$sneakFlag = $this->onGround and $this instanceof Player; @@ -881,7 +881,7 @@ abstract class Entity extends Location implements Metadatable{ $dy = $this->stepHeight; $dz = $movZ; - $axisalignedbb1 = clone $this->boundingBox; + $axisalignedbb1 = AxisAlignedBB::cloneBoundingBoxFromPool($this->boundingBox); $this->boundingBox->setBB($axisalignedbb); @@ -941,7 +941,7 @@ abstract class Entity extends Location implements Metadatable{ } - $pos = new Vector3( + $pos = Vector3::createVector( ($this->boundingBox->minX + $this->boundingBox->maxX) / 2, $this->boundingBox->minY - $this->ySize, ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2 @@ -956,7 +956,7 @@ abstract class Entity extends Location implements Metadatable{ if($this instanceof Player){ if(!$this->onGround or $movY != 0){ - $bb = clone $this->boundingBox; + $bb = AxisAlignedBB::cloneBoundingBoxFromPool($this->boundingBox); $bb->maxY = $bb->minY + 1; if(count($this->level->getCollisionBlocks($bb->expand(0.01, 0.01, 0.01))) > 0){ $this->onGround = true; @@ -998,12 +998,13 @@ abstract class Entity extends Location implements Metadatable{ $maxY = Math::floorFloat($this->boundingBox->maxY - 0.001); $maxZ = Math::floorFloat($this->boundingBox->maxZ - 0.001); - $vector = new Vector3(0, 0, 0); + $vector = Vector3::createVector(0, 0, 0); + $v = Vector3::createVector(0, 0, 0); - for($z = $minZ; $z <= $maxZ; ++$z){ - for($x = $minX; $x <= $maxX; ++$x){ - for($y = $minY; $y <= $maxY; ++$y){ - $block = $this->level->getBlock(new Vector3($x, $y, $z)); + for($v->z = $minZ; $v->z < $maxZ; ++$v->z){ + for($v->x = $minX; $v->x < $maxX; ++$v->x){ + for($v->y = $minY; $v->y < $maxY; ++$v->y){ + $block = $this->level->getBlock($v); if($block !== null and $block->hasEntityCollision){ $block->onEntityCollide($this); if(!($this instanceof Player)){ @@ -1082,7 +1083,7 @@ abstract class Entity extends Location implements Metadatable{ } public function getMotion(){ - return new Vector3($this->motionX, $this->motionY, $this->motionZ); + return Vector3::createVector($this->motionX, $this->motionY, $this->motionZ); } public function setMotion(Vector3 $motion){ @@ -1145,7 +1146,7 @@ abstract class Entity extends Location implements Metadatable{ $this->ySize = 0; $pos = $ev->getTo(); - $this->setMotion(new Vector3(0, 0, 0)); + $this->setMotion(Vector3::createVector(0, 0, 0)); if($this->setPositionAndRotation($pos, $yaw === null ? $this->yaw : $yaw, $pitch === null ? $this->pitch : $pitch, true) !== false){ $this->fallDistance = 0; $this->onGround = true; diff --git a/src/pocketmine/entity/FallingBlock.php b/src/pocketmine/entity/FallingBlock.php index ac83fe800..d8577ae7d 100644 --- a/src/pocketmine/entity/FallingBlock.php +++ b/src/pocketmine/entity/FallingBlock.php @@ -27,6 +27,7 @@ use pocketmine\event\entity\EntityBlockChangeEvent; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityRegainHealthEvent; use pocketmine\item\Item; +use pocketmine\math\Vector3; use pocketmine\nbt\tag\Byte; use pocketmine\nbt\tag\String; use pocketmine\network\protocol\AddEntityPacket; @@ -81,12 +82,12 @@ class FallingBlock extends Entity{ if(!$this->dead){ if($this->ticksLived === 1){ - $block = $this->level->getBlock($this->floor()); + $block = $this->level->getBlock($pos = Vector3::createVector($this->x, $this->y, $this->z)->floor()); if($block->getID() != $this->blockId){ $this->kill(); return true; } - $this->level->setBlock($this->floor(), Block::get(0), true); + $this->level->setBlock($pos, Block::get(0), true); } @@ -100,7 +101,7 @@ class FallingBlock extends Entity{ $this->motionY *= 1 - $this->drag; $this->motionZ *= $friction; - $pos = $this->floor(); + $pos = Vector3::createVector($this->x, $this->y, $this->z)->floor(); if($this->onGround){ $this->kill(); diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index 837a925a6..f201d736e 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -65,7 +65,7 @@ abstract class Living extends Entity implements Damageable{ public function hasLineOfSight(Entity $entity){ //TODO: head height return true; - //return $this->getLevel()->rayTraceBlocks(new Vector3($this->x, $this->y + $this->height, $this->z), new Vector3($entity->x, $entity->y + $entity->height, $entity->z)) === null; + //return $this->getLevel()->rayTraceBlocks(Vector3::createVector($this->x, $this->y + $this->height, $this->z), Vector3::createVector($entity->x, $entity->y + $entity->height, $entity->z)) === null; } public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){ @@ -99,7 +99,7 @@ abstract class Living extends Entity implements Damageable{ $f = sqrt($x ** 2 + $z ** 2); $base = 0.4; - $motion = new Vector3($this->motionX, $this->motionY, $this->motionZ); + $motion = Vector3::createVector($this->motionX, $this->motionY, $this->motionZ); $motion->x /= 2; $motion->y /= 2; diff --git a/src/pocketmine/event/inventory/InventoryTransactionEvent.php b/src/pocketmine/event/inventory/InventoryTransactionEvent.php index 15a68549d..53a4c4e5f 100644 --- a/src/pocketmine/event/inventory/InventoryTransactionEvent.php +++ b/src/pocketmine/event/inventory/InventoryTransactionEvent.php @@ -42,6 +42,9 @@ class InventoryTransactionEvent extends Event implements Cancellable{ $this->ts = $ts; } + /** + * @return TransactionGroup + */ public function getTransaction(){ return $this->ts; } diff --git a/src/pocketmine/inventory/SimpleTransactionGroup.php b/src/pocketmine/inventory/SimpleTransactionGroup.php index 06795daa0..9f37310a1 100644 --- a/src/pocketmine/inventory/SimpleTransactionGroup.php +++ b/src/pocketmine/inventory/SimpleTransactionGroup.php @@ -129,9 +129,8 @@ class SimpleTransactionGroup implements TransactionGroup{ public function canExecute(){ $haveItems = []; $needItems = []; - $this->matchItems($haveItems, $needItems); - return count($haveItems) === 0 and count($needItems) === 0 and count($this->transactions) > 0; + return $this->matchItems($haveItems, $needItems) and count($haveItems) === 0 and count($needItems) === 0 and count($this->transactions) > 0; } public function execute(){ diff --git a/src/pocketmine/level/Explosion.php b/src/pocketmine/level/Explosion.php index c22441dab..74a2f36cb 100644 --- a/src/pocketmine/level/Explosion.php +++ b/src/pocketmine/level/Explosion.php @@ -84,27 +84,31 @@ class Explosion{ return false; } + $pointer = Vector3::createVector(0, 0, 0); + $vector = Vector3::createVector(0, 0, 0); + $vBlock = Vector3::createVector(0, 0, 0); + $mRays = $this->rays - 1; for($i = 0; $i < $this->rays; ++$i){ for($j = 0; $j < $this->rays; ++$j){ //break 2 gets here for($k = 0; $k < $this->rays; ++$k){ if($i == 0 or $i == $mRays or $j == 0 or $j == $mRays or $k == 0 or $k == $mRays){ - $vector = new Vector3($i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1); //($i / $mRays) * 2 - 1 - $vector = $vector->normalize()->multiply($this->stepLen); - $pointer = clone $this->source; + $vector->setComponents($i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1); + $vector->setComponents(($vector->x / ($len = $vector->length())) * $this->stepLen, ($vector->y / $len) * $this->stepLen, ($vector->z / $len) * $this->stepLen); + $pointer->setComponents($this->source->x, $this->source->y, $this->source->z); for($blastForce = $this->size * (mt_rand(700, 1300) / 1000); $blastForce > 0; $blastForce -= $this->stepLen * 0.75){ - $vBlock = $pointer->floor(); + $x = (int) $pointer->x; + $y = (int) $pointer->y; + $z = (int) $pointer->z; + $vBlock->setComponents($pointer->x >= $x ? $x : $x - 1, $pointer->y >= $y ? $y : $y - 1, $pointer->z >= $z ? $z : $z - 1); if($vBlock->y < 0 or $vBlock->y > 127){ break; } $block = $this->level->getBlock($vBlock); if(!($block instanceof Air)){ - $block->x = $vBlock->x; - $block->y = $vBlock->y; - $block->z = $vBlock->z; $blastForce -= ($block->getHardness() / 5 + 0.3) * $this->stepLen; if($blastForce > 0){ $index = ($block->x << 15) + ($block->z << 7) + $block->y; @@ -113,7 +117,9 @@ class Explosion{ } } } - $pointer = $pointer->add($vector); + $pointer->x += $vector->x; + $pointer->y += $vector->y; + $pointer->z += $vector->z; } } } @@ -125,7 +131,7 @@ class Explosion{ public function explodeB(){ $send = []; - $source = $this->source->floor(); + $source = Vector3::cloneVector($this->source)->floor(); $yield = (1 / $this->size) * 100; if($this->what instanceof Entity){ @@ -146,7 +152,7 @@ class Explosion{ $minZ = Math::floorFloat($this->source->z - $explosionSize - 1); $maxZ = Math::floorFloat($this->source->z + $explosionSize + 1); - $explosionBB = new AxisAlignedBB($minX, $minY, $minZ, $maxX, $maxY, $maxZ); + $explosionBB = AxisAlignedBB::getBoundingBoxFromPool($minX, $minY, $minZ, $maxX, $maxY, $maxZ); $list = $this->level->getNearbyEntities($explosionBB, $this->what instanceof Entity ? $this->what : null); foreach($list as $entity){ diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 309c3e40e..63bf1ed7d 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -742,10 +742,12 @@ class Level implements ChunkManager, Metadatable{ $collides = []; - for($z = $minZ; $z < $maxZ; ++$z){ - for($x = $minX; $x < $maxX; ++$x){ - for($y = $minY - 1; $y < $maxY; ++$y){ - $block = $this->getBlock(new Vector3($x, $y, $z)); + $v = Vector3::createVector(0, 0, 0); + + for($v->z = $minZ; $v->z < $maxZ; ++$v->z){ + for($v->x = $minX; $v->x < $maxX; ++$v->x){ + for($v->y = $minY - 1; $v->y < $maxY; ++$v->y){ + $block = $this->getBlock($v); if(!($block instanceof Air)){ $block->collidesWithBB($bb, $collides); } @@ -787,11 +789,12 @@ class Level implements ChunkManager, Metadatable{ $maxZ = Math::floorFloat($bb->maxZ + 1); $collides = []; + $v = Vector3::createVector(0, 0, 0); - for($z = $minZ; $z < $maxZ; ++$z){ - for($x = $minX; $x < $maxX; ++$x){ - for($y = $minY - 1; $y < $maxY; ++$y){ - $block = $this->getBlock(new Vector3($x, $y, $z)); + for($v->z = $minZ; $v->z < $maxZ; ++$v->z){ + for($v->x = $minX; $v->x < $maxX; ++$v->x){ + for($v->y = $minY - 1; $v->y < $maxY; ++$v->y){ + $block = $this->getBlock($v); if(!($block instanceof Air)){ $block->collidesWithBB($bb, $collides); } @@ -801,7 +804,7 @@ class Level implements ChunkManager, Metadatable{ if($entities){ foreach($this->getCollidingEntities($bb->grow(0.25, 0.25, 0.25), $entity) as $ent){ - $collides[] = clone $ent->boundingBox; + $collides[] = AxisAlignedBB::cloneBoundingBoxFromPool($ent->boundingBox); } } @@ -819,7 +822,7 @@ class Level implements ChunkManager, Metadatable{ $y2 = (int) $pos2->y; $z2 = (int) $pos2->z; - $block = $this->getBlock(new Vector3($x1, $y1, $z1)); + $block = $this->getBlock(Vector3::createVector($x1, $y1, $z1)); if(!$flag1 or $block->getBoundingBox() !== null){ $ob = $block->calculateIntercept($pos1, $pos2); @@ -976,7 +979,7 @@ class Level implements ChunkManager, Metadatable{ $this->server->getPluginManager()->callEvent($ev = new BlockUpdateEvent($block)); if(!$ev->isCancelled()){ $ev->getBlock()->onUpdate(self::BLOCK_UPDATE_NORMAL); - foreach($this->getNearbyEntities(new AxisAlignedBB($block->x - 1, $block->y - 1, $block->z - 1, $block->x + 2, $block->y + 2, $block->z + 2)) as $entity){ + foreach($this->getNearbyEntities(AxisAlignedBB::getBoundingBoxFromPool($block->x - 1, $block->y - 1, $block->z - 1, $block->x + 2, $block->y + 2, $block->z + 2)) as $entity){ $entity->scheduleUpdate(); } } @@ -991,7 +994,7 @@ class Level implements ChunkManager, Metadatable{ * @param int $delay */ public function dropItem(Vector3 $source, Item $item, Vector3 $motion = null, $delay = 10){ - $motion = $motion === null ? new Vector3(lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1) : $motion; + $motion = $motion === null ? Vector3::createVector(lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1) : $motion; if($item->getID() > 0 and $item->getCount() > 0){ $itemEntity = new DroppedItem($this->getChunk($source->getX() >> 4, $source->getZ() >> 4), new Compound("", [ "Pos" => new Enum("Pos", [ @@ -1074,7 +1077,7 @@ class Level implements ChunkManager, Metadatable{ $level = $target->getLevel(); if($level instanceof Level){ - $above = $level->getBlock(new Vector3($target->x, $target->y + 1, $target->z)); + $above = $level->getBlock(Vector3::createVector($target->x, $target->y + 1, $target->z)); if($above instanceof Block){ if($above->getID() === Item::FIRE){ $level->setBlock($above, new Air(), true); @@ -1258,7 +1261,7 @@ class Level implements ChunkManager, Metadatable{ } /** - * Gets the list of all the entitites in this level + * Gets the list of all the entities in this level * * @return Entity[] */ @@ -1923,27 +1926,26 @@ class Level implements ChunkManager, Metadatable{ $x = Math::floorFloat($spawn->x); $y = Math::floorFloat($spawn->y); $z = Math::floorFloat($spawn->z); - for(; $y > 0; --$y){ - $v = new Vector3($x, $y, $z); + $v = Vector3::createVector($x, $y, $z); + for(; $v->y > 0; --$v->y){ $b = $this->getBlock($v->getSide(0)); - if($b === false){ + if($b === null){ return $spawn; }elseif(!($b instanceof Air)){ break; } } - for(; $y < 128; ++$y){ - $v = new Vector3($x, $y, $z); + for(; $v->y < 128; ++$v->y){ if($this->getBlock($v->getSide(1)) instanceof Air){ if($this->getBlock($v) instanceof Air){ - return new Position($spawn->x, $y === Math::floorFloat($spawn->y) ? $spawn->y : $y, $spawn->z, $this); + return new Position($spawn->x, $v->y === Math::floorFloat($spawn->y) ? $spawn->y : $v->y, $spawn->z, $this); } }else{ - ++$y; + ++$v->y; } } - return new Position($spawn->x, $y, $spawn->z, $this); + return new Position($spawn->x, $v->y, $spawn->z, $this); } return false; diff --git a/src/pocketmine/level/MovingObjectPosition.php b/src/pocketmine/level/MovingObjectPosition.php index 82757d791..4c73d64bd 100644 --- a/src/pocketmine/level/MovingObjectPosition.php +++ b/src/pocketmine/level/MovingObjectPosition.php @@ -64,7 +64,7 @@ class MovingObjectPosition{ $ob->blockX = $x; $ob->blockY = $y; $ob->blockZ = $z; - $ob->hitVector = new Vector3($hitVector->x, $hitVector->y, $hitVector->z); + $ob->hitVector = Vector3::createVector($hitVector->x, $hitVector->y, $hitVector->z); return $ob; } @@ -77,7 +77,7 @@ class MovingObjectPosition{ $ob = new MovingObjectPosition; $ob->typeOfHit = 1; $ob->entityHit = $entity; - $ob->hitVector = new Vector3($entity->x, $entity->y, $entity->z); + $ob->hitVector = Vector3::createVector($entity->x, $entity->y, $entity->z); return $ob; } } diff --git a/src/pocketmine/math/AxisAlignedBB.php b/src/pocketmine/math/AxisAlignedBB.php index 914896c21..e9bc2773e 100644 --- a/src/pocketmine/math/AxisAlignedBB.php +++ b/src/pocketmine/math/AxisAlignedBB.php @@ -22,11 +22,13 @@ namespace pocketmine\math; use pocketmine\level\MovingObjectPosition; -/** - * WARNING: This class is available on the PocketMine-MP Zephir project. - * If this class is modified, remember to modify the PHP C extension. - */ class AxisAlignedBB{ + + + /** @var AxisAlignedBB[] */ + private static $boundingBoxes = []; + private static $nextBoundingBox = 0; + public $minX; public $minY; public $minZ; @@ -43,6 +45,46 @@ class AxisAlignedBB{ $this->maxZ = $maxZ; } + public static function clearBoundingBoxes(){ + self::$nextBoundingBox = 0; + self::$boundingBoxes = []; + } + + public static function clearBoundingBoxPool(){ + self::$nextBoundingBox = 0; + } + + /** + * @param $minX + * @param $minY + * @param $minZ + * @param $maxX + * @param $maxY + * @param $maxZ + * + * @return AxisAlignedBB + */ + public static function getBoundingBoxFromPool($minX, $minY, $minZ, $maxX, $maxY, $maxZ){ + if(self::$nextBoundingBox >= count(self::$boundingBoxes)){ + self::$boundingBoxes[] = new AxisAlignedBB(0, 0, 0, 0, 0, 0); + } + + return self::$boundingBoxes[self::$nextBoundingBox++]->setBounds($minX, $minY, $minZ, $maxX, $maxY, $maxZ); + } + + /** + * @param AxisAlignedBB $bb + * + * @return AxisAlignedBB + */ + public static function cloneBoundingBoxFromPool(AxisAlignedBB $bb){ + if(self::$nextBoundingBox >= count(self::$boundingBoxes)){ + self::$boundingBoxes[] = new AxisAlignedBB(0, 0, 0, 0, 0, 0); + } + + return self::$boundingBoxes[self::$nextBoundingBox++]->setBounds($bb->minX, $bb->minY, $bb->minZ, $bb->maxX, $bb->maxY, $bb->maxZ); + } + public function setBounds($minX, $minY, $minZ, $maxX, $maxY, $maxZ){ $this->minX = $minX; $this->minY = $minY; @@ -55,7 +97,7 @@ class AxisAlignedBB{ } public function addCoord($x, $y, $z){ - $vec = clone $this; + $vec = self::cloneBoundingBoxFromPool($this); if($x < 0){ $vec->minX += $x; @@ -79,7 +121,7 @@ class AxisAlignedBB{ } public function grow($x, $y, $z){ - $vec = clone $this; + $vec = self::cloneBoundingBoxFromPool($this); $vec->minX -= $x; $vec->minY -= $y; $vec->minZ -= $z; @@ -113,7 +155,7 @@ class AxisAlignedBB{ } public function shrink($x, $y, $z){ - $vec = clone $this; + $vec = self::cloneBoundingBoxFromPool($this); $vec->minX += $x; $vec->minY += $y; $vec->minZ += $z; @@ -146,7 +188,7 @@ class AxisAlignedBB{ } public function getOffsetBoundingBox($x, $y, $z){ - $vec = clone $this; + $vec = self::cloneBoundingBoxFromPool($this); $vec->minX += $x; $vec->minY += $y; $vec->minZ += $z; diff --git a/src/pocketmine/math/Vector3.php b/src/pocketmine/math/Vector3.php index 8a8864d93..19bcba46b 100644 --- a/src/pocketmine/math/Vector3.php +++ b/src/pocketmine/math/Vector3.php @@ -27,6 +27,10 @@ namespace pocketmine\math; */ class Vector3{ + /** @var Vector3[] */ + private static $vectorList = []; + private static $nextVector = 0; + const SIDE_DOWN = 0; const SIDE_UP = 1; const SIDE_NORTH = 2; @@ -44,6 +48,38 @@ class Vector3{ $this->z = $z; } + public static function clearVectors(){ + self::$nextVector = 0; + self::$vectorList = []; + } + + public static function clearVectorList(){ + self::$nextVector = 0; + } + + /** + * @param $x + * @param $y + * @param $z + * + * @return Vector3 + */ + public static function createVector($x, $y, $z){ + if(self::$nextVector >= count(self::$vectorList)){ + self::$vectorList[] = new Vector3(0, 0, 0); + } + + return self::$vectorList[self::$nextVector++]->setComponents($x, $y, $z); + } + + public static function cloneVector(Vector3 $vector){ + if(self::$nextVector >= count(self::$vectorList)){ + self::$vectorList[] = new Vector3(0, 0, 0); + } + + return self::$vectorList[self::$nextVector++]->setComponents($vector->x, $vector->y, $vector->z); + } + public function getX(){ return $this->x; } @@ -97,9 +133,9 @@ class Vector3{ */ public function add($x, $y = 0, $z = 0){ if($x instanceof Vector3){ - return new Vector3($this->x + $x->x, $this->y + $x->y, $this->z + $x->z); + return self::createVector($this->x + $x->x, $this->y + $x->y, $this->z + $x->z); }else{ - return new Vector3($this->x + $x, $this->y + $y, $this->z + $z); + return self::createVector($this->x + $x, $this->y + $y, $this->z + $z); } } @@ -119,15 +155,15 @@ class Vector3{ } public function multiply($number){ - return new Vector3($this->x * $number, $this->y * $number, $this->z * $number); + return self::createVector($this->x * $number, $this->y * $number, $this->z * $number); } public function divide($number){ - return new Vector3($this->x / $number, $this->y / $number, $this->z / $number); + return self::createVector($this->x / $number, $this->y / $number, $this->z / $number); } public function ceil(){ - return new Vector3((int) ($this->x + 1), (int) ($this->y + 1), (int) ($this->z + 1)); + return self::createVector((int) ($this->x + 1), (int) ($this->y + 1), (int) ($this->z + 1)); } public function floor(){ @@ -148,17 +184,17 @@ class Vector3{ public function getSide($side, $step = 1){ switch((int) $side){ case self::SIDE_DOWN: - return new Vector3($this->x, $this->y - $step, $this->z); + return self::createVector($this->x, $this->y - $step, $this->z); case self::SIDE_UP: - return new Vector3($this->x, $this->y + $step, $this->z); + return self::createVector($this->x, $this->y + $step, $this->z); case self::SIDE_NORTH: - return new Vector3($this->x, $this->y, $this->z - $step); + return self::createVector($this->x, $this->y, $this->z - $step); case self::SIDE_SOUTH: - return new Vector3($this->x, $this->y, $this->z + $step); + return self::createVector($this->x, $this->y, $this->z + $step); case self::SIDE_WEST: - return new Vector3($this->x - $step, $this->y, $this->z); + return self::createVector($this->x - $step, $this->y, $this->z); case self::SIDE_EAST: - return new Vector3($this->x + $step, $this->y, $this->z); + return self::createVector($this->x + $step, $this->y, $this->z); default: return $this; } @@ -218,7 +254,7 @@ class Vector3{ return $this->divide($len); } - return new Vector3(0, 0, 0); + return self::createVector(0, 0, 0); } public function dot(Vector3 $v){ @@ -226,7 +262,7 @@ class Vector3{ } public function cross(Vector3 $v){ - return new Vector3( + return self::createVector( $this->y * $v->z - $this->z * $v->y, $this->z * $v->x - $this->x * $v->z, $this->x * $v->y - $this->y * $v->x @@ -256,7 +292,7 @@ class Vector3{ if($f < 0 or $f > 1){ return null; }else{ - return new Vector3($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f); + return self::createVector($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f); } } @@ -283,7 +319,7 @@ class Vector3{ if($f < 0 or $f > 1){ return null; }else{ - return new Vector3($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f); + return self::createVector($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f); } } @@ -310,10 +346,24 @@ class Vector3{ if($f < 0 or $f > 1){ return null; }else{ - return new Vector3($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f); + return self::createVector($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f); } } + /** + * @param $x + * @param $y + * @param $z + * + * @return Vector3 + */ + public function setComponents($x, $y, $z){ + $this->x = $x; + $this->y = $y; + $this->z = $z; + return $this; + } + public function __toString(){ return "Vector3(x=" . $this->x . ",y=" . $this->y . ",z=" . $this->z . ")"; } diff --git a/src/pocketmine/tile/Chest.php b/src/pocketmine/tile/Chest.php index 628228980..b0ff4f7d8 100644 --- a/src/pocketmine/tile/Chest.php +++ b/src/pocketmine/tile/Chest.php @@ -196,7 +196,7 @@ class Chest extends Spawnable implements InventoryHolder, Container{ */ public function getPair(){ if($this->isPaired()){ - $tile = $this->getLevel()->getTile(new Vector3((int) $this->namedtag["pairx"], $this->y, (int) $this->namedtag["pairz"])); + $tile = $this->getLevel()->getTile(Vector3::createVector((int) $this->namedtag["pairx"], $this->y, (int) $this->namedtag["pairz"])); if($tile instanceof Chest){ return $tile; } diff --git a/src/pocketmine/utils/BlockIterator.php b/src/pocketmine/utils/BlockIterator.php index 2e2197829..31eee943b 100644 --- a/src/pocketmine/utils/BlockIterator.php +++ b/src/pocketmine/utils/BlockIterator.php @@ -58,7 +58,7 @@ class BlockIterator implements \Iterator{ $this->level = $level; $this->maxDistance = (int) $maxDistance; - $startClone = clone $start; + $startClone = Vector3::createVector($start->x, $start->y, $start->z); $startClone->y += $yOffset; $this->currentDistance = 0; @@ -71,7 +71,7 @@ class BlockIterator implements \Iterator{ $secondPosition = 0; $thirdPosition = 0; - $startBlock = $this->level->getBlock($startClone->floor()); + $startBlock = $this->level->getBlock(Vector3::createVector($startClone->x, $startClone->y, $startClone->z)->floor()); if($this->getXLength($direction) > $mainDirection){ $this->mainFace = $this->getXFace($direction); From ecbbcc2e8ef702d6e5a677ca4ca2891c6287a6e1 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 27 Oct 2014 15:44:36 +0100 Subject: [PATCH 06/61] Drop invalid entities / tile entities on chunk loading --- src/pocketmine/level/format/generic/BaseFullChunk.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/pocketmine/level/format/generic/BaseFullChunk.php b/src/pocketmine/level/format/generic/BaseFullChunk.php index f4b674294..8bf5eb7ec 100644 --- a/src/pocketmine/level/format/generic/BaseFullChunk.php +++ b/src/pocketmine/level/format/generic/BaseFullChunk.php @@ -119,6 +119,10 @@ abstract class BaseFullChunk implements FullChunk{ continue; } + if(($nbt["Pos"][0] >> 4) !== $this->x or ($nbt["Pos"][2] >> 4) !== $this->z){ + continue; //Fixes entities allocated in wrong chunks. + } + //TODO: add all entities switch($nbt["id"]){ case DroppedItem::NETWORK_ID: @@ -144,6 +148,11 @@ abstract class BaseFullChunk implements FullChunk{ if(!isset($nbt->id)){ continue; } + + if(($nbt["x"] >> 4) !== $this->x or ($nbt["z"] >> 4) !== $this->z){ + continue; //Fixes tiles allocated in wrong chunks. + } + switch($nbt["id"]){ case Tile::CHEST: new Chest($this, $nbt); From a5a3f4801a3d026f9fb1d8120d775856bbe1bb53 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 27 Oct 2014 15:53:14 +0100 Subject: [PATCH 07/61] Fixed entities not getting ticks on movement --- src/pocketmine/Player.php | 6 +++--- src/pocketmine/entity/FallingBlock.php | 2 +- src/pocketmine/entity/PrimedTNT.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index bb2ad190d..82811922b 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1143,7 +1143,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $pk = new MovePlayerPacket; $pk->eid = 0; $pk->x = $from->x; - $pk->y = $from->y + $this->getEyeHeight(); + $pk->y = $from->y + $this->getEyeHeight() + 0.01; $pk->z = $from->z; $pk->bodyYaw = $from->yaw; $pk->pitch = $from->pitch; @@ -1477,7 +1477,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $pk = new MovePlayerPacket(); $pk->eid = 0; $pk->x = $this->x; - $pk->y = $this->y + $this->getEyeHeight(); + $pk->y = $this->y + $this->getEyeHeight() + 0.01; $pk->z = $this->z; $pk->bodyYaw = $this->yaw; $pk->pitch = $this->pitch; @@ -2540,7 +2540,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $pk = new MovePlayerPacket; $pk->eid = 0; $pk->x = $this->x; - $pk->y = $this->y + $this->getEyeHeight(); + $pk->y = $this->y + $this->getEyeHeight() + 0.01; $pk->z = $this->z; $pk->bodyYaw = $this->yaw; $pk->pitch = $this->pitch; diff --git a/src/pocketmine/entity/FallingBlock.php b/src/pocketmine/entity/FallingBlock.php index e18581603..250777810 100644 --- a/src/pocketmine/entity/FallingBlock.php +++ b/src/pocketmine/entity/FallingBlock.php @@ -126,7 +126,7 @@ class FallingBlock extends Entity{ $this->updateMovement(); } - return $hasUpdate or !$this->onGround or ($this->motionX == 0 and $this->motionY == 0 and $this->motionZ == 0); + return $hasUpdate or !$this->onGround or $this->motionX != 0 or $this->motionY != 0 or $this->motionZ != 0; } public function getBlock(){ diff --git a/src/pocketmine/entity/PrimedTNT.php b/src/pocketmine/entity/PrimedTNT.php index 160da00bc..d1e871132 100644 --- a/src/pocketmine/entity/PrimedTNT.php +++ b/src/pocketmine/entity/PrimedTNT.php @@ -116,7 +116,7 @@ class PrimedTNT extends Entity implements Explosive{ } - return $hasUpdate or $this->fuse > 0 or ($this->motionX == 0 and $this->motionY == 0 and $this->motionZ == 0); + return $hasUpdate or $this->fuse >= 0 or $this->motionX != 0 or $this->motionY != 0 or $this->motionZ != 0; } public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){ From 64f1ff066d81d13e24f901ae0b6f59f475dfaec3 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 27 Oct 2014 15:57:26 +0100 Subject: [PATCH 08/61] Fixed /setworldspawn changing sender data --- src/pocketmine/command/defaults/SetWorldSpawnCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/command/defaults/SetWorldSpawnCommand.php b/src/pocketmine/command/defaults/SetWorldSpawnCommand.php index 23ef04c97..d65b45fbe 100644 --- a/src/pocketmine/command/defaults/SetWorldSpawnCommand.php +++ b/src/pocketmine/command/defaults/SetWorldSpawnCommand.php @@ -46,7 +46,7 @@ class SetWorldSpawnCommand extends VanillaCommand{ if(count($args) === 0){ if($sender instanceof Player){ $level = $sender->getLevel(); - $pos = $sender->round(); + $pos = Vector3::cloneVector($sender)->round(); }else{ $sender->sendMessage(TextFormat::RED . "You can only perform this command as a player"); From 809fc44813de3a2e65983ba62000a982165b7157 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 27 Oct 2014 16:07:00 +0100 Subject: [PATCH 09/61] Bump API version to 1.6.1 --- src/pocketmine/PocketMine.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 9fd4d41fb..0701c6fd5 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -72,7 +72,7 @@ namespace pocketmine { use pocketmine\wizard\Installer; const VERSION = "Alpha_1.4dev"; - const API_VERSION = "1.6.0"; + const API_VERSION = "1.6.1"; const CODENAME = "絶好(Zekkou)ケーキ(Cake)"; const MINECRAFT_VERSION = "v0.9.5 alpha"; From f6aac8728bec80749af3d608b20a9e320ead6f3c Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 27 Oct 2014 18:43:58 +0100 Subject: [PATCH 10/61] Mark chunk to be saved when removing invalid entities/tiles --- src/pocketmine/level/format/generic/BaseFullChunk.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pocketmine/level/format/generic/BaseFullChunk.php b/src/pocketmine/level/format/generic/BaseFullChunk.php index 8bf5eb7ec..b24daba55 100644 --- a/src/pocketmine/level/format/generic/BaseFullChunk.php +++ b/src/pocketmine/level/format/generic/BaseFullChunk.php @@ -146,10 +146,12 @@ abstract class BaseFullChunk implements FullChunk{ foreach($this->NBTtiles as $nbt){ if($nbt instanceof Compound){ if(!isset($nbt->id)){ + $this->setChanged(); continue; } if(($nbt["x"] >> 4) !== $this->x or ($nbt["z"] >> 4) !== $this->z){ + $this->setChanged(); continue; //Fixes tiles allocated in wrong chunks. } From 3f5b129cf5db796471de4b5025631b3a998eb802 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 27 Oct 2014 19:39:24 +0100 Subject: [PATCH 11/61] Updated RakLib --- src/raklib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/raklib b/src/raklib index d5a195a74..879e8540d 160000 --- a/src/raklib +++ b/src/raklib @@ -1 +1 @@ -Subproject commit d5a195a742b2872d5edac82a7dafc00bbe28ee6a +Subproject commit 879e8540dd4623ec2f188d6e668ae801163a1875 From db82f76c11b2ac5e029da86f89e5e8e581fc5c44 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 27 Oct 2014 20:30:33 +0100 Subject: [PATCH 12/61] Improved network packets allocation --- src/pocketmine/Player.php | 61 ++--- src/pocketmine/block/Bed.php | 6 +- src/pocketmine/block/Door.php | 4 +- src/pocketmine/entity/Arrow.php | 4 +- src/pocketmine/entity/DroppedItem.php | 4 +- src/pocketmine/entity/Entity.php | 16 +- src/pocketmine/entity/FallingBlock.php | 4 +- src/pocketmine/entity/Human.php | 6 +- src/pocketmine/entity/Living.php | 2 +- src/pocketmine/entity/PrimedTNT.php | 4 +- src/pocketmine/entity/Villager.php | 4 +- src/pocketmine/entity/Zombie.php | 4 +- src/pocketmine/inventory/BaseInventory.php | 4 +- src/pocketmine/inventory/ChestInventory.php | 4 +- .../inventory/ContainerInventory.php | 4 +- src/pocketmine/inventory/PlayerInventory.php | 12 +- src/pocketmine/level/Explosion.php | 2 +- src/pocketmine/level/Level.php | 6 +- src/pocketmine/network/RakLibInterface.php | 230 +++++++----------- .../network/protocol/AddEntityPacket.php | 3 + .../network/protocol/AddItemEntityPacket.php | 3 + .../network/protocol/AddMobPacket.php | 3 + .../network/protocol/AddPaintingPacket.php | 3 + .../network/protocol/AddPlayerPacket.php | 3 + .../protocol/AdventureSettingsPacket.php | 3 + .../network/protocol/AnimatePacket.php | 3 + .../network/protocol/ChatPacket.php | 3 + .../network/protocol/ContainerClosePacket.php | 3 + .../network/protocol/ContainerOpenPacket.php | 3 + .../protocol/ContainerSetContentPacket.php | 9 + .../protocol/ContainerSetDataPacket.php | 3 + .../protocol/ContainerSetSlotPacket.php | 3 + .../network/protocol/DataPacket.php | 27 ++ .../network/protocol/DropItemPacket.php | 3 + .../network/protocol/EntityDataPacket.php | 3 + .../network/protocol/EntityEventPacket.php | 3 + .../network/protocol/ExplodePacket.php | 10 +- .../network/protocol/FullChunkDataPacket.php | 3 + .../network/protocol/HurtArmorPacket.php | 3 + .../network/protocol/InteractPacket.php | 3 + .../network/protocol/LevelEventPacket.php | 3 + .../network/protocol/LoginPacket.php | 3 + .../network/protocol/LoginStatusPacket.php | 3 + .../network/protocol/MessagePacket.php | 3 + .../network/protocol/MoveEntityPacket.php | 8 + .../network/protocol/MovePlayerPacket.php | 8 + .../network/protocol/PlayerActionPacket.php | 3 + .../protocol/PlayerArmorEquipmentPacket.php | 3 + .../protocol/PlayerEquipmentPacket.php | 3 + .../network/protocol/RemoveBlockPacket.php | 3 + .../network/protocol/RemoveEntityPacket.php | 3 + .../network/protocol/RemovePlayerPacket.php | 3 + .../network/protocol/RespawnPacket.php | 3 + .../network/protocol/RotateHeadPacket.php | 8 + .../network/protocol/SendInventoryPacket.php | 3 + .../network/protocol/SetEntityDataPacket.php | 3 + .../protocol/SetEntityMotionPacket.php | 8 + .../network/protocol/SetHealthPacket.php | 3 + .../protocol/SetSpawnPositionPacket.php | 3 + .../network/protocol/SetTimePacket.php | 3 + .../network/protocol/StartGamePacket.php | 3 + .../network/protocol/TakeItemEntityPacket.php | 3 + .../network/protocol/TileEventPacket.php | 3 + .../network/protocol/UnknownPacket.php | 3 + .../network/protocol/UnloadChunkPacket.php | 3 + .../network/protocol/UpdateBlockPacket.php | 3 + .../network/protocol/UseItemPacket.php | 3 + src/pocketmine/tile/Furnace.php | 4 +- src/pocketmine/tile/Spawnable.php | 2 +- 69 files changed, 366 insertions(+), 222 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 82811922b..4a0f422a2 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -581,7 +581,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ return; } - $pk = new FullChunkDataPacket; + $pk = FullChunkDataPacket::getFromPool(); $pk->chunkX = $x; $pk->chunkZ = $z; $pk->data = $payload; @@ -645,7 +645,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->blocked = false; - $pk = new SetTimePacket; + $pk = SetTimePacket::getFromPool(); $pk->time = $this->level->getTime(); $pk->started = $this->level->stopTime == false; $this->dataPacket($pk); @@ -834,7 +834,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $level = $pos->getLevel(); } $this->spawnPosition = new Position($pos->x, $pos->y, $pos->z, $level); - $pk = new SetSpawnPositionPacket; + $pk = SetSpawnPositionPacket::getFromPool(); $pk->x = (int) $this->spawnPosition->x; $pk->y = (int) $this->spawnPosition->y; $pk->z = (int) $this->spawnPosition->z; @@ -947,7 +947,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $spawnPosition = $this->getSpawn(); - $pk = new StartGamePacket; + $pk = StartGamePacket::getFromPool(); $pk->seed = $this->level->getSeed(); $pk->x = $this->x; $pk->y = $this->y + $this->getEyeHeight(); @@ -1017,7 +1017,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $flags |= 0x20; //Show Nametags } - $pk = new AdventureSettingsPacket; + $pk = AdventureSettingsPacket::getFromPool(); $pk->flags = $flags; $this->dataPacket($pk); } @@ -1125,7 +1125,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ if($to->distance($ev->getTo()) > 0.1){ //If plugins modify the destination $this->teleport($ev->getTo()); }else{ - $pk = new MovePlayerPacket; + $pk = MovePlayerPacket::getFromPool(); $pk->eid = $this->id; $pk->x = $this->x; $pk->y = $this->y; @@ -1140,7 +1140,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } if($revert){ - $pk = new MovePlayerPacket; + $pk = MovePlayerPacket::getFromPool(); $pk->eid = 0; $pk->x = $from->x; $pk->y = $from->y + $this->getEyeHeight() + 0.01; @@ -1206,11 +1206,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ continue; } - $pk = new TakeItemEntityPacket; + $pk = TakeItemEntityPacket::getFromPool(); $pk->eid = 0; $pk->target = $entity->getID(); $this->dataPacket($pk); - $pk = new TakeItemEntityPacket; + $pk = TakeItemEntityPacket::getFromPool(); $pk->eid = $this->getID(); $pk->target = $entity->getID(); Server::broadcastPacket($entity->getViewers(), $pk); @@ -1240,11 +1240,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ break; } - $pk = new TakeItemEntityPacket; + $pk = TakeItemEntityPacket::getFromPool(); $pk->eid = 0; $pk->target = $entity->getID(); $this->dataPacket($pk); - $pk = new TakeItemEntityPacket; + $pk = TakeItemEntityPacket::getFromPool(); $pk->eid = $this->getID(); $pk->target = $entity->getID(); Server::broadcastPacket($entity->getViewers(), $pk); @@ -1307,11 +1307,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } if($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL){ if($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL){ - $pk = new LoginStatusPacket; + $pk = LoginStatusPacket::getFromPool(); $pk->status = 1; $this->dataPacket($pk); }else{ - $pk = new LoginStatusPacket; + $pk = LoginStatusPacket::getFromPool(); $pk->status = 2; $this->dataPacket($pk); } @@ -1413,7 +1413,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->inventory->setHeldItemSlot(0); } - $pk = new LoginStatusPacket; + $pk = LoginStatusPacket::getFromPool(); $pk->status = 0; $this->dataPacket($pk); @@ -1425,7 +1425,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->dead = false; - $pk = new StartGamePacket; + $pk = StartGamePacket::getFromPool(); $pk->seed = $this->level->getSeed(); $pk->x = $this->x; $pk->y = $this->y; @@ -1438,17 +1438,18 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $pk->eid = 0; //Always use EntityID as zero for the actual player $this->dataPacket($pk); - $pk = new SetTimePacket(); + $pk = SetTimePacket::getFromPool(); $pk->time = $this->level->getTime(); + $pk->started = $this->level->stopTime == false; $this->dataPacket($pk); - $pk = new SetSpawnPositionPacket; + $pk = SetSpawnPositionPacket::getFromPool(); $pk->x = (int) $spawnPosition->x; $pk->y = (int) $spawnPosition->y; $pk->z = (int) $spawnPosition->z; $this->dataPacket($pk); - $pk = new SetHealthPacket(); + $pk = SetHealthPacket::getFromPool(); $pk->health = $this->getHealth(); $this->dataPacket($pk); if($this->getHealth() <= 0){ @@ -1474,7 +1475,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $revert = ($this->dead === true or $this->spawned !== true); if($revert or ($this->forceMovement instanceof Vector3 and $newPos->distance($this->forceMovement) > 0.2)){ - $pk = new MovePlayerPacket(); + $pk = MovePlayerPacket::getFromPool(); $pk->eid = 0; $pk->x = $this->x; $pk->y = $this->y + $this->getEyeHeight() + 0.01; @@ -1565,7 +1566,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $target = $this->level->getBlock($blockVector); $block = $target->getSide($packet->face); - $pk = new UpdateBlockPacket; + $pk = UpdateBlockPacket::getFromPool(); $pk->x = $target->x; $pk->y = $target->y; $pk->z = $target->z; @@ -1573,7 +1574,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $pk->meta = $target->getDamage(); $this->dataPacket($pk); - $pk = new UpdateBlockPacket; + $pk = UpdateBlockPacket::getFromPool(); $pk->x = $block->x; $pk->y = $block->y; $pk->z = $block->z; @@ -1612,7 +1613,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $target = $this->level->getBlock($blockVector); $block = $target->getSide($packet->face); - $pk = new UpdateBlockPacket; + $pk = UpdateBlockPacket::getFromPool(); $pk->x = $target->x; $pk->y = $target->y; $pk->z = $target->z; @@ -1620,7 +1621,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $pk->meta = $target->getDamage(); $this->dataPacket($pk); - $pk = new UpdateBlockPacket; + $pk = UpdateBlockPacket::getFromPool(); $pk->x = $block->x; $pk->y = $block->y; $pk->z = $block->z; @@ -1738,7 +1739,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $target = $this->level->getBlock($vector); $tile = $this->level->getTile($vector); - $pk = new UpdateBlockPacket; + $pk = UpdateBlockPacket::getFromPool(); $pk->x = $target->x; $pk->y = $target->y; $pk->z = $target->z; @@ -1887,7 +1888,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ break; } - $pk = new AnimatePacket(); + $pk = AnimatePacket::getFromPool(); $pk->eid = $this->getID(); $pk->action = $ev->getAnimationType(); Server::broadcastPacket($this->getViewers(), $pk); @@ -1961,7 +1962,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ break; } - $pk = new EntityEventPacket(); + $pk = EntityEventPacket::getFromPool(); $pk->eid = 0; $pk->event = 9; $this->dataPacket($pk); @@ -2247,7 +2248,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $mes = explode("\n", $message); foreach($mes as $m){ if($m !== ""){ - $pk = new MessagePacket; + $pk = MessagePacket::getFromPool(); $pk->source = ""; //Do not use this ;) $pk->message = $m; $this->dataPacket($pk); @@ -2462,7 +2463,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ public function setHealth($amount){ parent::setHealth($amount); if($this->spawned === true){ - $pk = new SetHealthPacket(); + $pk = SetHealthPacket::getFromPool(); $pk->health = $this->getHealth(); $this->dataPacket($pk); } @@ -2492,7 +2493,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ parent::attack($damage, $source); if($this->getLastDamageCause() === $source){ - $pk = new EntityEventPacket(); + $pk = EntityEventPacket::getFromPool(); $pk->eid = 0; $pk->event = 2; $this->dataPacket($pk); @@ -2537,7 +2538,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->forceMovement = $pos; $this->newPosition = $pos; - $pk = new MovePlayerPacket; + $pk = MovePlayerPacket::getFromPool(); $pk->eid = 0; $pk->x = $this->x; $pk->y = $this->y + $this->getEyeHeight() + 0.01; diff --git a/src/pocketmine/block/Bed.php b/src/pocketmine/block/Bed.php index e012b867f..f8137cf78 100644 --- a/src/pocketmine/block/Bed.php +++ b/src/pocketmine/block/Bed.php @@ -53,7 +53,7 @@ class Bed extends Transparent{ $isNight = ($time >= Level::TIME_NIGHT and $time < Level::TIME_SUNRISE); if($player instanceof Player and !$isNight){ - $pk = new ChatPacket; + $pk = ChatPacket::getFromPool(); $pk->message = "You can only sleep at night"; $player->dataPacket($pk); @@ -77,7 +77,7 @@ class Bed extends Transparent{ $b = $blockWest; }else{ if($player instanceof Player){ - $pk = new ChatPacket; + $pk = ChatPacket::getFromPool(); $pk->message = "This bed is incomplete"; $player->dataPacket($pk); } @@ -87,7 +87,7 @@ class Bed extends Transparent{ } if($player instanceof Player and $player->sleepOn($b) === false){ - $pk = new ChatPacket; + $pk = ChatPacket::getFromPool(); $pk->message = "This bed is occupied"; $player->dataPacket($pk); } diff --git a/src/pocketmine/block/Door.php b/src/pocketmine/block/Door.php index 04506d99b..7092e6530 100644 --- a/src/pocketmine/block/Door.php +++ b/src/pocketmine/block/Door.php @@ -271,7 +271,7 @@ abstract class Door extends Transparent{ if($player instanceof Player){ unset($players[$player->getID()]); } - $pk = new LevelEventPacket; + $pk = LevelEventPacket::getFromPool(); $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; @@ -290,7 +290,7 @@ abstract class Door extends Transparent{ if($player instanceof Player){ unset($players[$player->getID()]); } - $pk = new LevelEventPacket; + $pk = LevelEventPacket::getFromPool(); $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; diff --git a/src/pocketmine/entity/Arrow.php b/src/pocketmine/entity/Arrow.php index b24ad1116..1e4ec4c78 100644 --- a/src/pocketmine/entity/Arrow.php +++ b/src/pocketmine/entity/Arrow.php @@ -209,7 +209,7 @@ class Arrow extends Projectile{ } public function spawnTo(Player $player){ - $pk = new AddEntityPacket(); + $pk = AddEntityPacket::getFromPool(); $pk->type = Arrow::NETWORK_ID; $pk->eid = $this->getID(); $pk->x = $this->x; @@ -218,7 +218,7 @@ class Arrow extends Projectile{ $pk->did = 0; //TODO: send motion here $player->dataPacket($pk); - $pk = new SetEntityMotionPacket(); + $pk = SetEntityMotionPacket::getFromPool(); $pk->entities = [ [$this->getID(), $this->motionX, $this->motionY, $this->motionZ] ]; diff --git a/src/pocketmine/entity/DroppedItem.php b/src/pocketmine/entity/DroppedItem.php index 6d685134b..9584e2fe5 100644 --- a/src/pocketmine/entity/DroppedItem.php +++ b/src/pocketmine/entity/DroppedItem.php @@ -219,7 +219,7 @@ class DroppedItem extends Entity{ } public function spawnTo(Player $player){ - $pk = new AddItemEntityPacket(); + $pk = AddItemEntityPacket::getFromPool(); $pk->eid = $this->getID(); $pk->x = $this->x; $pk->y = $this->y; @@ -230,7 +230,7 @@ class DroppedItem extends Entity{ $pk->item = $this->getItem(); $player->dataPacket($pk); - $pk = new SetEntityMotionPacket; + $pk = SetEntityMotionPacket::getFromPool(); $pk->entities = [ [$this->getID(), $this->motionX, $this->motionY, $this->motionZ] ]; diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 990142918..3c2118f65 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -270,7 +270,7 @@ abstract class Entity extends Location implements Metadatable{ $player = [$player]; } - $pk = new SetEntityDataPacket(); + $pk = SetEntityDataPacket::getFromPool(); $pk->eid = $this->id; $pk->metadata = $this->getData(); $pk->encode(); @@ -278,7 +278,7 @@ abstract class Entity extends Location implements Metadatable{ foreach($player as $p){ if($p === $this){ /** @var Player $p */ - $pk2 = new SetEntityDataPacket(); + $pk2 = SetEntityDataPacket::getFromPool(); $pk2->eid = 0; $pk2->metadata = $this->getData(); $p->dataPacket($pk2); @@ -293,7 +293,7 @@ abstract class Entity extends Location implements Metadatable{ */ public function despawnFrom(Player $player){ if(isset($this->hasSpawned[$player->getID()])){ - $pk = new RemoveEntityPacket; + $pk = RemoveEntityPacket::getFromPool(); $pk->eid = $this->id; $player->dataPacket($pk); unset($this->hasSpawned[$player->getID()]); @@ -532,7 +532,7 @@ abstract class Entity extends Location implements Metadatable{ $this->lastPitch = $this->pitch; if($this instanceof Human){ - $pk = new MovePlayerPacket; + $pk = MovePlayerPacket::getFromPool(); $pk->eid = $this->id; $pk->x = $this->x; $pk->y = $this->y; @@ -542,7 +542,7 @@ abstract class Entity extends Location implements Metadatable{ $pk->bodyYaw = $this->yaw; }else{ //TODO: add to move list - $pk = new MoveEntityPacket(); + $pk = MoveEntityPacket::getFromPool(); $pk->entities = [ [$this->id, $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch] ]; @@ -556,7 +556,7 @@ abstract class Entity extends Location implements Metadatable{ $this->lastMotionY = $this->motionY; $this->lastMotionZ = $this->motionZ; - $pk = new SetEntityMotionPacket; + $pk = SetEntityMotionPacket::getFromPool(); $pk->entities = [ [$this->getID(), $this->motionX, $this->motionY, $this->motionZ] ]; @@ -726,7 +726,7 @@ abstract class Entity extends Location implements Metadatable{ $this->level->addEntity($this); if($this instanceof Player){ $this->usedChunks = []; - $pk = new SetTimePacket(); + $pk = SetTimePacket::getFromPool(); $pk->time = $this->level->getTime(); $pk->started = $this->level->stopTime == false; $this->dataPacket($pk); @@ -1100,7 +1100,7 @@ abstract class Entity extends Location implements Metadatable{ if(!$this->justCreated){ if($this instanceof Player){ - $pk = new SetEntityMotionPacket; + $pk = SetEntityMotionPacket::getFromPool(); $pk->entities = [ [0, $this->motionX, $this->motionY, $this->motionZ] ]; diff --git a/src/pocketmine/entity/FallingBlock.php b/src/pocketmine/entity/FallingBlock.php index 250777810..e05a6aa92 100644 --- a/src/pocketmine/entity/FallingBlock.php +++ b/src/pocketmine/entity/FallingBlock.php @@ -150,7 +150,7 @@ class FallingBlock extends Entity{ } public function spawnTo(Player $player){ - $pk = new AddEntityPacket; + $pk = AddEntityPacket::getFromPool(); $pk->type = FallingBlock::NETWORK_ID; $pk->eid = $this->getID(); $pk->x = $this->x; @@ -159,7 +159,7 @@ class FallingBlock extends Entity{ $pk->did = -$this->getBlock(); $player->dataPacket($pk); - $pk = new SetEntityMotionPacket; + $pk = SetEntityMotionPacket::getFromPool(); $pk->entities = [ [$this->getID(), $this->motionX, $this->motionY, $this->motionZ] ]; diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index d31e9f092..962860f1a 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -156,7 +156,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ if($player !== $this and !isset($this->hasSpawned[$player->getID()])){ $this->hasSpawned[$player->getID()] = $player; - $pk = new AddPlayerPacket; + $pk = AddPlayerPacket::getFromPool(); $pk->clientID = 0; if($player->getRemoveFormat()){ $pk->username = TextFormat::clean($this->nameTag); @@ -174,7 +174,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ $pk->metadata = $this->getData(); $player->dataPacket($pk); - $pk = new SetEntityMotionPacket; + $pk = SetEntityMotionPacket::getFromPool(); $pk->entities = [ [$this->getID(), $this->motionX, $this->motionY, $this->motionZ] ]; @@ -188,7 +188,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ public function despawnFrom(Player $player){ if(isset($this->hasSpawned[$player->getID()])){ - $pk = new RemovePlayerPacket; + $pk = RemovePlayerPacket::getFromPool(); $pk->eid = $this->id; $pk->clientID = 0; $player->dataPacket($pk); diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index f201d736e..c563ca964 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -76,7 +76,7 @@ abstract class Living extends Entity implements Damageable{ } } - $pk = new EntityEventPacket(); + $pk = EntityEventPacket::getFromPool(); $pk->eid = $this->getID(); $pk->event = 2; //Ouch! Server::broadcastPacket($this->hasSpawned, $pk); diff --git a/src/pocketmine/entity/PrimedTNT.php b/src/pocketmine/entity/PrimedTNT.php index d1e871132..335c3943a 100644 --- a/src/pocketmine/entity/PrimedTNT.php +++ b/src/pocketmine/entity/PrimedTNT.php @@ -140,7 +140,7 @@ class PrimedTNT extends Entity implements Explosive{ } public function spawnTo(Player $player){ - $pk = new AddEntityPacket(); + $pk = AddEntityPacket::getFromPool(); $pk->type = PrimedTNT::NETWORK_ID; $pk->eid = $this->getID(); $pk->x = $this->x; @@ -149,7 +149,7 @@ class PrimedTNT extends Entity implements Explosive{ $pk->did = 0; $player->dataPacket($pk); - $pk = new SetEntityMotionPacket(); + $pk = SetEntityMotionPacket::getFromPool(); $pk->entities = [ [$this->getID(), $this->motionX, $this->motionY, $this->motionZ] ]; diff --git a/src/pocketmine/entity/Villager.php b/src/pocketmine/entity/Villager.php index b2f01cc50..ed01d39e9 100644 --- a/src/pocketmine/entity/Villager.php +++ b/src/pocketmine/entity/Villager.php @@ -55,7 +55,7 @@ class Villager extends Creature implements NPC, Ageable{ } public function spawnTo(Player $player){ - $pk = new AddMobPacket(); + $pk = AddMobPacket::getFromPool(); $pk->eid = $this->getID(); $pk->type = Villager::NETWORK_ID; $pk->x = $this->x; @@ -66,7 +66,7 @@ class Villager extends Creature implements NPC, Ageable{ $pk->metadata = $this->getData(); $player->dataPacket($pk); - $pk = new SetEntityMotionPacket(); + $pk = SetEntityMotionPacket::getFromPool(); $pk->entities = [ [$this->getID(), $this->motionX, $this->motionY, $this->motionZ] ]; diff --git a/src/pocketmine/entity/Zombie.php b/src/pocketmine/entity/Zombie.php index 5d7c95442..8b45b8787 100644 --- a/src/pocketmine/entity/Zombie.php +++ b/src/pocketmine/entity/Zombie.php @@ -46,7 +46,7 @@ class Zombie extends Monster{ public function spawnTo(Player $player){ - $pk = new AddMobPacket(); + $pk = AddMobPacket::getFromPool(); $pk->eid = $this->getID(); $pk->type = Zombie::NETWORK_ID; $pk->x = $this->x; @@ -57,7 +57,7 @@ class Zombie extends Monster{ $pk->metadata = $this->getData(); $player->dataPacket($pk); - $pk = new SetEntityMotionPacket(); + $pk = SetEntityMotionPacket::getFromPool(); $pk->entities = [ [$this->getID(), $this->motionX, $this->motionY, $this->motionZ] ]; diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index 6353e2ca3..fce466242 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -384,7 +384,7 @@ abstract class BaseInventory implements Inventory{ $target = [$target]; } - $pk = new ContainerSetContentPacket(); + $pk = ContainerSetContentPacket::getFromPool(); $pk->slots = []; for($i = 0; $i < $this->getSize(); ++$i){ $pk->slots[$i] = $this->getItem($i); @@ -409,7 +409,7 @@ abstract class BaseInventory implements Inventory{ $target = [$target]; } - $pk = new ContainerSetSlotPacket; + $pk = ContainerSetSlotPacket::getFromPool(); $pk->slot = $index; $pk->item = clone $this->getItem($index); diff --git a/src/pocketmine/inventory/ChestInventory.php b/src/pocketmine/inventory/ChestInventory.php index 5ed416101..8d4ba3ff4 100644 --- a/src/pocketmine/inventory/ChestInventory.php +++ b/src/pocketmine/inventory/ChestInventory.php @@ -43,7 +43,7 @@ class ChestInventory extends ContainerInventory{ parent::onOpen($who); if(count($this->getViewers()) === 1){ - $pk = new TileEventPacket; + $pk = TileEventPacket::getFromPool(); $pk->x = $this->getHolder()->getX(); $pk->y = $this->getHolder()->getY(); $pk->z = $this->getHolder()->getZ(); @@ -57,7 +57,7 @@ class ChestInventory extends ContainerInventory{ public function onClose(Player $who){ if(count($this->getViewers()) === 1){ - $pk = new TileEventPacket; + $pk = TileEventPacket::getFromPool(); $pk->x = $this->getHolder()->getX(); $pk->y = $this->getHolder()->getY(); $pk->z = $this->getHolder()->getZ(); diff --git a/src/pocketmine/inventory/ContainerInventory.php b/src/pocketmine/inventory/ContainerInventory.php index a027e68ad..ea16b0574 100644 --- a/src/pocketmine/inventory/ContainerInventory.php +++ b/src/pocketmine/inventory/ContainerInventory.php @@ -29,7 +29,7 @@ use pocketmine\Player; abstract class ContainerInventory extends BaseInventory{ public function onOpen(Player $who){ parent::onOpen($who); - $pk = new ContainerOpenPacket; + $pk = ContainerOpenPacket::getFromPool(); $pk->windowid = $who->getWindowId($this); $pk->type = $this->getType()->getNetworkType(); $pk->slots = $this->getSize(); @@ -47,7 +47,7 @@ abstract class ContainerInventory extends BaseInventory{ } public function onClose(Player $who){ - $pk = new ContainerClosePacket; + $pk = ContainerClosePacket::getFromPool(); $pk->windowid = $who->getWindowId($this); $who->dataPacket($pk); parent::onClose($who); diff --git a/src/pocketmine/inventory/PlayerInventory.php b/src/pocketmine/inventory/PlayerInventory.php index 8c5cd325e..05e3eb894 100644 --- a/src/pocketmine/inventory/PlayerInventory.php +++ b/src/pocketmine/inventory/PlayerInventory.php @@ -66,7 +66,7 @@ class PlayerInventory extends BaseInventory{ $this->itemInHandIndex = $index; $item = $this->getItemInHand(); - $pk = new PlayerEquipmentPacket; + $pk = PlayerEquipmentPacket::getFromPool(); $pk->eid = $this->getHolder()->getID(); $pk->item = $item->getID(); $pk->meta = $item->getDamage(); @@ -126,7 +126,7 @@ class PlayerInventory extends BaseInventory{ $item = $this->getItemInHand(); - $pk = new PlayerEquipmentPacket; + $pk = PlayerEquipmentPacket::getFromPool(); $pk->eid = $this->getHolder()->getID(); $pk->item = $item->getID(); $pk->meta = $item->getDamage(); @@ -286,7 +286,7 @@ class PlayerInventory extends BaseInventory{ } } - $pk = new PlayerArmorEquipmentPacket; + $pk = PlayerArmorEquipmentPacket::getFromPool(); $pk->eid = $this->getHolder()->getID(); $pk->slots = $slots; $pk->encode(); @@ -298,7 +298,7 @@ class PlayerInventory extends BaseInventory{ //$pk2 = clone $pk; //$pk2->eid = 0; - $pk2 = new ContainerSetContentPacket; + $pk2 = ContainerSetContentPacket::getFromPool(); $pk2->windowid = 0x78; //Armor window id constant $pk2->slots = $armor; $player->dataPacket($pk2); @@ -333,7 +333,7 @@ class PlayerInventory extends BaseInventory{ $target = [$target]; } - $pk = new ContainerSetContentPacket(); + $pk = ContainerSetContentPacket::getFromPool(); $pk->slots = []; for($i = 0; $i < $this->getSize(); ++$i){ //Do not send armor by error here $pk->slots[$i] = $this->getItem($i); @@ -365,7 +365,7 @@ class PlayerInventory extends BaseInventory{ $target = [$target]; } - $pk = new ContainerSetSlotPacket; + $pk = ContainerSetSlotPacket::getFromPool(); $pk->slot = $index; $pk->item = clone $this->getItem($index); diff --git a/src/pocketmine/level/Explosion.php b/src/pocketmine/level/Explosion.php index 74a2f36cb..47ce62703 100644 --- a/src/pocketmine/level/Explosion.php +++ b/src/pocketmine/level/Explosion.php @@ -217,7 +217,7 @@ class Explosion{ $this->level->setBlockIdAt($block->x, $block->y, $block->z, 0); $send[] = new Vector3($block->x - $source->x, $block->y - $source->y, $block->z - $source->z); } - $pk = new ExplodePacket; + $pk = ExplodePacket::getFromPool(); $pk->x = $this->source->x; $pk->y = $this->source->y; $pk->z = $this->source->z; diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 63bf1ed7d..5d3154ea8 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -442,7 +442,7 @@ class Level implements ChunkManager, Metadatable{ * Changes to this function won't be recorded on the version. */ public function sendTime(){ - $pk = new SetTimePacket; + $pk = SetTimePacket::getFromPool(); $pk->time = (int) $this->time; $pk->started = $this->stopTime == false; @@ -539,7 +539,7 @@ class Level implements ChunkManager, Metadatable{ foreach($mini as $blocks){ /** @var Block $b */ foreach($blocks as $b){ - $pk = new UpdateBlockPacket(); + $pk = UpdateBlockPacket::getFromPool(); $pk->x = $b->x; $pk->y = $b->y; $pk->z = $b->z; @@ -949,7 +949,7 @@ class Level implements ChunkManager, Metadatable{ } //if($direct === true){ - $pk = new UpdateBlockPacket; + $pk = UpdateBlockPacket::getFromPool(); $pk->x = $pos->x; $pk->y = $pos->y; $pk->z = $pos->z; diff --git a/src/pocketmine/network/RakLibInterface.php b/src/pocketmine/network/RakLibInterface.php index 76d660a30..c01c50a7f 100644 --- a/src/pocketmine/network/RakLibInterface.php +++ b/src/pocketmine/network/RakLibInterface.php @@ -83,6 +83,8 @@ use raklib\server\ServerInstance; class RakLibInterface implements ServerInstance, SourceInterface{ + private $packetPool = []; + private $server; /** @var Player[] */ private $players = []; @@ -103,6 +105,9 @@ class RakLibInterface implements ServerInstance, SourceInterface{ private $externalThreaded; public function __construct(Server $server){ + + $this->registerPackets(); + $this->server = $server; $this->identifiers = new \SplObjectStorage(); @@ -115,6 +120,8 @@ class RakLibInterface implements ServerInstance, SourceInterface{ } public function doTick(){ + $this->cleanPacketPool(); + EncapsulatedPacket::cleanPacketPool(); $this->interface->sendTick(); } @@ -218,7 +225,7 @@ class RakLibInterface implements ServerInstance, SourceInterface{ if(!$packet->isEncoded){ $packet->encode(); } - $pk = new EncapsulatedPacket(); + $pk = EncapsulatedPacket::getPacketFromPool(); $pk->buffer = $packet->buffer; $pk->reliability = 2; if($needACK === true){ @@ -232,150 +239,87 @@ class RakLibInterface implements ServerInstance, SourceInterface{ return null; } - private function getPacket($buffer){ - $pid = ord($buffer{0}); - switch($pid){ //TODO: more efficient selection based on range - case ProtocolInfo::LOGIN_PACKET: - $data = new LoginPacket(); - break; - case ProtocolInfo::LOGIN_STATUS_PACKET: - $data = new LoginStatusPacket(); - break; - case ProtocolInfo::MESSAGE_PACKET: - $data = new MessagePacket(); - break; - case ProtocolInfo::SET_TIME_PACKET: - $data = new SetTimePacket(); - break; - case ProtocolInfo::START_GAME_PACKET: - $data = new StartGamePacket(); - break; - case ProtocolInfo::ADD_MOB_PACKET: - $data = new AddMobPacket(); - break; - case ProtocolInfo::ADD_PLAYER_PACKET: - $data = new AddPlayerPacket(); - break; - case ProtocolInfo::REMOVE_PLAYER_PACKET: - $data = new RemovePlayerPacket(); - break; - case ProtocolInfo::ADD_ENTITY_PACKET: - $data = new AddEntityPacket(); - break; - case ProtocolInfo::REMOVE_ENTITY_PACKET: - $data = new RemoveEntityPacket(); - break; - case ProtocolInfo::ADD_ITEM_ENTITY_PACKET: - $data = new AddItemEntityPacket(); - break; - case ProtocolInfo::TAKE_ITEM_ENTITY_PACKET: - $data = new TakeItemEntityPacket(); - break; - case ProtocolInfo::MOVE_ENTITY_PACKET: - $data = new MoveEntityPacket(); - break; - case ProtocolInfo::ROTATE_HEAD_PACKET: - $data = new RotateHeadPacket(); - break; - case ProtocolInfo::MOVE_PLAYER_PACKET: - $data = new MovePlayerPacket(); - break; - case ProtocolInfo::REMOVE_BLOCK_PACKET: - $data = new RemoveBlockPacket(); - break; - case ProtocolInfo::UPDATE_BLOCK_PACKET: - $data = new UpdateBlockPacket(); - break; - case ProtocolInfo::ADD_PAINTING_PACKET: - $data = new AddPaintingPacket(); - break; - case ProtocolInfo::EXPLODE_PACKET: - $data = new ExplodePacket(); - break; - case ProtocolInfo::LEVEL_EVENT_PACKET: - $data = new LevelEventPacket(); - break; - case ProtocolInfo::TILE_EVENT_PACKET: - $data = new TileEventPacket(); - break; - case ProtocolInfo::ENTITY_EVENT_PACKET: - $data = new EntityEventPacket(); - break; - case ProtocolInfo::PLAYER_EQUIPMENT_PACKET: - $data = new PlayerEquipmentPacket(); - break; - case ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET: - $data = new PlayerArmorEquipmentPacket(); - break; - case ProtocolInfo::INTERACT_PACKET: - $data = new InteractPacket(); - break; - case ProtocolInfo::USE_ITEM_PACKET: - $data = new UseItemPacket(); - break; - case ProtocolInfo::PLAYER_ACTION_PACKET: - $data = new PlayerActionPacket(); - break; - case ProtocolInfo::HURT_ARMOR_PACKET: - $data = new HurtArmorPacket(); - break; - case ProtocolInfo::SET_ENTITY_DATA_PACKET: - $data = new SetEntityDataPacket(); - break; - case ProtocolInfo::SET_ENTITY_MOTION_PACKET: - $data = new SetEntityMotionPacket(); - break; - case ProtocolInfo::SET_HEALTH_PACKET: - $data = new SetHealthPacket(); - break; - case ProtocolInfo::SET_SPAWN_POSITION_PACKET: - $data = new SetSpawnPositionPacket(); - break; - case ProtocolInfo::ANIMATE_PACKET: - $data = new AnimatePacket(); - break; - case ProtocolInfo::RESPAWN_PACKET: - $data = new RespawnPacket(); - break; - case ProtocolInfo::SEND_INVENTORY_PACKET: - $data = new SendInventoryPacket(); - break; - case ProtocolInfo::DROP_ITEM_PACKET: - $data = new DropItemPacket(); - break; - case ProtocolInfo::CONTAINER_OPEN_PACKET: - $data = new ContainerOpenPacket(); - break; - case ProtocolInfo::CONTAINER_CLOSE_PACKET: - $data = new ContainerClosePacket(); - break; - case ProtocolInfo::CONTAINER_SET_SLOT_PACKET: - $data = new ContainerSetSlotPacket(); - break; - case ProtocolInfo::CONTAINER_SET_DATA_PACKET: - $data = new ContainerSetDataPacket(); - break; - case ProtocolInfo::CONTAINER_SET_CONTENT_PACKET: - $data = new ContainerSetContentPacket(); - break; - case ProtocolInfo::CHAT_PACKET: - $data = new ChatPacket(); - break; - case ProtocolInfo::ADVENTURE_SETTINGS_PACKET: - $data = new AdventureSettingsPacket(); - break; - case ProtocolInfo::ENTITY_DATA_PACKET: - $data = new EntityDataPacket(); - break; - case ProtocolInfo::UNLOAD_CHUNK_PACKET: - $data = new UnloadChunkPacket(); - break; - default: - $data = new UnknownPacket(); - $data->packetID = $pid; - break; + public function registerPacket($id, $class){ + $this->packetPool[$id] = $class; + } + + /** + * @param $id + * + * @return DataPacket + */ + public function getPacketFromPool($id){ + if(isset($this->packetPool[$id])){ + /** @var DataPacket $class */ + $class = $this->packetPool[$id]; + return $class::getFromPool(); } + return null; + } + + public function cleanPacketPool(){ + foreach($this->packetPool as $class){ + /** @var DataPacket $class */ + $class::cleanPool(); + } + } + + private function registerPackets(){ + $this->registerPacket(ProtocolInfo::LOGIN_PACKET, LoginPacket::class); + $this->registerPacket(ProtocolInfo::LOGIN_STATUS_PACKET, LoginStatusPacket::class); + $this->registerPacket(ProtocolInfo::MESSAGE_PACKET, MessagePacket::class); + $this->registerPacket(ProtocolInfo::SET_TIME_PACKET, SetTimePacket::class); + $this->registerPacket(ProtocolInfo::START_GAME_PACKET, StartGamePacket::class); + $this->registerPacket(ProtocolInfo::ADD_MOB_PACKET, AddMobPacket::class); + $this->registerPacket(ProtocolInfo::ADD_PLAYER_PACKET, AddPlayerPacket::class); + $this->registerPacket(ProtocolInfo::REMOVE_PLAYER_PACKET, RemovePlayerPacket::class); + $this->registerPacket(ProtocolInfo::ADD_ENTITY_PACKET, AddEntityPacket::class); + $this->registerPacket(ProtocolInfo::REMOVE_ENTITY_PACKET, RemoveEntityPacket::class); + $this->registerPacket(ProtocolInfo::ADD_ITEM_ENTITY_PACKET, AddItemEntityPacket::class); + $this->registerPacket(ProtocolInfo::TAKE_ITEM_ENTITY_PACKET, TakeItemEntityPacket::class); + $this->registerPacket(ProtocolInfo::MOVE_ENTITY_PACKET, MoveEntityPacket::class); + $this->registerPacket(ProtocolInfo::ROTATE_HEAD_PACKET, RotateHeadPacket::class); + $this->registerPacket(ProtocolInfo::MOVE_PLAYER_PACKET, MovePlayerPacket::class); + $this->registerPacket(ProtocolInfo::REMOVE_BLOCK_PACKET, RemoveBlockPacket::class); + $this->registerPacket(ProtocolInfo::UPDATE_BLOCK_PACKET, UpdateBlockPacket::class); + $this->registerPacket(ProtocolInfo::ADD_PAINTING_PACKET, AddPaintingPacket::class); + $this->registerPacket(ProtocolInfo::EXPLODE_PACKET, ExplodePacket::class); + $this->registerPacket(ProtocolInfo::LEVEL_EVENT_PACKET, LevelEventPacket::class); + $this->registerPacket(ProtocolInfo::TILE_EVENT_PACKET, TileEventPacket::class); + $this->registerPacket(ProtocolInfo::ENTITY_EVENT_PACKET, EntityEventPacket::class); + $this->registerPacket(ProtocolInfo::PLAYER_EQUIPMENT_PACKET, PlayerEquipmentPacket::class); + $this->registerPacket(ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET, PlayerArmorEquipmentPacket::class); + $this->registerPacket(ProtocolInfo::INTERACT_PACKET, InteractPacket::class); + $this->registerPacket(ProtocolInfo::USE_ITEM_PACKET, UseItemPacket::class); + $this->registerPacket(ProtocolInfo::PLAYER_ACTION_PACKET, PlayerActionPacket::class); + $this->registerPacket(ProtocolInfo::HURT_ARMOR_PACKET, HurtArmorPacket::class); + $this->registerPacket(ProtocolInfo::SET_ENTITY_DATA_PACKET, SetEntityDataPacket::class); + $this->registerPacket(ProtocolInfo::SET_ENTITY_MOTION_PACKET, SetEntityMotionPacket::class); + $this->registerPacket(ProtocolInfo::SET_HEALTH_PACKET, SetHealthPacket::class); + $this->registerPacket(ProtocolInfo::SET_SPAWN_POSITION_PACKET, SetSpawnPositionPacket::class); + $this->registerPacket(ProtocolInfo::ANIMATE_PACKET, AnimatePacket::class); + $this->registerPacket(ProtocolInfo::RESPAWN_PACKET, RespawnPacket::class); + $this->registerPacket(ProtocolInfo::SEND_INVENTORY_PACKET, SendInventoryPacket::class); + $this->registerPacket(ProtocolInfo::DROP_ITEM_PACKET, DropItemPacket::class); + $this->registerPacket(ProtocolInfo::CONTAINER_OPEN_PACKET, ContainerOpenPacket::class); + $this->registerPacket(ProtocolInfo::CONTAINER_CLOSE_PACKET, ContainerClosePacket::class); + $this->registerPacket(ProtocolInfo::CONTAINER_SET_SLOT_PACKET, ContainerSetSlotPacket::class); + $this->registerPacket(ProtocolInfo::CONTAINER_SET_DATA_PACKET, ContainerSetDataPacket::class); + $this->registerPacket(ProtocolInfo::CONTAINER_SET_CONTENT_PACKET, ContainerSetContentPacket::class); + $this->registerPacket(ProtocolInfo::CHAT_PACKET, ChatPacket::class); + $this->registerPacket(ProtocolInfo::ADVENTURE_SETTINGS_PACKET, AdventureSettingsPacket::class); + $this->registerPacket(ProtocolInfo::ENTITY_DATA_PACKET, EntityDataPacket::class); + $this->registerPacket(ProtocolInfo::UNLOAD_CHUNK_PACKET, UnloadChunkPacket::class); + } + + private function getPacket($buffer){ + $pid = ord($buffer{0}); + + if(($data = $this->getPacketFromPool($pid)) === null){ + $data = UnknownPacket::getFromPool(); + $data->packetID = $pid; + } $data->setBuffer(substr($buffer, 1)); return $data; diff --git a/src/pocketmine/network/protocol/AddEntityPacket.php b/src/pocketmine/network/protocol/AddEntityPacket.php index aff5ae6cc..adf2d82ca 100644 --- a/src/pocketmine/network/protocol/AddEntityPacket.php +++ b/src/pocketmine/network/protocol/AddEntityPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class AddEntityPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $eid; public $type; public $x; diff --git a/src/pocketmine/network/protocol/AddItemEntityPacket.php b/src/pocketmine/network/protocol/AddItemEntityPacket.php index 8a7fa8384..fadf84ee5 100644 --- a/src/pocketmine/network/protocol/AddItemEntityPacket.php +++ b/src/pocketmine/network/protocol/AddItemEntityPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class AddItemEntityPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $eid; public $item; public $x; diff --git a/src/pocketmine/network/protocol/AddMobPacket.php b/src/pocketmine/network/protocol/AddMobPacket.php index aafb9ea3f..e0ce55383 100644 --- a/src/pocketmine/network/protocol/AddMobPacket.php +++ b/src/pocketmine/network/protocol/AddMobPacket.php @@ -24,6 +24,9 @@ namespace pocketmine\network\protocol; use pocketmine\utils\Binary; class AddMobPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $eid; public $type; public $x; diff --git a/src/pocketmine/network/protocol/AddPaintingPacket.php b/src/pocketmine/network/protocol/AddPaintingPacket.php index 97ff094b3..1cb292ebe 100644 --- a/src/pocketmine/network/protocol/AddPaintingPacket.php +++ b/src/pocketmine/network/protocol/AddPaintingPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class AddPaintingPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $eid; public $x; public $y; diff --git a/src/pocketmine/network/protocol/AddPlayerPacket.php b/src/pocketmine/network/protocol/AddPlayerPacket.php index 681e0c9d0..7137be69a 100644 --- a/src/pocketmine/network/protocol/AddPlayerPacket.php +++ b/src/pocketmine/network/protocol/AddPlayerPacket.php @@ -24,6 +24,9 @@ namespace pocketmine\network\protocol; use pocketmine\utils\Binary; class AddPlayerPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $clientID; public $username; public $eid; diff --git a/src/pocketmine/network/protocol/AdventureSettingsPacket.php b/src/pocketmine/network/protocol/AdventureSettingsPacket.php index 66ad09d91..8c4de6e73 100644 --- a/src/pocketmine/network/protocol/AdventureSettingsPacket.php +++ b/src/pocketmine/network/protocol/AdventureSettingsPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class AdventureSettingsPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $flags; public function pid(){ diff --git a/src/pocketmine/network/protocol/AnimatePacket.php b/src/pocketmine/network/protocol/AnimatePacket.php index b418cc148..fa17c317d 100644 --- a/src/pocketmine/network/protocol/AnimatePacket.php +++ b/src/pocketmine/network/protocol/AnimatePacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class AnimatePacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $action; public $eid; diff --git a/src/pocketmine/network/protocol/ChatPacket.php b/src/pocketmine/network/protocol/ChatPacket.php index 4dd9dc762..94f27a922 100644 --- a/src/pocketmine/network/protocol/ChatPacket.php +++ b/src/pocketmine/network/protocol/ChatPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class ChatPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $message; public function pid(){ diff --git a/src/pocketmine/network/protocol/ContainerClosePacket.php b/src/pocketmine/network/protocol/ContainerClosePacket.php index 46f2be2d8..23859a5fe 100644 --- a/src/pocketmine/network/protocol/ContainerClosePacket.php +++ b/src/pocketmine/network/protocol/ContainerClosePacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class ContainerClosePacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $windowid; public function pid(){ diff --git a/src/pocketmine/network/protocol/ContainerOpenPacket.php b/src/pocketmine/network/protocol/ContainerOpenPacket.php index 5c146f615..b2f78492c 100644 --- a/src/pocketmine/network/protocol/ContainerOpenPacket.php +++ b/src/pocketmine/network/protocol/ContainerOpenPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class ContainerOpenPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $windowid; public $type; public $slots; diff --git a/src/pocketmine/network/protocol/ContainerSetContentPacket.php b/src/pocketmine/network/protocol/ContainerSetContentPacket.php index dda4bb220..713fdf6c3 100644 --- a/src/pocketmine/network/protocol/ContainerSetContentPacket.php +++ b/src/pocketmine/network/protocol/ContainerSetContentPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class ContainerSetContentPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $windowid; public $slots = []; public $hotbar = []; @@ -31,6 +34,12 @@ class ContainerSetContentPacket extends DataPacket{ return Info::CONTAINER_SET_CONTENT_PACKET; } + public function clean(){ + $this->slots = []; + $this->hotbar = []; + return parent::clean(); + } + public function decode(){ $this->windowid = $this->getByte(); $count = $this->getShort(); diff --git a/src/pocketmine/network/protocol/ContainerSetDataPacket.php b/src/pocketmine/network/protocol/ContainerSetDataPacket.php index 160453832..9f68827bb 100644 --- a/src/pocketmine/network/protocol/ContainerSetDataPacket.php +++ b/src/pocketmine/network/protocol/ContainerSetDataPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class ContainerSetDataPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $windowid; public $property; public $value; diff --git a/src/pocketmine/network/protocol/ContainerSetSlotPacket.php b/src/pocketmine/network/protocol/ContainerSetSlotPacket.php index c24119150..dce05fdb6 100644 --- a/src/pocketmine/network/protocol/ContainerSetSlotPacket.php +++ b/src/pocketmine/network/protocol/ContainerSetSlotPacket.php @@ -24,6 +24,9 @@ namespace pocketmine\network\protocol; use pocketmine\item\Item; class ContainerSetSlotPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $windowid; public $slot; /** @var Item */ diff --git a/src/pocketmine/network/protocol/DataPacket.php b/src/pocketmine/network/protocol/DataPacket.php index b3ab23f74..7d7a599e0 100644 --- a/src/pocketmine/network/protocol/DataPacket.php +++ b/src/pocketmine/network/protocol/DataPacket.php @@ -25,6 +25,26 @@ use pocketmine\item\Item; use pocketmine\utils\Binary; abstract class DataPacket extends \stdClass{ + + /** @var DataPacket[] */ + public static $pool = []; + public static $next = 0; + + public static function getFromPool(){ + if(static::$next >= count(static::$pool)){ + $pk = static::class; + static::$pool[] = new $pk; + } + return static::$pool[static::$next++]->clean(); + } + + public static function cleanPool(){ + if(static::$next > 4096){ + static::$pool = []; + } + static::$next = 0; + } + private $offset = 0; public $buffer = ""; public $isEncoded = false; @@ -172,4 +192,11 @@ abstract class DataPacket extends \stdClass{ protected function feof(){ return !isset($this->buffer{$this->offset}); } + + public function clean(){ + $this->buffer = null; + $this->isEncoded = false; + $this->offset = 0; + return $this; + } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/DropItemPacket.php b/src/pocketmine/network/protocol/DropItemPacket.php index 99de843b3..83f57a1df 100644 --- a/src/pocketmine/network/protocol/DropItemPacket.php +++ b/src/pocketmine/network/protocol/DropItemPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class DropItemPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $eid; public $unknown; public $item; diff --git a/src/pocketmine/network/protocol/EntityDataPacket.php b/src/pocketmine/network/protocol/EntityDataPacket.php index ccc45f51e..78ed32963 100644 --- a/src/pocketmine/network/protocol/EntityDataPacket.php +++ b/src/pocketmine/network/protocol/EntityDataPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class EntityDataPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $x; public $y; public $z; diff --git a/src/pocketmine/network/protocol/EntityEventPacket.php b/src/pocketmine/network/protocol/EntityEventPacket.php index 2e27bcd91..40530f0a5 100644 --- a/src/pocketmine/network/protocol/EntityEventPacket.php +++ b/src/pocketmine/network/protocol/EntityEventPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class EntityEventPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $eid; public $event; diff --git a/src/pocketmine/network/protocol/ExplodePacket.php b/src/pocketmine/network/protocol/ExplodePacket.php index 410c9a9d2..f3ff0062c 100644 --- a/src/pocketmine/network/protocol/ExplodePacket.php +++ b/src/pocketmine/network/protocol/ExplodePacket.php @@ -23,16 +23,24 @@ namespace pocketmine\network\protocol; class ExplodePacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $x; public $y; public $z; public $radius; - public $records; + public $records = []; public function pid(){ return Info::EXPLODE_PACKET; } + public function clean(){ + $this->records = []; + return parent::clean(); + } + public function decode(){ } diff --git a/src/pocketmine/network/protocol/FullChunkDataPacket.php b/src/pocketmine/network/protocol/FullChunkDataPacket.php index 23e3b2487..e596457a2 100644 --- a/src/pocketmine/network/protocol/FullChunkDataPacket.php +++ b/src/pocketmine/network/protocol/FullChunkDataPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class FullChunkDataPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $chunkX; public $chunkZ; public $data; diff --git a/src/pocketmine/network/protocol/HurtArmorPacket.php b/src/pocketmine/network/protocol/HurtArmorPacket.php index 503e2a174..e99c40aa3 100644 --- a/src/pocketmine/network/protocol/HurtArmorPacket.php +++ b/src/pocketmine/network/protocol/HurtArmorPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class HurtArmorPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $health; public function pid(){ diff --git a/src/pocketmine/network/protocol/InteractPacket.php b/src/pocketmine/network/protocol/InteractPacket.php index 1b7de5ff3..679dcaa44 100644 --- a/src/pocketmine/network/protocol/InteractPacket.php +++ b/src/pocketmine/network/protocol/InteractPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class InteractPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $action; public $eid; public $target; diff --git a/src/pocketmine/network/protocol/LevelEventPacket.php b/src/pocketmine/network/protocol/LevelEventPacket.php index 232ec9812..912960ba0 100644 --- a/src/pocketmine/network/protocol/LevelEventPacket.php +++ b/src/pocketmine/network/protocol/LevelEventPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class LevelEventPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $evid; public $x; public $y; diff --git a/src/pocketmine/network/protocol/LoginPacket.php b/src/pocketmine/network/protocol/LoginPacket.php index d02c47cff..ee8b98f4e 100644 --- a/src/pocketmine/network/protocol/LoginPacket.php +++ b/src/pocketmine/network/protocol/LoginPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class LoginPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $username; public $protocol1; public $protocol2; diff --git a/src/pocketmine/network/protocol/LoginStatusPacket.php b/src/pocketmine/network/protocol/LoginStatusPacket.php index 1de99be2e..6bfb3fb87 100644 --- a/src/pocketmine/network/protocol/LoginStatusPacket.php +++ b/src/pocketmine/network/protocol/LoginStatusPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class LoginStatusPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $status; public function pid(){ diff --git a/src/pocketmine/network/protocol/MessagePacket.php b/src/pocketmine/network/protocol/MessagePacket.php index a4a36e810..da9849028 100644 --- a/src/pocketmine/network/protocol/MessagePacket.php +++ b/src/pocketmine/network/protocol/MessagePacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class MessagePacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $source; public $message; diff --git a/src/pocketmine/network/protocol/MoveEntityPacket.php b/src/pocketmine/network/protocol/MoveEntityPacket.php index 40f91b99d..254a67bb9 100644 --- a/src/pocketmine/network/protocol/MoveEntityPacket.php +++ b/src/pocketmine/network/protocol/MoveEntityPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class MoveEntityPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + // eid, x, y, z, yaw, pitch /** @var array[] */ @@ -32,6 +35,11 @@ class MoveEntityPacket extends DataPacket{ return Info::MOVE_ENTITY_PACKET; } + public function clean(){ + $this->entities = []; + return parent::clean(); + } + public function decode(){ } diff --git a/src/pocketmine/network/protocol/MovePlayerPacket.php b/src/pocketmine/network/protocol/MovePlayerPacket.php index 2f465baf7..08f618ee6 100644 --- a/src/pocketmine/network/protocol/MovePlayerPacket.php +++ b/src/pocketmine/network/protocol/MovePlayerPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class MovePlayerPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $eid; public $x; public $y; @@ -36,6 +39,11 @@ class MovePlayerPacket extends DataPacket{ return Info::MOVE_PLAYER_PACKET; } + public function clean(){ + $this->teleport = false; + return parent::clean(); + } + public function decode(){ $this->eid = $this->getInt(); $this->x = $this->getFloat(); diff --git a/src/pocketmine/network/protocol/PlayerActionPacket.php b/src/pocketmine/network/protocol/PlayerActionPacket.php index 4c322a1bf..7083ac53d 100644 --- a/src/pocketmine/network/protocol/PlayerActionPacket.php +++ b/src/pocketmine/network/protocol/PlayerActionPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class PlayerActionPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $action; public $x; public $y; diff --git a/src/pocketmine/network/protocol/PlayerArmorEquipmentPacket.php b/src/pocketmine/network/protocol/PlayerArmorEquipmentPacket.php index 8fa462ac7..12b2b5b45 100644 --- a/src/pocketmine/network/protocol/PlayerArmorEquipmentPacket.php +++ b/src/pocketmine/network/protocol/PlayerArmorEquipmentPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class PlayerArmorEquipmentPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $eid; public $slots = []; diff --git a/src/pocketmine/network/protocol/PlayerEquipmentPacket.php b/src/pocketmine/network/protocol/PlayerEquipmentPacket.php index 52cbf64ce..ef49395ce 100644 --- a/src/pocketmine/network/protocol/PlayerEquipmentPacket.php +++ b/src/pocketmine/network/protocol/PlayerEquipmentPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class PlayerEquipmentPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $eid; public $item; public $meta; diff --git a/src/pocketmine/network/protocol/RemoveBlockPacket.php b/src/pocketmine/network/protocol/RemoveBlockPacket.php index 75cdd6eb3..e38a61d8d 100644 --- a/src/pocketmine/network/protocol/RemoveBlockPacket.php +++ b/src/pocketmine/network/protocol/RemoveBlockPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class RemoveBlockPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $eid; public $x; public $y; diff --git a/src/pocketmine/network/protocol/RemoveEntityPacket.php b/src/pocketmine/network/protocol/RemoveEntityPacket.php index d5306fae3..a6e0bdd9f 100644 --- a/src/pocketmine/network/protocol/RemoveEntityPacket.php +++ b/src/pocketmine/network/protocol/RemoveEntityPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class RemoveEntityPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $eid; public function pid(){ diff --git a/src/pocketmine/network/protocol/RemovePlayerPacket.php b/src/pocketmine/network/protocol/RemovePlayerPacket.php index bc35b25e6..1f621244c 100644 --- a/src/pocketmine/network/protocol/RemovePlayerPacket.php +++ b/src/pocketmine/network/protocol/RemovePlayerPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class RemovePlayerPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $eid; public $clientID; diff --git a/src/pocketmine/network/protocol/RespawnPacket.php b/src/pocketmine/network/protocol/RespawnPacket.php index 076c9b4dd..7dd6086ea 100644 --- a/src/pocketmine/network/protocol/RespawnPacket.php +++ b/src/pocketmine/network/protocol/RespawnPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class RespawnPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $eid; public $x; public $y; diff --git a/src/pocketmine/network/protocol/RotateHeadPacket.php b/src/pocketmine/network/protocol/RotateHeadPacket.php index 92497f609..f47d05a5a 100644 --- a/src/pocketmine/network/protocol/RotateHeadPacket.php +++ b/src/pocketmine/network/protocol/RotateHeadPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class RotateHeadPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + // eid, yaw /** @var array[] */ @@ -32,6 +35,11 @@ class RotateHeadPacket extends DataPacket{ return Info::ROTATE_HEAD_PACKET; } + public function clean(){ + $this->entities = []; + return parent::clean(); + } + public function decode(){ } diff --git a/src/pocketmine/network/protocol/SendInventoryPacket.php b/src/pocketmine/network/protocol/SendInventoryPacket.php index c8322a91d..443a4f6e2 100644 --- a/src/pocketmine/network/protocol/SendInventoryPacket.php +++ b/src/pocketmine/network/protocol/SendInventoryPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class SendInventoryPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $eid; public $windowid; public $slots = []; diff --git a/src/pocketmine/network/protocol/SetEntityDataPacket.php b/src/pocketmine/network/protocol/SetEntityDataPacket.php index f1abadac7..3e6091f0b 100644 --- a/src/pocketmine/network/protocol/SetEntityDataPacket.php +++ b/src/pocketmine/network/protocol/SetEntityDataPacket.php @@ -24,6 +24,9 @@ namespace pocketmine\network\protocol; use pocketmine\utils\Binary; class SetEntityDataPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $eid; public $metadata; diff --git a/src/pocketmine/network/protocol/SetEntityMotionPacket.php b/src/pocketmine/network/protocol/SetEntityMotionPacket.php index 4b207be77..16e76eedd 100644 --- a/src/pocketmine/network/protocol/SetEntityMotionPacket.php +++ b/src/pocketmine/network/protocol/SetEntityMotionPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class SetEntityMotionPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + // eid, motX, motY, motZ /** @var array[] */ @@ -32,6 +35,11 @@ class SetEntityMotionPacket extends DataPacket{ return Info::SET_ENTITY_MOTION_PACKET; } + public function clean(){ + $this->entities = []; + return parent::clean(); + } + public function decode(){ } diff --git a/src/pocketmine/network/protocol/SetHealthPacket.php b/src/pocketmine/network/protocol/SetHealthPacket.php index 036402faa..2f9cc81fb 100644 --- a/src/pocketmine/network/protocol/SetHealthPacket.php +++ b/src/pocketmine/network/protocol/SetHealthPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class SetHealthPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $health; public function pid(){ diff --git a/src/pocketmine/network/protocol/SetSpawnPositionPacket.php b/src/pocketmine/network/protocol/SetSpawnPositionPacket.php index 0862adcad..785b9b553 100644 --- a/src/pocketmine/network/protocol/SetSpawnPositionPacket.php +++ b/src/pocketmine/network/protocol/SetSpawnPositionPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class SetSpawnPositionPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $x; public $z; public $y; diff --git a/src/pocketmine/network/protocol/SetTimePacket.php b/src/pocketmine/network/protocol/SetTimePacket.php index bfa51a5da..670f0e204 100644 --- a/src/pocketmine/network/protocol/SetTimePacket.php +++ b/src/pocketmine/network/protocol/SetTimePacket.php @@ -25,6 +25,9 @@ namespace pocketmine\network\protocol; use pocketmine\level\Level; class SetTimePacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $time; public $started = true; diff --git a/src/pocketmine/network/protocol/StartGamePacket.php b/src/pocketmine/network/protocol/StartGamePacket.php index eb610c1a2..dcf652b66 100644 --- a/src/pocketmine/network/protocol/StartGamePacket.php +++ b/src/pocketmine/network/protocol/StartGamePacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class StartGamePacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $seed; public $generator; public $gamemode; diff --git a/src/pocketmine/network/protocol/TakeItemEntityPacket.php b/src/pocketmine/network/protocol/TakeItemEntityPacket.php index 918382c18..6dee90837 100644 --- a/src/pocketmine/network/protocol/TakeItemEntityPacket.php +++ b/src/pocketmine/network/protocol/TakeItemEntityPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class TakeItemEntityPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $target; public $eid; diff --git a/src/pocketmine/network/protocol/TileEventPacket.php b/src/pocketmine/network/protocol/TileEventPacket.php index 28c01b7d6..8c461c7a8 100644 --- a/src/pocketmine/network/protocol/TileEventPacket.php +++ b/src/pocketmine/network/protocol/TileEventPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class TileEventPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $x; public $y; public $z; diff --git a/src/pocketmine/network/protocol/UnknownPacket.php b/src/pocketmine/network/protocol/UnknownPacket.php index f873d1919..93ac17343 100644 --- a/src/pocketmine/network/protocol/UnknownPacket.php +++ b/src/pocketmine/network/protocol/UnknownPacket.php @@ -24,6 +24,9 @@ namespace pocketmine\network\protocol; class UnknownPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $packetID = -1; public function pid(){ diff --git a/src/pocketmine/network/protocol/UnloadChunkPacket.php b/src/pocketmine/network/protocol/UnloadChunkPacket.php index 6a363152e..1a4ee0c3b 100644 --- a/src/pocketmine/network/protocol/UnloadChunkPacket.php +++ b/src/pocketmine/network/protocol/UnloadChunkPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class UnloadChunkPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $chunkX; public $chunkZ; diff --git a/src/pocketmine/network/protocol/UpdateBlockPacket.php b/src/pocketmine/network/protocol/UpdateBlockPacket.php index b24b86b30..f4aeb81bf 100644 --- a/src/pocketmine/network/protocol/UpdateBlockPacket.php +++ b/src/pocketmine/network/protocol/UpdateBlockPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class UpdateBlockPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $x; public $z; public $y; diff --git a/src/pocketmine/network/protocol/UseItemPacket.php b/src/pocketmine/network/protocol/UseItemPacket.php index 9a32f9d69..d198d9e4e 100644 --- a/src/pocketmine/network/protocol/UseItemPacket.php +++ b/src/pocketmine/network/protocol/UseItemPacket.php @@ -23,6 +23,9 @@ namespace pocketmine\network\protocol; class UseItemPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + public $x; public $y; public $z; diff --git a/src/pocketmine/tile/Furnace.php b/src/pocketmine/tile/Furnace.php index 5207aa827..2f722f500 100644 --- a/src/pocketmine/tile/Furnace.php +++ b/src/pocketmine/tile/Furnace.php @@ -252,13 +252,13 @@ class Furnace extends Tile implements InventoryHolder, Container{ foreach($this->getInventory()->getViewers() as $player){ $windowId = $player->getWindowId($this->getInventory()); if($windowId > 0){ - $pk = new ContainerSetDataPacket; + $pk = ContainerSetDataPacket::getFromPool(); $pk->windowid = $windowId; $pk->property = 0; //Smelting $pk->value = floor($this->namedtag["CookTime"]); $player->dataPacket($pk); - $pk = new ContainerSetDataPacket; + $pk = ContainerSetDataPacket::getFromPool(); $pk->windowid = $windowId; $pk->property = 1; //Fire icon $pk->value = $this->namedtag["BurnTicks"]; diff --git a/src/pocketmine/tile/Spawnable.php b/src/pocketmine/tile/Spawnable.php index 4e62c94d2..5f8d157b2 100644 --- a/src/pocketmine/tile/Spawnable.php +++ b/src/pocketmine/tile/Spawnable.php @@ -36,7 +36,7 @@ abstract class Spawnable extends Tile{ $nbt = new NBT(NBT::LITTLE_ENDIAN); $nbt->setData($this->getSpawnCompound()); - $pk = new EntityDataPacket; + $pk = EntityDataPacket::getFromPool(); $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; From ca92d2a0d3100e7e767acd4aa027989529b843ef Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 27 Oct 2014 20:30:58 +0100 Subject: [PATCH 13/61] Bumped API version to 1.7.0 --- src/pocketmine/PocketMine.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 0701c6fd5..046a4e597 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -72,7 +72,7 @@ namespace pocketmine { use pocketmine\wizard\Installer; const VERSION = "Alpha_1.4dev"; - const API_VERSION = "1.6.1"; + const API_VERSION = "1.7.0"; const CODENAME = "絶好(Zekkou)ケーキ(Cake)"; const MINECRAFT_VERSION = "v0.9.5 alpha"; From 8f1eb41ca51223e628131420682433b242615bda Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 28 Oct 2014 00:22:32 +0100 Subject: [PATCH 14/61] RakLib update --- src/raklib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/raklib b/src/raklib index 879e8540d..620703483 160000 --- a/src/raklib +++ b/src/raklib @@ -1 +1 @@ -Subproject commit 879e8540dd4623ec2f188d6e668ae801163a1875 +Subproject commit 62070348355f6ac6dba17a53939aa5c5b8d788c2 From 119b429ab8d652c764de8f1fb98bc1dc3bbfc2e4 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 28 Oct 2014 00:43:47 +0100 Subject: [PATCH 15/61] RakLib update --- src/raklib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/raklib b/src/raklib index 620703483..7e07ffbe9 160000 --- a/src/raklib +++ b/src/raklib @@ -1 +1 @@ -Subproject commit 62070348355f6ac6dba17a53939aa5c5b8d788c2 +Subproject commit 7e07ffbe9461c1b2487fac9dd7fd542f7fccec34 From 4299ebebcc4e545383b620577c67894c0da7db82 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 28 Oct 2014 00:55:07 +0100 Subject: [PATCH 16/61] Bump API version to 1.6.1 --- src/pocketmine/block/Lava.php | 4 ++++ src/pocketmine/block/Water.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/pocketmine/block/Lava.php b/src/pocketmine/block/Lava.php index 726844205..8d1e1127e 100644 --- a/src/pocketmine/block/Lava.php +++ b/src/pocketmine/block/Lava.php @@ -49,6 +49,10 @@ class Lava extends Liquid{ if(!$ev->isCancelled()){ $entity->setOnFire($ev->getDuration()); } + + if($entity instanceof Player){ + $entity->onGround = true; + } } public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ diff --git a/src/pocketmine/block/Water.php b/src/pocketmine/block/Water.php index 4ca589815..8a8bbe3be 100644 --- a/src/pocketmine/block/Water.php +++ b/src/pocketmine/block/Water.php @@ -36,6 +36,10 @@ class Water extends Liquid{ if($entity->fireTicks > 0){ $entity->extinguish(); } + + if($entity instanceof Player){ + $entity->onGround = true; + } } public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ From 69492474e46d2dbec52a45fef584dea349f4851e Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 28 Oct 2014 02:09:36 +0100 Subject: [PATCH 17/61] Improve #2238, do not crash when an invalid/corrupt RCON stop event happens --- src/pocketmine/network/rcon/RCON.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/network/rcon/RCON.php b/src/pocketmine/network/rcon/RCON.php index 60a24aab6..fa60f7837 100644 --- a/src/pocketmine/network/rcon/RCON.php +++ b/src/pocketmine/network/rcon/RCON.php @@ -38,7 +38,7 @@ class RCON{ private $socket; private $password; /** @var RCONInstance[] */ - private $workers; + private $workers = []; private $clientsPerThread; public function __construct(Server $server, $password, $port = 19132, $interface = "0.0.0.0", $threads = 1, $clientsPerThread = 50){ @@ -56,7 +56,7 @@ class RCON{ $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if($this->socket === false or !socket_bind($this->socket, $interface, (int) $port) or !socket_listen($this->socket)){ $this->server->getLogger()->critical("RCON can't be started: " . socket_strerror(socket_last_error())); - + $this->threads = 0; return; } socket_set_block($this->socket); From 144a871c072f7f6415ec66ad5c6f3cdf65f92c07 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 28 Oct 2014 10:03:10 +0100 Subject: [PATCH 18/61] Improved Vector3 and Block handling, less allocation on Positions --- src/pocketmine/Player.php | 7 ++- src/pocketmine/Server.php | 12 ++--- src/pocketmine/block/Block.php | 2 +- src/pocketmine/block/Cactus.php | 2 +- src/pocketmine/block/Grass.php | 2 +- src/pocketmine/block/Mycelium.php | 2 +- .../command/defaults/SpawnpointCommand.php | 4 +- .../command/defaults/TeleportCommand.php | 2 +- src/pocketmine/entity/Entity.php | 4 +- src/pocketmine/entity/FallingBlock.php | 4 +- .../event/entity/EntityMotionEvent.php | 5 +- .../event/entity/EntityMoveEvent.php | 2 +- src/pocketmine/level/Explosion.php | 2 +- src/pocketmine/level/Level.php | 8 ++-- src/pocketmine/level/Position.php | 48 +++++++++++++++++-- src/pocketmine/math/AxisAlignedBB.php | 6 ++- src/pocketmine/math/Vector3.php | 6 ++- src/pocketmine/tile/Chest.php | 2 +- 18 files changed, 85 insertions(+), 35 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 4a0f422a2..c87fb9c11 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -650,8 +650,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $pk->started = $this->level->stopTime == false; $this->dataPacket($pk); - $pos = new Position($this->x, $this->y, $this->z, $this->level); - $pos = $this->level->getSafeSpawn($pos); + $pos = $this->level->getSafeSpawn($this); $this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $pos)); @@ -809,8 +808,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ return false; } - $this->sleeping = $pos; - $this->teleport(new Position($pos->x + 0.5, $pos->y + 1, $pos->z + 0.5, $this->level)); + $this->sleeping = clone $pos; + $this->teleport(Position::createPosition($pos->x + 0.5, $pos->y + 1, $pos->z + 0.5, $this->level)); $this->sendMetadata($this->getViewers()); $this->sendMetadata($this); diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 18b76853b..6cb8bfaf6 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -50,6 +50,7 @@ use pocketmine\level\generator\GenerationRequestManager; use pocketmine\level\generator\Generator; use pocketmine\level\generator\Normal; use pocketmine\level\Level; +use pocketmine\level\Position; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Vector3; use pocketmine\metadata\EntityMetadataStore; @@ -917,6 +918,7 @@ class Server{ */ public function unloadLevel(Level $level, $forceUnload = false){ if($level->unload($forceUnload) === true){ + Position::clearPositions(); unset($this->levels[$level->getID()]); return true; @@ -2114,13 +2116,9 @@ class Server{ $this->generationManager->process(); - if(($this->tickCounter % 600) === 0){ - Vector3::clearVectors(); - AxisAlignedBB::clearBoundingBoxes(); - }else{ - Vector3::clearVectorList(); - AxisAlignedBB::clearBoundingBoxPool(); - } + Vector3::clearVectorList(); + Position::clearPositionList(); + AxisAlignedBB::clearBoundingBoxPool(); Timings::$serverTickTimer->stopTiming(); diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 6374fa73a..0cafde47b 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -686,7 +686,7 @@ class Block extends Position implements Metadatable{ $block = new Block($id, $meta); } - if($pos instanceof Position){ + if($pos !== null){ $block->x = $pos->x; $block->y = $pos->y; $block->z = $pos->z; diff --git a/src/pocketmine/block/Cactus.php b/src/pocketmine/block/Cactus.php index 29110b7da..b7e11434e 100644 --- a/src/pocketmine/block/Cactus.php +++ b/src/pocketmine/block/Cactus.php @@ -28,7 +28,7 @@ use pocketmine\event\entity\EntityDamageEvent; use pocketmine\item\Item; use pocketmine\level\Level; use pocketmine\math\AxisAlignedBB; -use pocketmine\math\Vector3 as Vector3; +use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\Server; diff --git a/src/pocketmine/block/Grass.php b/src/pocketmine/block/Grass.php index c36ef51aa..167b8a11a 100644 --- a/src/pocketmine/block/Grass.php +++ b/src/pocketmine/block/Grass.php @@ -56,7 +56,7 @@ class Grass extends Solid{ $z = mt_rand($this->z - 1, $this->z + 1); $block = $this->getLevel()->getBlockIdAt($x, $y, $z); if($block === Block::DIRT){ - $block = Block::get($block, $this->getLevel()->getBlockDataAt($x, $y, $z), new Position($x, $y, $z, $this->getLevel())); + $block = Block::get($block, $this->getLevel()->getBlockDataAt($x, $y, $z), Position::createPosition($x, $y, $z, $this->getLevel())); if($block->getSide(1) instanceof Transparent){ Server::getInstance()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($block, $this, new Grass())); if(!$ev->isCancelled()){ diff --git a/src/pocketmine/block/Mycelium.php b/src/pocketmine/block/Mycelium.php index 433661ade..784d2350d 100644 --- a/src/pocketmine/block/Mycelium.php +++ b/src/pocketmine/block/Mycelium.php @@ -47,7 +47,7 @@ class Mycelium extends Solid{ $z = mt_rand($this->z - 1, $this->z + 1); $block = $this->getLevel()->getBlockIdAt($x, $y, $z); if($block === Block::DIRT){ - $block = Block::get($block, $this->getLevel()->getBlockDataAt($x, $y, $z), new Position($x, $y, $z, $this->getLevel())); + $block = Block::get($block, $this->getLevel()->getBlockDataAt($x, $y, $z), Position::createPosition($x, $y, $z, $this->getLevel())); if($block->getSide(1) instanceof Transparent){ Server::getInstance()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($block, $this, new Mycelium())); if(!$ev->isCancelled()){ diff --git a/src/pocketmine/command/defaults/SpawnpointCommand.php b/src/pocketmine/command/defaults/SpawnpointCommand.php index 2aad6c167..8c05f7f30 100644 --- a/src/pocketmine/command/defaults/SpawnpointCommand.php +++ b/src/pocketmine/command/defaults/SpawnpointCommand.php @@ -70,14 +70,14 @@ class SpawnpointCommand extends VanillaCommand{ $x = (int) $this->getRelativeDouble($pos->x, $sender, $args[1]); $y = $this->getRelativeDouble($pos->y, $sender, $args[2], 0, 128); $z = $this->getRelativeDouble($pos->z, $sender, $args[3]); - $target->setSpawn(new Position($x, $y, $z, $level)); + $target->setSpawn(Position::createPosition($x, $y, $z, $level)); Command::broadcastCommandMessage($sender, "Set " . $target->getDisplayName() . "'s spawnpoint to " . $x . ", " . $y . ", " . $z); return true; } }elseif(count($args) <= 1){ if($sender instanceof Player){ - $pos = new Position((int) $sender->x, (int) $sender->y, (int) $sender->z, $sender->getLevel()); + $pos = Position::createPosition((int) $sender->x, (int) $sender->y, (int) $sender->z, $sender->getLevel()); $target->setSpawn($pos); Command::broadcastCommandMessage($sender, "Set " . $target->getDisplayName() . "'s spawnpoint to " . $pos->x . ", " . $pos->y . ", " . $pos->z); diff --git a/src/pocketmine/command/defaults/TeleportCommand.php b/src/pocketmine/command/defaults/TeleportCommand.php index fa6cf24e6..558648722 100644 --- a/src/pocketmine/command/defaults/TeleportCommand.php +++ b/src/pocketmine/command/defaults/TeleportCommand.php @@ -88,7 +88,7 @@ class TeleportCommand extends VanillaCommand{ } if(count($args) < 3){ - $pos = new Position($target->x, $target->y, $target->z, $target->getLevel()); + $pos = Position::clonePosition($target); $origin->teleport($pos); Command::broadcastCommandMessage($sender, "Teleported " . $origin->getDisplayName() . " to " . $target->getDisplayName()); diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 3c2118f65..6fd22b953 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -40,7 +40,7 @@ use pocketmine\level\Location; use pocketmine\level\Position; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Math; -use pocketmine\math\Vector3 as Vector3; +use pocketmine\math\Vector3; use pocketmine\metadata\Metadatable; use pocketmine\metadata\MetadataValue; use pocketmine\nbt\tag\Byte; @@ -737,7 +737,7 @@ abstract class Entity extends Location implements Metadatable{ } public function getPosition(){ - return new Position($this->x, $this->y, $this->z, $this->level); + return Position::createPosition($this->x, $this->y, $this->z, $this->level); } public function getLocation(){ diff --git a/src/pocketmine/entity/FallingBlock.php b/src/pocketmine/entity/FallingBlock.php index e05a6aa92..b23fa1067 100644 --- a/src/pocketmine/entity/FallingBlock.php +++ b/src/pocketmine/entity/FallingBlock.php @@ -88,7 +88,7 @@ class FallingBlock extends Entity{ if(!$this->dead){ if($this->ticksLived === 1){ - $block = $this->level->getBlock($pos = Vector3::createVector($this->x, $this->y, $this->z)->floor()); + $block = $this->level->getBlock($pos = Vector3::cloneVector($this)->floor()); if($block->getID() != $this->blockId){ $this->kill(); return true; @@ -107,7 +107,7 @@ class FallingBlock extends Entity{ $this->motionY *= 1 - $this->drag; $this->motionZ *= $friction; - $pos = Vector3::createVector($this->x, $this->y, $this->z)->floor(); + $pos = Vector3::cloneVector($this)->floor(); if($this->onGround){ $this->kill(); diff --git a/src/pocketmine/event/entity/EntityMotionEvent.php b/src/pocketmine/event/entity/EntityMotionEvent.php index 4d25620ea..6c0ea6b75 100644 --- a/src/pocketmine/event/entity/EntityMotionEvent.php +++ b/src/pocketmine/event/entity/EntityMotionEvent.php @@ -24,7 +24,7 @@ namespace pocketmine\event\entity; use pocketmine\entity\Entity; use pocketmine\Event; use pocketmine\event\Cancellable; -use pocketmine\math\Vector3 as Vector3; +use pocketmine\math\Vector3; class EntityMotionEvent extends EntityEvent implements Cancellable{ public static $handlerList = null; @@ -36,6 +36,9 @@ class EntityMotionEvent extends EntityEvent implements Cancellable{ $this->mot = $mot; } + /** + * @return Vector3 + */ public function getVector(){ return $this->mot; } diff --git a/src/pocketmine/event/entity/EntityMoveEvent.php b/src/pocketmine/event/entity/EntityMoveEvent.php index 74602a46a..099c9a7a4 100644 --- a/src/pocketmine/event/entity/EntityMoveEvent.php +++ b/src/pocketmine/event/entity/EntityMoveEvent.php @@ -24,7 +24,7 @@ namespace pocketmine\event\entity; use pocketmine\entity\Entity; use pocketmine\Event; use pocketmine\event\Cancellable; -use pocketmine\math\Vector3 as Vector3; +use pocketmine\math\Vector3; /** * @deprecated diff --git a/src/pocketmine/level/Explosion.php b/src/pocketmine/level/Explosion.php index 47ce62703..b4eeaf0e0 100644 --- a/src/pocketmine/level/Explosion.php +++ b/src/pocketmine/level/Explosion.php @@ -33,7 +33,7 @@ use pocketmine\event\entity\EntityExplodeEvent; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Math; -use pocketmine\math\Vector3 as Vector3; +use pocketmine\math\Vector3; use pocketmine\nbt\tag\Byte; use pocketmine\nbt\tag\Compound; use pocketmine\nbt\tag\Double; diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 5d3154ea8..908465c38 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -910,7 +910,7 @@ class Level implements ChunkManager, Metadatable{ return $this->blockCache[$index] = $air; } - return $this->blockCache[$index] = Block::get($blockId, $meta, new Position($pos->x, $pos->y, $pos->z, $this)); + return $this->blockCache[$index] = Block::get($blockId, $meta, $pos instanceof Position ? $pos : Position::createPosition($pos->x, $pos->y, $pos->z, $this)); } /** @@ -940,7 +940,7 @@ class Level implements ChunkManager, Metadatable{ if($this->getChunk($pos->x >> 4, $pos->z >> 4, true)->setBlock($pos->x & 0x0f, $pos->y & 0x7f, $pos->z & 0x0f, $block->getID(), $block->getDamage())){ if(!($pos instanceof Position)){ - $pos = new Position($pos->x, $pos->y, $pos->z, $this); + $pos = Position::createPosition($pos->x, $pos->y, $pos->z, $this); } $block->position($pos); $index = Level::chunkHash($pos->x >> 4, $pos->z >> 4); @@ -1938,14 +1938,14 @@ class Level implements ChunkManager, Metadatable{ for(; $v->y < 128; ++$v->y){ if($this->getBlock($v->getSide(1)) instanceof Air){ if($this->getBlock($v) instanceof Air){ - return new Position($spawn->x, $v->y === Math::floorFloat($spawn->y) ? $spawn->y : $v->y, $spawn->z, $this); + return Position::createPosition($spawn->x, $v->y === Math::floorFloat($spawn->y) ? $spawn->y : $v->y, $spawn->z, $this); } }else{ ++$v->y; } } - return new Position($spawn->x, $v->y, $spawn->z, $this); + return Position::createPosition($spawn->x, $v->y, $spawn->z, $this); } return false; diff --git a/src/pocketmine/level/Position.php b/src/pocketmine/level/Position.php index 8e5f63af1..a3c12460f 100644 --- a/src/pocketmine/level/Position.php +++ b/src/pocketmine/level/Position.php @@ -21,13 +21,54 @@ namespace pocketmine\level; -use pocketmine\math\Vector3 as Vector3; +use pocketmine\math\Vector3; class Position extends Vector3{ + /** @var Position[] */ + private static $positionList = []; + private static $nextPosition = 0; + /** @var Level */ public $level = null; + public static function clearPositions(){ + self::$nextPosition = 0; + self::$positionList = []; + } + + public static function clearPositionList(){ + if(self::$nextPosition > 65536){ + self::clearVectors(); + }else{ + self::$nextPosition = 0; + } + } + + /** + * @param $x + * @param $y + * @param $z + * @param Level $level + * + * @return Position + */ + public static function createPosition($x, $y, $z, Level $level){ + if(self::$nextPosition >= count(self::$positionList)){ + self::$positionList[] = new Position(0, 0, 0, null); + } + + return self::$positionList[self::$nextPosition++]->setLevel($level)->setComponents($x, $y, $z); + } + + public static function clonePosition(Position $pos){ + if(self::$nextPosition >= count(self::$positionList)){ + self::$positionList[] = new Position(0, 0, 0, null); + } + + return self::$positionList[self::$nextPosition++]->setLevel($pos->level)->setComponents($pos->x, $pos->y, $pos->z); + } + /** * @param int $x * @param int $y @@ -42,7 +83,7 @@ class Position extends Vector3{ } public static function fromObject(Vector3 $pos, Level $level = null){ - return new Position($pos->x, $pos->y, $pos->z, $level); + return self::createPosition($pos->x, $pos->y, $pos->z, $level); } /** @@ -52,8 +93,9 @@ class Position extends Vector3{ return $this->level; } - public function setLevel(Level $level, $strong = false){ + public function setLevel(Level $level){ $this->level = $level; + return $this; } /** diff --git a/src/pocketmine/math/AxisAlignedBB.php b/src/pocketmine/math/AxisAlignedBB.php index e9bc2773e..bb233da62 100644 --- a/src/pocketmine/math/AxisAlignedBB.php +++ b/src/pocketmine/math/AxisAlignedBB.php @@ -51,7 +51,11 @@ class AxisAlignedBB{ } public static function clearBoundingBoxPool(){ - self::$nextBoundingBox = 0; + if(self::$nextBoundingBox > 65536){ + self::clearBoundingBoxes(); + }else{ + self::$nextBoundingBox = 0; + } } /** diff --git a/src/pocketmine/math/Vector3.php b/src/pocketmine/math/Vector3.php index 19bcba46b..1c1abfcd5 100644 --- a/src/pocketmine/math/Vector3.php +++ b/src/pocketmine/math/Vector3.php @@ -54,7 +54,11 @@ class Vector3{ } public static function clearVectorList(){ - self::$nextVector = 0; + if(self::$nextVector > 65536){ + self::clearVectors(); + }else{ + self::$nextVector = 0; + } } /** diff --git a/src/pocketmine/tile/Chest.php b/src/pocketmine/tile/Chest.php index b0ff4f7d8..86b2b9a0f 100644 --- a/src/pocketmine/tile/Chest.php +++ b/src/pocketmine/tile/Chest.php @@ -26,7 +26,7 @@ use pocketmine\inventory\DoubleChestInventory; use pocketmine\inventory\InventoryHolder; use pocketmine\item\Item; use pocketmine\level\format\FullChunk; -use pocketmine\math\Vector3 as Vector3; +use pocketmine\math\Vector3; use pocketmine\nbt\NBT; use pocketmine\nbt\tag\Byte; use pocketmine\nbt\tag\Compound; From 350cee3d4192a19c5612c626cfd2d76ce508a0ce Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 28 Oct 2014 10:47:40 +0100 Subject: [PATCH 19/61] Added Event allocation pool, updated SPL with Class::onClassLoaded() --- src/pocketmine/Player.php | 58 +++++++++---------- src/pocketmine/Server.php | 12 ++-- src/pocketmine/block/Cactus.php | 4 +- src/pocketmine/block/Cake.php | 2 +- src/pocketmine/block/Crops.php | 4 +- src/pocketmine/block/Fire.php | 4 +- src/pocketmine/block/Grass.php | 2 +- src/pocketmine/block/Lava.php | 4 +- src/pocketmine/block/Leaves.php | 2 +- src/pocketmine/block/Leaves2.php | 2 +- src/pocketmine/block/MelonStem.php | 4 +- src/pocketmine/block/Mycelium.php | 2 +- src/pocketmine/block/PumpkinStem.php | 4 +- src/pocketmine/block/Sugarcane.php | 2 +- .../command/defaults/KillCommand.php | 2 +- src/pocketmine/entity/Arrow.php | 8 +-- src/pocketmine/entity/DroppedItem.php | 4 +- src/pocketmine/entity/Entity.php | 16 ++--- src/pocketmine/entity/FallingBlock.php | 2 +- src/pocketmine/entity/Living.php | 6 +- src/pocketmine/entity/PrimedTNT.php | 2 +- src/pocketmine/event/Event.php | 49 +++++++++++++++- .../event/block/BlockBreakEvent.php | 2 + src/pocketmine/event/block/BlockFormEvent.php | 2 + src/pocketmine/event/block/BlockGrowEvent.php | 2 + .../event/block/BlockPlaceEvent.php | 2 + .../event/block/BlockSpreadEvent.php | 2 + .../event/block/BlockUpdateEvent.php | 2 + .../event/block/LeavesDecayEvent.php | 2 + .../event/block/SignChangeEvent.php | 2 + .../event/entity/EntityArmorChangeEvent.php | 2 + .../event/entity/EntityBlockChangeEvent.php | 2 + .../entity/EntityCombustByBlockEvent.php | 2 + .../entity/EntityCombustByEntityEvent.php | 2 + .../event/entity/EntityCombustEvent.php | 2 + .../event/entity/EntityDamageByBlockEvent.php | 2 + .../entity/EntityDamageByEntityEvent.php | 2 + .../event/entity/EntityDamageEvent.php | 2 + .../event/entity/EntityDeathEvent.php | 2 + .../event/entity/EntityDespawnEvent.php | 2 + .../event/entity/EntityExplodeEvent.php | 2 + .../entity/EntityInventoryChangeEvent.php | 2 + .../event/entity/EntityLevelChangeEvent.php | 2 + .../event/entity/EntityMotionEvent.php | 2 + .../event/entity/EntityMoveEvent.php | 2 + .../event/entity/EntityRegainHealthEvent.php | 2 + .../event/entity/EntityShootBowEvent.php | 2 + .../event/entity/EntitySpawnEvent.php | 2 + .../event/entity/EntityTeleportEvent.php | 2 + .../event/entity/ExplosionPrimeEvent.php | 2 + .../event/entity/ItemDespawnEvent.php | 2 + .../event/entity/ItemSpawnEvent.php | 2 + .../event/entity/ProjectileHitEvent.php | 2 + .../event/entity/ProjectileLaunchEvent.php | 2 + .../event/inventory/CraftItemEvent.php | 2 + .../event/inventory/FurnaceBurnEvent.php | 2 + .../event/inventory/FurnaceSmeltEvent.php | 2 + .../event/inventory/InventoryCloseEvent.php | 2 + .../event/inventory/InventoryOpenEvent.php | 2 + .../inventory/InventoryPickupItemEvent.php | 2 + .../inventory/InventoryTransactionEvent.php | 2 + src/pocketmine/event/level/ChunkLoadEvent.php | 2 + .../event/level/ChunkPopulateEvent.php | 2 + .../event/level/ChunkUnloadEvent.php | 2 + src/pocketmine/event/level/LevelInitEvent.php | 2 + src/pocketmine/event/level/LevelLoadEvent.php | 2 + src/pocketmine/event/level/LevelSaveEvent.php | 2 + .../event/level/LevelUnloadEvent.php | 2 + .../event/level/SpawnChangeEvent.php | 2 + .../player/PlayerAchievementAwardedEvent.php | 2 + .../event/player/PlayerAnimationEvent.php | 2 + .../event/player/PlayerBedEnterEvent.php | 2 + .../event/player/PlayerBedLeaveEvent.php | 2 + .../event/player/PlayerBucketEmptyEvent.php | 2 + .../event/player/PlayerBucketFillEvent.php | 2 + .../event/player/PlayerChatEvent.php | 2 + .../player/PlayerCommandPreprocessEvent.php | 2 + .../event/player/PlayerDeathEvent.php | 2 + .../event/player/PlayerDropItemEvent.php | 2 + .../player/PlayerGameModeChangeEvent.php | 2 + .../event/player/PlayerInteractEvent.php | 2 + .../event/player/PlayerItemConsumeEvent.php | 2 + .../event/player/PlayerItemHeldEvent.php | 2 + .../event/player/PlayerJoinEvent.php | 2 + .../event/player/PlayerKickEvent.php | 2 + .../event/player/PlayerLoginEvent.php | 2 + .../event/player/PlayerMoveEvent.php | 2 + .../event/player/PlayerPreLoginEvent.php | 2 + .../event/player/PlayerQuitEvent.php | 2 + .../event/player/PlayerRespawnEvent.php | 2 + .../event/plugin/PluginDisableEvent.php | 2 + .../event/plugin/PluginEnableEvent.php | 2 + .../event/server/DataPacketReceiveEvent.php | 2 + .../event/server/DataPacketSendEvent.php | 2 + .../event/server/QueryRegenerateEvent.php | 2 + .../event/server/RemoteServerCommandEvent.php | 2 + .../event/server/ServerCommandEvent.php | 2 + src/pocketmine/inventory/BaseInventory.php | 6 +- .../inventory/CraftingTransactionGroup.php | 2 +- src/pocketmine/inventory/PlayerInventory.php | 6 +- .../inventory/SimpleTransactionGroup.php | 2 +- src/pocketmine/item/Bucket.php | 4 +- src/pocketmine/level/Explosion.php | 8 +-- src/pocketmine/level/Level.php | 32 +++++----- src/pocketmine/level/Position.php | 14 +++++ .../network/protocol/DataPacket.php | 3 +- src/pocketmine/network/query/QueryHandler.php | 2 +- src/pocketmine/network/rcon/RCON.php | 2 +- src/pocketmine/plugin/PharPluginLoader.php | 4 +- src/pocketmine/tile/Furnace.php | 4 +- src/spl | 2 +- 111 files changed, 327 insertions(+), 109 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index c87fb9c11..8c738c533 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -652,7 +652,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $pos = $this->level->getSafeSpawn($this); - $this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $pos)); + $this->server->getPluginManager()->callEvent($ev = PlayerRespawnEvent::createEvent($this, $pos)); $this->teleport($ev->getRespawnPosition()); @@ -660,7 +660,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->inventory->sendContents($this); $this->inventory->sendArmorContents($this); - $this->server->getPluginManager()->callEvent($ev = new PlayerJoinEvent($this, TextFormat::YELLOW . $this->getName() . " joined the game")); + $this->server->getPluginManager()->callEvent($ev = PlayerJoinEvent::createEvent($this, TextFormat::YELLOW . $this->getName() . " joined the game")); if(strlen(trim($ev->getJoinMessage())) > 0){ $this->server->broadcastMessage($ev->getJoinMessage()); } @@ -745,7 +745,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ if($this->connected === false){ return false; } - $this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this, $packet)); + $this->server->getPluginManager()->callEvent($ev = DataPacketSendEvent::createEvent($this, $packet)); if($ev->isCancelled()){ return false; } @@ -771,7 +771,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ if($this->connected === false){ return false; } - $this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this, $packet)); + $this->server->getPluginManager()->callEvent($ev = DataPacketSendEvent::createEvent($this, $packet)); if($ev->isCancelled()){ return false; } @@ -803,7 +803,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } } - $this->server->getPluginManager()->callEvent($ev = new PlayerBedEnterEvent($this, $this->level->getBlock($pos))); + $this->server->getPluginManager()->callEvent($ev = PlayerBedEnterEvent::createEvent($this, $this->level->getBlock($pos))); if($ev->isCancelled()){ return false; } @@ -842,7 +842,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ public function stopSleep(){ if($this->sleeping instanceof Vector3){ - $this->server->getPluginManager()->callEvent($ev = new PlayerBedLeaveEvent($this, $this->level->getBlock($this->sleeping))); + $this->server->getPluginManager()->callEvent($ev = PlayerBedLeaveEvent::createEvent($this, $this->level->getBlock($this->sleeping))); $this->sleeping = null; @@ -892,7 +892,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ return false; } } - $this->server->getPluginManager()->callEvent($ev = new PlayerAchievementAwardedEvent($this, $achievementId)); + $this->server->getPluginManager()->callEvent($ev = PlayerAchievementAwardedEvent::createEvent($this, $achievementId)); if(!$ev->isCancelled()){ $this->achievements[$achievementId] = true; Achievement::broadcast($this, $achievementId); @@ -926,7 +926,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ return false; } - $this->server->getPluginManager()->callEvent($ev = new PlayerGameModeChangeEvent($this, (int) $gm)); + $this->server->getPluginManager()->callEvent($ev = PlayerGameModeChangeEvent::createEvent($this, (int) $gm)); if($ev->isCancelled()){ return false; } @@ -1116,7 +1116,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->lastYaw = $to->yaw; $this->lastPitch = $to->pitch; - $ev = new PlayerMoveEvent($this, $from, $to); + $ev = PlayerMoveEvent::createEvent($this, $from, $to); $this->server->getPluginManager()->callEvent($ev); @@ -1200,7 +1200,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ continue; } - $this->server->getPluginManager()->callEvent($ev = new InventoryPickupItemEvent($this->inventory, $item)); + $this->server->getPluginManager()->callEvent($ev = InventoryPickupItemEvent::createEvent($this->inventory, $item)); if($ev->isCancelled()){ continue; } @@ -1225,7 +1225,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ continue; } - $this->server->getPluginManager()->callEvent($ev = new InventoryPickupItemEvent($this->inventory, $item)); + $this->server->getPluginManager()->callEvent($ev = InventoryPickupItemEvent::createEvent($this->inventory, $item)); if($ev->isCancelled()){ continue; } @@ -1282,7 +1282,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ return; } - $this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this, $packet)); + $this->server->getPluginManager()->callEvent($ev = DataPacketReceiveEvent::createEvent($this, $packet)); if($ev->isCancelled()){ return; } @@ -1324,7 +1324,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ return; } - $this->server->getPluginManager()->callEvent($ev = new PlayerPreLoginEvent($this, "Plugin reason")); + $this->server->getPluginManager()->callEvent($ev = PlayerPreLoginEvent::createEvent($this, "Plugin reason")); if($ev->isCancelled()){ $this->close("", $ev->getKickMessage()); @@ -1399,7 +1399,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ parent::__construct($this->level->getChunk($nbt["Pos"][0] >> 4, $nbt["Pos"][2] >> 4, true), $nbt); $this->loggedIn = true; - $this->server->getPluginManager()->callEvent($ev = new PlayerLoginEvent($this, "Plugin reason")); + $this->server->getPluginManager()->callEvent($ev = PlayerLoginEvent::createEvent($this, "Plugin reason")); if($ev->isCancelled()){ $this->close(TextFormat::YELLOW . $this->username . " has left the game", $ev->getKickMessage()); @@ -1673,7 +1673,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ ]); $f = 1.5; - $ev = new EntityShootBowEvent($this, $bow, new Arrow($this->chunk, $nbt, $this), $f); + $ev = EntityShootBowEvent::createEvent($this, $bow, new Arrow($this->chunk, $nbt, $this), $f); $this->server->getPluginManager()->callEvent($ev); @@ -1690,7 +1690,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } } if($ev->getProjectile() instanceof Projectile){ - $this->server->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($ev->getProjectile())); + $this->server->getPluginManager()->callEvent($projectileEv = ProjectileLaunchEvent::createEvent($ev->getProjectile())); if($projectileEv->isCancelled()){ $ev->getProjectile()->kill(); }else{ @@ -1852,7 +1852,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $damage[EntityDamageEvent::MODIFIER_ARMOR] = -intval($damage[EntityDamageEvent::MODIFIER_BASE] * $points * 0.04); } - $ev = new EntityDamageByEntityEvent($this, $target, EntityDamageEvent::CAUSE_ENTITY_ATTACK, $damage); + $ev = EntityDamageByEntityEvent::createEvent($this, $target, EntityDamageEvent::CAUSE_ENTITY_ATTACK, $damage); if($cancelled){ $ev->setCancelled(); } @@ -1882,7 +1882,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ break; } - $this->server->getPluginManager()->callEvent($ev = new PlayerAnimationEvent($this, $packet->action)); + $this->server->getPluginManager()->callEvent($ev = PlayerAnimationEvent::createEvent($this, $packet->action)); if($ev->isCancelled()){ break; } @@ -1899,7 +1899,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->craftingType = 0; - $this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $this->getSpawn())); + $this->server->getPluginManager()->callEvent($ev = PlayerRespawnEvent::createEvent($this, $this->getSpawn())); $this->teleport($ev->getRespawnPosition()); $this->fireTicks = 0; @@ -1955,7 +1955,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ ]; $slot = $this->inventory->getItemInHand(); if($this->getHealth() < 20 and isset($items[$slot->getID()])){ - $this->server->getPluginManager()->callEvent($ev = new PlayerItemConsumeEvent($this, $slot)); + $this->server->getPluginManager()->callEvent($ev = PlayerItemConsumeEvent::createEvent($this, $slot)); if($ev->isCancelled()){ $this->inventory->sendContents($this); break; @@ -1969,7 +1969,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ Server::broadcastPacket($this->getViewers(), $pk); $amount = $items[$slot->getID()]; - $this->server->getPluginManager()->callEvent($ev = new EntityRegainHealthEvent($this, $amount, EntityRegainHealthEvent::CAUSE_EATING)); + $this->server->getPluginManager()->callEvent($ev = EntityRegainHealthEvent::createEvent($this, $amount, EntityRegainHealthEvent::CAUSE_EATING)); if(!$ev->isCancelled()){ $this->heal($ev->getAmount(), $ev); } @@ -1989,7 +1989,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } $packet->eid = $this->id; $item = $this->inventory->getItemInHand(); - $ev = new PlayerDropItemEvent($this, $item); + $ev = PlayerDropItemEvent::createEvent($this, $item); $this->server->getPluginManager()->callEvent($ev); if($ev->isCancelled()){ $this->inventory->sendContents($this); @@ -2014,7 +2014,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $packet->message = TextFormat::clean($packet->message); if(trim($packet->message) != "" and strlen($packet->message) <= 255){ $message = $packet->message; - $this->server->getPluginManager()->callEvent($ev = new PlayerCommandPreprocessEvent($this, $message)); + $this->server->getPluginManager()->callEvent($ev = PlayerCommandPreprocessEvent::createEvent($this, $message)); if($ev->isCancelled()){ break; } @@ -2023,7 +2023,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->server->dispatchCommand($ev->getPlayer(), substr($ev->getMessage(), 1)); Timings::$playerCommandTimer->stopTiming(); }else{ - $this->server->getPluginManager()->callEvent($ev = new PlayerChatEvent($this, $ev->getMessage())); + $this->server->getPluginManager()->callEvent($ev = PlayerChatEvent::createEvent($this, $ev->getMessage())); if(!$ev->isCancelled()){ $this->server->broadcastMessage(sprintf($ev->getFormat(), $ev->getPlayer()->getDisplayName(), $ev->getMessage()), $ev->getRecipients()); } @@ -2037,7 +2037,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->craftingType = 0; $this->currentTransaction = null; if(isset($this->windowIndex[$packet->windowid])){ - $this->server->getPluginManager()->callEvent(new InventoryCloseEvent($this->windowIndex[$packet->windowid], $this)); + $this->server->getPluginManager()->callEvent(InventoryCloseEvent::createEvent($this->windowIndex[$packet->windowid], $this)); $this->removeWindow($this->windowIndex[$packet->windowid]); }else{ unset($this->windowIndex[$packet->windowid]); @@ -2192,7 +2192,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ if($nbt["id"] !== Tile::SIGN){ $t->spawnTo($this); }else{ - $ev = new SignChangeEvent($t->getBlock(), $this, [ + $ev = SignChangeEvent::createEvent($t->getBlock(), $this, [ $nbt["Text1"], $nbt["Text2"], $nbt["Text3"], $nbt["Text4"] ]); @@ -2223,7 +2223,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ * @return bool */ public function kick($reason = ""){ - $this->server->getPluginManager()->callEvent($ev = new PlayerKickEvent($this, $reason, TextFormat::YELLOW . $this->username . " has left the game")); + $this->server->getPluginManager()->callEvent($ev = PlayerKickEvent::createEvent($this, $reason, TextFormat::YELLOW . $this->username . " has left the game")); if(!$ev->isCancelled()){ $message = "Kicked by admin." . ($reason !== "" ? " Reason: " . $reason : ""); $this->sendMessage($message); @@ -2269,7 +2269,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ if($this->connected and !$this->closed){ $this->connected = false; if($this->username != ""){ - $this->server->getPluginManager()->callEvent($ev = new PlayerQuitEvent($this, $message)); + $this->server->getPluginManager()->callEvent($ev = PlayerQuitEvent::createEvent($this, $message)); if($this->server->getAutoSave() and $this->loggedIn === true){ $this->save(); } @@ -2439,7 +2439,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ Entity::kill(); - $this->server->getPluginManager()->callEvent($ev = new PlayerDeathEvent($this, $this->getDrops(), $message)); + $this->server->getPluginManager()->callEvent($ev = PlayerDeathEvent::createEvent($this, $this->getDrops(), $message)); if(!$ev->getKeepInventory()){ foreach($ev->getDrops() as $item){ diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 6cb8bfaf6..8ae5dde89 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -31,6 +31,7 @@ use pocketmine\command\CommandSender; use pocketmine\command\ConsoleCommandSender; use pocketmine\command\PluginIdentifiableCommand; use pocketmine\command\SimpleCommandMap; +use pocketmine\event\Event; use pocketmine\event\HandlerList; use pocketmine\event\level\LevelInitEvent; use pocketmine\event\level\LevelLoadEvent; @@ -974,7 +975,7 @@ class Server{ $level->initLevel(); - $this->getPluginManager()->callEvent(new LevelLoadEvent($level)); + $this->getPluginManager()->callEvent(LevelLoadEvent::createEvent($level)); /*foreach($entities->getAll() as $entity){ if(!isset($entity["id"])){ @@ -1109,9 +1110,9 @@ class Server{ $level->initLevel(); - $this->getPluginManager()->callEvent(new LevelInitEvent($level)); + $this->getPluginManager()->callEvent(LevelInitEvent::createEvent($level)); - $this->getPluginManager()->callEvent(new LevelLoadEvent($level)); + $this->getPluginManager()->callEvent(LevelLoadEvent::createEvent($level)); $this->getLogger()->notice("Spawn terrain for level \"$name\" is being generated in the background"); @@ -1743,7 +1744,7 @@ class Server{ public function checkConsole(){ Timings::$serverCommandTimer->startTiming(); if(($line = $this->console->getLine()) !== null){ - $this->pluginManager->callEvent($ev = new ServerCommandEvent($this->consoleSender, $line)); + $this->pluginManager->callEvent($ev = ServerCommandEvent::createEvent($this->consoleSender, $line)); if(!$ev->isCancelled()){ $this->dispatchCommand($ev->getSender(), $ev->getCommand()); } @@ -2119,6 +2120,9 @@ class Server{ Vector3::clearVectorList(); Position::clearPositionList(); AxisAlignedBB::clearBoundingBoxPool(); + if(($this->tickCounter % 4) === 0){ + Event::clearAllPools(); + } Timings::$serverTickTimer->stopTiming(); diff --git a/src/pocketmine/block/Cactus.php b/src/pocketmine/block/Cactus.php index b7e11434e..a0f0e3f43 100644 --- a/src/pocketmine/block/Cactus.php +++ b/src/pocketmine/block/Cactus.php @@ -55,7 +55,7 @@ class Cactus extends Transparent{ } public function onEntityCollide(Entity $entity){ - $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_CONTACT, 1); + $ev = EntityDamageByBlockEvent::createEvent($this, $entity, EntityDamageEvent::CAUSE_CONTACT, 1); Server::getInstance()->getPluginManager()->callEvent($ev); if(!$ev->isCancelled()){ $entity->attack($ev->getFinalDamage(), $ev); @@ -81,7 +81,7 @@ class Cactus extends Transparent{ for($y = 1; $y < 3; ++$y){ $b = $this->getLevel()->getBlock(Vector3::createVector($this->x, $this->y + $y, $this->z)); if($b->getID() === self::AIR){ - Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, new Cactus())); + Server::getInstance()->getPluginManager()->callEvent($ev = BlockGrowEvent::createEvent($b, new Cactus())); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($b, $ev->getNewState(), true); } diff --git a/src/pocketmine/block/Cake.php b/src/pocketmine/block/Cake.php index 7cff10727..8b6c6b1ce 100644 --- a/src/pocketmine/block/Cake.php +++ b/src/pocketmine/block/Cake.php @@ -81,7 +81,7 @@ class Cake extends Transparent{ public function onActivate(Item $item, Player $player = null){ if($player instanceof Player and $player->getHealth() < 20){ ++$this->meta; - Server::getInstance()->getPluginManager()->callEvent($ev = new EntityRegainHealthEvent($player, 3, EntityRegainHealthEvent::CAUSE_EATING)); + Server::getInstance()->getPluginManager()->callEvent($ev = EntityRegainHealthEvent::createEvent($player, 3, EntityRegainHealthEvent::CAUSE_EATING)); if(!$ev->isCancelled()){ $player->heal($ev->getAmount(), $ev); } diff --git a/src/pocketmine/block/Crops.php b/src/pocketmine/block/Crops.php index f7241c186..0324ea633 100644 --- a/src/pocketmine/block/Crops.php +++ b/src/pocketmine/block/Crops.php @@ -57,7 +57,7 @@ abstract class Crops extends Flowable{ $block->meta = 7; } - Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block)); + Server::getInstance()->getPluginManager()->callEvent($ev = BlockGrowEvent::createEvent($this, $block)); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($this, $ev->getNewState(), true, true); @@ -82,7 +82,7 @@ abstract class Crops extends Flowable{ if($this->meta < 0x07){ $block = clone $this; ++$block->meta; - Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block)); + Server::getInstance()->getPluginManager()->callEvent($ev = BlockGrowEvent::createEvent($this, $block)); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($this, $ev->getNewState(), true, true); diff --git a/src/pocketmine/block/Fire.php b/src/pocketmine/block/Fire.php index 7670c4c29..65b2488be 100644 --- a/src/pocketmine/block/Fire.php +++ b/src/pocketmine/block/Fire.php @@ -46,13 +46,13 @@ class Fire extends Flowable{ } public function onEntityCollide(Entity $entity){ - $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1); + $ev = EntityDamageByBlockEvent::createEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1); Server::getInstance()->getPluginManager()->callEvent($ev); if(!$ev->isCancelled()){ $entity->attack($ev->getFinalDamage(), $ev); } - $ev = new EntityCombustByBlockEvent($this, $entity, 8); + $ev = EntityCombustByBlockEvent::createEvent($this, $entity, 8); Server::getInstance()->getPluginManager()->callEvent($ev); if(!$ev->isCancelled()){ $entity->setOnFire($ev->getDuration()); diff --git a/src/pocketmine/block/Grass.php b/src/pocketmine/block/Grass.php index 167b8a11a..cc6a870e1 100644 --- a/src/pocketmine/block/Grass.php +++ b/src/pocketmine/block/Grass.php @@ -58,7 +58,7 @@ class Grass extends Solid{ if($block === Block::DIRT){ $block = Block::get($block, $this->getLevel()->getBlockDataAt($x, $y, $z), Position::createPosition($x, $y, $z, $this->getLevel())); if($block->getSide(1) instanceof Transparent){ - Server::getInstance()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($block, $this, new Grass())); + Server::getInstance()->getPluginManager()->callEvent($ev = BlockSpreadEvent::createEvent($block, $this, new Grass())); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($block, $ev->getNewState()); } diff --git a/src/pocketmine/block/Lava.php b/src/pocketmine/block/Lava.php index 8d1e1127e..2fc2dfc6c 100644 --- a/src/pocketmine/block/Lava.php +++ b/src/pocketmine/block/Lava.php @@ -38,13 +38,13 @@ class Lava extends Liquid{ public function onEntityCollide(Entity $entity){ $entity->fallDistance *= 0.5; - $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_LAVA, 4); + $ev = EntityDamageByBlockEvent::createEvent($this, $entity, EntityDamageEvent::CAUSE_LAVA, 4); Server::getInstance()->getPluginManager()->callEvent($ev); if(!$ev->isCancelled()){ $entity->attack($ev->getFinalDamage(), $ev); } - $ev = new EntityCombustByBlockEvent($this, $entity, 15); + $ev = EntityCombustByBlockEvent::createEvent($this, $entity, 15); Server::getInstance()->getPluginManager()->callEvent($ev); if(!$ev->isCancelled()){ $entity->setOnFire($ev->getDuration()); diff --git a/src/pocketmine/block/Leaves.php b/src/pocketmine/block/Leaves.php index 45f28e72c..337860352 100644 --- a/src/pocketmine/block/Leaves.php +++ b/src/pocketmine/block/Leaves.php @@ -124,7 +124,7 @@ class Leaves extends Transparent{ $visited = []; $check = 0; - Server::getInstance()->getPluginManager()->callEvent($ev = new LeavesDecayEvent($this)); + Server::getInstance()->getPluginManager()->callEvent($ev = LeavesDecayEvent::createEvent($this)); if($ev->isCancelled() or $this->findLog($this, $visited, 0, $check) === true){ $this->getLevel()->setBlock($this, $this, false, false); diff --git a/src/pocketmine/block/Leaves2.php b/src/pocketmine/block/Leaves2.php index 8c9083dd2..79f0d0f47 100644 --- a/src/pocketmine/block/Leaves2.php +++ b/src/pocketmine/block/Leaves2.php @@ -116,7 +116,7 @@ class Leaves2 extends Leaves{ $visited = []; $check = 0; - Server::getInstance()->getPluginManager()->callEvent($ev = new LeavesDecayEvent($this)); + Server::getInstance()->getPluginManager()->callEvent($ev = LeavesDecayEvent::createEvent($this)); if($ev->isCancelled() or $this->findLog($this, $visited, 0, $check) === true){ $this->getLevel()->setBlock($this, $this, false, false); diff --git a/src/pocketmine/block/MelonStem.php b/src/pocketmine/block/MelonStem.php index 3e69c11e0..62a10b370 100644 --- a/src/pocketmine/block/MelonStem.php +++ b/src/pocketmine/block/MelonStem.php @@ -42,7 +42,7 @@ class MelonStem extends Crops{ if($this->meta < 0x07){ $block = clone $this; ++$block->meta; - Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block)); + Server::getInstance()->getPluginManager()->callEvent($ev = BlockGrowEvent::createEvent($this, $block)); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($this, $ev->getNewState(), true); } @@ -58,7 +58,7 @@ class MelonStem extends Crops{ $side = $this->getSide(mt_rand(2, 5)); $d = $side->getSide(0); if($side->getID() === self::AIR and ($d->getID() === self::FARMLAND or $d->getID() === self::GRASS or $d->getID() === self::DIRT)){ - Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, new Melon())); + Server::getInstance()->getPluginManager()->callEvent($ev = BlockGrowEvent::createEvent($side, new Melon())); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($side, $ev->getNewState(), true); } diff --git a/src/pocketmine/block/Mycelium.php b/src/pocketmine/block/Mycelium.php index 784d2350d..6052f5157 100644 --- a/src/pocketmine/block/Mycelium.php +++ b/src/pocketmine/block/Mycelium.php @@ -49,7 +49,7 @@ class Mycelium extends Solid{ if($block === Block::DIRT){ $block = Block::get($block, $this->getLevel()->getBlockDataAt($x, $y, $z), Position::createPosition($x, $y, $z, $this->getLevel())); if($block->getSide(1) instanceof Transparent){ - Server::getInstance()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($block, $this, new Mycelium())); + Server::getInstance()->getPluginManager()->callEvent($ev = BlockSpreadEvent::createEvent($block, $this, new Mycelium())); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($block, $ev->getNewState()); } diff --git a/src/pocketmine/block/PumpkinStem.php b/src/pocketmine/block/PumpkinStem.php index 7123e7201..4ea7d7da0 100644 --- a/src/pocketmine/block/PumpkinStem.php +++ b/src/pocketmine/block/PumpkinStem.php @@ -42,7 +42,7 @@ class PumpkinStem extends Crops{ if($this->meta < 0x07){ $block = clone $this; ++$block->meta; - Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block)); + Server::getInstance()->getPluginManager()->callEvent($ev = BlockGrowEvent::createEvent($this, $block)); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($this, $ev->getNewState(), true); } @@ -58,7 +58,7 @@ class PumpkinStem extends Crops{ $side = $this->getSide(mt_rand(2, 5)); $d = $side->getSide(0); if($side->getID() === self::AIR and ($d->getID() === self::FARMLAND or $d->getID() === self::GRASS or $d->getID() === self::DIRT)){ - Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, new Pumpkin())); + Server::getInstance()->getPluginManager()->callEvent($ev = BlockGrowEvent::createEvent($side, new Pumpkin())); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($side, $ev->getNewState(), true); } diff --git a/src/pocketmine/block/Sugarcane.php b/src/pocketmine/block/Sugarcane.php index bf6cba252..c2c8679b2 100644 --- a/src/pocketmine/block/Sugarcane.php +++ b/src/pocketmine/block/Sugarcane.php @@ -51,7 +51,7 @@ class Sugarcane extends Flowable{ for($y = 1; $y < 3; ++$y){ $b = $this->getLevel()->getBlock(Vector3::createVector($this->x, $this->y + $y, $this->z)); if($b->getID() === self::AIR){ - Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, new Sugarcane())); + Server::getInstance()->getPluginManager()->callEvent($ev = BlockGrowEvent::createEvent($b, new Sugarcane())); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($b, $ev->getNewState(), true); } diff --git a/src/pocketmine/command/defaults/KillCommand.php b/src/pocketmine/command/defaults/KillCommand.php index 35cb93451..184dbb471 100644 --- a/src/pocketmine/command/defaults/KillCommand.php +++ b/src/pocketmine/command/defaults/KillCommand.php @@ -45,7 +45,7 @@ class KillCommand extends VanillaCommand{ } if($sender instanceof Player){ - $sender->getServer()->getPluginManager()->callEvent($ev = new EntityDamageEvent($sender, EntityDamageEvent::CAUSE_SUICIDE, 1000)); + $sender->getServer()->getPluginManager()->callEvent($ev = EntityDamageEvent::createEvent($sender, EntityDamageEvent::CAUSE_SUICIDE, 1000)); if($ev->isCancelled()){ return true; diff --git a/src/pocketmine/entity/Arrow.php b/src/pocketmine/entity/Arrow.php index 1e4ec4c78..086e5158a 100644 --- a/src/pocketmine/entity/Arrow.php +++ b/src/pocketmine/entity/Arrow.php @@ -123,13 +123,13 @@ class Arrow extends Projectile{ if($movingObjectPosition !== null){ if($movingObjectPosition->entityHit !== null){ - $this->server->getPluginManager()->callEvent(new ProjectileHitEvent($this)); + $this->server->getPluginManager()->callEvent(ProjectileHitEvent::createEvent($this)); $motion = sqrt($this->motionX ** 2 + $this->motionY ** 2 + $this->motionZ ** 2); $damage = ceil($motion * $this->damage); - $ev = new EntityDamageByEntityEvent($this->shootingEntity === null ? $this : $this->shootingEntity, $movingObjectPosition->entityHit, EntityDamageEvent::CAUSE_PROJECTILE, $damage); + $ev = EntityDamageByEntityEvent::createEvent($this->shootingEntity === null ? $this : $this->shootingEntity, $movingObjectPosition->entityHit, EntityDamageEvent::CAUSE_PROJECTILE, $damage); $this->server->getPluginManager()->callEvent($ev); @@ -138,7 +138,7 @@ class Arrow extends Projectile{ } if($this->fireTicks > 0){ - $ev = new EntityCombustByEntityEvent($this, $movingObjectPosition->entityHit, 5); + $ev = EntityCombustByEntityEvent::createEvent($this, $movingObjectPosition->entityHit, 5); $this->server->getPluginManager()->callEvent($ev); if(!$ev->isCancelled()){ $movingObjectPosition->entityHit->setOnFire($ev->getDuration()); @@ -157,7 +157,7 @@ class Arrow extends Projectile{ $this->motionY = 0; $this->motionZ = 0; - $this->server->getPluginManager()->callEvent(new ProjectileHitEvent($this)); + $this->server->getPluginManager()->callEvent(ProjectileHitEvent::createEvent($this)); } if(!$this->onGround or $this->motionX != 0 or $this->motionY != 0 or $this->motionZ != 0){ diff --git a/src/pocketmine/entity/DroppedItem.php b/src/pocketmine/entity/DroppedItem.php index 9584e2fe5..1ca2d8a38 100644 --- a/src/pocketmine/entity/DroppedItem.php +++ b/src/pocketmine/entity/DroppedItem.php @@ -70,7 +70,7 @@ class DroppedItem extends Entity{ $this->item = Item::get($this->namedtag->Item["id"], $this->namedtag->Item["Damage"], $this->namedtag->Item["Count"]); - $this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this)); + $this->server->getPluginManager()->callEvent(ItemSpawnEvent::createEvent($this)); } public function onUpdate($currentTick){ @@ -113,7 +113,7 @@ class DroppedItem extends Entity{ } if($this->age > 6000){ - $this->server->getPluginManager()->callEvent($ev = new ItemDespawnEvent($this)); + $this->server->getPluginManager()->callEvent($ev = ItemDespawnEvent::createEvent($this)); if($ev->isCancelled()){ $this->age = 0; }else{ diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 6fd22b953..3d63b1299 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -213,7 +213,7 @@ abstract class Entity extends Location implements Metadatable{ $this->level->addEntity($this); $this->initEntity(); $this->lastUpdate = $this->server->getTick(); - $this->server->getPluginManager()->callEvent(new EntitySpawnEvent($this)); + $this->server->getPluginManager()->callEvent(EntitySpawnEvent::createEvent($this)); $this->scheduleUpdate(); @@ -483,7 +483,7 @@ abstract class Entity extends Location implements Metadatable{ $this->checkBlockCollision(); if($this->y < 0 and $this->dead !== true){ - $this->server->getPluginManager()->callEvent($ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_VOID, 10)); + $this->server->getPluginManager()->callEvent($ev = EntityDamageEvent::createEvent($this, EntityDamageEvent::CAUSE_VOID, 10)); if(!$ev->isCancelled()){ $this->attack($ev->getFinalDamage(), $ev); } @@ -498,7 +498,7 @@ abstract class Entity extends Location implements Metadatable{ } }else{ if(($this->fireTicks % 20) === 0 or $tickDiff > 20){ - $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FIRE_TICK, 1); + $ev = EntityDamageEvent::createEvent($this, EntityDamageEvent::CAUSE_FIRE_TICK, 1); $this->server->getPluginManager()->callEvent($ev); if(!$ev->isCancelled()){ $this->attack($ev->getFinalDamage(), $ev); @@ -675,7 +675,7 @@ abstract class Entity extends Location implements Metadatable{ public function fall($fallDistance){ $damage = floor($fallDistance - 3); if($damage > 0){ - $this->server->getPluginManager()->callEvent($ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FALL, $damage)); + $this->server->getPluginManager()->callEvent($ev = EntityDamageEvent::createEvent($this, EntityDamageEvent::CAUSE_FALL, $damage)); if($ev->isCancelled()){ return; } @@ -701,7 +701,7 @@ abstract class Entity extends Location implements Metadatable{ protected function switchLevel(Level $targetLevel){ if($this->isValid()){ - $this->server->getPluginManager()->callEvent($ev = new EntityLevelChangeEvent($this, $this->level, $targetLevel)); + $this->server->getPluginManager()->callEvent($ev = EntityLevelChangeEvent::createEvent($this, $this->level, $targetLevel)); if($ev->isCancelled()){ return false; } @@ -1088,7 +1088,7 @@ abstract class Entity extends Location implements Metadatable{ public function setMotion(Vector3 $motion){ if(!$this->justCreated){ - $this->server->getPluginManager()->callEvent($ev = new EntityMotionEvent($this, $motion)); + $this->server->getPluginManager()->callEvent($ev = EntityMotionEvent::createEvent($this, $motion)); if($ev->isCancelled()){ return false; } @@ -1139,7 +1139,7 @@ abstract class Entity extends Location implements Metadatable{ } $from = Position::fromObject($this, $this->level); $to = Position::fromObject($pos, $pos instanceof Position ? $pos->getLevel() : $this->level); - $this->server->getPluginManager()->callEvent($ev = new EntityTeleportEvent($this, $from, $to)); + $this->server->getPluginManager()->callEvent($ev = EntityTeleportEvent::createEvent($this, $from, $to)); if($ev->isCancelled()){ return false; } @@ -1177,7 +1177,7 @@ abstract class Entity extends Location implements Metadatable{ public function close(){ if(!$this->closed){ - $this->server->getPluginManager()->callEvent(new EntityDespawnEvent($this)); + $this->server->getPluginManager()->callEvent(EntityDespawnEvent::createEvent($this)); $this->closed = true; unset($this->level->updateEntities[$this->id]); if($this->chunk instanceof FullChunk){ diff --git a/src/pocketmine/entity/FallingBlock.php b/src/pocketmine/entity/FallingBlock.php index b23fa1067..d9bb4d1ba 100644 --- a/src/pocketmine/entity/FallingBlock.php +++ b/src/pocketmine/entity/FallingBlock.php @@ -115,7 +115,7 @@ class FallingBlock extends Entity{ if(!$block->isFullBlock){ $this->getLevel()->dropItem($this, Item::get($this->getBlock(), $this->getDamage(), 1)); }else{ - $this->server->getPluginManager()->callEvent($ev = new EntityBlockChangeEvent($this, $block, Block::get($this->getBlock(), $this->getDamage()))); + $this->server->getPluginManager()->callEvent($ev = EntityBlockChangeEvent::createEvent($this, $block, Block::get($this->getBlock(), $this->getDamage()))); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($pos, $ev->getTo(), true); } diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index c563ca964..7aa6a7b9f 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -124,7 +124,7 @@ abstract class Living extends Entity implements Damageable{ return; } parent::kill(); - $this->server->getPluginManager()->callEvent($ev = new EntityDeathEvent($this, $this->getDrops())); + $this->server->getPluginManager()->callEvent($ev = EntityDeathEvent::createEvent($this, $this->getDrops())); foreach($ev->getDrops() as $item){ $this->getLevel()->dropItem($this, $item); } @@ -135,7 +135,7 @@ abstract class Living extends Entity implements Damageable{ parent::entityBaseTick(); if($this->dead !== true and $this->isInsideOfSolid()){ - $this->server->getPluginManager()->callEvent($ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 1)); + $this->server->getPluginManager()->callEvent($ev = EntityDamageEvent::createEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 1)); if(!$ev->isCancelled()){ $this->attack($ev->getFinalDamage(), $ev); } @@ -146,7 +146,7 @@ abstract class Living extends Entity implements Damageable{ if($this->airTicks <= -20){ $this->airTicks = 0; - $this->server->getPluginManager()->callEvent($ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2)); + $this->server->getPluginManager()->callEvent($ev = EntityDamageEvent::createEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2)); if(!$ev->isCancelled()){ $this->attack($ev->getFinalDamage(), $ev); } diff --git a/src/pocketmine/entity/PrimedTNT.php b/src/pocketmine/entity/PrimedTNT.php index 335c3943a..f2843980b 100644 --- a/src/pocketmine/entity/PrimedTNT.php +++ b/src/pocketmine/entity/PrimedTNT.php @@ -128,7 +128,7 @@ class PrimedTNT extends Entity implements Explosive{ } public function explode(){ - $this->server->getPluginManager()->callEvent($ev = new ExplosionPrimeEvent($this, 4)); + $this->server->getPluginManager()->callEvent($ev = ExplosionPrimeEvent::createEvent($this, 4)); if(!$ev->isCancelled()){ $explosion = new Explosion($this, $ev->getForce(), $this); diff --git a/src/pocketmine/event/Event.php b/src/pocketmine/event/Event.php index b1b0e54f7..b9280f199 100644 --- a/src/pocketmine/event/Event.php +++ b/src/pocketmine/event/Event.php @@ -24,16 +24,27 @@ */ namespace pocketmine\event; +use pocketmine\plugin\PluginManager; + abstract class Event{ /** * Any callable event must declare the static variable * * public static $handlerList = null; + * public static $eventPool = []; + * public static $nextEvent = 0; * * Not doing so will deny the proper event initialization */ + /** @var Event[] */ + public static $eventPool = []; + public static $nextEvent = 0; + + /** @var Event[] */ + private static $knownEvents = []; + protected $eventName = null; private $isCancelled = false; @@ -41,7 +52,7 @@ abstract class Event{ * @return string */ final public function getEventName(){ - return $this->eventName !== null ? get_class($this) : $this->eventName; + return $this->eventName !== null ? static::class : $this->eventName; } /** @@ -85,4 +96,40 @@ abstract class Event{ return static::$handlerList; } + public static function clearEventPool(){ + static::$nextEvent = 0; + } + + public static function clearAllPools(){ + foreach(self::$knownEvents as $event){ + $event::clearEventPool(); + } + } + + /** + * @param $params + * + * @return static + */ + public static function createEvent(...$params){ + if(static::$nextEvent >= count(static::$eventPool)){ + static::$eventPool[] = new static(...$params); + return static::$eventPool[static::$nextEvent++]; + } + $ev = static::$eventPool[static::$nextEvent++]; + $ev->__construct(...$params); + if($ev instanceof Cancellable){ + $ev->setCancelled(false); + } + return $ev; + } + + public static function onClassLoaded(){ + self::$knownEvents[static::class] = static::class; + } + + public static function getKnownEvents(){ + return self::$knownEvents; + } + } \ No newline at end of file diff --git a/src/pocketmine/event/block/BlockBreakEvent.php b/src/pocketmine/event/block/BlockBreakEvent.php index 2c4c14257..64113b7b8 100644 --- a/src/pocketmine/event/block/BlockBreakEvent.php +++ b/src/pocketmine/event/block/BlockBreakEvent.php @@ -28,6 +28,8 @@ use pocketmine\Player; class BlockBreakEvent extends BlockEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var \pocketmine\Player */ protected $player; diff --git a/src/pocketmine/event/block/BlockFormEvent.php b/src/pocketmine/event/block/BlockFormEvent.php index c757b97d2..e21c9db60 100644 --- a/src/pocketmine/event/block/BlockFormEvent.php +++ b/src/pocketmine/event/block/BlockFormEvent.php @@ -26,6 +26,8 @@ use pocketmine\event\Cancellable; class BlockFormEvent extends BlockGrowEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; public function __construct(Block $block, Block $newState){ parent::__construct($block, $newState); diff --git a/src/pocketmine/event/block/BlockGrowEvent.php b/src/pocketmine/event/block/BlockGrowEvent.php index cb2c739a4..c4c8b9bb2 100644 --- a/src/pocketmine/event/block/BlockGrowEvent.php +++ b/src/pocketmine/event/block/BlockGrowEvent.php @@ -26,6 +26,8 @@ use pocketmine\event\Cancellable; class BlockGrowEvent extends BlockEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var Block */ private $newState; diff --git a/src/pocketmine/event/block/BlockPlaceEvent.php b/src/pocketmine/event/block/BlockPlaceEvent.php index c57755e1c..d3799f1aa 100644 --- a/src/pocketmine/event/block/BlockPlaceEvent.php +++ b/src/pocketmine/event/block/BlockPlaceEvent.php @@ -31,6 +31,8 @@ use pocketmine\Player; */ class BlockPlaceEvent extends BlockEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var \pocketmine\Player */ protected $player; diff --git a/src/pocketmine/event/block/BlockSpreadEvent.php b/src/pocketmine/event/block/BlockSpreadEvent.php index d5344d5b9..eb2794047 100644 --- a/src/pocketmine/event/block/BlockSpreadEvent.php +++ b/src/pocketmine/event/block/BlockSpreadEvent.php @@ -26,6 +26,8 @@ use pocketmine\event\Cancellable; class BlockSpreadEvent extends BlockFormEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var Block */ private $source; diff --git a/src/pocketmine/event/block/BlockUpdateEvent.php b/src/pocketmine/event/block/BlockUpdateEvent.php index 5d01b0260..ad5604764 100644 --- a/src/pocketmine/event/block/BlockUpdateEvent.php +++ b/src/pocketmine/event/block/BlockUpdateEvent.php @@ -30,5 +30,7 @@ use pocketmine\Player; */ class BlockUpdateEvent extends BlockEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; } \ No newline at end of file diff --git a/src/pocketmine/event/block/LeavesDecayEvent.php b/src/pocketmine/event/block/LeavesDecayEvent.php index 9da0281da..594bc041d 100644 --- a/src/pocketmine/event/block/LeavesDecayEvent.php +++ b/src/pocketmine/event/block/LeavesDecayEvent.php @@ -26,6 +26,8 @@ use pocketmine\event\Cancellable; class LeavesDecayEvent extends BlockEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; public function __construct(Block $block){ parent::__construct($block); diff --git a/src/pocketmine/event/block/SignChangeEvent.php b/src/pocketmine/event/block/SignChangeEvent.php index 0ca3deb6a..5145178ee 100644 --- a/src/pocketmine/event/block/SignChangeEvent.php +++ b/src/pocketmine/event/block/SignChangeEvent.php @@ -30,6 +30,8 @@ use pocketmine\Player; */ class SignChangeEvent extends BlockEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var \pocketmine\Player */ private $player; diff --git a/src/pocketmine/event/entity/EntityArmorChangeEvent.php b/src/pocketmine/event/entity/EntityArmorChangeEvent.php index a5b5d0ba0..89db05d03 100644 --- a/src/pocketmine/event/entity/EntityArmorChangeEvent.php +++ b/src/pocketmine/event/entity/EntityArmorChangeEvent.php @@ -28,6 +28,8 @@ use pocketmine\item\Item; class EntityArmorChangeEvent extends EntityEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; private $oldItem; private $newItem; diff --git a/src/pocketmine/event/entity/EntityBlockChangeEvent.php b/src/pocketmine/event/entity/EntityBlockChangeEvent.php index 3d19301d0..8784ad3dc 100644 --- a/src/pocketmine/event/entity/EntityBlockChangeEvent.php +++ b/src/pocketmine/event/entity/EntityBlockChangeEvent.php @@ -30,6 +30,8 @@ use pocketmine\event\Cancellable; */ class EntityBlockChangeEvent extends EntityEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; private $from; private $to; diff --git a/src/pocketmine/event/entity/EntityCombustByBlockEvent.php b/src/pocketmine/event/entity/EntityCombustByBlockEvent.php index 6d3cc450e..dbf33e4d6 100644 --- a/src/pocketmine/event/entity/EntityCombustByBlockEvent.php +++ b/src/pocketmine/event/entity/EntityCombustByBlockEvent.php @@ -25,6 +25,8 @@ use pocketmine\block\Block; use pocketmine\entity\Entity; class EntityCombustByBlockEvent extends EntityCombustEvent{ + public static $eventPool = []; + public static $nextEvent = 0; protected $combuster; diff --git a/src/pocketmine/event/entity/EntityCombustByEntityEvent.php b/src/pocketmine/event/entity/EntityCombustByEntityEvent.php index e72a5e865..a8801cb8c 100644 --- a/src/pocketmine/event/entity/EntityCombustByEntityEvent.php +++ b/src/pocketmine/event/entity/EntityCombustByEntityEvent.php @@ -24,6 +24,8 @@ namespace pocketmine\event\entity; use pocketmine\entity\Entity; class EntityCombustByEntityEvent extends EntityCombustEvent{ + public static $eventPool = []; + public static $nextEvent = 0; protected $combuster; diff --git a/src/pocketmine/event/entity/EntityCombustEvent.php b/src/pocketmine/event/entity/EntityCombustEvent.php index 0bc0d6c27..9cf690df0 100644 --- a/src/pocketmine/event/entity/EntityCombustEvent.php +++ b/src/pocketmine/event/entity/EntityCombustEvent.php @@ -26,6 +26,8 @@ use pocketmine\event\Cancellable; class EntityCombustEvent extends EntityEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; protected $duration; diff --git a/src/pocketmine/event/entity/EntityDamageByBlockEvent.php b/src/pocketmine/event/entity/EntityDamageByBlockEvent.php index 0a92cc578..2ceb3bffd 100644 --- a/src/pocketmine/event/entity/EntityDamageByBlockEvent.php +++ b/src/pocketmine/event/entity/EntityDamageByBlockEvent.php @@ -25,6 +25,8 @@ use pocketmine\block\Block; use pocketmine\entity\Entity; class EntityDamageByBlockEvent extends EntityDamageEvent{ + public static $eventPool = []; + public static $nextEvent = 0; /** @var Block */ private $damager; diff --git a/src/pocketmine/event/entity/EntityDamageByEntityEvent.php b/src/pocketmine/event/entity/EntityDamageByEntityEvent.php index 1845afd68..aa0c757d1 100644 --- a/src/pocketmine/event/entity/EntityDamageByEntityEvent.php +++ b/src/pocketmine/event/entity/EntityDamageByEntityEvent.php @@ -24,6 +24,8 @@ namespace pocketmine\event\entity; use pocketmine\entity\Entity; class EntityDamageByEntityEvent extends EntityDamageEvent{ + public static $eventPool = []; + public static $nextEvent = 0; /** @var Entity */ private $damager; diff --git a/src/pocketmine/event/entity/EntityDamageEvent.php b/src/pocketmine/event/entity/EntityDamageEvent.php index 7d4b12bf4..eb397b84c 100644 --- a/src/pocketmine/event/entity/EntityDamageEvent.php +++ b/src/pocketmine/event/entity/EntityDamageEvent.php @@ -26,6 +26,8 @@ use pocketmine\event\Cancellable; class EntityDamageEvent extends EntityEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; const MODIFIER_BASE = 0; const MODIFIER_ARMOR = 1; diff --git a/src/pocketmine/event/entity/EntityDeathEvent.php b/src/pocketmine/event/entity/EntityDeathEvent.php index 51a5ed54e..3645ddf31 100644 --- a/src/pocketmine/event/entity/EntityDeathEvent.php +++ b/src/pocketmine/event/entity/EntityDeathEvent.php @@ -26,6 +26,8 @@ use pocketmine\item\Item; class EntityDeathEvent extends EntityEvent{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var Item[] */ private $drops = []; diff --git a/src/pocketmine/event/entity/EntityDespawnEvent.php b/src/pocketmine/event/entity/EntityDespawnEvent.php index fe080d83b..a5ff67242 100644 --- a/src/pocketmine/event/entity/EntityDespawnEvent.php +++ b/src/pocketmine/event/entity/EntityDespawnEvent.php @@ -33,6 +33,8 @@ use pocketmine\entity\Vehicle; */ class EntityDespawnEvent extends EntityEvent{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; private $entityType; diff --git a/src/pocketmine/event/entity/EntityExplodeEvent.php b/src/pocketmine/event/entity/EntityExplodeEvent.php index 46476a6eb..367978b38 100644 --- a/src/pocketmine/event/entity/EntityExplodeEvent.php +++ b/src/pocketmine/event/entity/EntityExplodeEvent.php @@ -31,6 +31,8 @@ use pocketmine\level\Position; */ class EntityExplodeEvent extends EntityEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var Position */ protected $position; diff --git a/src/pocketmine/event/entity/EntityInventoryChangeEvent.php b/src/pocketmine/event/entity/EntityInventoryChangeEvent.php index ca50c001c..f98ac426f 100644 --- a/src/pocketmine/event/entity/EntityInventoryChangeEvent.php +++ b/src/pocketmine/event/entity/EntityInventoryChangeEvent.php @@ -28,6 +28,8 @@ use pocketmine\item\Item; class EntityInventoryChangeEvent extends EntityEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; private $oldItem; private $newItem; diff --git a/src/pocketmine/event/entity/EntityLevelChangeEvent.php b/src/pocketmine/event/entity/EntityLevelChangeEvent.php index fcf8e4291..df1a0c671 100644 --- a/src/pocketmine/event/entity/EntityLevelChangeEvent.php +++ b/src/pocketmine/event/entity/EntityLevelChangeEvent.php @@ -28,6 +28,8 @@ use pocketmine\level\Level; class EntityLevelChangeEvent extends EntityEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; private $originLevel; private $targetLevel; diff --git a/src/pocketmine/event/entity/EntityMotionEvent.php b/src/pocketmine/event/entity/EntityMotionEvent.php index 6c0ea6b75..560bf747c 100644 --- a/src/pocketmine/event/entity/EntityMotionEvent.php +++ b/src/pocketmine/event/entity/EntityMotionEvent.php @@ -28,6 +28,8 @@ use pocketmine\math\Vector3; class EntityMotionEvent extends EntityEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; private $mot; diff --git a/src/pocketmine/event/entity/EntityMoveEvent.php b/src/pocketmine/event/entity/EntityMoveEvent.php index 099c9a7a4..378110828 100644 --- a/src/pocketmine/event/entity/EntityMoveEvent.php +++ b/src/pocketmine/event/entity/EntityMoveEvent.php @@ -31,6 +31,8 @@ use pocketmine\math\Vector3; */ class EntityMoveEvent extends EntityEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var \pocketmine\math\Vector3 */ private $pos; diff --git a/src/pocketmine/event/entity/EntityRegainHealthEvent.php b/src/pocketmine/event/entity/EntityRegainHealthEvent.php index 4be1d27da..37c47d3e3 100644 --- a/src/pocketmine/event/entity/EntityRegainHealthEvent.php +++ b/src/pocketmine/event/entity/EntityRegainHealthEvent.php @@ -26,6 +26,8 @@ use pocketmine\event\Cancellable; class EntityRegainHealthEvent extends EntityEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; const CAUSE_REGEN = 0; const CAUSE_EATING = 1; diff --git a/src/pocketmine/event/entity/EntityShootBowEvent.php b/src/pocketmine/event/entity/EntityShootBowEvent.php index 7efb2cdb5..5fc92b015 100644 --- a/src/pocketmine/event/entity/EntityShootBowEvent.php +++ b/src/pocketmine/event/entity/EntityShootBowEvent.php @@ -29,6 +29,8 @@ use pocketmine\item\Item; class EntityShootBowEvent extends EntityEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var Item */ private $bow; diff --git a/src/pocketmine/event/entity/EntitySpawnEvent.php b/src/pocketmine/event/entity/EntitySpawnEvent.php index d66947e8a..d865c537e 100644 --- a/src/pocketmine/event/entity/EntitySpawnEvent.php +++ b/src/pocketmine/event/entity/EntitySpawnEvent.php @@ -33,6 +33,8 @@ use pocketmine\entity\Vehicle; */ class EntitySpawnEvent extends EntityEvent{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; private $entityType; diff --git a/src/pocketmine/event/entity/EntityTeleportEvent.php b/src/pocketmine/event/entity/EntityTeleportEvent.php index 230e0e3dc..e4ac41475 100644 --- a/src/pocketmine/event/entity/EntityTeleportEvent.php +++ b/src/pocketmine/event/entity/EntityTeleportEvent.php @@ -28,6 +28,8 @@ use pocketmine\level\Position; class EntityTeleportEvent extends EntityEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var Position */ private $from; diff --git a/src/pocketmine/event/entity/ExplosionPrimeEvent.php b/src/pocketmine/event/entity/ExplosionPrimeEvent.php index e08d3bdca..66944c053 100644 --- a/src/pocketmine/event/entity/ExplosionPrimeEvent.php +++ b/src/pocketmine/event/entity/ExplosionPrimeEvent.php @@ -29,6 +29,8 @@ use pocketmine\event\Cancellable; */ class ExplosionPrimeEvent extends EntityEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; protected $force; private $blockBreaking; diff --git a/src/pocketmine/event/entity/ItemDespawnEvent.php b/src/pocketmine/event/entity/ItemDespawnEvent.php index f09249fa2..f37b3b51e 100644 --- a/src/pocketmine/event/entity/ItemDespawnEvent.php +++ b/src/pocketmine/event/entity/ItemDespawnEvent.php @@ -26,6 +26,8 @@ use pocketmine\event\Cancellable; class ItemDespawnEvent extends EntityEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** * @param DroppedItem $item diff --git a/src/pocketmine/event/entity/ItemSpawnEvent.php b/src/pocketmine/event/entity/ItemSpawnEvent.php index 52ee95bbd..5e369dde9 100644 --- a/src/pocketmine/event/entity/ItemSpawnEvent.php +++ b/src/pocketmine/event/entity/ItemSpawnEvent.php @@ -25,6 +25,8 @@ use pocketmine\entity\DroppedItem; class ItemSpawnEvent extends EntityEvent{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** * @param DroppedItem $item diff --git a/src/pocketmine/event/entity/ProjectileHitEvent.php b/src/pocketmine/event/entity/ProjectileHitEvent.php index 1da3406b3..51e514d33 100644 --- a/src/pocketmine/event/entity/ProjectileHitEvent.php +++ b/src/pocketmine/event/entity/ProjectileHitEvent.php @@ -25,6 +25,8 @@ use pocketmine\entity\Projectile; class ProjectileHitEvent extends EntityEvent{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** * @param Projectile $entity diff --git a/src/pocketmine/event/entity/ProjectileLaunchEvent.php b/src/pocketmine/event/entity/ProjectileLaunchEvent.php index f2104b5a8..cb945ab10 100644 --- a/src/pocketmine/event/entity/ProjectileLaunchEvent.php +++ b/src/pocketmine/event/entity/ProjectileLaunchEvent.php @@ -26,6 +26,8 @@ use pocketmine\event\Cancellable; class ProjectileLaunchEvent extends EntityEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** * @param Projectile $entity diff --git a/src/pocketmine/event/inventory/CraftItemEvent.php b/src/pocketmine/event/inventory/CraftItemEvent.php index 96eac6d43..d225f24f8 100644 --- a/src/pocketmine/event/inventory/CraftItemEvent.php +++ b/src/pocketmine/event/inventory/CraftItemEvent.php @@ -28,6 +28,8 @@ use pocketmine\inventory\Recipe; class CraftItemEvent extends Event implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var CraftingTransactionGroup */ private $ts; diff --git a/src/pocketmine/event/inventory/FurnaceBurnEvent.php b/src/pocketmine/event/inventory/FurnaceBurnEvent.php index 3294d9ed1..66e7b741a 100644 --- a/src/pocketmine/event/inventory/FurnaceBurnEvent.php +++ b/src/pocketmine/event/inventory/FurnaceBurnEvent.php @@ -28,6 +28,8 @@ use pocketmine\tile\Furnace; class FurnaceBurnEvent extends BlockEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; private $furnace; private $fuel; diff --git a/src/pocketmine/event/inventory/FurnaceSmeltEvent.php b/src/pocketmine/event/inventory/FurnaceSmeltEvent.php index cf65d418f..41ff9eaac 100644 --- a/src/pocketmine/event/inventory/FurnaceSmeltEvent.php +++ b/src/pocketmine/event/inventory/FurnaceSmeltEvent.php @@ -28,6 +28,8 @@ use pocketmine\tile\Furnace; class FurnaceSmeltEvent extends BlockEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; private $furnace; private $source; diff --git a/src/pocketmine/event/inventory/InventoryCloseEvent.php b/src/pocketmine/event/inventory/InventoryCloseEvent.php index 843b4df9e..257fd4ab9 100644 --- a/src/pocketmine/event/inventory/InventoryCloseEvent.php +++ b/src/pocketmine/event/inventory/InventoryCloseEvent.php @@ -26,6 +26,8 @@ use pocketmine\Player; class InventoryCloseEvent extends InventoryEvent{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var Player */ private $who; diff --git a/src/pocketmine/event/inventory/InventoryOpenEvent.php b/src/pocketmine/event/inventory/InventoryOpenEvent.php index 8d400cc90..ad68d5572 100644 --- a/src/pocketmine/event/inventory/InventoryOpenEvent.php +++ b/src/pocketmine/event/inventory/InventoryOpenEvent.php @@ -27,6 +27,8 @@ use pocketmine\Player; class InventoryOpenEvent extends InventoryEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var Player */ private $who; diff --git a/src/pocketmine/event/inventory/InventoryPickupItemEvent.php b/src/pocketmine/event/inventory/InventoryPickupItemEvent.php index 07793bb10..8f87fdf39 100644 --- a/src/pocketmine/event/inventory/InventoryPickupItemEvent.php +++ b/src/pocketmine/event/inventory/InventoryPickupItemEvent.php @@ -27,6 +27,8 @@ use pocketmine\item\Item; class InventoryPickupItemEvent extends InventoryEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var Item */ private $item; diff --git a/src/pocketmine/event/inventory/InventoryTransactionEvent.php b/src/pocketmine/event/inventory/InventoryTransactionEvent.php index 53a4c4e5f..5c8216f45 100644 --- a/src/pocketmine/event/inventory/InventoryTransactionEvent.php +++ b/src/pocketmine/event/inventory/InventoryTransactionEvent.php @@ -31,6 +31,8 @@ use pocketmine\inventory\TransactionGroup; */ class InventoryTransactionEvent extends Event implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var TransactionGroup */ private $ts; diff --git a/src/pocketmine/event/level/ChunkLoadEvent.php b/src/pocketmine/event/level/ChunkLoadEvent.php index cfe99f8bc..6631d52ec 100644 --- a/src/pocketmine/event/level/ChunkLoadEvent.php +++ b/src/pocketmine/event/level/ChunkLoadEvent.php @@ -28,6 +28,8 @@ use pocketmine\level\format\FullChunk; */ class ChunkLoadEvent extends ChunkEvent{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; private $newChunk; diff --git a/src/pocketmine/event/level/ChunkPopulateEvent.php b/src/pocketmine/event/level/ChunkPopulateEvent.php index b3f2aec8c..943bb1983 100644 --- a/src/pocketmine/event/level/ChunkPopulateEvent.php +++ b/src/pocketmine/event/level/ChunkPopulateEvent.php @@ -26,4 +26,6 @@ namespace pocketmine\event\level; */ class ChunkPopulateEvent extends ChunkEvent{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; } \ No newline at end of file diff --git a/src/pocketmine/event/level/ChunkUnloadEvent.php b/src/pocketmine/event/level/ChunkUnloadEvent.php index 257865a5f..f16294569 100644 --- a/src/pocketmine/event/level/ChunkUnloadEvent.php +++ b/src/pocketmine/event/level/ChunkUnloadEvent.php @@ -28,4 +28,6 @@ use pocketmine\event\Cancellable; */ class ChunkUnloadEvent extends ChunkEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; } \ No newline at end of file diff --git a/src/pocketmine/event/level/LevelInitEvent.php b/src/pocketmine/event/level/LevelInitEvent.php index 6e18f17f0..fad150f2a 100644 --- a/src/pocketmine/event/level/LevelInitEvent.php +++ b/src/pocketmine/event/level/LevelInitEvent.php @@ -26,4 +26,6 @@ namespace pocketmine\event\level; */ class LevelInitEvent extends LevelEvent{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; } \ No newline at end of file diff --git a/src/pocketmine/event/level/LevelLoadEvent.php b/src/pocketmine/event/level/LevelLoadEvent.php index 84d300f13..28ebbabdd 100644 --- a/src/pocketmine/event/level/LevelLoadEvent.php +++ b/src/pocketmine/event/level/LevelLoadEvent.php @@ -26,4 +26,6 @@ namespace pocketmine\event\level; */ class LevelLoadEvent extends LevelEvent{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; } \ No newline at end of file diff --git a/src/pocketmine/event/level/LevelSaveEvent.php b/src/pocketmine/event/level/LevelSaveEvent.php index 0fa652d6e..211d3ca98 100644 --- a/src/pocketmine/event/level/LevelSaveEvent.php +++ b/src/pocketmine/event/level/LevelSaveEvent.php @@ -26,4 +26,6 @@ namespace pocketmine\event\level; */ class LevelSaveEvent extends LevelEvent{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; } \ No newline at end of file diff --git a/src/pocketmine/event/level/LevelUnloadEvent.php b/src/pocketmine/event/level/LevelUnloadEvent.php index 412ca7e97..1b42c0f97 100644 --- a/src/pocketmine/event/level/LevelUnloadEvent.php +++ b/src/pocketmine/event/level/LevelUnloadEvent.php @@ -28,4 +28,6 @@ use pocketmine\event\Cancellable; */ class LevelUnloadEvent extends LevelEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; } \ No newline at end of file diff --git a/src/pocketmine/event/level/SpawnChangeEvent.php b/src/pocketmine/event/level/SpawnChangeEvent.php index cc0e82e90..6d4855597 100644 --- a/src/pocketmine/event/level/SpawnChangeEvent.php +++ b/src/pocketmine/event/level/SpawnChangeEvent.php @@ -30,6 +30,8 @@ use pocketmine\level\Position; */ class SpawnChangeEvent extends LevelEvent{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var Position */ private $previousSpawn; diff --git a/src/pocketmine/event/player/PlayerAchievementAwardedEvent.php b/src/pocketmine/event/player/PlayerAchievementAwardedEvent.php index 671f391fc..c2d62d787 100644 --- a/src/pocketmine/event/player/PlayerAchievementAwardedEvent.php +++ b/src/pocketmine/event/player/PlayerAchievementAwardedEvent.php @@ -29,6 +29,8 @@ use pocketmine\Player; */ class PlayerAchievementAwardedEvent extends PlayerEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var string */ protected $achievement; diff --git a/src/pocketmine/event/player/PlayerAnimationEvent.php b/src/pocketmine/event/player/PlayerAnimationEvent.php index 5c979cf60..8cd78e6b2 100644 --- a/src/pocketmine/event/player/PlayerAnimationEvent.php +++ b/src/pocketmine/event/player/PlayerAnimationEvent.php @@ -29,6 +29,8 @@ use pocketmine\Player; */ class PlayerAnimationEvent extends PlayerEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; const ARM_SWING = 1; diff --git a/src/pocketmine/event/player/PlayerBedEnterEvent.php b/src/pocketmine/event/player/PlayerBedEnterEvent.php index 4faf04248..7c547994e 100644 --- a/src/pocketmine/event/player/PlayerBedEnterEvent.php +++ b/src/pocketmine/event/player/PlayerBedEnterEvent.php @@ -27,6 +27,8 @@ use pocketmine\Player; class PlayerBedEnterEvent extends PlayerEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; private $bed; diff --git a/src/pocketmine/event/player/PlayerBedLeaveEvent.php b/src/pocketmine/event/player/PlayerBedLeaveEvent.php index 80d8cb124..ed375ddbb 100644 --- a/src/pocketmine/event/player/PlayerBedLeaveEvent.php +++ b/src/pocketmine/event/player/PlayerBedLeaveEvent.php @@ -26,6 +26,8 @@ use pocketmine\Player; class PlayerBedLeaveEvent extends PlayerEvent{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; private $bed; diff --git a/src/pocketmine/event/player/PlayerBucketEmptyEvent.php b/src/pocketmine/event/player/PlayerBucketEmptyEvent.php index 3e0955c53..cdacebdd7 100644 --- a/src/pocketmine/event/player/PlayerBucketEmptyEvent.php +++ b/src/pocketmine/event/player/PlayerBucketEmptyEvent.php @@ -27,6 +27,8 @@ use pocketmine\Player; class PlayerBucketEmptyEvent extends PlayerBucketEvent{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; public function __construct(Player $who, Block $blockClicked, $blockFace, Item $bucket, Item $itemInHand){ parent::__construct($who, $blockClicked, $blockFace, $bucket, $itemInHand); diff --git a/src/pocketmine/event/player/PlayerBucketFillEvent.php b/src/pocketmine/event/player/PlayerBucketFillEvent.php index af19c7bf6..7324fb780 100644 --- a/src/pocketmine/event/player/PlayerBucketFillEvent.php +++ b/src/pocketmine/event/player/PlayerBucketFillEvent.php @@ -27,6 +27,8 @@ use pocketmine\Player; class PlayerBucketFillEvent extends PlayerBucketEvent{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; public function __construct(Player $who, Block $blockClicked, $blockFace, Item $bucket, Item $itemInHand){ parent::__construct($who, $blockClicked, $blockFace, $bucket, $itemInHand); diff --git a/src/pocketmine/event/player/PlayerChatEvent.php b/src/pocketmine/event/player/PlayerChatEvent.php index 95650070b..edc54921a 100644 --- a/src/pocketmine/event/player/PlayerChatEvent.php +++ b/src/pocketmine/event/player/PlayerChatEvent.php @@ -30,6 +30,8 @@ use pocketmine\Server; */ class PlayerChatEvent extends PlayerEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var string */ protected $message; diff --git a/src/pocketmine/event/player/PlayerCommandPreprocessEvent.php b/src/pocketmine/event/player/PlayerCommandPreprocessEvent.php index bd54b7797..a2a9296a8 100644 --- a/src/pocketmine/event/player/PlayerCommandPreprocessEvent.php +++ b/src/pocketmine/event/player/PlayerCommandPreprocessEvent.php @@ -34,6 +34,8 @@ use pocketmine\Player; */ class PlayerCommandPreprocessEvent extends PlayerEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var string */ protected $message; diff --git a/src/pocketmine/event/player/PlayerDeathEvent.php b/src/pocketmine/event/player/PlayerDeathEvent.php index a4b98c82d..33623affc 100644 --- a/src/pocketmine/event/player/PlayerDeathEvent.php +++ b/src/pocketmine/event/player/PlayerDeathEvent.php @@ -27,6 +27,8 @@ use pocketmine\Player; class PlayerDeathEvent extends EntityDeathEvent{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; private $deathMessage; private $keepInventory = false; diff --git a/src/pocketmine/event/player/PlayerDropItemEvent.php b/src/pocketmine/event/player/PlayerDropItemEvent.php index 0f5cbdd73..b389db8fe 100644 --- a/src/pocketmine/event/player/PlayerDropItemEvent.php +++ b/src/pocketmine/event/player/PlayerDropItemEvent.php @@ -30,6 +30,8 @@ use pocketmine\Player; */ class PlayerDropItemEvent extends PlayerEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var Item */ private $drop; diff --git a/src/pocketmine/event/player/PlayerGameModeChangeEvent.php b/src/pocketmine/event/player/PlayerGameModeChangeEvent.php index dedce2fc9..6da670adc 100644 --- a/src/pocketmine/event/player/PlayerGameModeChangeEvent.php +++ b/src/pocketmine/event/player/PlayerGameModeChangeEvent.php @@ -29,6 +29,8 @@ use pocketmine\Player; */ class PlayerGameModeChangeEvent extends PlayerEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var int */ protected $gamemode; diff --git a/src/pocketmine/event/player/PlayerInteractEvent.php b/src/pocketmine/event/player/PlayerInteractEvent.php index 20a7c2f6a..b5b3f9bfe 100644 --- a/src/pocketmine/event/player/PlayerInteractEvent.php +++ b/src/pocketmine/event/player/PlayerInteractEvent.php @@ -31,6 +31,8 @@ use pocketmine\Player; */ class PlayerInteractEvent extends PlayerEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** * @var \pocketmine\block\Block; diff --git a/src/pocketmine/event/player/PlayerItemConsumeEvent.php b/src/pocketmine/event/player/PlayerItemConsumeEvent.php index b306230f5..96e7462cc 100644 --- a/src/pocketmine/event/player/PlayerItemConsumeEvent.php +++ b/src/pocketmine/event/player/PlayerItemConsumeEvent.php @@ -30,6 +30,8 @@ use pocketmine\Player; */ class PlayerItemConsumeEvent extends PlayerEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var Item */ private $item; diff --git a/src/pocketmine/event/player/PlayerItemHeldEvent.php b/src/pocketmine/event/player/PlayerItemHeldEvent.php index fb359ecb5..0f7008792 100644 --- a/src/pocketmine/event/player/PlayerItemHeldEvent.php +++ b/src/pocketmine/event/player/PlayerItemHeldEvent.php @@ -28,6 +28,8 @@ use pocketmine\Player; class PlayerItemHeldEvent extends PlayerEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; private $item; private $slot; diff --git a/src/pocketmine/event/player/PlayerJoinEvent.php b/src/pocketmine/event/player/PlayerJoinEvent.php index c684f442c..86169590a 100644 --- a/src/pocketmine/event/player/PlayerJoinEvent.php +++ b/src/pocketmine/event/player/PlayerJoinEvent.php @@ -28,6 +28,8 @@ use pocketmine\Player; */ class PlayerJoinEvent extends PlayerEvent{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var string */ protected $joinMessage; diff --git a/src/pocketmine/event/player/PlayerKickEvent.php b/src/pocketmine/event/player/PlayerKickEvent.php index 27f612fd3..c0eb9dae9 100644 --- a/src/pocketmine/event/player/PlayerKickEvent.php +++ b/src/pocketmine/event/player/PlayerKickEvent.php @@ -29,6 +29,8 @@ use pocketmine\Player; */ class PlayerKickEvent extends PlayerEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var string */ protected $quitMessage; diff --git a/src/pocketmine/event/player/PlayerLoginEvent.php b/src/pocketmine/event/player/PlayerLoginEvent.php index 6d05df41a..c59ebc7d4 100644 --- a/src/pocketmine/event/player/PlayerLoginEvent.php +++ b/src/pocketmine/event/player/PlayerLoginEvent.php @@ -29,6 +29,8 @@ use pocketmine\Player; */ class PlayerLoginEvent extends PlayerEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var string */ protected $kickMessage; diff --git a/src/pocketmine/event/player/PlayerMoveEvent.php b/src/pocketmine/event/player/PlayerMoveEvent.php index bf29dd1c0..b8f8da7f9 100644 --- a/src/pocketmine/event/player/PlayerMoveEvent.php +++ b/src/pocketmine/event/player/PlayerMoveEvent.php @@ -27,6 +27,8 @@ use pocketmine\Player; class PlayerMoveEvent extends PlayerEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; private $from; private $to; diff --git a/src/pocketmine/event/player/PlayerPreLoginEvent.php b/src/pocketmine/event/player/PlayerPreLoginEvent.php index b3df86a1f..c4c0072fe 100644 --- a/src/pocketmine/event/player/PlayerPreLoginEvent.php +++ b/src/pocketmine/event/player/PlayerPreLoginEvent.php @@ -29,6 +29,8 @@ use pocketmine\Player; */ class PlayerPreLoginEvent extends PlayerEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var string */ protected $kickMessage; diff --git a/src/pocketmine/event/player/PlayerQuitEvent.php b/src/pocketmine/event/player/PlayerQuitEvent.php index 713426960..a5fb1c814 100644 --- a/src/pocketmine/event/player/PlayerQuitEvent.php +++ b/src/pocketmine/event/player/PlayerQuitEvent.php @@ -28,6 +28,8 @@ use pocketmine\Player; */ class PlayerQuitEvent extends PlayerEvent{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var string */ protected $quitMessage; diff --git a/src/pocketmine/event/player/PlayerRespawnEvent.php b/src/pocketmine/event/player/PlayerRespawnEvent.php index 64cc2b6b0..25146804b 100644 --- a/src/pocketmine/event/player/PlayerRespawnEvent.php +++ b/src/pocketmine/event/player/PlayerRespawnEvent.php @@ -29,6 +29,8 @@ use pocketmine\Player; */ class PlayerRespawnEvent extends PlayerEvent{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var Position */ protected $position; diff --git a/src/pocketmine/event/plugin/PluginDisableEvent.php b/src/pocketmine/event/plugin/PluginDisableEvent.php index 6fcb68295..1d85e9093 100644 --- a/src/pocketmine/event/plugin/PluginDisableEvent.php +++ b/src/pocketmine/event/plugin/PluginDisableEvent.php @@ -27,6 +27,8 @@ use pocketmine\plugin\Plugin; class PluginDisableEvent extends PluginEvent{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** * @param Plugin $plugin diff --git a/src/pocketmine/event/plugin/PluginEnableEvent.php b/src/pocketmine/event/plugin/PluginEnableEvent.php index 2e5bec73d..94fe2207b 100644 --- a/src/pocketmine/event/plugin/PluginEnableEvent.php +++ b/src/pocketmine/event/plugin/PluginEnableEvent.php @@ -27,6 +27,8 @@ use pocketmine\plugin\Plugin; class PluginEnableEvent extends PluginEvent{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** * @param Plugin $plugin diff --git a/src/pocketmine/event/server/DataPacketReceiveEvent.php b/src/pocketmine/event/server/DataPacketReceiveEvent.php index b8bc6392a..8bba901c2 100644 --- a/src/pocketmine/event/server/DataPacketReceiveEvent.php +++ b/src/pocketmine/event/server/DataPacketReceiveEvent.php @@ -28,6 +28,8 @@ use pocketmine\Player; class DataPacketReceiveEvent extends ServerEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; private $packet; private $player; diff --git a/src/pocketmine/event/server/DataPacketSendEvent.php b/src/pocketmine/event/server/DataPacketSendEvent.php index eefaa0ee7..88afb2d45 100644 --- a/src/pocketmine/event/server/DataPacketSendEvent.php +++ b/src/pocketmine/event/server/DataPacketSendEvent.php @@ -28,6 +28,8 @@ use pocketmine\Player; class DataPacketSendEvent extends ServerEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; private $packet; private $player; diff --git a/src/pocketmine/event/server/QueryRegenerateEvent.php b/src/pocketmine/event/server/QueryRegenerateEvent.php index 2d3fe6ea2..810b8ba61 100644 --- a/src/pocketmine/event/server/QueryRegenerateEvent.php +++ b/src/pocketmine/event/server/QueryRegenerateEvent.php @@ -27,6 +27,8 @@ use pocketmine\utils\Binary; class QueryRegenerateEvent extends ServerEvent{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; const GAME_ID = "MINECRAFTPE"; diff --git a/src/pocketmine/event/server/RemoteServerCommandEvent.php b/src/pocketmine/event/server/RemoteServerCommandEvent.php index 412c992c8..a680b1c34 100644 --- a/src/pocketmine/event/server/RemoteServerCommandEvent.php +++ b/src/pocketmine/event/server/RemoteServerCommandEvent.php @@ -28,6 +28,8 @@ use pocketmine\command\CommandSender; */ class RemoteServerCommandEvent extends ServerCommandEvent{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** * @param CommandSender $sender diff --git a/src/pocketmine/event/server/ServerCommandEvent.php b/src/pocketmine/event/server/ServerCommandEvent.php index 6a82e67d7..d5d350b53 100644 --- a/src/pocketmine/event/server/ServerCommandEvent.php +++ b/src/pocketmine/event/server/ServerCommandEvent.php @@ -34,6 +34,8 @@ use pocketmine\event\Cancellable; */ class ServerCommandEvent extends ServerEvent implements Cancellable{ public static $handlerList = null; + public static $eventPool = []; + public static $nextEvent = 0; /** @var string */ protected $command; diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index fce466242..2f7608ac3 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -131,7 +131,7 @@ abstract class BaseInventory implements Inventory{ $holder = $this->getHolder(); if($holder instanceof Entity){ - Server::getInstance()->getPluginManager()->callEvent($ev = new EntityInventoryChangeEvent($holder, $this->getItem($index), $item, $index)); + Server::getInstance()->getPluginManager()->callEvent($ev = EntityInventoryChangeEvent::createEvent($holder, $this->getItem($index), $item, $index)); if($ev->isCancelled()){ $this->sendContents($this->getViewers()); @@ -298,7 +298,7 @@ abstract class BaseInventory implements Inventory{ $old = $this->slots[$index]; $holder = $this->getHolder(); if($holder instanceof Entity){ - Server::getInstance()->getPluginManager()->callEvent($ev = new EntityInventoryChangeEvent($holder, $old, $item, $index)); + Server::getInstance()->getPluginManager()->callEvent($ev = EntityInventoryChangeEvent::createEvent($holder, $old, $item, $index)); if($ev->isCancelled()){ $this->sendContents($this->getViewers()); @@ -350,7 +350,7 @@ abstract class BaseInventory implements Inventory{ } public function open(Player $who){ - $who->getServer()->getPluginManager()->callEvent($ev = new InventoryOpenEvent($this, $who)); + $who->getServer()->getPluginManager()->callEvent($ev = InventoryOpenEvent::createEvent($this, $who)); if($ev->isCancelled()){ return false; } diff --git a/src/pocketmine/inventory/CraftingTransactionGroup.php b/src/pocketmine/inventory/CraftingTransactionGroup.php index 74d23da20..eb20ca930 100644 --- a/src/pocketmine/inventory/CraftingTransactionGroup.php +++ b/src/pocketmine/inventory/CraftingTransactionGroup.php @@ -92,7 +92,7 @@ class CraftingTransactionGroup extends SimpleTransactionGroup{ return false; } - Server::getInstance()->getPluginManager()->callEvent($ev = new CraftItemEvent($this, $this->getMatchingRecipe())); + Server::getInstance()->getPluginManager()->callEvent($ev = CraftItemEvent::createEvent($this, $this->getMatchingRecipe())); if($ev->isCancelled()){ foreach($this->inventories as $inventory){ $inventory->sendContents($inventory->getViewers()); diff --git a/src/pocketmine/inventory/PlayerInventory.php b/src/pocketmine/inventory/PlayerInventory.php index 05e3eb894..43837f396 100644 --- a/src/pocketmine/inventory/PlayerInventory.php +++ b/src/pocketmine/inventory/PlayerInventory.php @@ -103,7 +103,7 @@ class PlayerInventory extends BaseInventory{ if($slot >= -1 and $slot < $this->getSize()){ $item = $this->getItem($slot); if($this->getHolder() instanceof Player){ - Server::getInstance()->getPluginManager()->callEvent($ev = new PlayerItemHeldEvent($this->getHolder(), $item, $slot, $this->itemInHandIndex)); + Server::getInstance()->getPluginManager()->callEvent($ev = PlayerItemHeldEvent::createEvent($this->getHolder(), $item, $slot, $this->itemInHandIndex)); if($ev->isCancelled()){ $this->sendHeldItem($this->getHolder()); @@ -203,7 +203,7 @@ class PlayerInventory extends BaseInventory{ } if($index >= $this->getSize()){ //Armor change - Server::getInstance()->getPluginManager()->callEvent($ev = new EntityArmorChangeEvent($this->getHolder(), $this->getItem($index), $item, $index)); + Server::getInstance()->getPluginManager()->callEvent($ev = EntityArmorChangeEvent::createEvent($this->getHolder(), $this->getItem($index), $item, $index)); if($ev->isCancelled() and $this->getHolder() instanceof Player){ $this->sendArmorContents($this->getViewers()); $this->sendContents($this->getViewers()); @@ -229,7 +229,7 @@ class PlayerInventory extends BaseInventory{ $item = Item::get(Item::AIR, null, 0); $old = $this->slots[$index]; if($index >= $this->getSize() and $index < $this->size){ //Armor change - Server::getInstance()->getPluginManager()->callEvent($ev = new EntityArmorChangeEvent($this->getHolder(), $old, $item, $index)); + Server::getInstance()->getPluginManager()->callEvent($ev = EntityArmorChangeEvent::createEvent($this->getHolder(), $old, $item, $index)); if($ev->isCancelled()){ $this->sendArmorContents($this->getViewers()); $this->sendContents($this->getViewers()); diff --git a/src/pocketmine/inventory/SimpleTransactionGroup.php b/src/pocketmine/inventory/SimpleTransactionGroup.php index 9f37310a1..6b0da023c 100644 --- a/src/pocketmine/inventory/SimpleTransactionGroup.php +++ b/src/pocketmine/inventory/SimpleTransactionGroup.php @@ -138,7 +138,7 @@ class SimpleTransactionGroup implements TransactionGroup{ return false; } - Server::getInstance()->getPluginManager()->callEvent($ev = new InventoryTransactionEvent($this)); + Server::getInstance()->getPluginManager()->callEvent($ev = InventoryTransactionEvent::createEvent($this)); if($ev->isCancelled()){ foreach($this->inventories as $inventory){ $inventory->sendContents($inventory->getViewers()); diff --git a/src/pocketmine/item/Bucket.php b/src/pocketmine/item/Bucket.php index 7b528a076..0cf8c9eaf 100644 --- a/src/pocketmine/item/Bucket.php +++ b/src/pocketmine/item/Bucket.php @@ -43,7 +43,7 @@ class Bucket extends Item{ if($target instanceof Liquid and $target->getDamage() === 0){ $result = clone $this; $result->setDamage($target->getID()); - $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result)); + $player->getServer()->getPluginManager()->callEvent($ev = PlayerBucketFillEvent::createEvent($player, $block, $face, $this, $result)); if(!$ev->isCancelled()){ $player->getLevel()->setBlock($target, new Air(), true, true); if($player->isSurvival()){ @@ -57,7 +57,7 @@ class Bucket extends Item{ }elseif($targetBlock instanceof Liquid){ $result = clone $this; $result->setDamage(0); - $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result)); + $player->getServer()->getPluginManager()->callEvent($ev = PlayerBucketFillEvent::createEvent($player, $block, $face, $this, $result)); if(!$ev->isCancelled()){ $player->getLevel()->setBlock($block, $targetBlock, true, true); if($player->isSurvival()){ diff --git a/src/pocketmine/level/Explosion.php b/src/pocketmine/level/Explosion.php index b4eeaf0e0..aa2920c82 100644 --- a/src/pocketmine/level/Explosion.php +++ b/src/pocketmine/level/Explosion.php @@ -135,7 +135,7 @@ class Explosion{ $yield = (1 / $this->size) * 100; if($this->what instanceof Entity){ - $this->level->getServer()->getPluginManager()->callEvent($ev = new EntityExplodeEvent($this->what, $this->source, $this->affectedBlocks, $yield)); + $this->level->getServer()->getPluginManager()->callEvent($ev = EntityExplodeEvent::createEvent($this->what, $this->source, $this->affectedBlocks, $yield)); if($ev->isCancelled()){ return false; }else{ @@ -166,11 +166,11 @@ class Explosion{ $damage = (int) ((($impact * $impact + $impact) / 2) * 8 * $explosionSize + 1); if($this->what instanceof Entity){ - $ev = new EntityDamageByEntityEvent($this->what, $entity, EntityDamageEvent::CAUSE_ENTITY_EXPLOSION, $damage); + $ev = EntityDamageByEntityEvent::createEvent($this->what, $entity, EntityDamageEvent::CAUSE_ENTITY_EXPLOSION, $damage); }elseif($this->what instanceof Block){ - $ev = new EntityDamageByBlockEvent($this->what, $entity, EntityDamageEvent::CAUSE_BLOCK_EXPLOSION, $damage); + $ev = EntityDamageByBlockEvent::createEvent($this->what, $entity, EntityDamageEvent::CAUSE_BLOCK_EXPLOSION, $damage); }else{ - $ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_BLOCK_EXPLOSION, $damage); + $ev = EntityDamageEvent::createEvent($entity, EntityDamageEvent::CAUSE_BLOCK_EXPLOSION, $damage); } $this->level->getServer()->getPluginManager()->callEvent($ev); diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 908465c38..d88dea416 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -176,6 +176,8 @@ class Level implements ChunkManager, Metadatable{ private $useSections; private $blockOrder; + private $temporalPosition; + protected $chunkTickRadius; protected $chunkTickList = []; protected $chunksPerTick; @@ -267,6 +269,7 @@ class Level implements ChunkManager, Metadatable{ $this->clearChunksOnTick = (bool) $this->server->getProperty("chunk-ticking.clear-tick-list", false); $this->timings = new LevelTimings($this); + $this->temporalPosition = new Position(0, 0, 0, $this); } public function initLevel(){ @@ -318,6 +321,7 @@ class Level implements ChunkManager, Metadatable{ $this->provider = null; $this->blockMetadata = null; $this->blockCache = []; + $this->temporalPosition = null; } /** @@ -343,7 +347,7 @@ class Level implements ChunkManager, Metadatable{ */ public function unload($force = false){ - $ev = new LevelUnloadEvent($this); + $ev = LevelUnloadEvent::createEvent($this); if($this === $this->server->getDefaultLevel() and $force !== true){ $ev->setCancelled(true); @@ -675,7 +679,7 @@ class Level implements ChunkManager, Metadatable{ return false; } - $this->server->getPluginManager()->callEvent(new LevelSaveEvent($this)); + $this->server->getPluginManager()->callEvent(LevelSaveEvent::createEvent($this)); $this->provider->setTime((int) $this->time); $this->saveChunks(); @@ -707,7 +711,7 @@ class Level implements ChunkManager, Metadatable{ } for($side = 0; $side <= 5; ++$side){ - $this->server->getPluginManager()->callEvent($ev = new BlockUpdateEvent($block->getSide($side))); + $this->server->getPluginManager()->callEvent($ev = BlockUpdateEvent::createEvent($block->getSide($side))); if(!$ev->isCancelled()){ $ev->getBlock()->onUpdate(self::BLOCK_UPDATE_NORMAL); } @@ -910,7 +914,7 @@ class Level implements ChunkManager, Metadatable{ return $this->blockCache[$index] = $air; } - return $this->blockCache[$index] = Block::get($blockId, $meta, $pos instanceof Position ? $pos : Position::createPosition($pos->x, $pos->y, $pos->z, $this)); + return $this->blockCache[$index] = Block::get($blockId, $meta, $this->temporalPosition->setComponents($pos->x, $pos->y, $pos->z)); } /** @@ -940,7 +944,7 @@ class Level implements ChunkManager, Metadatable{ if($this->getChunk($pos->x >> 4, $pos->z >> 4, true)->setBlock($pos->x & 0x0f, $pos->y & 0x7f, $pos->z & 0x0f, $block->getID(), $block->getDamage())){ if(!($pos instanceof Position)){ - $pos = Position::createPosition($pos->x, $pos->y, $pos->z, $this); + $pos = $this->temporalPosition->setComponents($pos->x, $pos->y, $pos->z); } $block->position($pos); $index = Level::chunkHash($pos->x >> 4, $pos->z >> 4); @@ -959,7 +963,7 @@ class Level implements ChunkManager, Metadatable{ Server::broadcastPacket($this->getUsingChunk($pos->x >> 4, $pos->z >> 4), $pk); /*}else{ if(!($pos instanceof Position)){ - $pos = new Position($pos->x, $pos->y, $pos->z, $this); + $pos = $this->temporalPosition->setComponents($pos->x, $pos->y, $pos->z); } $block->position($pos); if(!isset($this->changedBlocks[$index])){ @@ -976,7 +980,7 @@ class Level implements ChunkManager, Metadatable{ if($update === true){ $this->updateAround($pos); - $this->server->getPluginManager()->callEvent($ev = new BlockUpdateEvent($block)); + $this->server->getPluginManager()->callEvent($ev = BlockUpdateEvent::createEvent($block)); if(!$ev->isCancelled()){ $ev->getBlock()->onUpdate(self::BLOCK_UPDATE_NORMAL); foreach($this->getNearbyEntities(AxisAlignedBB::getBoundingBoxFromPool($block->x - 1, $block->y - 1, $block->z - 1, $block->x + 2, $block->y + 2, $block->z + 2)) as $entity){ @@ -1044,7 +1048,7 @@ class Level implements ChunkManager, Metadatable{ } if($player instanceof Player){ - $ev = new BlockBreakEvent($player, $target, $item, ($player->getGamemode() & 0x01) === 1 ? true : false); + $ev = BlockBreakEvent::createEvent($player, $target, $item, ($player->getGamemode() & 0x01) === 1 ? true : false); $lastTime = $player->lastBreak - 0.1; //TODO: replace with true lag if(($player->getGamemode() & 0x01) > 0){ @@ -1145,7 +1149,7 @@ class Level implements ChunkManager, Metadatable{ } if($player instanceof Player){ - $ev = new PlayerInteractEvent($player, $item, $target, $face); + $ev = PlayerInteractEvent::createEvent($player, $item, $target, $face); if(!$player->isOp() and ($distance = $this->server->getConfigInt("spawn-protection", 16)) > -1){ $t = new Vector2($target->x, $target->z); $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z); @@ -1210,7 +1214,7 @@ class Level implements ChunkManager, Metadatable{ if($player instanceof Player){ - $ev = new BlockPlaceEvent($player, $hand, $block, $target, $item); + $ev = BlockPlaceEvent::createEvent($player, $hand, $block, $target, $item); if(!$player->isOp() and ($distance = $this->server->getConfigInt("spawn-protection", 16)) > -1){ $t = new Vector2($target->x, $target->z); $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z); @@ -1585,7 +1589,7 @@ class Level implements ChunkManager, Metadatable{ $this->setChunk($x, $z, $chunk); $chunk = $this->getChunk($x, $z); if($chunk instanceof FullChunk and (!($oldChunk instanceof FullChunk) or $oldChunk->isPopulated() === false) and $chunk->isPopulated()){ - $this->server->getPluginManager()->callEvent(new ChunkPopulateEvent($chunk)); + $this->server->getPluginManager()->callEvent(ChunkPopulateEvent::createEvent($chunk)); } } @@ -1669,7 +1673,7 @@ class Level implements ChunkManager, Metadatable{ public function setSpawnLocation(Vector3 $pos){ $previousSpawn = $this->getSpawnLocation(); $this->provider->setSpawn($pos); - $this->server->getPluginManager()->callEvent(new SpawnChangeEvent($this, $previousSpawn)); + $this->server->getPluginManager()->callEvent(SpawnChangeEvent::createEvent($this, $previousSpawn)); } public function requestChunk($x, $z, Player $player, $order = LevelProvider::ORDER_ZXY){ @@ -1832,7 +1836,7 @@ class Level implements ChunkManager, Metadatable{ } } - $this->server->getPluginManager()->callEvent(new ChunkLoadEvent($chunk, !$chunk->isGenerated())); + $this->server->getPluginManager()->callEvent(ChunkLoadEvent::createEvent($chunk, !$chunk->isGenerated())); return true; } @@ -1867,7 +1871,7 @@ class Level implements ChunkManager, Metadatable{ $chunk = $this->getChunk($x, $z); if($chunk instanceof FullChunk){ - $this->server->getPluginManager()->callEvent($ev = new ChunkUnloadEvent($chunk)); + $this->server->getPluginManager()->callEvent($ev = ChunkUnloadEvent::createEvent($chunk)); if($ev->isCancelled()){ return false; } diff --git a/src/pocketmine/level/Position.php b/src/pocketmine/level/Position.php index a3c12460f..8b04aa4dc 100644 --- a/src/pocketmine/level/Position.php +++ b/src/pocketmine/level/Position.php @@ -168,4 +168,18 @@ class Position extends Vector3{ return "Position(level=" . ($this->isValid() ? $this->getLevel()->getName() : "null") . ",x=" . $this->x . ",y=" . $this->y . ",z=" . $this->z . ")"; } + /** + * @param $x + * @param $y + * @param $z + * + * @return Position + */ + public function setComponents($x, $y, $z){ + $this->x = $x; + $this->y = $y; + $this->z = $z; + return $this; + } + } diff --git a/src/pocketmine/network/protocol/DataPacket.php b/src/pocketmine/network/protocol/DataPacket.php index 7d7a599e0..5aa928815 100644 --- a/src/pocketmine/network/protocol/DataPacket.php +++ b/src/pocketmine/network/protocol/DataPacket.php @@ -32,8 +32,7 @@ abstract class DataPacket extends \stdClass{ public static function getFromPool(){ if(static::$next >= count(static::$pool)){ - $pk = static::class; - static::$pool[] = new $pk; + static::$pool[] = new static; } return static::$pool[static::$next++]->clean(); } diff --git a/src/pocketmine/network/query/QueryHandler.php b/src/pocketmine/network/query/QueryHandler.php index 750f5e0ca..90074a7ca 100644 --- a/src/pocketmine/network/query/QueryHandler.php +++ b/src/pocketmine/network/query/QueryHandler.php @@ -58,7 +58,7 @@ class QueryHandler{ } public function regenerateInfo(){ - $this->server->getPluginManager()->callEvent($ev = new QueryRegenerateEvent($this->server, 5)); + $this->server->getPluginManager()->callEvent($ev = QueryRegenerateEvent::createEvent($this->server, 5)); $this->longData = $ev->getLongQuery(); $this->shortData = $ev->getShortQuery(); $this->timeout = microtime(true) + $ev->getTimeout(); diff --git a/src/pocketmine/network/rcon/RCON.php b/src/pocketmine/network/rcon/RCON.php index fa60f7837..6218fb209 100644 --- a/src/pocketmine/network/rcon/RCON.php +++ b/src/pocketmine/network/rcon/RCON.php @@ -94,7 +94,7 @@ class RCON{ $response = new RemoteConsoleCommandSender(); $command = $this->workers[$n]->cmd; - $this->server->getPluginManager()->callEvent($ev = new RemoteServerCommandEvent($response, $command)); + $this->server->getPluginManager()->callEvent($ev = RemoteServerCommandEvent::createEvent($response, $command)); if(!$ev->isCancelled()){ $this->server->dispatchCommand($ev->getSender(), $ev->getCommand()); diff --git a/src/pocketmine/plugin/PharPluginLoader.php b/src/pocketmine/plugin/PharPluginLoader.php index 65efa2d8c..abfda8c91 100644 --- a/src/pocketmine/plugin/PharPluginLoader.php +++ b/src/pocketmine/plugin/PharPluginLoader.php @@ -121,7 +121,7 @@ class PharPluginLoader implements PluginLoader{ $plugin->setEnabled(true); - $this->server->getPluginManager()->callEvent(new PluginEnableEvent($plugin)); + $this->server->getPluginManager()->callEvent(PluginEnableEvent::createEvent($plugin)); } } @@ -132,7 +132,7 @@ class PharPluginLoader implements PluginLoader{ if($plugin instanceof PluginBase and $plugin->isEnabled()){ $this->server->getLogger()->info("Disabling " . $plugin->getDescription()->getFullName()); - $this->server->getPluginManager()->callEvent(new PluginDisableEvent($plugin)); + $this->server->getPluginManager()->callEvent(PluginDisableEvent::createEvent($plugin)); $plugin->setEnabled(false); } diff --git a/src/pocketmine/tile/Furnace.php b/src/pocketmine/tile/Furnace.php index 2f722f500..fc364747d 100644 --- a/src/pocketmine/tile/Furnace.php +++ b/src/pocketmine/tile/Furnace.php @@ -169,7 +169,7 @@ class Furnace extends Tile implements InventoryHolder, Container{ } protected function checkFuel(Item $fuel){ - $this->server->getPluginManager()->callEvent($ev = new FurnaceBurnEvent($this, $fuel, $fuel->getFuelTime())); + $this->server->getPluginManager()->callEvent($ev = FurnaceBurnEvent::createEvent($this, $fuel, $fuel->getFuelTime())); if($ev->isCancelled()){ return; @@ -219,7 +219,7 @@ class Furnace extends Tile implements InventoryHolder, Container{ if($this->namedtag["CookTime"] >= 200){ //10 seconds $product = Item::get($smelt->getResult()->getID(), $smelt->getResult()->getDamage(), $product->getCount() + 1); - $this->server->getPluginManager()->callEvent($ev = new FurnaceSmeltEvent($this, $raw, $product)); + $this->server->getPluginManager()->callEvent($ev = FurnaceSmeltEvent::createEvent($this, $raw, $product)); if(!$ev->isCancelled()){ $this->inventory->setResult($ev->getResult()); diff --git a/src/spl b/src/spl index 1095acf14..dd275a8f9 160000 --- a/src/spl +++ b/src/spl @@ -1 +1 @@ -Subproject commit 1095acf146aaf8c9dffeea4d04999322fd5627d9 +Subproject commit dd275a8f9909cd1e52079173e4447c7a88d7e22e From b9f1812f61319e1a96b723d9c2a2cbc7947a09ab Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 28 Oct 2014 11:05:32 +0100 Subject: [PATCH 20/61] Disallow further modification of Signs by its creator after load/unload --- src/pocketmine/level/Level.php | 8 ++++---- src/pocketmine/tile/Sign.php | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index d88dea416..0925e1fd7 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1363,15 +1363,15 @@ class Level implements ChunkManager, Metadatable{ } /** - * Returns the Tile in a position, or false if not found + * Returns the Tile in a position, or null if not found * * @param Vector3 $pos * - * @return bool|Tile + * @return Tile */ public function getTile(Vector3 $pos){ if($pos instanceof Position and $pos->getLevel() !== $this){ - return false; + return null; } $tiles = $this->getChunkTiles($pos->x >> 4, $pos->z >> 4); if(count($tiles) > 0){ @@ -1382,7 +1382,7 @@ class Level implements ChunkManager, Metadatable{ } } - return false; + return null; } /** diff --git a/src/pocketmine/tile/Sign.php b/src/pocketmine/tile/Sign.php index ce020f900..fae67c191 100644 --- a/src/pocketmine/tile/Sign.php +++ b/src/pocketmine/tile/Sign.php @@ -46,6 +46,11 @@ class Sign extends Spawnable{ parent::__construct($chunk, $nbt); } + public function saveNBT(){ + parent::saveNBT(); + unset($this->namedtag->Creator); + } + public function setText($line1 = "", $line2 = "", $line3 = "", $line4 = ""){ $this->namedtag->Text1 = new String("Text1", $line1); $this->namedtag->Text2 = new String("Text2", $line2); From a5b85c549aac00e9f4bfa0b398628c27db145858 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 28 Oct 2014 12:13:31 +0100 Subject: [PATCH 21/61] Added Snowballs --- src/pocketmine/Player.php | 38 ++++++- src/pocketmine/entity/Arrow.php | 150 ++------------------------ src/pocketmine/entity/Projectile.php | 156 +++++++++++++++++++++++++++ src/pocketmine/entity/Snowball.php | 58 ++++++++++ 4 files changed, 257 insertions(+), 145 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 8c738c533..b8dfbf512 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -29,6 +29,7 @@ use pocketmine\entity\Entity; use pocketmine\entity\Human; use pocketmine\entity\Living; use pocketmine\entity\Projectile; +use pocketmine\entity\Snowball; use pocketmine\event\block\SignChangeEvent; use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\event\entity\EntityDamageEvent; @@ -1629,7 +1630,42 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->dataPacket($pk); break; }elseif($packet->face === 0xff){ - //TODO: add event + $item = $this->inventory->getItemInHand(); + if($item->getID() === Item::SNOWBALL){ + $nbt = new Compound("", [ + "Pos" => new Enum("Pos", [ + new Double("", $this->x), + new Double("", $this->y + $this->getEyeHeight()), + new Double("", $this->z) + ]), + "Motion" => new Enum("Motion", [ + new Double("", -sin($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI)), + new Double("", -sin($this->pitch / 180 * M_PI)), + new Double("", cos($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI)) + ]), + "Rotation" => new Enum("Rotation", [ + new Float("", $this->yaw), + new Float("", $this->pitch) + ]), + ]); + + $f = 1.5; + $snowball = new Snowball($this->chunk, $nbt, $this); + $snowball->setMotion($snowball->getMotion()->multiply($f)); + if($this->isSurvival()){ + $this->inventory->removeItem(Item::get(Item::SNOWBALL, 0, 1)); + } + if($snowball instanceof Projectile){ + $this->server->getPluginManager()->callEvent($projectileEv = ProjectileLaunchEvent::createEvent($snowball)); + if($projectileEv->isCancelled()){ + $snowball->kill(); + }else{ + $snowball->spawnToAll(); + } + }else{ + $snowball->spawnToAll(); + } + } $this->inAction = true; $this->startAction = microtime(true); $this->sendMetadata($this->getViewers()); diff --git a/src/pocketmine/entity/Arrow.php b/src/pocketmine/entity/Arrow.php index 086e5158a..f0a127a8b 100644 --- a/src/pocketmine/entity/Arrow.php +++ b/src/pocketmine/entity/Arrow.php @@ -21,17 +21,8 @@ namespace pocketmine\entity; - -use pocketmine\event\entity\EntityCombustByEntityEvent; -use pocketmine\event\entity\EntityDamageByEntityEvent; -use pocketmine\event\entity\EntityDamageEvent; -use pocketmine\event\entity\EntityRegainHealthEvent; -use pocketmine\event\entity\ProjectileHitEvent; use pocketmine\level\format\FullChunk; -use pocketmine\level\MovingObjectPosition; -use pocketmine\math\Vector3; use pocketmine\nbt\tag\Compound; -use pocketmine\nbt\tag\Short; use pocketmine\nbt\tag\String; use pocketmine\network\protocol\AddEntityPacket; use pocketmine\network\protocol\SetEntityMotionPacket; @@ -44,13 +35,10 @@ class Arrow extends Projectile{ public $length = 0.5; public $height = 0.5; - /** @var Entity */ - public $shootingEntity = null; - protected $gravity = 0.05; protected $drag = 0.01; - private $damage = 6; + protected $damage = 6; public function __construct(FullChunk $chunk, Compound $nbt, Entity $shootingEntity = null){ $this->shootingEntity = $shootingEntity; @@ -59,11 +47,7 @@ class Arrow extends Projectile{ protected function initEntity(){ $this->namedtag->id = new String("id", "Arrow"); - $this->setMaxHealth(1); - $this->setHealth(1); - if(isset($this->namedtag->Age)){ - $this->age = $this->namedtag["Age"]; - } + parent::initEntity(); } @@ -74,105 +58,11 @@ class Arrow extends Projectile{ $this->timings->startTiming(); - $tickDiff = max(1, $currentTick - $this->lastUpdate); - $this->lastUpdate = $currentTick; - - $hasUpdate = $this->entityBaseTick($tickDiff); - - if(!$this->dead){ - - $movingObjectPosition = null; - - $this->motionY -= $this->gravity; - - $this->keepMovement = $this->checkObstruction($this->x, ($this->boundingBox->minY + $this->boundingBox->maxY) / 2, $this->z); - - $moveVector = Vector3::createVector($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ); - - $list = $this->getLevel()->getCollidingEntities($this->boundingBox->addCoord($this->motionX, $this->motionY, $this->motionZ)->expand(1, 1, 1), $this); - - $nearDistance = PHP_INT_MAX; - $nearEntity = null; - - foreach($list as $entity){ - if(/*!$entity->canCollideWith($this) or */ - ($entity === $this->shootingEntity and $this->ticksLived < 5) - ){ - continue; - } - - $axisalignedbb = $entity->boundingBox->grow(0.3, 0.3, 0.3); - $ob = $axisalignedbb->calculateIntercept($this, $moveVector); - - if($ob === null){ - continue; - } - - $distance = $this->distance($ob->hitVector); - - if($distance < $nearDistance){ - $nearDistance = $distance; - $nearEntity = $entity; - } - } - - if($nearEntity !== null){ - $movingObjectPosition = MovingObjectPosition::fromEntity($nearEntity); - } - - if($movingObjectPosition !== null){ - if($movingObjectPosition->entityHit !== null){ - - $this->server->getPluginManager()->callEvent(ProjectileHitEvent::createEvent($this)); - - $motion = sqrt($this->motionX ** 2 + $this->motionY ** 2 + $this->motionZ ** 2); - $damage = ceil($motion * $this->damage); - - - $ev = EntityDamageByEntityEvent::createEvent($this->shootingEntity === null ? $this : $this->shootingEntity, $movingObjectPosition->entityHit, EntityDamageEvent::CAUSE_PROJECTILE, $damage); - - $this->server->getPluginManager()->callEvent($ev); - - if(!$ev->isCancelled()){ - $movingObjectPosition->entityHit->attack($ev->getFinalDamage(), $ev); - } - - if($this->fireTicks > 0){ - $ev = EntityCombustByEntityEvent::createEvent($this, $movingObjectPosition->entityHit, 5); - $this->server->getPluginManager()->callEvent($ev); - if(!$ev->isCancelled()){ - $movingObjectPosition->entityHit->setOnFire($ev->getDuration()); - } - } - - $this->kill(); - return true; - } - } - - $this->move($this->motionX, $this->motionY, $this->motionZ); - - if($this->onGround and ($this->motionX != 0 or $this->motionY != 0 or $this->motionZ != 0)){ - $this->motionX = 0; - $this->motionY = 0; - $this->motionZ = 0; - - $this->server->getPluginManager()->callEvent(ProjectileHitEvent::createEvent($this)); - } - - if(!$this->onGround or $this->motionX != 0 or $this->motionY != 0 or $this->motionZ != 0){ - $f = sqrt(($this->motionX ** 2) + ($this->motionZ ** 2)); - $this->yaw = (atan2($this->motionX, $this->motionZ) * 180 / M_PI); - $this->pitch = (atan2($this->motionY, $f) * 180 / M_PI); - $hasUpdate = true; - } - - if($this->age > 1200){ - $this->kill(); - $hasUpdate = true; - } - $this->updateMovement(); + $hasUpdate = parent::onUpdate($currentTick); + if($this->age > 1200){ + $this->kill(); + $hasUpdate = true; } $this->timings->stopTiming(); @@ -180,34 +70,6 @@ class Arrow extends Projectile{ return $hasUpdate; } - public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){ - - } - - public function heal($amount, $source = EntityRegainHealthEvent::CAUSE_MAGIC){ - - } - - public function saveNBT(){ - parent::saveNBT(); - $this->namedtag->Age = new Short("Age", $this->age); - } - - public function getData(){ - $flags = 0; - $flags |= $this->fireTicks > 0 ? 1 : 0; - - return [ - 0 => ["type" => 0, "value" => $flags], - 1 => ["type" => 1, "value" => $this->airTicks], - 16 => ["type" => 0, "value" => 0] //Is critical - ]; - } - - public function canCollideWith(Entity $entity){ - return $entity instanceof Living and !$this->onGround; - } - public function spawnTo(Player $player){ $pk = AddEntityPacket::getFromPool(); $pk->type = Arrow::NETWORK_ID; diff --git a/src/pocketmine/entity/Projectile.php b/src/pocketmine/entity/Projectile.php index 320a49e53..3de60df75 100644 --- a/src/pocketmine/entity/Projectile.php +++ b/src/pocketmine/entity/Projectile.php @@ -22,6 +22,162 @@ namespace pocketmine\entity; +use pocketmine\event\entity\EntityCombustByEntityEvent; +use pocketmine\event\entity\EntityDamageByEntityEvent; +use pocketmine\event\entity\EntityDamageEvent; +use pocketmine\event\entity\EntityRegainHealthEvent; +use pocketmine\event\entity\ProjectileHitEvent; +use pocketmine\level\MovingObjectPosition; +use pocketmine\math\Vector3; +use pocketmine\nbt\tag\Short; + abstract class Projectile extends Entity{ + /** @var Entity */ + public $shootingEntity = null; + protected $damage = 0; + + protected function initEntity(){ + $this->setMaxHealth(1); + $this->setHealth(1); + if(isset($this->namedtag->Age)){ + $this->age = $this->namedtag["Age"]; + } + + } + + public function canCollideWith(Entity $entity){ + return $entity instanceof Living and !$this->onGround; + } + + public function getData(){ + $flags = 0; + $flags |= $this->fireTicks > 0 ? 1 : 0; + + return [ + 0 => ["type" => 0, "value" => $flags], + 1 => ["type" => 1, "value" => $this->airTicks], + 16 => ["type" => 0, "value" => 0] //Is critical + ]; + } + + public function saveNBT(){ + parent::saveNBT(); + $this->namedtag->Age = new Short("Age", $this->age); + } + + public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){ + + } + + public function heal($amount, $source = EntityRegainHealthEvent::CAUSE_MAGIC){ + + } + + public function onUpdate($currentTick){ + if($this->closed){ + return false; + } + + + + $tickDiff = max(1, $currentTick - $this->lastUpdate); + $this->lastUpdate = $currentTick; + + $hasUpdate = $this->entityBaseTick($tickDiff); + + if(!$this->dead){ + + $movingObjectPosition = null; + + $this->motionY -= $this->gravity; + + $this->keepMovement = $this->checkObstruction($this->x, ($this->boundingBox->minY + $this->boundingBox->maxY) / 2, $this->z); + + $moveVector = Vector3::createVector($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ); + + $list = $this->getLevel()->getCollidingEntities($this->boundingBox->addCoord($this->motionX, $this->motionY, $this->motionZ)->expand(1, 1, 1), $this); + + $nearDistance = PHP_INT_MAX; + $nearEntity = null; + + foreach($list as $entity){ + if(/*!$entity->canCollideWith($this) or */ + ($entity === $this->shootingEntity and $this->ticksLived < 5) + ){ + continue; + } + + $axisalignedbb = $entity->boundingBox->grow(0.3, 0.3, 0.3); + $ob = $axisalignedbb->calculateIntercept($this, $moveVector); + + if($ob === null){ + continue; + } + + $distance = $this->distance($ob->hitVector); + + if($distance < $nearDistance){ + $nearDistance = $distance; + $nearEntity = $entity; + } + } + + if($nearEntity !== null){ + $movingObjectPosition = MovingObjectPosition::fromEntity($nearEntity); + } + + if($movingObjectPosition !== null){ + if($movingObjectPosition->entityHit !== null){ + + $this->server->getPluginManager()->callEvent(ProjectileHitEvent::createEvent($this)); + + $motion = sqrt($this->motionX ** 2 + $this->motionY ** 2 + $this->motionZ ** 2); + $damage = ceil($motion * $this->damage); + + + $ev = EntityDamageByEntityEvent::createEvent($this->shootingEntity === null ? $this : $this->shootingEntity, $movingObjectPosition->entityHit, EntityDamageEvent::CAUSE_PROJECTILE, $damage); + + $this->server->getPluginManager()->callEvent($ev); + + if(!$ev->isCancelled()){ + $movingObjectPosition->entityHit->attack($ev->getFinalDamage(), $ev); + } + + if($this->fireTicks > 0){ + $ev = EntityCombustByEntityEvent::createEvent($this, $movingObjectPosition->entityHit, 5); + $this->server->getPluginManager()->callEvent($ev); + if(!$ev->isCancelled()){ + $movingObjectPosition->entityHit->setOnFire($ev->getDuration()); + } + } + + $this->kill(); + return true; + } + } + + $this->move($this->motionX, $this->motionY, $this->motionZ); + + if($this->onGround and ($this->motionX != 0 or $this->motionY != 0 or $this->motionZ != 0)){ + $this->motionX = 0; + $this->motionY = 0; + $this->motionZ = 0; + + $this->server->getPluginManager()->callEvent(ProjectileHitEvent::createEvent($this)); + } + + if(!$this->onGround or $this->motionX != 0 or $this->motionY != 0 or $this->motionZ != 0){ + $f = sqrt(($this->motionX ** 2) + ($this->motionZ ** 2)); + $this->yaw = (atan2($this->motionX, $this->motionZ) * 180 / M_PI); + $this->pitch = (atan2($this->motionY, $f) * 180 / M_PI); + $hasUpdate = true; + } + + $this->updateMovement(); + + } + + return $hasUpdate; + } } \ No newline at end of file diff --git a/src/pocketmine/entity/Snowball.php b/src/pocketmine/entity/Snowball.php index 87761b64d..4d70cc8a3 100644 --- a/src/pocketmine/entity/Snowball.php +++ b/src/pocketmine/entity/Snowball.php @@ -22,10 +22,68 @@ namespace pocketmine\entity; +use pocketmine\level\format\FullChunk; +use pocketmine\nbt\tag\Compound; use pocketmine\nbt\tag\String; +use pocketmine\network\protocol\AddEntityPacket; +use pocketmine\network\protocol\SetEntityMotionPacket; +use pocketmine\Player; class Snowball extends Projectile{ + const NETWORK_ID = 81; + + public $width = 0.25; + public $length = 0.25; + public $height = 0.25; + + protected $gravity = 0.03; + protected $drag = 0.01; + + public function __construct(FullChunk $chunk, Compound $nbt, Entity $shootingEntity = null){ + $this->shootingEntity = $shootingEntity; + parent::__construct($chunk, $nbt); + } + + public function onUpdate($currentTick){ + if($this->closed){ + return false; + } + + $this->timings->startTiming(); + + $hasUpdate = parent::onUpdate($currentTick); + + if($this->age > 1200 or $this->onGround){ + $this->kill(); + $hasUpdate = true; + } + + $this->timings->stopTiming(); + + return $hasUpdate; + } + protected function initEntity(){ $this->namedtag->id = new String("id", "Snowball"); + parent::initEntity(); + } + + public function spawnTo(Player $player){ + $pk = AddEntityPacket::getFromPool(); + $pk->type = Snowball::NETWORK_ID; + $pk->eid = $this->getID(); + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $pk->did = 0; //TODO: send motion here + $player->dataPacket($pk); + + $pk = SetEntityMotionPacket::getFromPool(); + $pk->entities = [ + [$this->getID(), $this->motionX, $this->motionY, $this->motionZ] + ]; + $player->dataPacket($pk); + + parent::spawnTo($player); } } \ No newline at end of file From 34ae760def60e790bb172bf0ab6fee6e6884ecbf Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 28 Oct 2014 13:09:27 +0100 Subject: [PATCH 22/61] New way to spawn entities/tiles using a global register table, allow overriding default entity/tile classes via classes --- src/pocketmine/Player.php | 6 +-- src/pocketmine/Server.php | 34 +++++++++++++++++ src/pocketmine/block/BurningFurnace.php | 4 +- src/pocketmine/block/Chest.php | 4 +- src/pocketmine/block/Fallable.php | 7 ++-- src/pocketmine/block/TNT.php | 3 +- src/pocketmine/entity/Entity.php | 36 ++++++++++++++++++ .../{FallingBlock.php => FallingSand.php} | 8 ++-- .../entity/{DroppedItem.php => Item.php} | 11 +++--- .../event/entity/EntityDespawnEvent.php | 4 +- .../event/entity/EntitySpawnEvent.php | 4 +- .../event/entity/ItemDespawnEvent.php | 8 ++-- .../event/entity/ItemSpawnEvent.php | 8 ++-- src/pocketmine/item/SpawnEgg.php | 31 +--------------- src/pocketmine/level/Explosion.php | 2 +- src/pocketmine/level/Level.php | 6 +-- .../level/format/generic/BaseFullChunk.php | 37 +++++-------------- src/pocketmine/tile/Tile.php | 35 ++++++++++++++++++ 18 files changed, 154 insertions(+), 94 deletions(-) rename src/pocketmine/entity/{FallingBlock.php => FallingSand.php} (97%) rename src/pocketmine/entity/{DroppedItem.php => Item.php} (95%) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index b8dfbf512..dfac68181 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -24,7 +24,7 @@ namespace pocketmine; use pocketmine\block\Block; use pocketmine\command\CommandSender; use pocketmine\entity\Arrow; -use pocketmine\entity\DroppedItem; +use pocketmine\entity\Item as DroppedItem; use pocketmine\entity\Entity; use pocketmine\entity\Human; use pocketmine\entity\Living; @@ -1650,7 +1650,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ ]); $f = 1.5; - $snowball = new Snowball($this->chunk, $nbt, $this); + $snowball = Entity::createEntity("Snowball", $this->chunk, $nbt, $this); $snowball->setMotion($snowball->getMotion()->multiply($f)); if($this->isSurvival()){ $this->inventory->removeItem(Item::get(Item::SNOWBALL, 0, 1)); @@ -1709,7 +1709,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ ]); $f = 1.5; - $ev = EntityShootBowEvent::createEvent($this, $bow, new Arrow($this->chunk, $nbt, $this), $f); + $ev = EntityShootBowEvent::createEvent($this, $bow, Entity::createEntity("Arrow", $this->chunk, $nbt, $this), $f); $this->server->getPluginManager()->callEvent($ev); diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 8ae5dde89..049f4acec 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -31,12 +31,21 @@ use pocketmine\command\CommandSender; use pocketmine\command\ConsoleCommandSender; use pocketmine\command\PluginIdentifiableCommand; use pocketmine\command\SimpleCommandMap; +use pocketmine\entity\Arrow; +use pocketmine\entity\Entity; +use pocketmine\entity\FallingSand; +use pocketmine\entity\Human; +use pocketmine\entity\PrimedTNT; +use pocketmine\entity\Snowball; +use pocketmine\entity\Villager; +use pocketmine\entity\Zombie; use pocketmine\event\Event; use pocketmine\event\HandlerList; use pocketmine\event\level\LevelInitEvent; use pocketmine\event\level\LevelLoadEvent; use pocketmine\event\server\ServerCommandEvent; use pocketmine\event\Timings; +use pocketmine\entity\Item as DroppedItem; use pocketmine\event\TimingsHandler; use pocketmine\inventory\CraftingManager; use pocketmine\inventory\InventoryType; @@ -82,6 +91,10 @@ use pocketmine\plugin\PluginManager; use pocketmine\scheduler\CallbackTask; use pocketmine\scheduler\SendUsageTask; use pocketmine\scheduler\ServerScheduler; +use pocketmine\tile\Chest; +use pocketmine\tile\Furnace; +use pocketmine\tile\Sign; +use pocketmine\tile\Tile; use pocketmine\updater\AutoUpdater; use pocketmine\utils\Binary; use pocketmine\utils\Cache; @@ -1553,6 +1566,9 @@ class Server{ $this->consoleSender = new ConsoleCommandSender(); $this->commandMap = new SimpleCommandMap($this); + $this->registerEntities(); + $this->registerTiles(); + InventoryType::init(); Block::init(); Item::init(); @@ -2142,4 +2158,22 @@ class Server{ return true; } + private function registerEntities(){ + Entity::registerEntity(Arrow::class); + Entity::registerEntity(DroppedItem::class); + Entity::registerEntity(FallingSand::class); + Entity::registerEntity(PrimedTNT::class); + Entity::registerEntity(Snowball::class); + Entity::registerEntity(Villager::class); + Entity::registerEntity(Zombie::class); + + Entity::registerEntity(Human::class, true); + } + + private function registerTiles(){ + Tile::registerTile(Chest::class); + Tile::registerTile(Furnace::class); + Tile::registerTile(Sign::class); + } + } diff --git a/src/pocketmine/block/BurningFurnace.php b/src/pocketmine/block/BurningFurnace.php index 12a58907b..5c9b46d86 100644 --- a/src/pocketmine/block/BurningFurnace.php +++ b/src/pocketmine/block/BurningFurnace.php @@ -55,7 +55,7 @@ class BurningFurnace extends Solid{ new Int("z", $this->z) ]); $nbt->Items->setTagType(NBT::TAG_Compound); - new Furnace($this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); + Tile::createTile("Furnace", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); return true; } @@ -81,7 +81,7 @@ class BurningFurnace extends Solid{ new Int("z", $this->z) ]); $nbt->Items->setTagType(NBT::TAG_Compound); - $furnace = new Furnace($this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); + $furnace = Tile::createTile("Furnace", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); } if(($player->getGamemode() & 0x01) === 0x01){ diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index 9242b4a99..2b670f315 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -90,9 +90,9 @@ class Chest extends Transparent{ new Int("z", $this->z) ]); $nbt->Items->setTagType(NBT::TAG_Compound); - $tile = new TileChest($this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); + $tile = Tile::createTile("Chest", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); - if($chest instanceof TileChest){ + if($chest instanceof TileChest and $tile instanceof TileChest){ $chest->pairWith($tile); $tile->pairWith($chest); } diff --git a/src/pocketmine/block/Fallable.php b/src/pocketmine/block/Fallable.php index 8faf46acf..448878fc9 100644 --- a/src/pocketmine/block/Fallable.php +++ b/src/pocketmine/block/Fallable.php @@ -21,7 +21,8 @@ namespace pocketmine\block; -use pocketmine\entity\FallingBlock; +use pocketmine\entity\Entity; +use pocketmine\entity\FallingSand; use pocketmine\item\Item; use pocketmine\level\Level; use pocketmine\nbt\tag\Byte; @@ -46,7 +47,7 @@ abstract class Fallable extends Solid{ if($this->hasPhysics === true and $type === Level::BLOCK_UPDATE_NORMAL){ $down = $this->getSide(0); if($down->getID() === self::AIR or ($down instanceof Liquid)){ - $fall = new FallingBlock($this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), new Compound("", [ + $fall = Entity::createEntity("FallingSand", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), new Compound("", [ "Pos" => new Enum("Pos", [ new Double("", $this->x + 0.5), new Double("", $this->y), @@ -67,8 +68,6 @@ abstract class Fallable extends Solid{ $fall->spawnToAll(); } - - return false; } } } \ No newline at end of file diff --git a/src/pocketmine/block/TNT.php b/src/pocketmine/block/TNT.php index 5dc758ac9..31a68c3ff 100644 --- a/src/pocketmine/block/TNT.php +++ b/src/pocketmine/block/TNT.php @@ -21,6 +21,7 @@ namespace pocketmine\block; +use pocketmine\entity\Entity; use pocketmine\entity\PrimedTNT; use pocketmine\item\Item; use pocketmine\nbt\tag\Byte; @@ -44,7 +45,7 @@ class TNT extends Solid{ $this->getLevel()->setBlock($this, new Air(), true); $mot = (new Random())->nextSignedFloat() * M_PI * 2; - $tnt = new PrimedTNT($this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), new Compound("", [ + $tnt = Entity::createEntity("PrimedTNT", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), new Compound("", [ "Pos" => new Enum("Pos", [ new Double("", $this->x + 0.5), new Double("", $this->y), diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 3d63b1299..c874a8b3d 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -62,9 +62,12 @@ use pocketmine\Server; abstract class Entity extends Location implements Metadatable{ + const NETWORK_ID = -1; public static $entityCount = 1; + /** @var Entity[] */ + private static $knownEntities = []; /** * @var Player[] @@ -219,6 +222,39 @@ abstract class Entity extends Location implements Metadatable{ } + /** + * @param int|string $type + * @param FullChunk $chunk + * @param Compound $nbt + * @param $args + * + * @return Entity + */ + public static function createEntity($type, FullChunk $chunk, Compound $nbt, ...$args){ + if(isset(self::$knownEntities[$type])){ + $class = self::$knownEntities[$type]; + return new $class($chunk, $nbt, ...$args); + } + + return null; + } + + public static function registerEntity($className, $force = false){ + $class = new \ReflectionClass($className); + if(is_a($className, Entity::class, true) and !$class->isAbstract()){ + if($className::NETWORK_ID !== -1){ + self::$knownEntities[$className::NETWORK_ID] = $className; + }elseif(!$force){ + return false; + } + + self::$knownEntities[$class->getShortName()] = $className; + return true; + } + + return false; + } + public function saveNBT(){ $this->namedtag->Pos = new Enum("Pos", [ new Double(0, $this->x), diff --git a/src/pocketmine/entity/FallingBlock.php b/src/pocketmine/entity/FallingSand.php similarity index 97% rename from src/pocketmine/entity/FallingBlock.php rename to src/pocketmine/entity/FallingSand.php index d9bb4d1ba..a4a0115bb 100644 --- a/src/pocketmine/entity/FallingBlock.php +++ b/src/pocketmine/entity/FallingSand.php @@ -35,8 +35,7 @@ use pocketmine\network\protocol\AddEntityPacket; use pocketmine\network\protocol\SetEntityMotionPacket; use pocketmine\Player; -class FallingBlock extends Entity{ - +class FallingSand extends Entity{ const NETWORK_ID = 66; public $width = 0.98; @@ -54,8 +53,7 @@ class FallingBlock extends Entity{ $this->namedtag->id = new String("id", "FallingSand"); if(isset($this->namedtag->TileID)){ $this->blockId = $this->namedtag["TileID"]; - } - elseif(isset($this->namedtag->Tile)){ + }elseif(isset($this->namedtag->Tile)){ $this->blockId = $this->namedtag["Tile"]; $this->namedtag["TileID"] = new Int("TileID", $this->blockId); } @@ -151,7 +149,7 @@ class FallingBlock extends Entity{ public function spawnTo(Player $player){ $pk = AddEntityPacket::getFromPool(); - $pk->type = FallingBlock::NETWORK_ID; + $pk->type = FallingSand::NETWORK_ID; $pk->eid = $this->getID(); $pk->x = $this->x; $pk->y = $this->y; diff --git a/src/pocketmine/entity/DroppedItem.php b/src/pocketmine/entity/Item.php similarity index 95% rename from src/pocketmine/entity/DroppedItem.php rename to src/pocketmine/entity/Item.php index 1ca2d8a38..9707ddd56 100644 --- a/src/pocketmine/entity/DroppedItem.php +++ b/src/pocketmine/entity/Item.php @@ -25,7 +25,7 @@ use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityRegainHealthEvent; use pocketmine\event\entity\ItemDespawnEvent; use pocketmine\event\entity\ItemSpawnEvent; -use pocketmine\item\Item; +use pocketmine\item\Item as ItemItem; use pocketmine\math\Vector3; use pocketmine\nbt\tag\Byte; use pocketmine\nbt\tag\Compound; @@ -35,12 +35,13 @@ use pocketmine\network\protocol\AddItemEntityPacket; use pocketmine\network\protocol\SetEntityMotionPacket; use pocketmine\Player; -class DroppedItem extends Entity{ +class Item extends Entity{ + const NETWORK_ID = 64; protected $owner = null; protected $thrower = null; protected $pickupDelay = 0; - /** @var Item */ + /** @var ItemItem */ protected $item; public $width = 0.25; @@ -67,7 +68,7 @@ class DroppedItem extends Entity{ if(isset($this->namedtag->Thrower)){ $this->thrower = $this->namedtag["Thrower"]; } - $this->item = Item::get($this->namedtag->Item["id"], $this->namedtag->Item["Damage"], $this->namedtag->Item["Count"]); + $this->item = ItemItem::get($this->namedtag->Item["id"], $this->namedtag->Item["Damage"], $this->namedtag->Item["Count"]); $this->server->getPluginManager()->callEvent(ItemSpawnEvent::createEvent($this)); @@ -166,7 +167,7 @@ class DroppedItem extends Entity{ } /** - * @return Item + * @return ItemItem */ public function getItem(){ return $this->item; diff --git a/src/pocketmine/event/entity/EntityDespawnEvent.php b/src/pocketmine/event/entity/EntityDespawnEvent.php index a5ff67242..d02c13c4b 100644 --- a/src/pocketmine/event/entity/EntityDespawnEvent.php +++ b/src/pocketmine/event/entity/EntityDespawnEvent.php @@ -22,7 +22,7 @@ namespace pocketmine\event\entity; use pocketmine\entity\Creature; -use pocketmine\entity\DroppedItem; +use pocketmine\entity\Item; use pocketmine\entity\Entity; use pocketmine\entity\Human; use pocketmine\entity\Projectile; @@ -85,7 +85,7 @@ class EntityDespawnEvent extends EntityEvent{ * @return bool */ public function isItem(){ - return $this->entity instanceof DroppedItem; + return $this->entity instanceof Item; } } \ No newline at end of file diff --git a/src/pocketmine/event/entity/EntitySpawnEvent.php b/src/pocketmine/event/entity/EntitySpawnEvent.php index d865c537e..8fde50ec6 100644 --- a/src/pocketmine/event/entity/EntitySpawnEvent.php +++ b/src/pocketmine/event/entity/EntitySpawnEvent.php @@ -22,7 +22,7 @@ namespace pocketmine\event\entity; use pocketmine\entity\Creature; -use pocketmine\entity\DroppedItem; +use pocketmine\entity\Item; use pocketmine\entity\Entity; use pocketmine\entity\Human; use pocketmine\entity\Projectile; @@ -92,7 +92,7 @@ class EntitySpawnEvent extends EntityEvent{ * @return bool */ public function isItem(){ - return $this->entity instanceof DroppedItem; + return $this->entity instanceof Item; } } \ No newline at end of file diff --git a/src/pocketmine/event/entity/ItemDespawnEvent.php b/src/pocketmine/event/entity/ItemDespawnEvent.php index f37b3b51e..f1998688e 100644 --- a/src/pocketmine/event/entity/ItemDespawnEvent.php +++ b/src/pocketmine/event/entity/ItemDespawnEvent.php @@ -21,7 +21,7 @@ namespace pocketmine\event\entity; -use pocketmine\entity\DroppedItem; +use pocketmine\entity\Item; use pocketmine\event\Cancellable; class ItemDespawnEvent extends EntityEvent implements Cancellable{ @@ -30,15 +30,15 @@ class ItemDespawnEvent extends EntityEvent implements Cancellable{ public static $nextEvent = 0; /** - * @param DroppedItem $item + * @param Item $item */ - public function __construct(DroppedItem $item){ + public function __construct(Item $item){ $this->entity = $item; } /** - * @return DroppedItem + * @return Item */ public function getEntity(){ return $this->entity; diff --git a/src/pocketmine/event/entity/ItemSpawnEvent.php b/src/pocketmine/event/entity/ItemSpawnEvent.php index 5e369dde9..02aa93f91 100644 --- a/src/pocketmine/event/entity/ItemSpawnEvent.php +++ b/src/pocketmine/event/entity/ItemSpawnEvent.php @@ -21,7 +21,7 @@ namespace pocketmine\event\entity; -use pocketmine\entity\DroppedItem; +use pocketmine\entity\Item; class ItemSpawnEvent extends EntityEvent{ public static $handlerList = null; @@ -29,15 +29,15 @@ class ItemSpawnEvent extends EntityEvent{ public static $nextEvent = 0; /** - * @param DroppedItem $item + * @param Item $item */ - public function __construct(DroppedItem $item){ + public function __construct(Item $item){ $this->entity = $item; } /** - * @return DroppedItem + * @return Item */ public function getEntity(){ return $this->entity; diff --git a/src/pocketmine/item/SpawnEgg.php b/src/pocketmine/item/SpawnEgg.php index 65e74157e..be8f19795 100644 --- a/src/pocketmine/item/SpawnEgg.php +++ b/src/pocketmine/item/SpawnEgg.php @@ -66,37 +66,10 @@ class SpawnEgg extends Item{ ]), ]); - switch($this->meta){ - case Villager::NETWORK_ID: - $nbt->Health = new Short("Health", 20); - $entity = new Villager($chunk, $nbt); - break; - case Zombie::NETWORK_ID: - $nbt->Health = new Short("Health", 20); - $entity = new Zombie($chunk, $nbt); - break; - /* - //TODO: use entity constants - case 10: - case 11: - case 12: - case 13: - $data = array( - "x" => $block->x + 0.5, - "y" => $block->y, - "z" => $block->z + 0.5, - ); - //$e = Server::getInstance()->api->entity->add($block->level, ENTITY_MOB, $this->meta, $data); - //Server::getInstance()->api->entity->spawnToAll($e); - if(($player->gamemode & 0x01) === 0){ - --$this->count; - } - - return true;*/ - } + $entity = Entity::createEntity($this->meta, $chunk, $nbt); if($entity instanceof Entity){ - if(($player->gamemode & 0x01) === 0){ + if($player->isSurvival()){ --$this->count; } $entity->spawnToAll(); diff --git a/src/pocketmine/level/Explosion.php b/src/pocketmine/level/Explosion.php index aa2920c82..61a59c8df 100644 --- a/src/pocketmine/level/Explosion.php +++ b/src/pocketmine/level/Explosion.php @@ -191,7 +191,7 @@ class Explosion{ if($block instanceof TNT){ $mot = (new Random())->nextSignedFloat() * M_PI * 2; - $tnt = new PrimedTNT($this->level->getChunk($block->x >> 4, $block->z >> 4), new Compound("", [ + $tnt = Entity::createEntity("PrimedTNT", $this->level->getChunk($block->x >> 4, $block->z >> 4), new Compound("", [ "Pos" => new Enum("Pos", [ new Double("", $block->x + 0.5), new Double("", $block->y), diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 0925e1fd7..c3ae3eb04 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -45,7 +45,7 @@ use pocketmine\block\SnowLayer; use pocketmine\block\Sugarcane; use pocketmine\block\Wheat; use pocketmine\entity\Arrow; -use pocketmine\entity\DroppedItem; +use pocketmine\entity\Item as DroppedItem; use pocketmine\entity\Entity; use pocketmine\event\block\BlockBreakEvent; use pocketmine\event\block\BlockPlaceEvent; @@ -1000,7 +1000,7 @@ class Level implements ChunkManager, Metadatable{ public function dropItem(Vector3 $source, Item $item, Vector3 $motion = null, $delay = 10){ $motion = $motion === null ? Vector3::createVector(lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1) : $motion; if($item->getID() > 0 and $item->getCount() > 0){ - $itemEntity = new DroppedItem($this->getChunk($source->getX() >> 4, $source->getZ() >> 4), new Compound("", [ + $itemEntity = Entity::createEntity("Item", $this->getChunk($source->getX() >> 4, $source->getZ() >> 4), new Compound("", [ "Pos" => new Enum("Pos", [ new Double("", $source->getX()), new Double("", $source->getY()), @@ -1233,7 +1233,7 @@ class Level implements ChunkManager, Metadatable{ } if($hand->getID() === Item::SIGN_POST or $hand->getID() === Item::WALL_SIGN){ - $tile = new Sign($this->getChunk($block->x >> 4, $block->z >> 4), new Compound(false, [ + $tile = Tile::createTile("Sign", $this->getChunk($block->x >> 4, $block->z >> 4), new Compound(false, [ "id" => new String("id", Tile::SIGN), "x" => new Int("x", $block->x), "y" => new Int("y", $block->y), diff --git a/src/pocketmine/level/format/generic/BaseFullChunk.php b/src/pocketmine/level/format/generic/BaseFullChunk.php index b24daba55..b315736d6 100644 --- a/src/pocketmine/level/format/generic/BaseFullChunk.php +++ b/src/pocketmine/level/format/generic/BaseFullChunk.php @@ -21,10 +21,7 @@ namespace pocketmine\level\format\generic; -use pocketmine\entity\Arrow; -use pocketmine\entity\DroppedItem; use pocketmine\entity\Entity; -use pocketmine\entity\FallingBlock; use pocketmine\level\format\FullChunk; use pocketmine\level\format\LevelProvider; use pocketmine\nbt\tag\Compound; @@ -116,27 +113,20 @@ abstract class BaseFullChunk implements FullChunk{ foreach($this->NBTentities as $nbt){ if($nbt instanceof Compound){ if(!isset($nbt->id)){ + $this->setChanged(); continue; } if(($nbt["Pos"][0] >> 4) !== $this->x or ($nbt["Pos"][2] >> 4) !== $this->z){ + $this->setChanged(); continue; //Fixes entities allocated in wrong chunks. } - //TODO: add all entities - switch($nbt["id"]){ - case DroppedItem::NETWORK_ID: - case "Item": - (new DroppedItem($this, $nbt))->spawnToAll(); - break; - case Arrow::NETWORK_ID: - case "Arrow": - (new Arrow($this, $nbt))->spawnToAll(); - break; - case FallingBlock::NETWORK_ID: - case "FallingSand": - (new FallingBlock($this, $nbt))->spawnToAll(); - break; + if(($entity = Entity::createEntity($nbt["id"], $this, $nbt)) instanceof Entity){ + $entity->spawnToAll(); + }else{ + $this->setChanged(); + continue; } } } @@ -155,16 +145,9 @@ abstract class BaseFullChunk implements FullChunk{ continue; //Fixes tiles allocated in wrong chunks. } - switch($nbt["id"]){ - case Tile::CHEST: - new Chest($this, $nbt); - break; - case Tile::FURNACE: - new Furnace($this, $nbt); - break; - case Tile::SIGN: - new Sign($this, $nbt); - break; + if(Tile::createTile($nbt["id"], $this, $nbt) === null){ + $this->setChanged(); + continue; } } } diff --git a/src/pocketmine/tile/Tile.php b/src/pocketmine/tile/Tile.php index b87fd6a43..d22bebe38 100644 --- a/src/pocketmine/tile/Tile.php +++ b/src/pocketmine/tile/Tile.php @@ -40,6 +40,9 @@ abstract class Tile extends Position{ public static $tileCount = 1; + /** @var Tile[] */ + private static $knownTiles = []; + /** @var Chunk */ public $chunk; public $name; @@ -58,6 +61,38 @@ abstract class Tile extends Position{ /** @var \pocketmine\event\TimingsHandler */ public $tickTimer; + /** + * @param string $type + * @param FullChunk $chunk + * @param Compound $nbt + * @param $args + * + * @return Tile + */ + public static function createTile($type, FullChunk $chunk, Compound $nbt, ...$args){ + if(isset(self::$knownTiles[$type])){ + $class = self::$knownTiles[$type]; + return new $class($chunk, $nbt, ...$args); + } + + return null; + } + + /** + * @param $className + * + * @return bool + */ + public static function registerTile($className){ + $class = new \ReflectionClass($className); + if(is_a($className, Tile::class, true) and !$class->isAbstract()){ + self::$knownTiles[$class->getShortName()] = $className; + return true; + } + + return false; + } + public function __construct(FullChunk $chunk, Compound $nbt){ if($chunk === null or $chunk->getProvider() === null){ throw new \Exception("Invalid garbage Chunk given to Tile"); From 5bf2174cad88c47f630fdcf2419e2503135034a6 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 28 Oct 2014 13:16:20 +0100 Subject: [PATCH 23/61] Fixed UseItemPacket being able to be sent before spawning --- src/pocketmine/Player.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index dfac68181..2b000a37b 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1558,6 +1558,10 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } break; case ProtocolInfo::USE_ITEM_PACKET: + if($this->spawned === false or $this->dead === true){ + break; + } + $blockVector = Vector3::createVector($packet->x, $packet->y, $packet->z); $this->craftingType = 0; From 8080643cc90006d24ffff18f27c379f2e80c0f0e Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 28 Oct 2014 13:18:40 +0100 Subject: [PATCH 24/61] Fixed plugins crashing the server when teleporting players on an invalid event --- src/pocketmine/Player.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 2b000a37b..9a0735ea8 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -426,6 +426,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->setLevel($this->server->getDefaultLevel(), true); $this->viewDistance = $this->server->getViewDistance(); $this->newPosition = new Vector3(0, 0, 0); + $this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0); } /** @@ -1561,7 +1562,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ if($this->spawned === false or $this->dead === true){ break; } - + $blockVector = Vector3::createVector($packet->x, $packet->y, $packet->z); $this->craftingType = 0; From 0fce83c67137d5e45eca6d379967533cfc308ea4 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 28 Oct 2014 13:27:30 +0100 Subject: [PATCH 25/61] Fixed #2189 --- src/pocketmine/Player.php | 1 + src/pocketmine/block/Fallable.php | 2 +- src/pocketmine/entity/FallingSand.php | 6 +++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 9a0735ea8..0634795ca 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -73,6 +73,7 @@ use pocketmine\level\format\LevelProvider; use pocketmine\level\Level; use pocketmine\level\Location; use pocketmine\level\Position; +use pocketmine\math\AxisAlignedBB; use pocketmine\math\Vector3; use pocketmine\metadata\MetadataValue; use pocketmine\nbt\NBT; diff --git a/src/pocketmine/block/Fallable.php b/src/pocketmine/block/Fallable.php index 448878fc9..2216fba21 100644 --- a/src/pocketmine/block/Fallable.php +++ b/src/pocketmine/block/Fallable.php @@ -63,7 +63,7 @@ abstract class Fallable extends Solid{ new Float("", 0) ]), "TileID" => new Int("TileID", $this->getID()), - "Data" => new Byte("Data", $this->getDamage()), + "TileData" => new Byte("TileData", $this->getDamage()), ])); $fall->spawnToAll(); diff --git a/src/pocketmine/entity/FallingSand.php b/src/pocketmine/entity/FallingSand.php index a4a0115bb..b1e32b263 100644 --- a/src/pocketmine/entity/FallingSand.php +++ b/src/pocketmine/entity/FallingSand.php @@ -58,6 +58,10 @@ class FallingSand extends Entity{ $this->namedtag["TileID"] = new Int("TileID", $this->blockId); } + if(isset($this->namedtag->TileData)){ + $this->damage = $this->namedtag["TileData"]; + } + if($this->blockId === 0){ $this->close(); } @@ -154,7 +158,7 @@ class FallingSand extends Entity{ $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; - $pk->did = -$this->getBlock(); + $pk->did = -($this->getBlock() | $this->getDamage() << 0x10); $player->dataPacket($pk); $pk = SetEntityMotionPacket::getFromPool(); From b6f7ee20fc997d28c9047388300994f8dd007f1a Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 28 Oct 2014 20:43:36 +0100 Subject: [PATCH 26/61] Added Error -> Exception handling --- src/pocketmine/Player.php | 8 +++- src/pocketmine/PocketMine.php | 50 +------------------------ src/pocketmine/Server.php | 30 ++++++++++++++- src/pocketmine/block/Fallable.php | 2 +- src/pocketmine/entity/FallingSand.php | 8 ++-- src/pocketmine/entity/Human.php | 8 ++-- src/pocketmine/entity/Living.php | 4 +- src/pocketmine/entity/Zombie.php | 10 ++--- src/pocketmine/plugin/PluginManager.php | 27 ++++++++++--- src/pocketmine/utils/MainLogger.php | 41 ++++++++++++++++++++ src/spl | 2 +- 11 files changed, 114 insertions(+), 76 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 0634795ca..f51e4b0e2 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1474,9 +1474,13 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $newPos = new Vector3($packet->x, $packet->y, $packet->z); - $revert = ($this->dead === true or $this->spawned !== true); + $revert = false; + if($this->dead === true or $this->spawned !== true){ + $revert = true; + $this->forceMovement = new Vector3($this->x, $this->y, $this->z); + } - if($revert or ($this->forceMovement instanceof Vector3 and $newPos->distance($this->forceMovement) > 0.2)){ + if($this->forceMovement instanceof Vector3 and ($revert or $newPos->distance($this->forceMovement) > 0.2)){ $pk = MovePlayerPacket::getFromPool(); $pk->eid = 0; $pk->x = $this->x; diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 046a4e597..1b04a82de 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -327,55 +327,7 @@ namespace pocketmine { return rtrim(str_replace(["\\", ".php", "phar://", rtrim(str_replace(["\\", "phar://"], ["/", ""], \pocketmine\PATH), "/"), rtrim(str_replace(["\\", "phar://"], ["/", ""], \pocketmine\PLUGIN_PATH), "/")], ["/", "", "", "", ""], $path), "/"); } - function error_handler($errno, $errstr, $errfile, $errline, $context, $trace = null){ - global $lastError; - if(error_reporting() === 0){ //@ error-con..trol - return false; - } - $errorConversion = [ - E_ERROR => "E_ERROR", - E_WARNING => "E_WARNING", - E_PARSE => "E_PARSE", - E_NOTICE => "E_NOTICE", - E_CORE_ERROR => "E_CORE_ERROR", - E_CORE_WARNING => "E_CORE_WARNING", - E_COMPILE_ERROR => "E_COMPILE_ERROR", - E_COMPILE_WARNING => "E_COMPILE_WARNING", - E_USER_ERROR => "E_USER_ERROR", - E_USER_WARNING => "E_USER_WARNING", - E_USER_NOTICE => "E_USER_NOTICE", - E_STRICT => "E_STRICT", - E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR", - E_DEPRECATED => "E_DEPRECATED", - E_USER_DEPRECATED => "E_USER_DEPRECATED", - ]; - $type = ($errno === E_ERROR or $errno === E_USER_ERROR) ? LogLevel::ERROR : (($errno === E_USER_WARNING or $errno === E_WARNING) ? LogLevel::WARNING : LogLevel::NOTICE); - $errno = isset($errorConversion[$errno]) ? $errorConversion[$errno] : $errno; - if(($pos = strpos($errstr, "\n")) !== false){ - $errstr = substr($errstr, 0, $pos); - } - $logger = MainLogger::getLogger(); - $oldFile = $errfile; - $errfile = cleanPath($errfile); - $logger->log($type, "An $errno error happened: \"$errstr\" in \"$errfile\" at line $errline"); - - foreach(($trace = getTrace($trace === null ? 3 : 0, $trace)) as $i => $line){ - $logger->debug($line); - } - - $lastError = [ - "type" => $type, - "message" => $errstr, - "fullFile" => $oldFile, - "file" => $errfile, - "line" => $errline, - "trace" => $trace - ]; - - return true; - } - - set_error_handler("\\pocketmine\\error_handler", E_ALL); + set_error_handler([\ExceptionHandler::class, "handler"], -1); $errors = 0; diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 049f4acec..579cc5706 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -1950,12 +1950,38 @@ class Server{ } } - public function exceptionHandler(\Exception $e){ + public function exceptionHandler(\Exception $e, $trace = null){ if($e === null){ return; } - error_handler(E_ERROR, $e->getMessage(), $e->getFile(), $e->getLine(), [], $e->getTrace()); + global $lastError; + + $errstr = $e->getMessage(); + $errfile = $e->getFile(); + $errno = $e->getCode(); + $errline = $e->getLine(); + + $type = ($errno === E_ERROR or $errno === E_USER_ERROR) ? \LogLevel::ERROR : (($errno === E_USER_WARNING or $errno === E_WARNING) ? \LogLevel::WARNING : \LogLevel::NOTICE); + if(($pos = strpos($errstr, "\n")) !== false){ + $errstr = substr($errstr, 0, $pos); + } + + $errfile = cleanPath($errfile); + + if($this->logger instanceof MainLogger){ + $this->logger->logException($e, $trace); + } + + $lastError = [ + "type" => $type, + "message" => $errstr, + "fullFile" => $e->getFile(), + "file" => $errfile, + "line" => $errline, + "trace" => getTrace($trace === null ? 3 : 0, $trace) + ]; + global $lastExceptionError, $lastError; $lastExceptionError = $lastError; $this->crashDump(); diff --git a/src/pocketmine/block/Fallable.php b/src/pocketmine/block/Fallable.php index 2216fba21..448878fc9 100644 --- a/src/pocketmine/block/Fallable.php +++ b/src/pocketmine/block/Fallable.php @@ -63,7 +63,7 @@ abstract class Fallable extends Solid{ new Float("", 0) ]), "TileID" => new Int("TileID", $this->getID()), - "TileData" => new Byte("TileData", $this->getDamage()), + "Data" => new Byte("Data", $this->getDamage()), ])); $fall->spawnToAll(); diff --git a/src/pocketmine/entity/FallingSand.php b/src/pocketmine/entity/FallingSand.php index b1e32b263..b73464793 100644 --- a/src/pocketmine/entity/FallingSand.php +++ b/src/pocketmine/entity/FallingSand.php @@ -26,7 +26,7 @@ use pocketmine\block\Block; use pocketmine\event\entity\EntityBlockChangeEvent; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityRegainHealthEvent; -use pocketmine\item\Item; +use pocketmine\item\Item as ItemItem; use pocketmine\math\Vector3; use pocketmine\nbt\tag\Byte; use pocketmine\nbt\tag\Int; @@ -58,8 +58,8 @@ class FallingSand extends Entity{ $this->namedtag["TileID"] = new Int("TileID", $this->blockId); } - if(isset($this->namedtag->TileData)){ - $this->damage = $this->namedtag["TileData"]; + if(isset($this->namedtag->Data)){ + $this->damage = $this->namedtag["Data"]; } if($this->blockId === 0){ @@ -115,7 +115,7 @@ class FallingSand extends Entity{ $this->kill(); $block = $this->level->getBlock($pos); if(!$block->isFullBlock){ - $this->getLevel()->dropItem($this, Item::get($this->getBlock(), $this->getDamage(), 1)); + $this->getLevel()->dropItem($this, ItemItem::get($this->getBlock(), $this->getDamage(), 1)); }else{ $this->server->getPluginManager()->callEvent($ev = EntityBlockChangeEvent::createEvent($this, $block, Block::get($this->getBlock(), $this->getDamage()))); if(!$ev->isCancelled()){ diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index 962860f1a..ef45e9a93 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -23,7 +23,7 @@ namespace pocketmine\entity; use pocketmine\inventory\InventoryHolder; use pocketmine\inventory\PlayerInventory; -use pocketmine\item\Item; +use pocketmine\item\Item as ItemItem; use pocketmine\nbt\NBT; use pocketmine\nbt\tag\Byte; use pocketmine\nbt\tag\Compound; @@ -67,9 +67,9 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ if($item["Slot"] >= 0 and $item["Slot"] < 9){ //Hotbar $this->inventory->setHotbarSlotIndex($item["Slot"], isset($item["TrueSlot"]) ? $item["TrueSlot"] : -1); }elseif($item["Slot"] >= 100 and $item["Slot"] < 104){ //Armor - $this->inventory->setItem($this->inventory->getSize() + $item["Slot"] - 100, Item::get($item["id"], $item["Damage"], $item["Count"]), $this); + $this->inventory->setItem($this->inventory->getSize() + $item["Slot"] - 100, ItemItem::get($item["id"], $item["Damage"], $item["Count"]), $this); }else{ - $this->inventory->setItem($item["Slot"] - 9, Item::get($item["id"], $item["Damage"], $item["Count"]), $this); + $this->inventory->setItem($item["Slot"] - 9, ItemItem::get($item["id"], $item["Damage"], $item["Count"]), $this); } } @@ -140,7 +140,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ //Armor for($slot = 100; $slot < 104; ++$slot){ $item = $this->inventory->getItem($this->inventory->getSize() + $slot - 100); - if($item instanceof Item and $item->getID() !== Item::AIR){ + if($item instanceof ItemItem and $item->getID() !== ItemItem::AIR){ $this->namedtag->Inventory[$slot] = new Compound(false, [ new Byte("Count", $item->getCount()), new Short("Damage", $item->getDamage()), diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index 7aa6a7b9f..ade61e16c 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -28,7 +28,7 @@ use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityDeathEvent; use pocketmine\event\entity\EntityRegainHealthEvent; use pocketmine\event\Timings; -use pocketmine\item\Item; +use pocketmine\item\Item as ItemItem; use pocketmine\math\Vector3; use pocketmine\nbt\tag\Short; use pocketmine\network\protocol\EntityEventPacket; @@ -163,7 +163,7 @@ abstract class Living extends Entity implements Damageable{ } /** - * @return Item[] + * @return ItemItem[] */ public function getDrops(){ return []; diff --git a/src/pocketmine/entity/Zombie.php b/src/pocketmine/entity/Zombie.php index 8b45b8787..243ea7a5f 100644 --- a/src/pocketmine/entity/Zombie.php +++ b/src/pocketmine/entity/Zombie.php @@ -23,7 +23,7 @@ namespace pocketmine\entity; use pocketmine\event\entity\EntityDamageByEntityEvent; -use pocketmine\item\Item; +use pocketmine\item\Item as ItemItem; use pocketmine\nbt\tag\String; use pocketmine\network\protocol\AddMobPacket; use pocketmine\network\protocol\SetEntityMotionPacket; @@ -83,19 +83,19 @@ class Zombie extends Monster{ public function getDrops(){ $drops = [ - Item::get(Item::FEATHER, 0, 1) + ItemItem::get(Item::FEATHER, 0, 1) ]; if($this->lastDamageCause instanceof EntityDamageByEntityEvent and $this->lastDamageCause->getEntity() instanceof Player){ if(mt_rand(0, 199) < 5){ switch(mt_rand(0, 2)){ case 0: - $drops[] = Item::get(Item::IRON_INGOT, 0, 1); + $drops[] = ItemItem::get(ItemItem::IRON_INGOT, 0, 1); break; case 1: - $drops[] = Item::get(Item::CARROT, 0, 1); + $drops[] = ItemItem::get(ItemItem::CARROT, 0, 1); break; case 2: - $drops[] = Item::get(Item::POTATO, 0, 1); + $drops[] = ItemItem::get(ItemItem::POTATO, 0, 1); break; } } diff --git a/src/pocketmine/plugin/PluginManager.php b/src/pocketmine/plugin/PluginManager.php index 179893ac6..b3a82027c 100644 --- a/src/pocketmine/plugin/PluginManager.php +++ b/src/pocketmine/plugin/PluginManager.php @@ -33,6 +33,7 @@ use pocketmine\event\TimingsHandler; use pocketmine\permission\Permissible; use pocketmine\permission\Permission; use pocketmine\Server; +use pocketmine\utils\MainLogger; /** * Manages all the plugins, Permissions and Permissibles @@ -546,12 +547,18 @@ class PluginManager{ */ public function enablePlugin(Plugin $plugin){ if(!$plugin->isEnabled()){ - - foreach($plugin->getDescription()->getPermissions() as $perm){ - $this->addPermission($perm); + try{ + foreach($plugin->getDescription()->getPermissions() as $perm){ + $this->addPermission($perm); + } + $plugin->getPluginLoader()->enablePlugin($plugin); + }catch(\Exception $e){ + $logger = Server::getInstance()->getLogger(); + if($logger instanceof MainLogger){ + $logger->logException($e); + } + $this->disablePlugin($plugin); } - - $plugin->getPluginLoader()->enablePlugin($plugin); } } @@ -617,7 +624,15 @@ class PluginManager{ */ public function disablePlugin(Plugin $plugin){ if($plugin->isEnabled()){ - $plugin->getPluginLoader()->disablePlugin($plugin); + try{ + $plugin->getPluginLoader()->disablePlugin($plugin); + }catch(\Exception $e){ + $logger = Server::getInstance()->getLogger(); + if($logger instanceof MainLogger){ + $logger->logException($e); + } + } + $this->server->getScheduler()->cancelTasks($plugin); HandlerList::unregisterAll($plugin); foreach($plugin->getDescription()->getPermissions() as $perm){ diff --git a/src/pocketmine/utils/MainLogger.php b/src/pocketmine/utils/MainLogger.php index cd2c8bfe7..463c9bb7a 100644 --- a/src/pocketmine/utils/MainLogger.php +++ b/src/pocketmine/utils/MainLogger.php @@ -102,6 +102,47 @@ class MainLogger extends \AttachableThreadedLogger{ $this->logDebug = (bool) $logDebug; } + public function logException(\Exception $e, $trace = null){ + $errstr = $e->getMessage(); + $errfile = $e->getFile(); + $errno = $e->getCode(); + $errline = $e->getLine(); + + $errorConversion = [ + 0 => "EXCEPTION", + E_ERROR => "E_ERROR", + E_WARNING => "E_WARNING", + E_PARSE => "E_PARSE", + E_NOTICE => "E_NOTICE", + E_CORE_ERROR => "E_CORE_ERROR", + E_CORE_WARNING => "E_CORE_WARNING", + E_COMPILE_ERROR => "E_COMPILE_ERROR", + E_COMPILE_WARNING => "E_COMPILE_WARNING", + E_USER_ERROR => "E_USER_ERROR", + E_USER_WARNING => "E_USER_WARNING", + E_USER_NOTICE => "E_USER_NOTICE", + E_STRICT => "E_STRICT", + E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR", + E_DEPRECATED => "E_DEPRECATED", + E_USER_DEPRECATED => "E_USER_DEPRECATED", + ]; + if($errno === 0){ + $type = LogLevel::CRITICAL; + }else{ + $type = ($errno === E_ERROR or $errno === E_USER_ERROR) ? LogLevel::ERROR : (($errno === E_USER_WARNING or $errno === E_WARNING) ? LogLevel::WARNING : LogLevel::NOTICE); + } + $errno = isset($errorConversion[$errno]) ? $errorConversion[$errno] : $errno; + if(($pos = strpos($errstr, "\n")) !== false){ + $errstr = substr($errstr, 0, $pos); + } + $errfile = \pocketmine\cleanPath($errfile); + $this->log($type, get_class($e).": \"$errstr\" ($errno) in \"$errfile\" at line $errline"); + + foreach(($trace = \pocketmine\getTrace($trace === null ? 4 : 0, $trace)) as $i => $line){ + $this->debug($line); + } + } + public function log($level, $message){ switch($level){ case LogLevel::EMERGENCY: diff --git a/src/spl b/src/spl index dd275a8f9..cccae3510 160000 --- a/src/spl +++ b/src/spl @@ -1 +1 @@ -Subproject commit dd275a8f9909cd1e52079173e4447c7a88d7e22e +Subproject commit cccae3510b3e05def83a58323dc3b3878aa7b384 From 8c4faa8622400a49ccbdf323dd511e264fc4c9ff Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 28 Oct 2014 21:07:12 +0100 Subject: [PATCH 27/61] Added extra Exceptions --- src/pocketmine/Player.php | 2 +- src/pocketmine/Server.php | 8 +++--- src/pocketmine/entity/Entity.php | 3 ++- src/pocketmine/event/HandlerList.php | 2 +- .../event/entity/EntityDamageEvent.php | 2 +- .../inventory/CraftingInventory.php | 2 +- src/pocketmine/inventory/ShapedRecipe.php | 6 ++--- src/pocketmine/inventory/ShapelessRecipe.php | 4 +-- src/pocketmine/level/Level.php | 19 +++++++------- src/pocketmine/level/Position.php | 5 ++-- .../level/format/LevelProviderManager.php | 5 ++-- src/pocketmine/level/format/anvil/Anvil.php | 3 ++- .../level/format/anvil/ChunkRequestTask.php | 3 ++- .../level/format/generic/BaseChunk.php | 18 ++++++------- .../level/format/generic/BaseFullChunk.php | 2 -- .../format/generic/BaseLevelProvider.php | 3 ++- .../format/generic/EmptyChunkSection.php | 11 ++++---- .../level/format/mcregion/McRegion.php | 5 ++-- .../generator/GenerationChunkManager.php | 7 ++--- .../generator/GenerationInstanceManager.php | 3 ++- .../generator/GenerationRequestManager.php | 3 ++- .../metadata/BlockMetadataStore.php | 16 ++++++------ src/pocketmine/metadata/MetadataStore.php | 3 ++- src/pocketmine/permission/PermissibleBase.php | 11 ++++---- src/pocketmine/permission/Permission.php | 4 +-- .../permission/PermissionAttachment.php | 5 ++-- .../permission/PermissionAttachmentInfo.php | 4 +-- src/pocketmine/plugin/PharPluginLoader.php | 5 ++-- src/pocketmine/plugin/PluginDescription.php | 5 ++-- src/pocketmine/plugin/PluginManager.php | 11 ++++---- src/pocketmine/scheduler/ServerScheduler.php | 13 +++++++--- src/pocketmine/tile/Tile.php | 3 ++- src/pocketmine/utils/BlockIterator.php | 2 +- src/pocketmine/utils/ChunkException.php | 26 +++++++++++++++++++ src/pocketmine/utils/LevelException.php | 26 +++++++++++++++++++ src/pocketmine/utils/PluginException.php | 26 +++++++++++++++++++ src/pocketmine/utils/ServerException.php | 26 +++++++++++++++++++ 37 files changed, 215 insertions(+), 87 deletions(-) create mode 100644 src/pocketmine/utils/ChunkException.php create mode 100644 src/pocketmine/utils/LevelException.php create mode 100644 src/pocketmine/utils/PluginException.php create mode 100644 src/pocketmine/utils/ServerException.php diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index f51e4b0e2..b9ffc969d 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2355,7 +2355,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ */ public function save(){ if($this->closed){ - throw new \Exception("Tried to save closed player"); + throw new \InvalidStateException("Tried to save closed player"); } parent::saveNBT(); diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 579cc5706..fe40c0345 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -99,7 +99,9 @@ use pocketmine\updater\AutoUpdater; use pocketmine\utils\Binary; use pocketmine\utils\Cache; use pocketmine\utils\Config; +use pocketmine\utils\LevelException; use pocketmine\utils\MainLogger; +use pocketmine\utils\ServerException; use pocketmine\utils\TextFormat; use pocketmine\utils\TextWrapper; use pocketmine\utils\Utils; @@ -948,11 +950,11 @@ class Server{ * * @return bool * - * @throws \Exception + * @throws LevelException */ public function loadLevel($name){ if(trim($name) === ""){ - throw new \Exception("Invalid empty level name"); + throw new LevelException("Invalid empty level name"); } if($this->isLevelLoaded($name)){ return true; @@ -1780,7 +1782,7 @@ class Server{ */ public function dispatchCommand(CommandSender $sender, $commandLine){ if(!($sender instanceof CommandSender)){ - throw new \Exception("CommandSender is not valid"); + throw new ServerException("CommandSender is not valid"); } if($this->commandMap->dispatch($sender, $commandLine)){ diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index c874a8b3d..aa6e575b9 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -59,6 +59,7 @@ use pocketmine\network\protocol\SetTimePacket; use pocketmine\Player; use pocketmine\plugin\Plugin; use pocketmine\Server; +use pocketmine\utils\ChunkException; abstract class Entity extends Location implements Metadatable{ @@ -158,7 +159,7 @@ abstract class Entity extends Location implements Metadatable{ public function __construct(FullChunk $chunk, Compound $nbt){ if($chunk === null or $chunk->getProvider() === null){ - throw new \Exception("Invalid garbage Chunk given to Entity"); + throw new ChunkException("Invalid garbage Chunk given to Entity"); } $this->timings = Timings::getEntityTimings($this); diff --git a/src/pocketmine/event/HandlerList.php b/src/pocketmine/event/HandlerList.php index 67fb3efac..cc4d680fe 100644 --- a/src/pocketmine/event/HandlerList.php +++ b/src/pocketmine/event/HandlerList.php @@ -90,7 +90,7 @@ class HandlerList{ return; } if(isset($this->handlerSlots[$listener->getPriority()][spl_object_hash($listener)])){ - throw new \Exception("This listener is already registered to priority " . $listener->getPriority()); + throw new \InvalidStateException("This listener is already registered to priority " . $listener->getPriority()); } $this->handlers = null; $this->handlerSlots[$listener->getPriority()][spl_object_hash($listener)] = $listener; diff --git a/src/pocketmine/event/entity/EntityDamageEvent.php b/src/pocketmine/event/entity/EntityDamageEvent.php index eb397b84c..7467a569c 100644 --- a/src/pocketmine/event/entity/EntityDamageEvent.php +++ b/src/pocketmine/event/entity/EntityDamageEvent.php @@ -76,7 +76,7 @@ class EntityDamageEvent extends EntityEvent implements Cancellable{ $this->originals = $this->modifiers; if(!isset($this->modifiers[self::MODIFIER_BASE])){ - throw new \Exception("BASE Damage modifier missing"); + throw new \InvalidArgumentException("BASE Damage modifier missing"); } } diff --git a/src/pocketmine/inventory/CraftingInventory.php b/src/pocketmine/inventory/CraftingInventory.php index 2a6d650a6..503287a3a 100644 --- a/src/pocketmine/inventory/CraftingInventory.php +++ b/src/pocketmine/inventory/CraftingInventory.php @@ -41,7 +41,7 @@ class CraftingInventory extends BaseInventory{ */ public function __construct(InventoryHolder $holder, Inventory $resultInventory, InventoryType $inventoryType){ if($inventoryType->getDefaultTitle() !== "Crafting"){ - throw new \Exception("Invalid Inventory type, expected CRAFTING or WORKBENCH"); + throw new \InvalidStateException("Invalid Inventory type, expected CRAFTING or WORKBENCH"); } $this->resultInventory = $resultInventory; parent::__construct($holder, $inventoryType); diff --git a/src/pocketmine/inventory/ShapedRecipe.php b/src/pocketmine/inventory/ShapedRecipe.php index bed1e0d25..6371a68d8 100644 --- a/src/pocketmine/inventory/ShapedRecipe.php +++ b/src/pocketmine/inventory/ShapedRecipe.php @@ -42,14 +42,14 @@ class ShapedRecipe implements Recipe{ */ public function __construct(Item $result, array $shape = []){ if(count($shape) === 0){ - throw new \Exception("Must provide a shape"); + throw new \InvalidArgumentException("Must provide a shape"); } if(count($shape) > 3){ - throw new \Exception("Crafting recipes should be 1, 2, 3 rows, not " . count($shape)); + throw new \InvalidStateException("Crafting recipes should be 1, 2, 3 rows, not " . count($shape)); } foreach($shape as $row){ if(strlen($row) === 0 or strlen($row) > 3){ - throw new \Exception("Crafting rows should be 1, 2, 3 characters, not " . count($row)); + throw new \InvalidStateException("Crafting rows should be 1, 2, 3 characters, not " . count($row)); } $this->rows[] = $row; $len = strlen($row); diff --git a/src/pocketmine/inventory/ShapelessRecipe.php b/src/pocketmine/inventory/ShapelessRecipe.php index 68d4d02c5..be87c8006 100644 --- a/src/pocketmine/inventory/ShapelessRecipe.php +++ b/src/pocketmine/inventory/ShapelessRecipe.php @@ -44,11 +44,11 @@ class ShapelessRecipe implements Recipe{ * * @returns ShapelessRecipe * - * @throws \Exception + * @throws \InvalidArgumentException */ public function addIngredient(Item $item){ if(count($this->ingredients) >= 9){ - throw new \Exception("Shapeless recipes cannot have more than 9 ingredients"); + throw new \InvalidArgumentException("Shapeless recipes cannot have more than 9 ingredients"); } $it = clone $item; diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index c3ae3eb04..b8aac2888 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -92,6 +92,7 @@ use pocketmine\tile\Chest; use pocketmine\tile\Sign; use pocketmine\tile\Tile; use pocketmine\utils\Cache; +use pocketmine\utils\LevelException; use pocketmine\utils\ReversePriorityQueue; use pocketmine\utils\TextFormat; @@ -250,7 +251,7 @@ class Level implements ChunkManager, Metadatable{ if(is_subclass_of($provider, LevelProvider::class, true)){ $this->provider = new $provider($this, $path); }else{ - throw new \Exception("Provider is not a subclass of LevelProvider"); + throw new LevelException("Provider is not a subclass of LevelProvider"); } $this->server->getLogger()->info("Preparing level \"" . $this->provider->getName() . "\""); $this->generator = Generator::getGenerator($this->provider->getGenerator()); @@ -1736,11 +1737,11 @@ class Level implements ChunkManager, Metadatable{ * * @param Entity $entity * - * @throws \RuntimeException + * @throws LevelException */ public function removeEntity(Entity $entity){ if($entity->getLevel() !== $this){ - throw new \RuntimeException("Invalid Entity level"); + throw new LevelException("Invalid Entity level"); } if($entity instanceof Player){ @@ -1757,11 +1758,11 @@ class Level implements ChunkManager, Metadatable{ /** * @param Entity $entity * - * @throws \RuntimeException + * @throws LevelException */ public function addEntity(Entity $entity){ if($entity->getLevel() !== $this){ - throw new \RuntimeException("Invalid Entity level"); + throw new LevelException("Invalid Entity level"); } if($entity instanceof Player){ $this->players[$entity->getID()] = $entity; @@ -1772,11 +1773,11 @@ class Level implements ChunkManager, Metadatable{ /** * @param Tile $tile * - * @throws \RuntimeException + * @throws LevelException */ public function addTile(Tile $tile){ if($tile->getLevel() !== $this){ - throw new \RuntimeException("Invalid Tile level"); + throw new LevelException("Invalid Tile level"); } $this->tiles[$tile->getID()] = $tile; } @@ -1784,11 +1785,11 @@ class Level implements ChunkManager, Metadatable{ /** * @param Tile $tile * - * @throws \RuntimeException + * @throws LevelException */ public function removeTile(Tile $tile){ if($tile->getLevel() !== $this){ - throw new \RuntimeException("Invalid Tile level"); + throw new LevelException("Invalid Tile level"); } unset($this->tiles[$tile->getID()]); diff --git a/src/pocketmine/level/Position.php b/src/pocketmine/level/Position.php index 8b04aa4dc..a5c5d0249 100644 --- a/src/pocketmine/level/Position.php +++ b/src/pocketmine/level/Position.php @@ -22,6 +22,7 @@ namespace pocketmine\level; use pocketmine\math\Vector3; +use pocketmine\utils\LevelException; class Position extends Vector3{ @@ -139,11 +140,11 @@ class Position extends Vector3{ * * @return Position * - * @throws \RuntimeException + * @throws LevelException */ public function getSide($side, $step = 1){ if(!$this->isValid()){ - throw new \RuntimeException("Undefined Level reference"); + throw new LevelException("Undefined Level reference"); } return Position::fromObject(parent::getSide($side, $step), $this->level); diff --git a/src/pocketmine/level/format/LevelProviderManager.php b/src/pocketmine/level/format/LevelProviderManager.php index ec0ed87aa..bf89ca439 100644 --- a/src/pocketmine/level/format/LevelProviderManager.php +++ b/src/pocketmine/level/format/LevelProviderManager.php @@ -22,6 +22,7 @@ namespace pocketmine\level\format; use pocketmine\Server; +use pocketmine\utils\LevelException; abstract class LevelProviderManager{ protected static $providers = []; @@ -30,11 +31,11 @@ abstract class LevelProviderManager{ * @param Server $server * @param string $class * - * @throws \Exception + * @throws LevelException */ public static function addProvider(Server $server, $class){ if(!is_subclass_of($class, LevelProvider::class)){ - throw new \Exception("Class is not a subclass of LevelProvider"); + throw new LevelException("Class is not a subclass of LevelProvider"); } self::$providers[strtolower($class::getProviderName())] = $class; } diff --git a/src/pocketmine/level/format/anvil/Anvil.php b/src/pocketmine/level/format/anvil/Anvil.php index 6cf3d435d..ffcb37f00 100644 --- a/src/pocketmine/level/format/anvil/Anvil.php +++ b/src/pocketmine/level/format/anvil/Anvil.php @@ -27,6 +27,7 @@ use pocketmine\level\Level; use pocketmine\nbt\tag\Byte; use pocketmine\nbt\tag\ByteArray; use pocketmine\nbt\tag\Compound; +use pocketmine\utils\ChunkException; class Anvil extends McRegion{ @@ -93,7 +94,7 @@ class Anvil extends McRegion{ public function setChunk($chunkX, $chunkZ, FullChunk $chunk){ if(!($chunk instanceof Chunk)){ - throw new \Exception("Invalid Chunk class"); + throw new ChunkException("Invalid Chunk class"); } $chunk->setProvider($this); diff --git a/src/pocketmine/level/format/anvil/ChunkRequestTask.php b/src/pocketmine/level/format/anvil/ChunkRequestTask.php index 9fa648009..964e36f18 100644 --- a/src/pocketmine/level/format/anvil/ChunkRequestTask.php +++ b/src/pocketmine/level/format/anvil/ChunkRequestTask.php @@ -27,6 +27,7 @@ use pocketmine\scheduler\AsyncTask; use pocketmine\Server; use pocketmine\tile\Spawnable; use pocketmine\utils\Binary; +use pocketmine\utils\ChunkException; class ChunkRequestTask extends AsyncTask{ @@ -50,7 +51,7 @@ class ChunkRequestTask extends AsyncTask{ $this->chunkZ = $chunkZ; $chunk = $level->getChunk($chunkX, $chunkZ, false); if(!($chunk instanceof Chunk)){ - throw new \Exception("Invalid Chunk sent"); + throw new ChunkException("Invalid Chunk sent"); } $this->biomeIds = $chunk->getBiomeIdArray(); $this->biomeColors = $chunk->getBiomeColorArray(); diff --git a/src/pocketmine/level/format/generic/BaseChunk.php b/src/pocketmine/level/format/generic/BaseChunk.php index 71d0fb0f8..6f8ccadb8 100644 --- a/src/pocketmine/level/format/generic/BaseChunk.php +++ b/src/pocketmine/level/format/generic/BaseChunk.php @@ -28,6 +28,7 @@ use pocketmine\level\format\LevelProvider; use pocketmine\nbt\tag\Compound; use pocketmine\tile\Tile; use pocketmine\utils\Binary; +use pocketmine\utils\ChunkException; abstract class BaseChunk extends BaseFullChunk implements Chunk{ @@ -62,7 +63,7 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{ * @param Compound[] $entities * @param Compound[] $tiles * - * @throws \Exception + * @throws ChunkException */ protected function __construct($provider, $x, $z, array $sections, $biomeIds = null, array $biomeColors = [], array $entities = [], array $tiles = []){ $this->provider = $provider; @@ -72,12 +73,11 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{ if($section instanceof ChunkSection){ $this->sections[$Y] = $section; }else{ - trigger_error("Received invalid ChunkSection instance", E_USER_ERROR); - throw new \Exception("Received invalid ChunkSection instance"); + throw new ChunkException("Received invalid ChunkSection instance"); } if($Y >= self::SECTION_COUNT){ - throw new \Exception("Invalid amount of chunks"); + throw new ChunkException("Invalid amount of chunks"); } } @@ -105,7 +105,7 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{ try{ $this->hasChanged = true; return $this->sections[$y >> 4]->setBlock($x, $y & 0x0f, $z, $blockId & 0xff, $meta & 0x0f); - }catch(\Exception $e){ + }catch(ChunkException $e){ $level = $this->getProvider(); $this->setInternalSection($Y = $y >> 4, $level::createChunkSection($Y)); return $this->sections[$y >> 4]->setBlock($x, $y & 0x0f, $z, $blockId & 0xff, $meta & 0x0f); @@ -120,7 +120,7 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{ try{ $this->sections[$y >> 4]->setBlockId($x, $y & 0x0f, $z, $id); $this->hasChanged = true; - }catch(\Exception $e){ + }catch(ChunkException $e){ $level = $this->getProvider(); $this->setInternalSection($Y = $y >> 4, $level::createChunkSection($Y)); $this->setBlockId($x, $y, $z, $id); @@ -135,7 +135,7 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{ try{ $this->sections[$y >> 4]->setBlockData($x, $y & 0x0f, $z, $data); $this->hasChanged = true; - }catch(\Exception $e){ + }catch(ChunkException $e){ $level = $this->getProvider(); $this->setInternalSection($Y = $y >> 4, $level::createChunkSection($Y)); $this->setBlockData($x, $y, $z, $data); @@ -150,7 +150,7 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{ try{ $this->sections[$y >> 4]->getBlockSkyLight($x, $y & 0x0f, $z, $data); $this->hasChanged = true; - }catch(\Exception $e){ + }catch(ChunkException $e){ $level = $this->getProvider(); $this->setInternalSection($Y = $y >> 4, $level::createChunkSection($Y)); $this->setBlockSkyLight($x, $y, $z, $data); @@ -165,7 +165,7 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{ try{ $this->sections[$y >> 4]->getBlockSkyLight($x, $y & 0x0f, $z, $data); $this->hasChanged = true; - }catch(\Exception $e){ + }catch(ChunkException $e){ $level = $this->getProvider(); $this->setInternalSection($Y = $y >> 4, $level::createChunkSection($Y)); $this->setBlockLight($x, $y, $z, $data); diff --git a/src/pocketmine/level/format/generic/BaseFullChunk.php b/src/pocketmine/level/format/generic/BaseFullChunk.php index b315736d6..f6396a3bd 100644 --- a/src/pocketmine/level/format/generic/BaseFullChunk.php +++ b/src/pocketmine/level/format/generic/BaseFullChunk.php @@ -78,8 +78,6 @@ abstract class BaseFullChunk implements FullChunk{ * @param int[] $biomeColors * @param Compound[] $entities * @param Compound[] $tiles - * - * @throws \Exception */ protected function __construct($provider, $x, $z, $blocks, $data, $skyLight, $blockLight, $biomeIds = null, array $biomeColors = [], array $entities = [], array $tiles = []){ $this->provider = $provider; diff --git a/src/pocketmine/level/format/generic/BaseLevelProvider.php b/src/pocketmine/level/format/generic/BaseLevelProvider.php index b393c26c6..003a5f2b5 100644 --- a/src/pocketmine/level/format/generic/BaseLevelProvider.php +++ b/src/pocketmine/level/format/generic/BaseLevelProvider.php @@ -27,6 +27,7 @@ use pocketmine\math\Vector3; use pocketmine\nbt\NBT; use pocketmine\nbt\tag\Compound; use pocketmine\nbt\tag\Int; +use pocketmine\utils\LevelException; abstract class BaseLevelProvider implements LevelProvider{ /** @var Level */ @@ -46,7 +47,7 @@ abstract class BaseLevelProvider implements LevelProvider{ if($levelData->Data instanceof Compound){ $this->levelData = $levelData->Data; }else{ - throw new \Exception("Invalid level.dat"); + throw new LevelException("Invalid level.dat"); } } diff --git a/src/pocketmine/level/format/generic/EmptyChunkSection.php b/src/pocketmine/level/format/generic/EmptyChunkSection.php index ec8ab9790..11fc28f0f 100644 --- a/src/pocketmine/level/format/generic/EmptyChunkSection.php +++ b/src/pocketmine/level/format/generic/EmptyChunkSection.php @@ -22,6 +22,7 @@ namespace pocketmine\level\format\generic; use pocketmine\level\format\ChunkSection; +use pocketmine\utils\ChunkException; /** * Stub used to detect empty chunks @@ -64,7 +65,7 @@ class EmptyChunkSection implements ChunkSection{ } final public function setBlock($x, $y, $z, $id = null, $meta = null){ - throw new \Exception("Tried to modify an empty Chunk"); + throw new ChunkException("Tried to modify an empty Chunk"); } public function getIdArray(){ @@ -84,7 +85,7 @@ class EmptyChunkSection implements ChunkSection{ } final public function setBlockId($x, $y, $z, $id){ - throw new \Exception("Tried to modify an empty Chunk"); + throw new ChunkException("Tried to modify an empty Chunk"); } final public function getBlockData($x, $y, $z){ @@ -92,7 +93,7 @@ class EmptyChunkSection implements ChunkSection{ } final public function setBlockData($x, $y, $z, $data){ - throw new \Exception("Tried to modify an empty Chunk"); + throw new ChunkException("Tried to modify an empty Chunk"); } final public function getBlockLight($x, $y, $z){ @@ -100,7 +101,7 @@ class EmptyChunkSection implements ChunkSection{ } final public function setBlockLight($x, $y, $z, $level){ - throw new \Exception("Tried to modify an empty Chunk"); + throw new ChunkException("Tried to modify an empty Chunk"); } final public function getBlockSkyLight($x, $y, $z){ @@ -108,6 +109,6 @@ class EmptyChunkSection implements ChunkSection{ } final public function setBlockSkyLight($x, $y, $z, $level){ - throw new \Exception("Tried to modify an empty Chunk"); + throw new ChunkException("Tried to modify an empty Chunk"); } } \ No newline at end of file diff --git a/src/pocketmine/level/format/mcregion/McRegion.php b/src/pocketmine/level/format/mcregion/McRegion.php index 4b6f5c09f..236000341 100644 --- a/src/pocketmine/level/format/mcregion/McRegion.php +++ b/src/pocketmine/level/format/mcregion/McRegion.php @@ -33,6 +33,7 @@ use pocketmine\nbt\tag\Long; use pocketmine\nbt\tag\String; use pocketmine\tile\Spawnable; use pocketmine\utils\Binary; +use pocketmine\utils\ChunkException; class McRegion extends BaseLevelProvider{ @@ -109,7 +110,7 @@ class McRegion extends BaseLevelProvider{ public function requestChunkTask($x, $z){ $chunk = $this->getChunk($x, $z, false); if(!($chunk instanceof Chunk)){ - throw new \Exception("Invalid Chunk sent"); + throw new ChunkException("Invalid Chunk sent"); } $tiles = ""; @@ -239,7 +240,7 @@ class McRegion extends BaseLevelProvider{ public function setChunk($chunkX, $chunkZ, FullChunk $chunk){ if(!($chunk instanceof Chunk)){ - throw new \Exception("Invalid Chunk class"); + throw new ChunkException("Invalid Chunk class"); } $chunk->setProvider($this); diff --git a/src/pocketmine/level/generator/GenerationChunkManager.php b/src/pocketmine/level/generator/GenerationChunkManager.php index 21db6b20c..2d50857e8 100644 --- a/src/pocketmine/level/generator/GenerationChunkManager.php +++ b/src/pocketmine/level/generator/GenerationChunkManager.php @@ -24,6 +24,7 @@ namespace pocketmine\level\generator; use pocketmine\level\ChunkManager; use pocketmine\level\format\FullChunk; use pocketmine\level\Level; +use pocketmine\utils\ChunkException; use pocketmine\utils\Random; class GenerationChunkManager implements ChunkManager{ @@ -45,7 +46,7 @@ class GenerationChunkManager implements ChunkManager{ public function __construct(GenerationManager $manager, $levelID, $seed, $class, array $options){ if(!class_exists($class, true) or !is_subclass_of($class, Generator::class)){ - throw new \Exception("Class $class does not exists or is not a subclass of Generator"); + throw new \InvalidStateException("Class $class does not exists or is not a subclass of Generator"); } $this->levelID = $levelID; @@ -75,13 +76,13 @@ class GenerationChunkManager implements ChunkManager{ * * @return FullChunk * - * @throws \Exception + * @throws ChunkException */ public function getChunk($chunkX, $chunkZ){ $index = Level::chunkHash($chunkX, $chunkZ); $chunk = !isset($this->chunks[$index]) ? $this->requestChunk($chunkX, $chunkZ) : $this->chunks[$index]; if($chunk === null){ - throw new \Exception("null Chunk received"); + throw new ChunkException("null Chunk received"); } return $chunk; diff --git a/src/pocketmine/level/generator/GenerationInstanceManager.php b/src/pocketmine/level/generator/GenerationInstanceManager.php index 0761ff60e..bae2c511c 100644 --- a/src/pocketmine/level/generator/GenerationInstanceManager.php +++ b/src/pocketmine/level/generator/GenerationInstanceManager.php @@ -24,6 +24,7 @@ namespace pocketmine\level\generator; use pocketmine\level\format\FullChunk; use pocketmine\level\Level; use pocketmine\Server; +use pocketmine\utils\ChunkException; class GenerationInstanceManager extends GenerationRequestManager{ @@ -78,7 +79,7 @@ class GenerationInstanceManager extends GenerationRequestManager{ if($chunk instanceof FullChunk){ return $chunk; }else{ - throw new \Exception("Invalid Chunk given"); + throw new ChunkException("Invalid Chunk given"); } }else{ $this->generationManager->closeLevel($levelID); diff --git a/src/pocketmine/level/generator/GenerationRequestManager.php b/src/pocketmine/level/generator/GenerationRequestManager.php index b8f4b00bd..820622d8a 100644 --- a/src/pocketmine/level/generator/GenerationRequestManager.php +++ b/src/pocketmine/level/generator/GenerationRequestManager.php @@ -25,6 +25,7 @@ use pocketmine\level\format\FullChunk; use pocketmine\level\Level; use pocketmine\Server; use pocketmine\utils\Binary; +use pocketmine\utils\ChunkException; class GenerationRequestManager{ @@ -87,7 +88,7 @@ class GenerationRequestManager{ if($chunk instanceof FullChunk){ $this->sendChunk($levelID, $chunk); }else{ - throw new \Exception("Invalid Chunk given"); + throw new ChunkException("Invalid Chunk given"); } }else{ $buffer = chr(GenerationManager::PACKET_CLOSE_LEVEL) . Binary::writeInt($levelID); diff --git a/src/pocketmine/metadata/BlockMetadataStore.php b/src/pocketmine/metadata/BlockMetadataStore.php index f4d03c387..093824768 100644 --- a/src/pocketmine/metadata/BlockMetadataStore.php +++ b/src/pocketmine/metadata/BlockMetadataStore.php @@ -43,45 +43,45 @@ class BlockMetadataStore extends MetadataStore{ public function getMetadata($block, $metadataKey){ if($block instanceof Block){ - throw new \Exception("Object must be a Block"); + throw new \InvalidArgumentException("Object must be a Block"); } if($block->getLevel() === $this->owningLevel){ return parent::getMetadata($block, $metadataKey); }else{ - throw new \Exception("Block does not belong to world " . $this->owningLevel->getName()); + throw new \InvalidStateException("Block does not belong to world " . $this->owningLevel->getName()); } } public function hasMetadata($block, $metadataKey){ if($block instanceof Block){ - throw new \Exception("Object must be a Block"); + throw new \InvalidArgumentException("Object must be a Block"); } if($block->getLevel() === $this->owningLevel){ return parent::hasMetadata($block, $metadataKey); }else{ - throw new \Exception("Block does not belong to world " . $this->owningLevel->getName()); + throw new \InvalidStateException("Block does not belong to world " . $this->owningLevel->getName()); } } public function removeMetadata($block, $metadataKey, Plugin $owningPlugin){ if($block instanceof Block){ - throw new \Exception("Object must be a Block"); + throw new \InvalidArgumentException("Object must be a Block"); } if($block->getLevel() === $this->owningLevel){ parent::hasMetadata($block, $metadataKey, $owningPlugin); }else{ - throw new \Exception("Block does not belong to world " . $this->owningLevel->getName()); + throw new \InvalidStateException("Block does not belong to world " . $this->owningLevel->getName()); } } public function setMetadata($block, $metadataKey, MetadataValue $newMetadatavalue){ if($block instanceof Block){ - throw new \Exception("Object must be a Block"); + throw new \InvalidArgumentException("Object must be a Block"); } if($block->getLevel() === $this->owningLevel){ parent::setMetadata($block, $metadataKey, $newMetadatavalue); }else{ - throw new \Exception("Block does not belong to world " . $this->owningLevel->getName()); + throw new \InvalidStateException("Block does not belong to world " . $this->owningLevel->getName()); } } } \ No newline at end of file diff --git a/src/pocketmine/metadata/MetadataStore.php b/src/pocketmine/metadata/MetadataStore.php index d980f276e..77e4ef03c 100644 --- a/src/pocketmine/metadata/MetadataStore.php +++ b/src/pocketmine/metadata/MetadataStore.php @@ -25,6 +25,7 @@ namespace pocketmine\metadata; use pocketmine\plugin\Plugin; +use pocketmine\utils\PluginException; abstract class MetadataStore{ /** @var \WeakMap[] */ @@ -42,7 +43,7 @@ abstract class MetadataStore{ public function setMetadata($subject, $metadataKey, MetadataValue $newMetadataValue){ $owningPlugin = $newMetadataValue->getOwningPlugin(); if($owningPlugin === null){ - throw new \Exception("Plugin cannot be null"); + throw new PluginException("Plugin cannot be null"); } $key = $this->disambiguate($subject, $metadataKey); diff --git a/src/pocketmine/permission/PermissibleBase.php b/src/pocketmine/permission/PermissibleBase.php index 9c7705a76..bb394bde3 100644 --- a/src/pocketmine/permission/PermissibleBase.php +++ b/src/pocketmine/permission/PermissibleBase.php @@ -24,6 +24,7 @@ namespace pocketmine\permission; use pocketmine\event\Timings; use pocketmine\plugin\Plugin; use pocketmine\Server; +use pocketmine\utils\PluginException; class PermissibleBase implements Permissible{ /** @var ServerOperator */ @@ -72,7 +73,7 @@ class PermissibleBase implements Permissible{ */ public function setOp($value){ if($this->opable === null){ - throw new \Exception("Cannot change op value as no ServerOperator is set"); + throw new \LogicException("Cannot change op value as no ServerOperator is set"); }else{ $this->opable->setOp($value); } @@ -120,13 +121,13 @@ class PermissibleBase implements Permissible{ * * @return PermissionAttachment * - * @throws \Exception + * @throws PluginException */ public function addAttachment(Plugin $plugin, $name = null, $value = null){ if($plugin === null){ - throw new \Exception("Plugin cannot be null"); + throw new PluginException("Plugin cannot be null"); }elseif(!$plugin->isEnabled()){ - throw new \Exception("Plugin " . $plugin->getDescription()->getName() . " is disabled"); + throw new PluginException("Plugin " . $plugin->getDescription()->getName() . " is disabled"); } $result = new PermissionAttachment($plugin, $this->parent); @@ -147,7 +148,7 @@ class PermissibleBase implements Permissible{ */ public function removeAttachment(PermissionAttachment $attachment){ if($attachment === null){ - throw new \Exception("Attachment cannot be null"); + throw new \InvalidStateException("Attachment cannot be null"); } if(isset($this->attachments[spl_object_hash($attachment)])){ diff --git a/src/pocketmine/permission/Permission.php b/src/pocketmine/permission/Permission.php index 23977abea..3220f9a74 100644 --- a/src/pocketmine/permission/Permission.php +++ b/src/pocketmine/permission/Permission.php @@ -225,7 +225,7 @@ class Permission{ if($value !== null){ $default = $value; }else{ - throw new \Exception("'default' key contained unknown value"); + throw new \InvalidStateException("'default' key contained unknown value"); } } @@ -240,7 +240,7 @@ class Permission{ $children[$k] = true; } }else{ - throw new \Exception("'children' key is of wrong type"); + throw new \InvalidStateException("'children' key is of wrong type"); } } diff --git a/src/pocketmine/permission/PermissionAttachment.php b/src/pocketmine/permission/PermissionAttachment.php index 75a8daba2..f87ebc000 100644 --- a/src/pocketmine/permission/PermissionAttachment.php +++ b/src/pocketmine/permission/PermissionAttachment.php @@ -22,6 +22,7 @@ namespace pocketmine\permission; use pocketmine\plugin\Plugin; +use pocketmine\utils\PluginException; class PermissionAttachment{ /** @var PermissionRemovedExecutor */ @@ -42,11 +43,11 @@ class PermissionAttachment{ * @param Plugin $plugin * @param Permissible $permissible * - * @throws \Exception + * @throws PluginException */ public function __construct(Plugin $plugin, Permissible $permissible){ if(!$plugin->isEnabled()){ - throw new \Exception("Plugin " . $plugin->getDescription()->getName() . " is disabled"); + throw new PluginException("Plugin " . $plugin->getDescription()->getName() . " is disabled"); } $this->permissible = $permissible; diff --git a/src/pocketmine/permission/PermissionAttachmentInfo.php b/src/pocketmine/permission/PermissionAttachmentInfo.php index ecb66c1c2..78f5f8650 100644 --- a/src/pocketmine/permission/PermissionAttachmentInfo.php +++ b/src/pocketmine/permission/PermissionAttachmentInfo.php @@ -41,11 +41,11 @@ class PermissionAttachmentInfo{ * @param PermissionAttachment $attachment * @param bool $value * - * @throws \Exception + * @throws \InvalidStateException */ public function __construct(Permissible $permissible, $permission, $attachment, $value){ if($permission === null){ - throw new \Exception("Permission may not be null"); + throw new \InvalidStateException("Permission may not be null"); } $this->permissible = $permissible; diff --git a/src/pocketmine/plugin/PharPluginLoader.php b/src/pocketmine/plugin/PharPluginLoader.php index abfda8c91..4aa020be2 100644 --- a/src/pocketmine/plugin/PharPluginLoader.php +++ b/src/pocketmine/plugin/PharPluginLoader.php @@ -24,6 +24,7 @@ namespace pocketmine\plugin; use pocketmine\event\plugin\PluginDisableEvent; use pocketmine\event\plugin\PluginEnableEvent; use pocketmine\Server; +use pocketmine\utils\PluginException; /** * Handles different types of plugins @@ -54,7 +55,7 @@ class PharPluginLoader implements PluginLoader{ $this->server->getLogger()->info("Loading " . $description->getFullName()); $dataFolder = dirname($file) . DIRECTORY_SEPARATOR . $description->getName(); if(file_exists($dataFolder) and !is_dir($dataFolder)){ - throw new \Exception("Projected dataFolder '" . $dataFolder . "' for " . $description->getName() . " exists and is not a directory"); + throw new \InvalidStateException("Projected dataFolder '" . $dataFolder . "' for " . $description->getName() . " exists and is not a directory"); } $file = "phar://$file"; $className = $description->getMain(); @@ -66,7 +67,7 @@ class PharPluginLoader implements PluginLoader{ return $plugin; }else{ - throw new \Exception("Couldn't load plugin " . $description->getName() . ": main class not found"); + throw new PluginException("Couldn't load plugin " . $description->getName() . ": main class not found"); } } diff --git a/src/pocketmine/plugin/PluginDescription.php b/src/pocketmine/plugin/PluginDescription.php index 28f24948b..634e417fa 100644 --- a/src/pocketmine/plugin/PluginDescription.php +++ b/src/pocketmine/plugin/PluginDescription.php @@ -22,6 +22,7 @@ namespace pocketmine\plugin; use pocketmine\permission\Permission; +use pocketmine\utils\PluginException; class PluginDescription{ private $name; @@ -53,12 +54,12 @@ class PluginDescription{ /** * @param array $plugin * - * @throws \Exception + * @throws PluginException */ private function loadMap(array $plugin){ $this->name = preg_replace("[^A-Za-z0-9 _.-]", "", $plugin["name"]); if($this->name === ""){ - throw new \Exception("Invalid PluginDescription name"); + throw new PluginException("Invalid PluginDescription name"); } $this->name = str_replace(" ", "_", $this->name); $this->version = $plugin["version"]; diff --git a/src/pocketmine/plugin/PluginManager.php b/src/pocketmine/plugin/PluginManager.php index b3a82027c..9701713e8 100644 --- a/src/pocketmine/plugin/PluginManager.php +++ b/src/pocketmine/plugin/PluginManager.php @@ -34,6 +34,7 @@ use pocketmine\permission\Permissible; use pocketmine\permission\Permission; use pocketmine\Server; use pocketmine\utils\MainLogger; +use pocketmine\utils\PluginException; /** * Manages all the plugins, Permissions and Permissibles @@ -675,11 +676,11 @@ class PluginManager{ * @param Listener $listener * @param Plugin $plugin * - * @throws \Exception + * @throws PluginException */ public function registerEvents(Listener $listener, Plugin $plugin){ if(!$plugin->isEnabled()){ - throw new \Exception("Plugin attempted to register " . get_class($listener) . " while not enabled"); + throw new PluginException("Plugin attempted to register " . get_class($listener) . " while not enabled"); } $reflection = new \ReflectionClass(get_class($listener)); @@ -723,15 +724,15 @@ class PluginManager{ * @param Plugin $plugin * @param bool $ignoreCancelled * - * @throws \Exception + * @throws PluginException */ public function registerEvent($event, Listener $listener, $priority, EventExecutor $executor, Plugin $plugin, $ignoreCancelled = false){ if(!is_subclass_of($event, Event::class) or (new \ReflectionClass($event))->isAbstract()){ - throw new \Exception($event . " is not a valid Event"); + throw new PluginException($event . " is not a valid Event"); } if(!$plugin->isEnabled()){ - throw new \Exception("Plugin attempted to register " . $event . " while not enabled"); + throw new PluginException("Plugin attempted to register " . $event . " while not enabled"); } $timings = new TimingsHandler("Plugin: " . $plugin->getDescription()->getFullName() . " Event: " . get_class($listener) . "::" . ($executor instanceof MethodEventExecutor ? $executor->getMethod() : "???") . "(" . (new \ReflectionClass($event))->getShortName() . ")", self::$pluginParentTimer); diff --git a/src/pocketmine/scheduler/ServerScheduler.php b/src/pocketmine/scheduler/ServerScheduler.php index f64d39f83..835e647f8 100644 --- a/src/pocketmine/scheduler/ServerScheduler.php +++ b/src/pocketmine/scheduler/ServerScheduler.php @@ -26,6 +26,7 @@ namespace pocketmine\scheduler; use pocketmine\plugin\Plugin; use pocketmine\Server; +use pocketmine\utils\PluginException; use pocketmine\utils\ReversePriorityQueue; class ServerScheduler{ @@ -165,14 +166,14 @@ class ServerScheduler{ * * @return null|TaskHandler * - * @throws \Exception + * @throws PluginException */ private function addTask(Task $task, $delay, $period){ if($task instanceof PluginTask){ if(!($task->getOwner() instanceof Plugin)){ - throw new \Exception("Invalid owner of PluginTask " . get_class($task)); + throw new PluginException("Invalid owner of PluginTask " . get_class($task)); }elseif(!$task->getOwner()->isEnabled()){ - throw new \Exception("Plugin '" . $task->getOwner()->getName() . "' attempted to register a task while disabled"); + throw new PluginException("Plugin '" . $task->getOwner()->getName() . "' attempted to register a task while disabled"); } } @@ -231,7 +232,11 @@ class ServerScheduler{ continue; }else{ $task->timings->startTiming(); - $task->run($this->currentTick); + try{ + $task->run($this->currentTick); + }catch (\Exception $e){ + Server::getInstance()->getLogger()->critical("Could not execute task ". $task->getTaskName() .": ".$e->getMessage()); + } $task->timings->stopTiming(); } if($task->isRepeating()){ diff --git a/src/pocketmine/tile/Tile.php b/src/pocketmine/tile/Tile.php index d22bebe38..7acf9307f 100644 --- a/src/pocketmine/tile/Tile.php +++ b/src/pocketmine/tile/Tile.php @@ -32,6 +32,7 @@ use pocketmine\level\Level; use pocketmine\level\Position; use pocketmine\nbt\tag\Compound; use pocketmine\nbt\tag\Int; +use pocketmine\utils\ChunkException; abstract class Tile extends Position{ const SIGN = "Sign"; @@ -95,7 +96,7 @@ abstract class Tile extends Position{ public function __construct(FullChunk $chunk, Compound $nbt){ if($chunk === null or $chunk->getProvider() === null){ - throw new \Exception("Invalid garbage Chunk given to Tile"); + throw new ChunkException("Invalid garbage Chunk given to Tile"); } $this->timings = Timings::getTileEntityTimings($this); diff --git a/src/pocketmine/utils/BlockIterator.php b/src/pocketmine/utils/BlockIterator.php index 31eee943b..c11a168dd 100644 --- a/src/pocketmine/utils/BlockIterator.php +++ b/src/pocketmine/utils/BlockIterator.php @@ -162,7 +162,7 @@ class BlockIterator implements \Iterator{ } if(!$startBlockFound){ - throw new \Exception("Start block missed in BlockIterator"); + throw new \RuntimeException("Start block missed in BlockIterator"); } $this->maxDistanceInt = round($maxDistance / (sqrt($mainDirection ** 2 + $secondDirection ** 2 + $thirdDirection ** 2) / $mainDirection)); diff --git a/src/pocketmine/utils/ChunkException.php b/src/pocketmine/utils/ChunkException.php new file mode 100644 index 000000000..201033109 --- /dev/null +++ b/src/pocketmine/utils/ChunkException.php @@ -0,0 +1,26 @@ + Date: Tue, 28 Oct 2014 22:05:54 +0100 Subject: [PATCH 28/61] Fixed InventoryPickupItemEvent --- src/pocketmine/Player.php | 4 ++-- src/pocketmine/event/inventory/InventoryPickupItemEvent.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index b9ffc969d..8e44d0a18 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1203,7 +1203,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ continue; } - $this->server->getPluginManager()->callEvent($ev = InventoryPickupItemEvent::createEvent($this->inventory, $item)); + $this->server->getPluginManager()->callEvent($ev = InventoryPickupItemEvent::createEvent($this->inventory, $entity)); if($ev->isCancelled()){ continue; } @@ -1228,7 +1228,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ continue; } - $this->server->getPluginManager()->callEvent($ev = InventoryPickupItemEvent::createEvent($this->inventory, $item)); + $this->server->getPluginManager()->callEvent($ev = InventoryPickupItemEvent::createEvent($this->inventory, $entity)); if($ev->isCancelled()){ continue; } diff --git a/src/pocketmine/event/inventory/InventoryPickupItemEvent.php b/src/pocketmine/event/inventory/InventoryPickupItemEvent.php index 8f87fdf39..67943f0ec 100644 --- a/src/pocketmine/event/inventory/InventoryPickupItemEvent.php +++ b/src/pocketmine/event/inventory/InventoryPickupItemEvent.php @@ -23,7 +23,7 @@ namespace pocketmine\event\inventory; use pocketmine\event\Cancellable; use pocketmine\inventory\Inventory; -use pocketmine\item\Item; +use pocketmine\entity\Item; class InventoryPickupItemEvent extends InventoryEvent implements Cancellable{ public static $handlerList = null; From 7eed92e8fb9276776f2bfaa1300f1d8f24f9482a Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 29 Oct 2014 00:31:17 +0100 Subject: [PATCH 29/61] Use Player->forceMovement on MovePlayerPacket non-tick revert --- src/pocketmine/Player.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 8e44d0a18..30b16d8df 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1483,12 +1483,12 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ if($this->forceMovement instanceof Vector3 and ($revert or $newPos->distance($this->forceMovement) > 0.2)){ $pk = MovePlayerPacket::getFromPool(); $pk->eid = 0; - $pk->x = $this->x; - $pk->y = $this->y + $this->getEyeHeight() + 0.01; - $pk->z = $this->z; - $pk->bodyYaw = $this->yaw; - $pk->pitch = $this->pitch; - $pk->yaw = $this->yaw; + $pk->x = $this->forceMovement->x; + $pk->y = $this->forceMovement->y + $this->getEyeHeight() + 0.01; + $pk->z = $this->forceMovement->z; + $pk->bodyYaw = $packet->bodyYaw; + $pk->pitch = $packet->pitch; + $pk->yaw = $packet->yaw; $pk->teleport = true; $this->directDataPacket($pk); }else{ From cbe0fe5e46e3f93b7fbc4a36c98d4423e52fb42a Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 29 Oct 2014 00:41:13 +0100 Subject: [PATCH 30/61] Added Entity->onGround setting when entities keep moving without checks --- src/pocketmine/entity/Entity.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index aa6e575b9..ac77d4093 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -818,6 +818,7 @@ abstract class Entity extends Location implements Metadatable{ $this->boundingBox->offset($dx, $dy, $dz); $pos = Vector3::createVector(($this->boundingBox->minX + $this->boundingBox->maxX) / 2, $this->boundingBox->minY - $this->ySize, ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2); $this->setPosition($pos); + $this->onGround = $this instanceof Player ? true : false; }else{ Timings::$entityMoveTimer->startTiming(); From 0680b983808de7a2a62539ef92c63dae84b3d703 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 29 Oct 2014 01:07:30 +0100 Subject: [PATCH 31/61] Remove chunks from advanced cache after setting --- src/pocketmine/level/Level.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index b8aac2888..9e4bee249 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1606,6 +1606,9 @@ class Level implements ChunkManager, Metadatable{ $this->provider->setChunk($x, $z, $chunk); $this->chunks[$index] = $chunk; } + if(ADVANCED_CACHE == true){ + Cache::remove("world:" . $this->getID() . ":$x:$z"); + } $chunk->setChanged(); } From 78f8d0280d2000647cdf2dac3178d343d4353e64 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 29 Oct 2014 01:14:09 +0100 Subject: [PATCH 32/61] Removed unused imports --- src/pocketmine/OfflinePlayer.php | 2 +- src/pocketmine/Player.php | 3 +-- src/pocketmine/PocketMine.php | 1 - src/pocketmine/Server.php | 2 +- src/pocketmine/block/Fallable.php | 1 - src/pocketmine/block/TNT.php | 1 - src/pocketmine/block/Wheat.php | 2 -- src/pocketmine/command/defaults/KillCommand.php | 1 - src/pocketmine/event/Event.php | 2 -- src/pocketmine/event/block/BlockUpdateEvent.php | 2 -- src/pocketmine/event/entity/EntityDespawnEvent.php | 2 +- src/pocketmine/event/entity/EntitySpawnEvent.php | 2 +- src/pocketmine/event/inventory/InventoryPickupItemEvent.php | 2 +- src/pocketmine/item/Bucket.php | 1 - src/pocketmine/item/SpawnEgg.php | 3 --- src/pocketmine/level/Explosion.php | 1 - src/pocketmine/level/Level.php | 3 +-- src/pocketmine/level/format/generic/BaseFullChunk.php | 3 --- src/pocketmine/utils/BlockIterator.php | 2 +- 19 files changed, 8 insertions(+), 28 deletions(-) diff --git a/src/pocketmine/OfflinePlayer.php b/src/pocketmine/OfflinePlayer.php index 03bdeab49..0bab443a8 100644 --- a/src/pocketmine/OfflinePlayer.php +++ b/src/pocketmine/OfflinePlayer.php @@ -62,7 +62,7 @@ class OfflinePlayer implements IPlayer{ return $this->server->isOp(strtolower($this->getName())); } - public function setOp($value){ + public functiottOp($value){ if($value === $this->isOp()){ return; } diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 30b16d8df..53f957ff6 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -24,12 +24,11 @@ namespace pocketmine; use pocketmine\block\Block; use pocketmine\command\CommandSender; use pocketmine\entity\Arrow; -use pocketmine\entity\Item as DroppedItem; use pocketmine\entity\Entity; use pocketmine\entity\Human; +use pocketmine\entity\Item as DroppedItem; use pocketmine\entity\Living; use pocketmine\entity\Projectile; -use pocketmine\entity\Snowball; use pocketmine\event\block\SignChangeEvent; use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\event\entity\EntityDamageEvent; diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 1b04a82de..18493335a 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -65,7 +65,6 @@ namespace { } namespace pocketmine { - use LogLevel; use pocketmine\utils\Binary; use pocketmine\utils\MainLogger; use pocketmine\utils\Utils; diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index fe40c0345..5e0458edb 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -35,6 +35,7 @@ use pocketmine\entity\Arrow; use pocketmine\entity\Entity; use pocketmine\entity\FallingSand; use pocketmine\entity\Human; +use pocketmine\entity\Item as DroppedItem; use pocketmine\entity\PrimedTNT; use pocketmine\entity\Snowball; use pocketmine\entity\Villager; @@ -45,7 +46,6 @@ use pocketmine\event\level\LevelInitEvent; use pocketmine\event\level\LevelLoadEvent; use pocketmine\event\server\ServerCommandEvent; use pocketmine\event\Timings; -use pocketmine\entity\Item as DroppedItem; use pocketmine\event\TimingsHandler; use pocketmine\inventory\CraftingManager; use pocketmine\inventory\InventoryType; diff --git a/src/pocketmine/block/Fallable.php b/src/pocketmine/block/Fallable.php index 448878fc9..01711fe10 100644 --- a/src/pocketmine/block/Fallable.php +++ b/src/pocketmine/block/Fallable.php @@ -22,7 +22,6 @@ namespace pocketmine\block; use pocketmine\entity\Entity; -use pocketmine\entity\FallingSand; use pocketmine\item\Item; use pocketmine\level\Level; use pocketmine\nbt\tag\Byte; diff --git a/src/pocketmine/block/TNT.php b/src/pocketmine/block/TNT.php index 31a68c3ff..90bf9b01b 100644 --- a/src/pocketmine/block/TNT.php +++ b/src/pocketmine/block/TNT.php @@ -22,7 +22,6 @@ namespace pocketmine\block; use pocketmine\entity\Entity; -use pocketmine\entity\PrimedTNT; use pocketmine\item\Item; use pocketmine\nbt\tag\Byte; use pocketmine\nbt\tag\Compound; diff --git a/src/pocketmine/block/Wheat.php b/src/pocketmine/block/Wheat.php index 7db1c20e1..fe29fd52e 100644 --- a/src/pocketmine/block/Wheat.php +++ b/src/pocketmine/block/Wheat.php @@ -22,8 +22,6 @@ namespace pocketmine\block; use pocketmine\item\Item; -use pocketmine\level\Level; -use pocketmine\Player; class Wheat extends Crops{ public function __construct($meta = 0){ diff --git a/src/pocketmine/command/defaults/KillCommand.php b/src/pocketmine/command/defaults/KillCommand.php index 184dbb471..4c0841ee0 100644 --- a/src/pocketmine/command/defaults/KillCommand.php +++ b/src/pocketmine/command/defaults/KillCommand.php @@ -24,7 +24,6 @@ namespace pocketmine\command\defaults; use pocketmine\command\CommandSender; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\Player; -use pocketmine\Server; use pocketmine\utils\TextFormat; class KillCommand extends VanillaCommand{ diff --git a/src/pocketmine/event/Event.php b/src/pocketmine/event/Event.php index b9280f199..29ed1ea54 100644 --- a/src/pocketmine/event/Event.php +++ b/src/pocketmine/event/Event.php @@ -24,8 +24,6 @@ */ namespace pocketmine\event; -use pocketmine\plugin\PluginManager; - abstract class Event{ /** diff --git a/src/pocketmine/event/block/BlockUpdateEvent.php b/src/pocketmine/event/block/BlockUpdateEvent.php index ad5604764..a3c8ef7f6 100644 --- a/src/pocketmine/event/block/BlockUpdateEvent.php +++ b/src/pocketmine/event/block/BlockUpdateEvent.php @@ -21,9 +21,7 @@ namespace pocketmine\event\block; -use pocketmine\block\Block; use pocketmine\event\Cancellable; -use pocketmine\Player; /** * Called when a block tries to be updated due to a neighbor change diff --git a/src/pocketmine/event/entity/EntityDespawnEvent.php b/src/pocketmine/event/entity/EntityDespawnEvent.php index d02c13c4b..c769d731a 100644 --- a/src/pocketmine/event/entity/EntityDespawnEvent.php +++ b/src/pocketmine/event/entity/EntityDespawnEvent.php @@ -22,9 +22,9 @@ namespace pocketmine\event\entity; use pocketmine\entity\Creature; -use pocketmine\entity\Item; use pocketmine\entity\Entity; use pocketmine\entity\Human; +use pocketmine\entity\Item; use pocketmine\entity\Projectile; use pocketmine\entity\Vehicle; diff --git a/src/pocketmine/event/entity/EntitySpawnEvent.php b/src/pocketmine/event/entity/EntitySpawnEvent.php index 8fde50ec6..a010d71cf 100644 --- a/src/pocketmine/event/entity/EntitySpawnEvent.php +++ b/src/pocketmine/event/entity/EntitySpawnEvent.php @@ -22,9 +22,9 @@ namespace pocketmine\event\entity; use pocketmine\entity\Creature; -use pocketmine\entity\Item; use pocketmine\entity\Entity; use pocketmine\entity\Human; +use pocketmine\entity\Item; use pocketmine\entity\Projectile; use pocketmine\entity\Vehicle; diff --git a/src/pocketmine/event/inventory/InventoryPickupItemEvent.php b/src/pocketmine/event/inventory/InventoryPickupItemEvent.php index 67943f0ec..ca265cf38 100644 --- a/src/pocketmine/event/inventory/InventoryPickupItemEvent.php +++ b/src/pocketmine/event/inventory/InventoryPickupItemEvent.php @@ -21,9 +21,9 @@ namespace pocketmine\event\inventory; +use pocketmine\entity\Item; use pocketmine\event\Cancellable; use pocketmine\inventory\Inventory; -use pocketmine\entity\Item; class InventoryPickupItemEvent extends InventoryEvent implements Cancellable{ public static $handlerList = null; diff --git a/src/pocketmine/item/Bucket.php b/src/pocketmine/item/Bucket.php index 0cf8c9eaf..a616ade9c 100644 --- a/src/pocketmine/item/Bucket.php +++ b/src/pocketmine/item/Bucket.php @@ -24,7 +24,6 @@ namespace pocketmine\item; use pocketmine\block\Air; use pocketmine\block\Block; use pocketmine\block\Liquid; -use pocketmine\block\Water; use pocketmine\event\player\PlayerBucketFillEvent; use pocketmine\level\Level; use pocketmine\Player; diff --git a/src/pocketmine/item/SpawnEgg.php b/src/pocketmine/item/SpawnEgg.php index be8f19795..6b472cba0 100644 --- a/src/pocketmine/item/SpawnEgg.php +++ b/src/pocketmine/item/SpawnEgg.php @@ -23,15 +23,12 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\entity\Entity; -use pocketmine\entity\Villager; -use pocketmine\entity\Zombie; use pocketmine\level\format\FullChunk; use pocketmine\level\Level; use pocketmine\nbt\tag\Compound; use pocketmine\nbt\tag\Double; use pocketmine\nbt\tag\Enum; use pocketmine\nbt\tag\Float; -use pocketmine\nbt\tag\Short; use pocketmine\Player; class SpawnEgg extends Item{ diff --git a/src/pocketmine/level/Explosion.php b/src/pocketmine/level/Explosion.php index 61a59c8df..68414d986 100644 --- a/src/pocketmine/level/Explosion.php +++ b/src/pocketmine/level/Explosion.php @@ -25,7 +25,6 @@ use pocketmine\block\Air; use pocketmine\block\Block; use pocketmine\block\TNT; use pocketmine\entity\Entity; -use pocketmine\entity\PrimedTNT; use pocketmine\event\entity\EntityDamageByBlockEvent; use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\event\entity\EntityDamageEvent; diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 9e4bee249..232590831 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -45,8 +45,8 @@ use pocketmine\block\SnowLayer; use pocketmine\block\Sugarcane; use pocketmine\block\Wheat; use pocketmine\entity\Arrow; -use pocketmine\entity\Item as DroppedItem; use pocketmine\entity\Entity; +use pocketmine\entity\Item as DroppedItem; use pocketmine\event\block\BlockBreakEvent; use pocketmine\event\block\BlockPlaceEvent; use pocketmine\event\block\BlockUpdateEvent; @@ -89,7 +89,6 @@ use pocketmine\plugin\Plugin; use pocketmine\scheduler\AsyncTask; use pocketmine\Server; use pocketmine\tile\Chest; -use pocketmine\tile\Sign; use pocketmine\tile\Tile; use pocketmine\utils\Cache; use pocketmine\utils\LevelException; diff --git a/src/pocketmine/level/format/generic/BaseFullChunk.php b/src/pocketmine/level/format/generic/BaseFullChunk.php index f6396a3bd..3878fd868 100644 --- a/src/pocketmine/level/format/generic/BaseFullChunk.php +++ b/src/pocketmine/level/format/generic/BaseFullChunk.php @@ -26,9 +26,6 @@ use pocketmine\level\format\FullChunk; use pocketmine\level\format\LevelProvider; use pocketmine\nbt\tag\Compound; use pocketmine\Player; -use pocketmine\tile\Chest; -use pocketmine\tile\Furnace; -use pocketmine\tile\Sign; use pocketmine\tile\Tile; use pocketmine\utils\Binary; diff --git a/src/pocketmine/utils/BlockIterator.php b/src/pocketmine/utils/BlockIterator.php index c11a168dd..aec0705ce 100644 --- a/src/pocketmine/utils/BlockIterator.php +++ b/src/pocketmine/utils/BlockIterator.php @@ -21,8 +21,8 @@ namespace pocketmine\utils; -use pocketmine\level\Level; use pocketmine\block\Block; +use pocketmine\level\Level; use pocketmine\math\Vector3; /** From 7e4f862634369f9d3c6340da5e0f39d6cd42e483 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 29 Oct 2014 11:42:29 +0100 Subject: [PATCH 33/61] Fixed typo in OfflinePlayer --- src/pocketmine/OfflinePlayer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/OfflinePlayer.php b/src/pocketmine/OfflinePlayer.php index 0bab443a8..03bdeab49 100644 --- a/src/pocketmine/OfflinePlayer.php +++ b/src/pocketmine/OfflinePlayer.php @@ -62,7 +62,7 @@ class OfflinePlayer implements IPlayer{ return $this->server->isOp(strtolower($this->getName())); } - public functiottOp($value){ + public function setOp($value){ if($value === $this->isOp()){ return; } From 56e848488a5cf211b022210fccb8d3b9c67e2509 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 29 Oct 2014 12:10:48 +0100 Subject: [PATCH 34/61] Fixed Trapdoor recipe --- src/pocketmine/inventory/CraftingManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/inventory/CraftingManager.php b/src/pocketmine/inventory/CraftingManager.php index 4c5a79fa4..18d3fec8d 100644 --- a/src/pocketmine/inventory/CraftingManager.php +++ b/src/pocketmine/inventory/CraftingManager.php @@ -77,7 +77,7 @@ class CraftingManager{ $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::GLASS_PANE, 0, 16)))->addIngredient(Item::get(Item::GLASS, 0, 6))); $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::LADDER, 0, 2)))->addIngredient(Item::get(Item::STICK, 0, 7))); $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::NETHER_REACTOR, 0, 1)))->addIngredient(Item::get(Item::DIAMOND, 0, 3))->addIngredient(Item::get(Item::IRON_INGOT, 0, 6))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::TRAPDOOR, 0, 2)))->addIngredient(Item::get(Item::WOODEN_PLANK, null, 2))); + $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::TRAPDOOR, 0, 2)))->addIngredient(Item::get(Item::WOODEN_PLANK, null, 6))); $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::WOODEN_DOOR, 0, 1)))->addIngredient(Item::get(Item::WOODEN_PLANK, null, 6))); $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::WOODEN_STAIRS, 0, 4)))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::OAK, 6))); $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::WOOD_SLAB, Planks::OAK, 6)))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::OAK, 3))); From dda8b03349461974178209cb99a8926a3afdb0a3 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 29 Oct 2014 12:12:54 +0100 Subject: [PATCH 35/61] Fixed Bowl recipe --- src/pocketmine/inventory/CraftingManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/inventory/CraftingManager.php b/src/pocketmine/inventory/CraftingManager.php index 18d3fec8d..7a78268c5 100644 --- a/src/pocketmine/inventory/CraftingManager.php +++ b/src/pocketmine/inventory/CraftingManager.php @@ -96,7 +96,7 @@ class CraftingManager{ $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::CLOCK, 0, 1)))->addIngredient(Item::get(Item::GOLD_INGOT, 0, 4))->addIngredient(Item::get(Item::REDSTONE_DUST, 0, 1))); $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::COMPASS, 0, 1)))->addIngredient(Item::get(Item::IRON_INGOT, 0, 4))->addIngredient(Item::get(Item::REDSTONE_DUST, 0, 1))); $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::TNT, 0, 1)))->addIngredient(Item::get(Item::GUNPOWDER, 0, 5))->addIngredient(Item::get(Item::SAND, null, 4))); //TODO: check if TNT can be crafted with red sand - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::BOWL, 0, 1)))->addIngredient(Item::get(Item::WOODEN_PLANKS, null, 3))); + $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::BOWL, 0, 4)))->addIngredient(Item::get(Item::WOODEN_PLANKS, null, 3))); $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::MINECART, 0, 1)))->addIngredient(Item::get(Item::IRON_INGOT, 0, 5))); $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::BOOK, 0, 1)))->addIngredient(Item::get(Item::PAPER, 0, 3))); $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::BOOKSHELF, 0, 1)))->addIngredient(Item::get(Item::WOODEN_PLANK, null, 6))->addIngredient(Item::get(Item::BOOK, 0, 3))); From 50cfeaa393b966d1ab35c9c3e5ee85de3626177d Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 29 Oct 2014 12:36:34 +0100 Subject: [PATCH 36/61] Fixed Stonecutter recipe --- src/pocketmine/inventory/CraftingManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/inventory/CraftingManager.php b/src/pocketmine/inventory/CraftingManager.php index 7a78268c5..878d8c32c 100644 --- a/src/pocketmine/inventory/CraftingManager.php +++ b/src/pocketmine/inventory/CraftingManager.php @@ -57,7 +57,7 @@ class CraftingManager{ $this->registerRecipe((new ShapelessRecipe(Item::get(Item::LIT_PUMPKIN, 0, 1)))->addIngredient(Item::get(Item::PUMPKIN, 0, 1))->addIngredient(Item::get(Item::TORCH, 0, 1))); $this->registerRecipe((new ShapelessRecipe(Item::get(Item::SNOW_BLOCK, 0, 1)))->addIngredient(Item::get(Item::SNOWBALL, 0, 1))); $this->registerRecipe((new ShapelessRecipe(Item::get(Item::STICK, 0, 4)))->addIngredient(Item::get(Item::WOODEN_PLANK, null, 2))); - $this->registerRecipe((new ShapelessRecipe(Item::get(Item::STONECUTTER, 0, 1)))->addIngredient(Item::get(Item::COBBLESTONE, 0, 1))); + $this->registerRecipe((new ShapelessRecipe(Item::get(Item::STONECUTTER, 0, 1)))->addIngredient(Item::get(Item::COBBLESTONE, 0, 4))); $this->registerRecipe((new ShapelessRecipe(Item::get(Item::WOODEN_PLANK, Planks::OAK, 4)))->addIngredient(Item::get(Item::WOOD, Wood::OAK, 1))); $this->registerRecipe((new ShapelessRecipe(Item::get(Item::WOODEN_PLANK, Planks::SPRUCE, 4)))->addIngredient(Item::get(Item::WOOD, Wood::SPRUCE, 1))); $this->registerRecipe((new ShapelessRecipe(Item::get(Item::WOODEN_PLANK, Planks::BIRCH, 4)))->addIngredient(Item::get(Item::WOOD, Wood::BIRCH, 1))); From afaa2cf722ec351ef9f2655ff8ad4d5c20864bb3 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 29 Oct 2014 12:57:26 +0100 Subject: [PATCH 37/61] Fixed Double Chest behavior --- src/pocketmine/block/Chest.php | 6 ++-- .../inventory/ContainerInventory.php | 9 ++--- .../inventory/DoubleChestInventory.php | 35 +++++++++++++++++++ src/pocketmine/tile/Chest.php | 5 +-- 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index 2b670f315..6b5b38d3b 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -62,7 +62,7 @@ class Chest extends Transparent{ 3 => 3, ]; - $chest = false; + $chest = null; $this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0]; for($side = 2; $side <= 5; ++$side){ @@ -130,11 +130,11 @@ class Chest extends Transparent{ new Int("z", $this->z) ]); $nbt->Items->setTagType(NBT::TAG_Compound); - $chest = new TileChest($this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); + $chest = Tile::createTile("Chest", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); } - if(($player->gamemode & 0x01) === 0x01){ + if($player->isCreative()){ return true; } $player->addWindow($chest->getInventory()); diff --git a/src/pocketmine/inventory/ContainerInventory.php b/src/pocketmine/inventory/ContainerInventory.php index ea16b0574..d0666cc54 100644 --- a/src/pocketmine/inventory/ContainerInventory.php +++ b/src/pocketmine/inventory/ContainerInventory.php @@ -33,10 +33,11 @@ abstract class ContainerInventory extends BaseInventory{ $pk->windowid = $who->getWindowId($this); $pk->type = $this->getType()->getNetworkType(); $pk->slots = $this->getSize(); - if($this->holder instanceof Vector3){ - $pk->x = $this->holder->getX(); - $pk->y = $this->holder->getY(); - $pk->z = $this->holder->getZ(); + $holder = $this->getHolder(); + if($holder instanceof Vector3){ + $pk->x = $holder->getX(); + $pk->y = $holder->getY(); + $pk->z = $holder->getZ(); }else{ $pk->x = $pk->y = $pk->z = 0; } diff --git a/src/pocketmine/inventory/DoubleChestInventory.php b/src/pocketmine/inventory/DoubleChestInventory.php index f819795c8..706d273da 100644 --- a/src/pocketmine/inventory/DoubleChestInventory.php +++ b/src/pocketmine/inventory/DoubleChestInventory.php @@ -22,6 +22,10 @@ namespace pocketmine\inventory; use pocketmine\item\Item; +use pocketmine\level\Level; +use pocketmine\network\protocol\TileEventPacket; +use pocketmine\Player; +use pocketmine\Server; use pocketmine\tile\Chest; class DoubleChestInventory extends ChestInventory implements InventoryHolder{ @@ -83,6 +87,37 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{ } } + public function onOpen(Player $who){ + parent::onOpen($who); + + if(count($this->getViewers()) === 1){ + $pk = TileEventPacket::getFromPool(); + $pk->x = $this->right->getHolder()->getX(); + $pk->y = $this->right->getHolder()->getY(); + $pk->z = $this->right->getHolder()->getZ(); + $pk->case1 = 1; + $pk->case2 = 2; + if(($level = $this->right->getHolder()->getLevel()) instanceof Level){ + Server::broadcastPacket($level->getUsingChunk($this->right->getHolder()->getX() >> 4, $this->right->getHolder()->getZ() >> 4), $pk); + } + } + } + + public function onClose(Player $who){ + if(count($this->getViewers()) === 1){ + $pk = TileEventPacket::getFromPool(); + $pk->x = $this->right->getHolder()->getX(); + $pk->y = $this->right->getHolder()->getY(); + $pk->z = $this->right->getHolder()->getZ(); + $pk->case1 = 1; + $pk->case2 = 0; + if(($level = $this->right->getHolder()->getLevel()) instanceof Level){ + Server::broadcastPacket($level->getUsingChunk($this->right->getHolder()->getX() >> 4, $this->right->getHolder()->getZ() >> 4), $pk); + } + } + parent::onClose($who); + } + /** * @return ChestInventory */ diff --git a/src/pocketmine/tile/Chest.php b/src/pocketmine/tile/Chest.php index 86b2b9a0f..89e7826b6 100644 --- a/src/pocketmine/tile/Chest.php +++ b/src/pocketmine/tile/Chest.php @@ -55,8 +55,6 @@ class Chest extends Spawnable implements InventoryHolder, Container{ for($i = 0; $i < $this->getSize(); ++$i){ $this->inventory->setItem($i, $this->getItem($i)); } - - $this->checkPairing(); } public function close(){ @@ -158,6 +156,9 @@ class Chest extends Spawnable implements InventoryHolder, Container{ * @return ChestInventory|DoubleChestInventory */ public function getInventory(){ + if($this->isPaired() and $this->doubleInventory === null){ + $this->checkPairing(); + } return $this->doubleInventory instanceof DoubleChestInventory ? $this->doubleInventory : $this->inventory; } From 5e55c3a8f06600501f368b9ecf84d3a926f8432f Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 29 Oct 2014 13:21:14 +0100 Subject: [PATCH 38/61] Fixed Chest->unpair() --- src/pocketmine/tile/Chest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/tile/Chest.php b/src/pocketmine/tile/Chest.php index 89e7826b6..913e9424a 100644 --- a/src/pocketmine/tile/Chest.php +++ b/src/pocketmine/tile/Chest.php @@ -230,14 +230,16 @@ class Chest extends Spawnable implements InventoryHolder, Container{ } $tile = $this->getPair(); - unset($this->namedtag->pairx, $this->namedtag->pairz, $tile->namedtag->pairx, $tile->namedtag->pairz); + unset($this->namedtag->pairx, $this->namedtag->pairz); $this->spawnToAll(); - $this->checkPairing(); if($tile instanceof Chest){ + unset($tile->namedtag->pairx, $tile->namedtag->pairz); + $tile->checkPairing(); $tile->spawnToAll(); } + $this->checkPairing(); return true; } From 72c09045d5b9505be3790f928c6b8f6874b5f47b Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 29 Oct 2014 13:21:54 +0100 Subject: [PATCH 39/61] Fixed Zombie drops crash --- src/pocketmine/entity/Zombie.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/entity/Zombie.php b/src/pocketmine/entity/Zombie.php index 243ea7a5f..0061439ef 100644 --- a/src/pocketmine/entity/Zombie.php +++ b/src/pocketmine/entity/Zombie.php @@ -83,7 +83,7 @@ class Zombie extends Monster{ public function getDrops(){ $drops = [ - ItemItem::get(Item::FEATHER, 0, 1) + ItemItem::get(ItemItem::FEATHER, 0, 1) ]; if($this->lastDamageCause instanceof EntityDamageByEntityEvent and $this->lastDamageCause->getEntity() instanceof Player){ if(mt_rand(0, 199) < 5){ From 6f64af3066935aad822cd35bbc32f654cb74e3c9 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 29 Oct 2014 14:23:51 +0100 Subject: [PATCH 40/61] Reuse even more objects! --- src/pocketmine/block/Grass.php | 6 ++-- src/pocketmine/block/Mycelium.php | 6 ++-- src/pocketmine/entity/Entity.php | 25 ++++++------- src/pocketmine/level/Level.php | 8 +++-- src/pocketmine/math/AxisAlignedBB.php | 51 +++++++++------------------ src/pocketmine/math/Vector3.php | 9 ++--- 6 files changed, 46 insertions(+), 59 deletions(-) diff --git a/src/pocketmine/block/Grass.php b/src/pocketmine/block/Grass.php index cc6a870e1..8f7c6185f 100644 --- a/src/pocketmine/block/Grass.php +++ b/src/pocketmine/block/Grass.php @@ -26,6 +26,7 @@ use pocketmine\item\Item; use pocketmine\level\generator\object\TallGrass as TallGrassObject; use pocketmine\level\Level; use pocketmine\level\Position; +use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\Server; use pocketmine\utils\Random; @@ -54,9 +55,8 @@ class Grass extends Solid{ $x = mt_rand($this->x - 1, $this->x + 1); $y = mt_rand($this->y - 2, $this->y + 2); $z = mt_rand($this->z - 1, $this->z + 1); - $block = $this->getLevel()->getBlockIdAt($x, $y, $z); - if($block === Block::DIRT){ - $block = Block::get($block, $this->getLevel()->getBlockDataAt($x, $y, $z), Position::createPosition($x, $y, $z, $this->getLevel())); + $block = $this->getLevel()->getBlock(Vector3::createVector($x, $y, $z)); + if($block->getID() === Block::DIRT){ if($block->getSide(1) instanceof Transparent){ Server::getInstance()->getPluginManager()->callEvent($ev = BlockSpreadEvent::createEvent($block, $this, new Grass())); if(!$ev->isCancelled()){ diff --git a/src/pocketmine/block/Mycelium.php b/src/pocketmine/block/Mycelium.php index 6052f5157..5e0096112 100644 --- a/src/pocketmine/block/Mycelium.php +++ b/src/pocketmine/block/Mycelium.php @@ -25,6 +25,7 @@ use pocketmine\event\block\BlockSpreadEvent; use pocketmine\item\Item; use pocketmine\level\Level; use pocketmine\level\Position; +use pocketmine\math\Vector3; use pocketmine\Server; class Mycelium extends Solid{ @@ -45,9 +46,8 @@ class Mycelium extends Solid{ $x = mt_rand($this->x - 1, $this->x + 1); $y = mt_rand($this->y - 2, $this->y + 2); $z = mt_rand($this->z - 1, $this->z + 1); - $block = $this->getLevel()->getBlockIdAt($x, $y, $z); - if($block === Block::DIRT){ - $block = Block::get($block, $this->getLevel()->getBlockDataAt($x, $y, $z), Position::createPosition($x, $y, $z, $this->getLevel())); + $block = $this->getLevel()->getBlock(Vector3::createVector($x, $y, $z)); + if($block->getID() === Block::DIRT){ if($block->getSide(1) instanceof Transparent){ Server::getInstance()->getPluginManager()->callEvent($ev = BlockSpreadEvent::createEvent($block, $this, new Mycelium())); if(!$ev->isCancelled()){ diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index ac77d4093..b65a397df 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -424,15 +424,17 @@ abstract class Entity extends Location implements Metadatable{ $list = $this->level->getCollisionBlocks($this->boundingBox); - if(count($list) === 0 and !$this->level->isFullBlock(Vector3::createVector($i, $j, $k))){ + $v = Vector3::createVector($i, $j, $k); + + if(count($list) === 0 and !$this->level->isFullBlock($v->setComponents($i, $j, $k))){ return false; }else{ - $flag = !$this->level->isFullBlock(Vector3::createVector($i - 1, $j, $k)); - $flag1 = !$this->level->isFullBlock(Vector3::createVector($i + 1, $j, $k)); - //$flag2 = !$this->level->isFullBlock(Vector3::createVector($i, $j - 1, $k)); - $flag3 = !$this->level->isFullBlock(Vector3::createVector($i, $j + 1, $k)); - $flag4 = !$this->level->isFullBlock(Vector3::createVector($i, $j, $k - 1)); - $flag5 = !$this->level->isFullBlock(Vector3::createVector($i, $j, $k + 1)); + $flag = !$this->level->isFullBlock($v->setComponents($i - 1, $j, $k)); + $flag1 = !$this->level->isFullBlock($v->setComponents($i + 1, $j, $k)); + //$flag2 = !$this->level->isFullBlock($v->setComponents($i, $j - 1, $k)); + $flag3 = !$this->level->isFullBlock($v->setComponents($i, $j + 1, $k)); + $flag4 = !$this->level->isFullBlock($v->setComponents($i, $j, $k - 1)); + $flag5 = !$this->level->isFullBlock($v->setComponents($i, $j, $k + 1)); $direction = 3; //UP! $limit = 9999; @@ -782,10 +784,10 @@ abstract class Entity extends Location implements Metadatable{ } public function isInsideOfWater(){ - $block = $this->level->getBlock($pos = Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z)->floor()); + $block = $this->level->getBlock(Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z)->floor()); if($block instanceof Water){ - $f = ($pos->y + 1) - ($block->getFluidHeightPercent() - 0.1111111); + $f = ($block->y + 1) - ($block->getFluidHeightPercent() - 0.1111111); return $y < $f; } @@ -793,7 +795,7 @@ abstract class Entity extends Location implements Metadatable{ } public function isInsideOfSolid(){ - $block = $this->level->getBlock($pos = Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z)->floor()); + $block = $this->level->getBlock(Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z)->floor()); $bb = $block->getBoundingBox(); @@ -816,8 +818,7 @@ abstract class Entity extends Location implements Metadatable{ if($this->keepMovement){ $this->boundingBox->offset($dx, $dy, $dz); - $pos = Vector3::createVector(($this->boundingBox->minX + $this->boundingBox->maxX) / 2, $this->boundingBox->minY - $this->ySize, ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2); - $this->setPosition($pos); + $this->setPosition(Vector3::createVector(($this->boundingBox->minX + $this->boundingBox->maxX) / 2, $this->boundingBox->minY - $this->ySize, ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2)); $this->onGround = $this instanceof Player ? true : false; }else{ diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 232590831..6279f3f42 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -176,7 +176,10 @@ class Level implements ChunkManager, Metadatable{ private $useSections; private $blockOrder; + /** @var Position */ private $temporalPosition; + /** @var Vector3 */ + private $temporalVector; protected $chunkTickRadius; protected $chunkTickList = []; @@ -270,6 +273,7 @@ class Level implements ChunkManager, Metadatable{ $this->timings = new LevelTimings($this); $this->temporalPosition = new Position(0, 0, 0, $this); + $this->temporalVector = new Vector3(0, 0, 0); } public function initLevel(){ @@ -746,7 +750,7 @@ class Level implements ChunkManager, Metadatable{ $collides = []; - $v = Vector3::createVector(0, 0, 0); + $v = $this->temporalVector; for($v->z = $minZ; $v->z < $maxZ; ++$v->z){ for($v->x = $minX; $v->x < $maxX; ++$v->x){ @@ -793,7 +797,7 @@ class Level implements ChunkManager, Metadatable{ $maxZ = Math::floorFloat($bb->maxZ + 1); $collides = []; - $v = Vector3::createVector(0, 0, 0); + $v = $this->temporalVector; for($v->z = $minZ; $v->z < $maxZ; ++$v->z){ for($v->x = $minX; $v->x < $maxX; ++$v->x){ diff --git a/src/pocketmine/math/AxisAlignedBB.php b/src/pocketmine/math/AxisAlignedBB.php index bb233da62..c871036b2 100644 --- a/src/pocketmine/math/AxisAlignedBB.php +++ b/src/pocketmine/math/AxisAlignedBB.php @@ -101,39 +101,36 @@ class AxisAlignedBB{ } public function addCoord($x, $y, $z){ - $vec = self::cloneBoundingBoxFromPool($this); + $minX = $this->minX; + $minY = $this->minY; + $minZ = $this->minZ; + $maxX = $this->maxX; + $maxY = $this->maxY; + $maxZ = $this->maxZ; if($x < 0){ - $vec->minX += $x; + $minX += $x; }elseif($x > 0){ - $vec->maxX += $x; + $maxX += $x; } if($y < 0){ - $vec->minY += $y; + $minY += $y; }elseif($y > 0){ - $vec->maxY += $y; + $maxY += $y; } if($z < 0){ - $vec->minZ += $z; + $minZ += $z; }elseif($z > 0){ - $vec->maxZ += $z; + $maxZ += $z; } - return $vec; + return self::getBoundingBoxFromPool($minX, $minY, $minZ, $maxX, $maxY, $maxZ); } public function grow($x, $y, $z){ - $vec = self::cloneBoundingBoxFromPool($this); - $vec->minX -= $x; - $vec->minY -= $y; - $vec->minZ -= $z; - $vec->maxX += $x; - $vec->maxY += $y; - $vec->maxZ += $z; - - return $vec; + return self::getBoundingBoxFromPool($this->minX - $x, $this->minY - $y, $this->minZ - $z, $this->maxX + $x, $this->maxY + $y, $this->maxZ + $z); } public function expand($x, $y, $z){ @@ -159,15 +156,7 @@ class AxisAlignedBB{ } public function shrink($x, $y, $z){ - $vec = self::cloneBoundingBoxFromPool($this); - $vec->minX += $x; - $vec->minY += $y; - $vec->minZ += $z; - $vec->maxX -= $x; - $vec->maxY -= $y; - $vec->maxZ -= $z; - - return $vec; + return self::getBoundingBoxFromPool($this->minX + $x, $this->minY + $y, $this->minZ + $z, $this->maxX - $x, $this->maxY - $y, $this->maxZ - $z); } public function contract($x, $y, $z){ @@ -192,15 +181,7 @@ class AxisAlignedBB{ } public function getOffsetBoundingBox($x, $y, $z){ - $vec = self::cloneBoundingBoxFromPool($this); - $vec->minX += $x; - $vec->minY += $y; - $vec->minZ += $z; - $vec->maxX += $x; - $vec->maxY += $y; - $vec->maxZ += $z; - - return $vec; + return self::getBoundingBoxFromPool($this->minX + $x, $this->minY + $y, $this->minZ + $z, $this->maxX + $x, $this->maxY + $y, $this->maxZ + $z); } public function calculateXOffset(AxisAlignedBB $bb, $x){ diff --git a/src/pocketmine/math/Vector3.php b/src/pocketmine/math/Vector3.php index 1c1abfcd5..3384c5bc5 100644 --- a/src/pocketmine/math/Vector3.php +++ b/src/pocketmine/math/Vector3.php @@ -21,10 +21,6 @@ namespace pocketmine\math; -/** - * WARNING: This class is available on the PocketMine-MP Zephir project. - * If this class is modified, remember to modify the PHP C extension. - */ class Vector3{ /** @var Vector3[] */ @@ -76,6 +72,11 @@ class Vector3{ return self::$vectorList[self::$nextVector++]->setComponents($x, $y, $z); } + /** + * @param Vector3 $vector + * + * @return Vector3 + */ public static function cloneVector(Vector3 $vector){ if(self::$nextVector >= count(self::$vectorList)){ self::$vectorList[] = new Vector3(0, 0, 0); From 289bc56b4b9343d88ec65fd4595c6f57ba2121de Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 29 Oct 2014 15:43:23 +0100 Subject: [PATCH 41/61] Blocks now save their bounding box, fixed entity block collision check --- src/pocketmine/Server.php | 7 +++++-- src/pocketmine/block/Bed.php | 2 +- src/pocketmine/block/Block.php | 14 ++++++++++++++ src/pocketmine/block/Cactus.php | 2 +- src/pocketmine/block/Cake.php | 2 +- src/pocketmine/block/Carpet.php | 2 +- src/pocketmine/block/Chest.php | 2 +- src/pocketmine/block/Door.php | 2 +- src/pocketmine/block/EndPortal.php | 2 +- src/pocketmine/block/Farmland.php | 2 +- src/pocketmine/block/Fence.php | 2 +- src/pocketmine/block/FenceGate.php | 2 +- src/pocketmine/block/Ladder.php | 2 +- src/pocketmine/block/Slab.php | 2 +- src/pocketmine/block/SoulSand.php | 2 +- src/pocketmine/block/Stair.php | 2 +- src/pocketmine/block/StoneWall.php | 2 +- src/pocketmine/block/Thin.php | 2 +- src/pocketmine/block/Trapdoor.php | 2 +- src/pocketmine/block/Vine.php | 2 +- src/pocketmine/block/WoodSlab.php | 2 +- src/pocketmine/entity/Entity.php | 6 +++--- src/pocketmine/entity/Living.php | 17 +++++++++++++++++ src/pocketmine/event/Event.php | 2 +- src/pocketmine/level/Level.php | 8 ++++---- src/pocketmine/network/protocol/DataPacket.php | 2 +- 26 files changed, 64 insertions(+), 30 deletions(-) diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 5e0458edb..f4fbc1f2e 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -2163,9 +2163,12 @@ class Server{ Vector3::clearVectorList(); Position::clearPositionList(); - AxisAlignedBB::clearBoundingBoxPool(); - if(($this->tickCounter % 4) === 0){ + if(($this->tickCounter % 20) === 0){ Event::clearAllPools(); + foreach($this->levels as $level){ + $level->clearCache(); + } + AxisAlignedBB::clearBoundingBoxPool(); } Timings::$serverTickTimer->stopTiming(); diff --git a/src/pocketmine/block/Bed.php b/src/pocketmine/block/Bed.php index f8137cf78..93df3b604 100644 --- a/src/pocketmine/block/Bed.php +++ b/src/pocketmine/block/Bed.php @@ -35,7 +35,7 @@ class Bed extends Transparent{ $this->hardness = 1; } - public function getBoundingBox(){ + protected function recalculateBoundingBox(){ return AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 0cafde47b..6739bd562 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -528,6 +528,9 @@ class Block extends Position implements Metadatable{ public $z = 0; public $frictionFactor = 0.6; + /** @var AxisAlignedBB */ + protected $boundingBox = null; + public static function init(){ if(count(self::$list) === 0){ self::$list = [ @@ -897,6 +900,17 @@ class Block extends Position implements Metadatable{ * @return AxisAlignedBB */ public function getBoundingBox(){ + if($this->boundingBox !== null){ + return $this->boundingBox; + }else{ + return $this->boundingBox = $this->recalculateBoundingBox(); + } + } + + /** + * @return AxisAlignedBB + */ + protected function recalculateBoundingBox(){ return AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, diff --git a/src/pocketmine/block/Cactus.php b/src/pocketmine/block/Cactus.php index a0f0e3f43..b01cf58ae 100644 --- a/src/pocketmine/block/Cactus.php +++ b/src/pocketmine/block/Cactus.php @@ -42,7 +42,7 @@ class Cactus extends Transparent{ $this->hardness = 2; } - public function getBoundingBox(){ + protected function recalculateBoundingBox(){ return AxisAlignedBB::getBoundingBoxFromPool( $this->x + 0.0625, diff --git a/src/pocketmine/block/Cake.php b/src/pocketmine/block/Cake.php index 8b6c6b1ce..af24166b6 100644 --- a/src/pocketmine/block/Cake.php +++ b/src/pocketmine/block/Cake.php @@ -37,7 +37,7 @@ class Cake extends Transparent{ $this->hardness = 2.5; } - public function getBoundingBox(){ + protected function recalculateBoundingBox(){ $f = (1 + $this->getDamage() * 2) / 16; diff --git a/src/pocketmine/block/Carpet.php b/src/pocketmine/block/Carpet.php index d7b315072..b950eeb8e 100644 --- a/src/pocketmine/block/Carpet.php +++ b/src/pocketmine/block/Carpet.php @@ -53,7 +53,7 @@ class Carpet extends Flowable{ $this->isSolid = true; } - public function getBoundingBox(){ + protected function recalculateBoundingBox(){ return AxisAlignedBB::getBoundingBoxFromPool( $this->x, diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index 6b5b38d3b..4ddd1f1f2 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -42,7 +42,7 @@ class Chest extends Transparent{ $this->hardness = 15; } - public function getBoundingBox(){ + protected function recalculateBoundingBox(){ return AxisAlignedBB::getBoundingBoxFromPool( $this->x + 0.0625, diff --git a/src/pocketmine/block/Door.php b/src/pocketmine/block/Door.php index 7092e6530..674ce94e0 100644 --- a/src/pocketmine/block/Door.php +++ b/src/pocketmine/block/Door.php @@ -52,7 +52,7 @@ abstract class Door extends Transparent{ return $first & 0x07 | ($flag ? 8 : 0) | ($flag1 ? 0x10 : 0); } - public function getBoundingBox(){ + protected function recalculateBoundingBox(){ $f = 0.1875; $damage = $this->getFullDamage(); diff --git a/src/pocketmine/block/EndPortal.php b/src/pocketmine/block/EndPortal.php index af4ef3132..15602c19b 100644 --- a/src/pocketmine/block/EndPortal.php +++ b/src/pocketmine/block/EndPortal.php @@ -29,7 +29,7 @@ class EndPortal extends Solid{ $this->hardness = 18000000; } - public function getBoundingBox(){ + protected function recalculateBoundingBox(){ return AxisAlignedBB::getBoundingBoxFromPool( $this->x, diff --git a/src/pocketmine/block/Farmland.php b/src/pocketmine/block/Farmland.php index 004f7f8f8..47750e77c 100644 --- a/src/pocketmine/block/Farmland.php +++ b/src/pocketmine/block/Farmland.php @@ -30,7 +30,7 @@ class Farmland extends Solid{ $this->hardness = 3; } - public function getBoundingBox(){ + protected function recalculateBoundingBox(){ return AxisAlignedBB::getBoundingBoxFromPool( $this->x, diff --git a/src/pocketmine/block/Fence.php b/src/pocketmine/block/Fence.php index 35bd7c246..a9abe1551 100644 --- a/src/pocketmine/block/Fence.php +++ b/src/pocketmine/block/Fence.php @@ -31,7 +31,7 @@ class Fence extends Transparent{ $this->hardness = 15; } - public function getBoundingBox(){ + protected function recalculateBoundingBox(){ $flag = $this->canConnect($this->getSide(2)); $flag1 = $this->canConnect($this->getSide(3)); diff --git a/src/pocketmine/block/FenceGate.php b/src/pocketmine/block/FenceGate.php index 9195347aa..5e2fae303 100644 --- a/src/pocketmine/block/FenceGate.php +++ b/src/pocketmine/block/FenceGate.php @@ -38,7 +38,7 @@ class FenceGate extends Transparent{ } - public function getBoundingBox(){ + protected function recalculateBoundingBox(){ if(($this->getDamage() & 0x04) > 0){ return null; diff --git a/src/pocketmine/block/Ladder.php b/src/pocketmine/block/Ladder.php index 10b7c4fb8..6a7270414 100644 --- a/src/pocketmine/block/Ladder.php +++ b/src/pocketmine/block/Ladder.php @@ -43,7 +43,7 @@ class Ladder extends Transparent{ $entity->onGround = true; } - public function getBoundingBox(){ + protected function recalculateBoundingBox(){ $f = 0.125; diff --git a/src/pocketmine/block/Slab.php b/src/pocketmine/block/Slab.php index 35bdcc09a..da112638c 100644 --- a/src/pocketmine/block/Slab.php +++ b/src/pocketmine/block/Slab.php @@ -47,7 +47,7 @@ class Slab extends Transparent{ $this->hardness = 30; } - public function getBoundingBox(){ + protected function recalculateBoundingBox(){ if(($this->meta & 0x08) > 0){ return AxisAlignedBB::getBoundingBoxFromPool( diff --git a/src/pocketmine/block/SoulSand.php b/src/pocketmine/block/SoulSand.php index 3276c7613..c3d77be53 100644 --- a/src/pocketmine/block/SoulSand.php +++ b/src/pocketmine/block/SoulSand.php @@ -30,7 +30,7 @@ class SoulSand extends Solid{ $this->hardness = 2.5; } - public function getBoundingBox(){ + protected function recalculateBoundingBox(){ return AxisAlignedBB::getBoundingBoxFromPool( $this->x, diff --git a/src/pocketmine/block/Stair.php b/src/pocketmine/block/Stair.php index c88f5bafd..35287b5de 100644 --- a/src/pocketmine/block/Stair.php +++ b/src/pocketmine/block/Stair.php @@ -113,7 +113,7 @@ abstract class Stair extends Transparent{ } */ - public function getBoundingBox(){ + protected function recalculateBoundingBox(){ if(($this->getDamage() & 0x04) > 0){ return AxisAlignedBB::getBoundingBoxFromPool( diff --git a/src/pocketmine/block/StoneWall.php b/src/pocketmine/block/StoneWall.php index a665e2bb8..7410a44a0 100644 --- a/src/pocketmine/block/StoneWall.php +++ b/src/pocketmine/block/StoneWall.php @@ -36,7 +36,7 @@ class StoneWall extends Transparent{ $this->hardness = 30; } - public function getBoundingBox(){ + protected function recalculateBoundingBox(){ $flag = $this->canConnect($this->getSide(2)); $flag1 = $this->canConnect($this->getSide(3)); diff --git a/src/pocketmine/block/Thin.php b/src/pocketmine/block/Thin.php index 59a0f6b50..17b51790f 100644 --- a/src/pocketmine/block/Thin.php +++ b/src/pocketmine/block/Thin.php @@ -29,7 +29,7 @@ abstract class Thin extends Transparent{ public $isFullBlock = false; public $isSolid = false; - public function getBoundingBox(){ + protected function recalculateBoundingBox(){ $f = 0.4375; $f1 = 0.5625; diff --git a/src/pocketmine/block/Trapdoor.php b/src/pocketmine/block/Trapdoor.php index cceb46d11..a706e9cb6 100644 --- a/src/pocketmine/block/Trapdoor.php +++ b/src/pocketmine/block/Trapdoor.php @@ -37,7 +37,7 @@ class Trapdoor extends Transparent{ $this->hardness = 15; } - public function getBoundingBox(){ + protected function recalculateBoundingBox(){ $damage = $this->getDamage(); diff --git a/src/pocketmine/block/Vine.php b/src/pocketmine/block/Vine.php index a1e63f3b0..deb70ee32 100644 --- a/src/pocketmine/block/Vine.php +++ b/src/pocketmine/block/Vine.php @@ -43,7 +43,7 @@ class Vine extends Transparent{ $entity->fallDistance = 0; } - public function getBoundingBox(){ + protected function recalculateBoundingBox(){ $f1 = 1; $f2 = 1; diff --git a/src/pocketmine/block/WoodSlab.php b/src/pocketmine/block/WoodSlab.php index 804c3d68f..9f0476364 100644 --- a/src/pocketmine/block/WoodSlab.php +++ b/src/pocketmine/block/WoodSlab.php @@ -45,7 +45,7 @@ class WoodSlab extends Transparent{ $this->hardness = 15; } - public function getBoundingBox(){ + protected function recalculateBoundingBox(){ if(($this->meta & 0x08) > 0){ return AxisAlignedBB::getBoundingBoxFromPool( diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index b65a397df..2fbab1fa3 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -1040,9 +1040,9 @@ abstract class Entity extends Location implements Metadatable{ $vector = Vector3::createVector(0, 0, 0); $v = Vector3::createVector(0, 0, 0); - for($v->z = $minZ; $v->z < $maxZ; ++$v->z){ - for($v->x = $minX; $v->x < $maxX; ++$v->x){ - for($v->y = $minY; $v->y < $maxY; ++$v->y){ + for($v->z = $minZ; $v->z <= $maxZ; ++$v->z){ + for($v->x = $minX; $v->x <= $maxX; ++$v->x){ + for($v->y = $minY; $v->y <= $maxY; ++$v->y){ $block = $this->level->getBlock($v); if($block !== null and $block->hasEntityCollision){ $block->onEntityCollide($this); diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index ade61e16c..8c8d6f4e4 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -69,9 +69,26 @@ abstract class Living extends Entity implements Damageable{ } public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){ + + if($this->attackTime > 0){ $lastCause = $this->getLastDamageCause(); if($lastCause instanceof EntityDamageEvent and $lastCause->getDamage() >= $damage){ + if($source instanceof EntityDamageEvent){ + $source->setCancelled(); + $this->server->getPluginManager()->callEvent($source); + $damage = $source->getFinalDamage(); + if($source->isCancelled()){ + return; + } + }else{ + return; + } + } + }elseif($source instanceof EntityDamageEvent){ + $this->server->getPluginManager()->callEvent($source); + $damage = $source->getFinalDamage(); + if($source->isCancelled()){ return; } } diff --git a/src/pocketmine/event/Event.php b/src/pocketmine/event/Event.php index 29ed1ea54..e58950086 100644 --- a/src/pocketmine/event/Event.php +++ b/src/pocketmine/event/Event.php @@ -50,7 +50,7 @@ abstract class Event{ * @return string */ final public function getEventName(){ - return $this->eventName !== null ? static::class : $this->eventName; + return $this->eventName != null ? get_class($this) : $this->eventName; } /** diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 6279f3f42..234118cf2 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -517,10 +517,6 @@ class Level implements ChunkManager, Metadatable{ $this->tickChunks(); $this->timings->doTickTiles->stopTiming(); - if(($currentTick % 200) === 0){ - $this->blockCache = []; - } - if(count($this->changedCount) > 0){ if(count($this->players) > 0){ foreach($this->changedCount as $index => $mini){ @@ -571,6 +567,10 @@ class Level implements ChunkManager, Metadatable{ $this->timings->doTick->stopTiming(); } + public function clearCache(){ + $this->blockCache = []; + } + private function tickChunks(){ if($this->chunksPerTick <= 0 or count($this->players) === 0){ return; diff --git a/src/pocketmine/network/protocol/DataPacket.php b/src/pocketmine/network/protocol/DataPacket.php index 5aa928815..a42f64c03 100644 --- a/src/pocketmine/network/protocol/DataPacket.php +++ b/src/pocketmine/network/protocol/DataPacket.php @@ -38,7 +38,7 @@ abstract class DataPacket extends \stdClass{ } public static function cleanPool(){ - if(static::$next > 4096){ + if(static::$next > 16384){ static::$pool = []; } static::$next = 0; From 8a768cea336cdf5226c439da825bd95e1dcedfb0 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 29 Oct 2014 16:02:40 +0100 Subject: [PATCH 42/61] EntityDamageEvent and children now only fire if the attack is possible, moved event trigger to Entity->attack() --- src/pocketmine/Player.php | 15 +++++++++++---- src/pocketmine/block/Cactus.php | 5 +---- src/pocketmine/block/Fire.php | 5 +---- src/pocketmine/block/Lava.php | 5 +---- src/pocketmine/entity/Entity.php | 18 +++++------------- src/pocketmine/entity/Human.php | 15 --------------- src/pocketmine/entity/Item.php | 7 +++++++ src/pocketmine/entity/Living.php | 14 ++++---------- src/pocketmine/entity/Projectile.php | 6 +----- src/pocketmine/level/Explosion.php | 9 ++------- 10 files changed, 33 insertions(+), 66 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 53f957ff6..8c88fc88f 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1901,7 +1901,9 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ if($cancelled){ $ev->setCancelled(); } - $this->server->getPluginManager()->callEvent($ev); + + $target->attack($ev->getFinalDamage(), $ev); + if($ev->isCancelled()){ if($item->isTool() and $this->isSurvival()){ $this->inventory->sendContents($this); @@ -1909,8 +1911,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ break; } - $target->attack($ev->getFinalDamage(), $ev); - if($item->isTool() and $this->isSurvival()){ if($item->useOn($target) and $item->getDamage() >= $item->getMaxDurability()){ $this->inventory->setItemInHand(Item::get(Item::AIR, 0, 1), $this); @@ -2517,7 +2517,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ if($this->dead === true){ return; } - if(($this->getGamemode() & 0x01) === 1){ + if($this->isCreative() === 1){ if($source instanceof EntityDamageEvent){ $cause = $source->getCause(); }else{ @@ -2529,6 +2529,9 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ and $cause !== EntityDamageEvent::CAUSE_SUICIDE and $cause !== EntityDamageEvent::CAUSE_VOID ){ + if($source instanceof EntityDamageEvent){ + $source->setCancelled(); + } return; } } @@ -2536,6 +2539,10 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ parent::attack($damage, $source); + if($source instanceof EntityDamageEvent and $source->isCancelled()){ + return; + } + if($this->getLastDamageCause() === $source){ $pk = EntityEventPacket::getFromPool(); $pk->eid = 0; diff --git a/src/pocketmine/block/Cactus.php b/src/pocketmine/block/Cactus.php index b01cf58ae..cad2d9e66 100644 --- a/src/pocketmine/block/Cactus.php +++ b/src/pocketmine/block/Cactus.php @@ -56,10 +56,7 @@ class Cactus extends Transparent{ public function onEntityCollide(Entity $entity){ $ev = EntityDamageByBlockEvent::createEvent($this, $entity, EntityDamageEvent::CAUSE_CONTACT, 1); - Server::getInstance()->getPluginManager()->callEvent($ev); - if(!$ev->isCancelled()){ - $entity->attack($ev->getFinalDamage(), $ev); - } + $entity->attack($ev->getFinalDamage(), $ev); } public function onUpdate($type){ diff --git a/src/pocketmine/block/Fire.php b/src/pocketmine/block/Fire.php index 65b2488be..43c7d21d1 100644 --- a/src/pocketmine/block/Fire.php +++ b/src/pocketmine/block/Fire.php @@ -47,10 +47,7 @@ class Fire extends Flowable{ public function onEntityCollide(Entity $entity){ $ev = EntityDamageByBlockEvent::createEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1); - Server::getInstance()->getPluginManager()->callEvent($ev); - if(!$ev->isCancelled()){ - $entity->attack($ev->getFinalDamage(), $ev); - } + $entity->attack($ev->getFinalDamage(), $ev); $ev = EntityCombustByBlockEvent::createEvent($this, $entity, 8); Server::getInstance()->getPluginManager()->callEvent($ev); diff --git a/src/pocketmine/block/Lava.php b/src/pocketmine/block/Lava.php index 2fc2dfc6c..75b57d472 100644 --- a/src/pocketmine/block/Lava.php +++ b/src/pocketmine/block/Lava.php @@ -39,10 +39,7 @@ class Lava extends Liquid{ public function onEntityCollide(Entity $entity){ $entity->fallDistance *= 0.5; $ev = EntityDamageByBlockEvent::createEvent($this, $entity, EntityDamageEvent::CAUSE_LAVA, 4); - Server::getInstance()->getPluginManager()->callEvent($ev); - if(!$ev->isCancelled()){ - $entity->attack($ev->getFinalDamage(), $ev); - } + $entity->attack($ev->getFinalDamage(), $ev); $ev = EntityCombustByBlockEvent::createEvent($this, $entity, 15); Server::getInstance()->getPluginManager()->callEvent($ev); diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 2fbab1fa3..92dbcd320 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -384,7 +384,7 @@ abstract class Entity extends Location implements Metadatable{ * @param int|EntityDamageEvent $type */ public function setLastDamageCause($type){ - $this->lastDamageCause = $type; + $this->lastDamageCause = $type instanceof EntityDamageEvent ? clone $type : $type; } /** @@ -522,10 +522,8 @@ abstract class Entity extends Location implements Metadatable{ $this->checkBlockCollision(); if($this->y < 0 and $this->dead !== true){ - $this->server->getPluginManager()->callEvent($ev = EntityDamageEvent::createEvent($this, EntityDamageEvent::CAUSE_VOID, 10)); - if(!$ev->isCancelled()){ - $this->attack($ev->getFinalDamage(), $ev); - } + $ev = EntityDamageEvent::createEvent($this, EntityDamageEvent::CAUSE_VOID, 10); + $this->attack($ev->getFinalDamage(), $ev); $hasUpdate = true; } @@ -538,10 +536,7 @@ abstract class Entity extends Location implements Metadatable{ }else{ if(($this->fireTicks % 20) === 0 or $tickDiff > 20){ $ev = EntityDamageEvent::createEvent($this, EntityDamageEvent::CAUSE_FIRE_TICK, 1); - $this->server->getPluginManager()->callEvent($ev); - if(!$ev->isCancelled()){ - $this->attack($ev->getFinalDamage(), $ev); - } + $this->attack($ev->getFinalDamage(), $ev); } $this->fireTicks -= $tickDiff; } @@ -714,10 +709,7 @@ abstract class Entity extends Location implements Metadatable{ public function fall($fallDistance){ $damage = floor($fallDistance - 3); if($damage > 0){ - $this->server->getPluginManager()->callEvent($ev = EntityDamageEvent::createEvent($this, EntityDamageEvent::CAUSE_FALL, $damage)); - if($ev->isCancelled()){ - return; - } + $ev = EntityDamageEvent::createEvent($this, EntityDamageEvent::CAUSE_FALL, $damage); $this->attack($ev->getFinalDamage(), $ev); } } diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index ef45e9a93..99b2dc2fa 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -208,21 +208,6 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ 17 => ["type" => 6, "value" => [0, 0, 0]], ]; - /*if($this->class === ENTITY_MOB and $this->type === MOB_SHEEP){ - if(!isset($this->data["Sheared"])){ - $this->data["Sheared"] = 0; - $this->data["Color"] = mt_rand(0,15); - } - $d[16]["value"] = (($this->data["Sheared"] == 1 ? 1:0) << 4) | ($this->data["Color"] & 0x0F); - }elseif($this->type === OBJECT_PRIMEDTNT){ - $d[16]["value"] = (int) max(0, $this->data["fuse"] - (microtime(true) - $this->spawntime) * 20); - }elseif($this->class === ENTITY_PLAYER){ - if($this->player->sleeping !== false){ - $d[16]["value"] = 2; - $d[17]["value"] = array($this->player->sleeping->x, $this->player->sleeping->y, $this->player->sleeping->z); - } - }*/ - return $d; } diff --git a/src/pocketmine/entity/Item.php b/src/pocketmine/entity/Item.php index 9707ddd56..96f629ca0 100644 --- a/src/pocketmine/entity/Item.php +++ b/src/pocketmine/entity/Item.php @@ -131,6 +131,13 @@ class Item extends Entity{ } public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){ + if($source instanceof EntityDamageEvent){ + $this->server->getPluginManager()->callEvent($source); + $damage = $source->getFinalDamage(); + if($source->isCancelled()){ + return; + } + } $this->setLastDamageCause($source); $this->setHealth($this->getHealth() - $damage); } diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index 8c8d6f4e4..59c734da9 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -69,8 +69,6 @@ abstract class Living extends Entity implements Damageable{ } public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){ - - if($this->attackTime > 0){ $lastCause = $this->getLastDamageCause(); if($lastCause instanceof EntityDamageEvent and $lastCause->getDamage() >= $damage){ @@ -152,10 +150,8 @@ abstract class Living extends Entity implements Damageable{ parent::entityBaseTick(); if($this->dead !== true and $this->isInsideOfSolid()){ - $this->server->getPluginManager()->callEvent($ev = EntityDamageEvent::createEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 1)); - if(!$ev->isCancelled()){ - $this->attack($ev->getFinalDamage(), $ev); - } + $ev = EntityDamageEvent::createEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 1); + $this->attack($ev->getFinalDamage(), $ev); } if($this->dead !== true and $this->isInsideOfWater()){ @@ -163,10 +159,8 @@ abstract class Living extends Entity implements Damageable{ if($this->airTicks <= -20){ $this->airTicks = 0; - $this->server->getPluginManager()->callEvent($ev = EntityDamageEvent::createEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2)); - if(!$ev->isCancelled()){ - $this->attack($ev->getFinalDamage(), $ev); - } + $ev = EntityDamageEvent::createEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2); + $this->attack($ev->getFinalDamage(), $ev); } }else{ $this->airTicks = 300; diff --git a/src/pocketmine/entity/Projectile.php b/src/pocketmine/entity/Projectile.php index 3de60df75..c13ae5be0 100644 --- a/src/pocketmine/entity/Projectile.php +++ b/src/pocketmine/entity/Projectile.php @@ -136,12 +136,8 @@ abstract class Projectile extends Entity{ $ev = EntityDamageByEntityEvent::createEvent($this->shootingEntity === null ? $this : $this->shootingEntity, $movingObjectPosition->entityHit, EntityDamageEvent::CAUSE_PROJECTILE, $damage); + $movingObjectPosition->entityHit->attack($ev->getFinalDamage(), $ev); - $this->server->getPluginManager()->callEvent($ev); - - if(!$ev->isCancelled()){ - $movingObjectPosition->entityHit->attack($ev->getFinalDamage(), $ev); - } if($this->fireTicks > 0){ $ev = EntityCombustByEntityEvent::createEvent($this, $movingObjectPosition->entityHit, 5); diff --git a/src/pocketmine/level/Explosion.php b/src/pocketmine/level/Explosion.php index 68414d986..3a5632a28 100644 --- a/src/pocketmine/level/Explosion.php +++ b/src/pocketmine/level/Explosion.php @@ -172,13 +172,8 @@ class Explosion{ $ev = EntityDamageEvent::createEvent($entity, EntityDamageEvent::CAUSE_BLOCK_EXPLOSION, $damage); } - $this->level->getServer()->getPluginManager()->callEvent($ev); - - if(!$ev->isCancelled()){ - $entity->attack($ev->getFinalDamage(), $ev); - $entity->setMotion($motion->multiply($impact)); - } - + $entity->attack($ev->getFinalDamage(), $ev); + $entity->setMotion($motion->multiply($impact)); } } From 00b282d40c337c44163bd294f561f36a6bdd7406 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 29 Oct 2014 16:13:47 +0100 Subject: [PATCH 43/61] Improved cache pool cleanup times --- src/pocketmine/Server.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index f4fbc1f2e..21f829b0f 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -2163,12 +2163,15 @@ class Server{ Vector3::clearVectorList(); Position::clearPositionList(); - if(($this->tickCounter % 20) === 0){ + if(($this->tickCounter % 4) === 0){ Event::clearAllPools(); - foreach($this->levels as $level){ - $level->clearCache(); + + if(($this->tickCounter % 80) === 0){ + foreach($this->levels as $level){ + $level->clearCache(); + } + AxisAlignedBB::clearBoundingBoxPool(); } - AxisAlignedBB::clearBoundingBoxPool(); } Timings::$serverTickTimer->stopTiming(); From 022a978ffbbd702b59158b58044385452a4d1c23 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 29 Oct 2014 16:29:00 +0100 Subject: [PATCH 44/61] Added InventoryPickupArrowEvent --- src/pocketmine/Player.php | 3 +- .../inventory/InventoryPickupArrowEvent.php | 52 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/pocketmine/event/inventory/InventoryPickupArrowEvent.php diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 8c88fc88f..61247eb4e 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -36,6 +36,7 @@ use pocketmine\event\entity\EntityRegainHealthEvent; use pocketmine\event\entity\EntityShootBowEvent; use pocketmine\event\entity\ProjectileLaunchEvent; use pocketmine\event\inventory\InventoryCloseEvent; +use pocketmine\event\inventory\InventoryPickupArrowEvent; use pocketmine\event\inventory\InventoryPickupItemEvent; use pocketmine\event\player\PlayerAchievementAwardedEvent; use pocketmine\event\player\PlayerAnimationEvent; @@ -1202,7 +1203,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ continue; } - $this->server->getPluginManager()->callEvent($ev = InventoryPickupItemEvent::createEvent($this->inventory, $entity)); + $this->server->getPluginManager()->callEvent($ev = InventoryPickupArrowEvent::createEvent($this->inventory, $entity)); if($ev->isCancelled()){ continue; } diff --git a/src/pocketmine/event/inventory/InventoryPickupArrowEvent.php b/src/pocketmine/event/inventory/InventoryPickupArrowEvent.php new file mode 100644 index 000000000..8c600c1dc --- /dev/null +++ b/src/pocketmine/event/inventory/InventoryPickupArrowEvent.php @@ -0,0 +1,52 @@ +arrow = $arrow; + parent::__construct($inventory); + } + + /** + * @return Arrow + */ + public function getArrow(){ + return $this->arrow; + } + +} \ No newline at end of file From d57e37896db91accc67542902a1391e7c78de8bf Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 29 Oct 2014 17:43:21 +0100 Subject: [PATCH 45/61] Improved Region / RakLib --- .../level/format/mcregion/RegionLoader.php | 12 ++++++------ src/raklib | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/pocketmine/level/format/mcregion/RegionLoader.php b/src/pocketmine/level/format/mcregion/RegionLoader.php index 64a0eb13d..8514a172d 100644 --- a/src/pocketmine/level/format/mcregion/RegionLoader.php +++ b/src/pocketmine/level/format/mcregion/RegionLoader.php @@ -277,8 +277,8 @@ class RegionLoader{ $this->lastSector = 1; $table = fread($this->filePointer, 4 * 1024 * 2); for($i = 0; $i < 1024; ++$i){ - $index = Binary::readInt(substr($table, $i << 2, 4)); - $this->locationTable[$i] = [($index & ~0xff) >> 8, $index & 0xff, Binary::readInt(substr($table, 4096 + ($i << 2), 4))]; + $index = unpack("N", substr($table, $i << 2, 4))[1]; + $this->locationTable[$i] = [($index & ~0xff) >> 8, $index & 0xff, unpack("N", substr($table, 4096 + ($i << 2), 4))[1]]; if(($this->locationTable[$i][0] + $this->locationTable[$i][1] - 1) > $this->lastSector){ $this->lastSector = $this->locationTable[$i][0] + $this->locationTable[$i][1] - 1; } @@ -286,16 +286,16 @@ class RegionLoader{ } private function writeLocationTable(){ - $table = ""; + $write = []; for($i = 0; $i < 1024; ++$i){ - $table .= Binary::writeInt(($this->locationTable[$i][0] << 8) | $this->locationTable[$i][1]); + $write[] = ($this->locationTable[$i][0] << 8) | $this->locationTable[$i][1]; } for($i = 0; $i < 1024; ++$i){ - $table .= Binary::writeInt($this->locationTable[$i][2]); + $write[] = $this->locationTable[$i][2]; } fseek($this->filePointer, 0); - fwrite($this->filePointer, $table, 4096 * 2); + fwrite($this->filePointer, pack("N*", ...$write), 4096 * 2); } protected function writeLocationIndex($index){ diff --git a/src/raklib b/src/raklib index 7e07ffbe9..a15d851da 160000 --- a/src/raklib +++ b/src/raklib @@ -1 +1 @@ -Subproject commit 7e07ffbe9461c1b2487fac9dd7fd542f7fccec34 +Subproject commit a15d851daa87698499a1485e37e76422cfb3f0c4 From c4c374e3fa5189eab98cc657f37508d62f4d8383 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 29 Oct 2014 21:52:27 +0100 Subject: [PATCH 46/61] Added extra chunk sending timings --- src/pocketmine/event/LevelTimings.php | 8 ++++++++ src/pocketmine/level/Level.php | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/src/pocketmine/event/LevelTimings.php b/src/pocketmine/event/LevelTimings.php index 5f20c68a6..ef78dcbd2 100644 --- a/src/pocketmine/event/LevelTimings.php +++ b/src/pocketmine/event/LevelTimings.php @@ -56,6 +56,11 @@ class LevelTimings{ /** @var TimingsHandler */ public $tickEntities; + /** @var TimingsHandler */ + public $syncChunkSendTimer; + /** @var TimingsHandler */ + public $syncChunkSendPrepareTimer; + /** @var TimingsHandler */ public $syncChunkLoadTimer; /** @var TimingsHandler */ @@ -87,6 +92,9 @@ class LevelTimings{ $this->tileEntityTick = new TimingsHandler("** " . $name . "tileEntityTick"); $this->tileEntityPending = new TimingsHandler("** " . $name . "tileEntityPending"); + $this->syncChunkSendTimer = new TimingsHandler("** " . $name . "syncChunkSend"); + $this->syncChunkSendPrepareTimer = new TimingsHandler("** " . $name . "syncChunkSendPrepare"); + $this->syncChunkLoadTimer = new TimingsHandler("** " . $name . "syncChunkLoad"); $this->syncChunkLoadDataTimer = new TimingsHandler("** " . $name . "syncChunkLoad - Data"); $this->syncChunkLoadStructuresTimer = new TimingsHandler("** " . $name . "syncChunkLoad - Structures"); diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 234118cf2..ac85f4652 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1694,6 +1694,8 @@ class Level implements ChunkManager, Metadatable{ protected function processChunkRequest(){ if(count($this->chunkSendQueue) > 0){ + $this->timings->syncChunkSendTimer->startTiming(); + $x = null; $z = null; foreach($this->chunkSendQueue as $index => $players){ @@ -1711,12 +1713,16 @@ class Level implements ChunkManager, Metadatable{ unset($this->chunkSendQueue[$index]); }else{ $this->chunkSendTasks[$index] = true; + $this->timings->syncChunkSendPrepareTimer->startTiming(); $task = $this->provider->requestChunkTask($x, $z); if($task instanceof AsyncTask){ $this->server->getScheduler()->scheduleAsyncTask($task); } + $this->timings->syncChunkSendPrepareTimer->stopTiming(); } } + + $this->timings->syncChunkSendTimer->stopTiming(); } } From 8cb9dd9a140f02905ffe21e85975e9c9d08ea181 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 29 Oct 2014 22:58:40 +0100 Subject: [PATCH 47/61] Fixed #2244 --- src/pocketmine/Player.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 61247eb4e..539edb762 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2518,7 +2518,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ if($this->dead === true){ return; } - if($this->isCreative() === 1){ + if($this->isCreative()){ if($source instanceof EntityDamageEvent){ $cause = $source->getCause(); }else{ From d8f9def7f418b1611c0c0817e7744eec307dfdf1 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 30 Oct 2014 07:58:53 +0100 Subject: [PATCH 48/61] Added preprocessor optimizations --- .../level/conversor/pmf/LevelFormat.php | 8 +-- src/pocketmine/nbt/NBT.php | 8 ++- src/pocketmine/nbt/tag/Byte.php | 4 +- src/pocketmine/nbt/tag/ByteArray.php | 2 + src/pocketmine/nbt/tag/Compound.php | 2 + src/pocketmine/nbt/tag/Double.php | 2 + src/pocketmine/nbt/tag/Enum.php | 2 + src/pocketmine/nbt/tag/Float.php | 2 + src/pocketmine/nbt/tag/Int.php | 2 + src/pocketmine/nbt/tag/IntArray.php | 2 + src/pocketmine/nbt/tag/Long.php | 2 + src/pocketmine/nbt/tag/Short.php | 2 + src/pocketmine/nbt/tag/String.php | 2 + .../network/protocol/AddEntityPacket.php | 2 + .../network/protocol/AddItemEntityPacket.php | 2 + .../network/protocol/AddMobPacket.php | 2 + .../network/protocol/AddPaintingPacket.php | 2 + .../network/protocol/AddPlayerPacket.php | 2 + .../protocol/AdventureSettingsPacket.php | 2 + .../network/protocol/AnimatePacket.php | 2 + .../network/protocol/ChatPacket.php | 2 + .../network/protocol/ContainerClosePacket.php | 2 + .../network/protocol/ContainerOpenPacket.php | 2 + .../protocol/ContainerSetContentPacket.php | 2 + .../protocol/ContainerSetDataPacket.php | 2 + .../protocol/ContainerSetSlotPacket.php | 2 + .../network/protocol/DataPacket.php | 6 +- .../network/protocol/DropItemPacket.php | 2 + .../network/protocol/EntityDataPacket.php | 2 + .../network/protocol/EntityEventPacket.php | 2 + .../network/protocol/ExplodePacket.php | 2 + .../network/protocol/FullChunkDataPacket.php | 2 + .../network/protocol/HurtArmorPacket.php | 2 + .../network/protocol/InteractPacket.php | 2 + .../network/protocol/LevelEventPacket.php | 2 + .../network/protocol/LoginPacket.php | 2 + .../network/protocol/LoginStatusPacket.php | 2 + .../network/protocol/MessagePacket.php | 2 + .../network/protocol/MoveEntityPacket.php | 2 + .../network/protocol/MovePlayerPacket.php | 2 + .../network/protocol/PlayerActionPacket.php | 2 + .../protocol/PlayerArmorEquipmentPacket.php | 2 + .../protocol/PlayerEquipmentPacket.php | 2 + .../network/protocol/RemoveBlockPacket.php | 2 + .../network/protocol/RemoveEntityPacket.php | 2 + .../network/protocol/RemovePlayerPacket.php | 2 + .../network/protocol/RespawnPacket.php | 2 + .../network/protocol/RotateHeadPacket.php | 2 + .../network/protocol/SendInventoryPacket.php | 2 + .../network/protocol/SetEntityDataPacket.php | 2 + .../protocol/SetEntityMotionPacket.php | 2 + .../network/protocol/SetHealthPacket.php | 2 + .../protocol/SetSpawnPositionPacket.php | 2 + .../network/protocol/SetTimePacket.php | 2 + .../network/protocol/StartGamePacket.php | 2 + .../network/protocol/TakeItemEntityPacket.php | 2 + .../network/protocol/TileEventPacket.php | 2 + .../network/protocol/UnknownPacket.php | 2 + .../network/protocol/UnloadChunkPacket.php | 2 + .../network/protocol/UpdateBlockPacket.php | 2 + .../network/protocol/UseItemPacket.php | 2 + src/pocketmine/utils/Binary.php | 56 +++++++++++-------- src/raklib | 2 +- 63 files changed, 163 insertions(+), 35 deletions(-) diff --git a/src/pocketmine/level/conversor/pmf/LevelFormat.php b/src/pocketmine/level/conversor/pmf/LevelFormat.php index a0f1696f0..de1894594 100644 --- a/src/pocketmine/level/conversor/pmf/LevelFormat.php +++ b/src/pocketmine/level/conversor/pmf/LevelFormat.php @@ -126,7 +126,7 @@ class LevelFormat extends PMF{ return false; } - $this->levelData["name"] = $this->read(Binary::readShort($this->read(2), false)); + $this->levelData["name"] = $this->read(Binary::readShort($this->read(2))); $this->levelData["seed"] = Binary::readInt($this->read(4)); $this->levelData["time"] = Binary::readInt($this->read(4)); $this->levelData["spawnX"] = Binary::readFloat($this->read(4)); @@ -140,11 +140,11 @@ class LevelFormat extends PMF{ if($this->levelData["height"] !== 8){ return false; } - $this->levelData["generator"] = $this->read(Binary::readShort($this->read(2), false)); - $this->levelData["generatorSettings"] = unserialize($this->read(Binary::readShort($this->read(2), false))); + $this->levelData["generator"] = $this->read(Binary::readShort($this->read(2))); + $this->levelData["generatorSettings"] = unserialize($this->read(Binary::readShort($this->read(2)))); } - $this->levelData["extra"] = @zlib_decode($this->read(Binary::readShort($this->read(2), false))); + $this->levelData["extra"] = @zlib_decode($this->read(Binary::readShort($this->read(2)))); $upgrade = false; if($this->levelData["version"] === 0){ diff --git a/src/pocketmine/nbt/NBT.php b/src/pocketmine/nbt/NBT.php index 1a76b95ba..3f112564f 100644 --- a/src/pocketmine/nbt/NBT.php +++ b/src/pocketmine/nbt/NBT.php @@ -41,6 +41,8 @@ use pocketmine\nbt\tag\Tag; use pocketmine\utils\Binary; use pocketmine\utils\Utils; +#include + /** * Named Binary Tag encoder/decoder */ @@ -61,7 +63,7 @@ class NBT{ const TAG_Compound = 10; const TAG_IntArray = 11; - private $buffer; + public $buffer; private $offset; public $endianness; private $data; @@ -191,8 +193,8 @@ class NBT{ $tag->write($this); } - public function getByte($signed = false){ - return Binary::readByte($this->get(1), $signed); + public function getByte(){ + return Binary::readByte($this->get(1)); } public function putByte($v){ diff --git a/src/pocketmine/nbt/tag/Byte.php b/src/pocketmine/nbt/tag/Byte.php index 883ff834a..07b72e641 100644 --- a/src/pocketmine/nbt/tag/Byte.php +++ b/src/pocketmine/nbt/tag/Byte.php @@ -23,6 +23,8 @@ namespace pocketmine\nbt\tag; use pocketmine\nbt\NBT; +#include + class Byte extends NamedTag{ public function getType(){ @@ -30,7 +32,7 @@ class Byte extends NamedTag{ } public function read(NBT $nbt){ - $this->value = $nbt->getByte(true); + $this->value = $nbt->getByte(); } public function write(NBT $nbt){ diff --git a/src/pocketmine/nbt/tag/ByteArray.php b/src/pocketmine/nbt/tag/ByteArray.php index 08387696b..5f80e1452 100644 --- a/src/pocketmine/nbt/tag/ByteArray.php +++ b/src/pocketmine/nbt/tag/ByteArray.php @@ -23,6 +23,8 @@ namespace pocketmine\nbt\tag; use pocketmine\nbt\NBT; +#include + class ByteArray extends NamedTag{ public function getType(){ diff --git a/src/pocketmine/nbt/tag/Compound.php b/src/pocketmine/nbt/tag/Compound.php index e68751b1f..959a27491 100644 --- a/src/pocketmine/nbt/tag/Compound.php +++ b/src/pocketmine/nbt/tag/Compound.php @@ -23,6 +23,8 @@ namespace pocketmine\nbt\tag; use pocketmine\nbt\NBT; +#include + class Compound extends NamedTag implements \ArrayAccess{ public function __construct($name = "", $value = []){ diff --git a/src/pocketmine/nbt/tag/Double.php b/src/pocketmine/nbt/tag/Double.php index ecac412cb..45be031c8 100644 --- a/src/pocketmine/nbt/tag/Double.php +++ b/src/pocketmine/nbt/tag/Double.php @@ -23,6 +23,8 @@ namespace pocketmine\nbt\tag; use pocketmine\nbt\NBT; +#include + class Double extends NamedTag{ public function getType(){ diff --git a/src/pocketmine/nbt/tag/Enum.php b/src/pocketmine/nbt/tag/Enum.php index cd5d28586..6b89b1d75 100644 --- a/src/pocketmine/nbt/tag/Enum.php +++ b/src/pocketmine/nbt/tag/Enum.php @@ -24,6 +24,8 @@ namespace pocketmine\nbt\tag; use pocketmine\nbt\NBT; use pocketmine\nbt\tag\Enum as TagEnum; +#include + class Enum extends NamedTag implements \ArrayAccess, \Countable{ private $tagType; diff --git a/src/pocketmine/nbt/tag/Float.php b/src/pocketmine/nbt/tag/Float.php index 5294ff45f..fffebf70e 100644 --- a/src/pocketmine/nbt/tag/Float.php +++ b/src/pocketmine/nbt/tag/Float.php @@ -23,6 +23,8 @@ namespace pocketmine\nbt\tag; use pocketmine\nbt\NBT; +#include + class Float extends NamedTag{ public function getType(){ diff --git a/src/pocketmine/nbt/tag/Int.php b/src/pocketmine/nbt/tag/Int.php index 4f4bf8091..a479faca2 100644 --- a/src/pocketmine/nbt/tag/Int.php +++ b/src/pocketmine/nbt/tag/Int.php @@ -23,6 +23,8 @@ namespace pocketmine\nbt\tag; use pocketmine\nbt\NBT; +#include + class Int extends NamedTag{ public function getType(){ diff --git a/src/pocketmine/nbt/tag/IntArray.php b/src/pocketmine/nbt/tag/IntArray.php index ad39c148b..8eada159d 100644 --- a/src/pocketmine/nbt/tag/IntArray.php +++ b/src/pocketmine/nbt/tag/IntArray.php @@ -23,6 +23,8 @@ namespace pocketmine\nbt\tag; use pocketmine\nbt\NBT; +#include + class IntArray extends NamedTag{ public function getType(){ diff --git a/src/pocketmine/nbt/tag/Long.php b/src/pocketmine/nbt/tag/Long.php index 6e1031663..43d899282 100644 --- a/src/pocketmine/nbt/tag/Long.php +++ b/src/pocketmine/nbt/tag/Long.php @@ -23,6 +23,8 @@ namespace pocketmine\nbt\tag; use pocketmine\nbt\NBT; +#include + class Long extends NamedTag{ public function getType(){ diff --git a/src/pocketmine/nbt/tag/Short.php b/src/pocketmine/nbt/tag/Short.php index 56f79b1b5..f2f1698ad 100644 --- a/src/pocketmine/nbt/tag/Short.php +++ b/src/pocketmine/nbt/tag/Short.php @@ -23,6 +23,8 @@ namespace pocketmine\nbt\tag; use pocketmine\nbt\NBT; +#include + class Short extends NamedTag{ public function getType(){ diff --git a/src/pocketmine/nbt/tag/String.php b/src/pocketmine/nbt/tag/String.php index 2edf10b00..f615b1090 100644 --- a/src/pocketmine/nbt/tag/String.php +++ b/src/pocketmine/nbt/tag/String.php @@ -23,6 +23,8 @@ namespace pocketmine\nbt\tag; use pocketmine\nbt\NBT; +#include + class String extends NamedTag{ public function getType(){ diff --git a/src/pocketmine/network/protocol/AddEntityPacket.php b/src/pocketmine/network/protocol/AddEntityPacket.php index adf2d82ca..a020fc1d0 100644 --- a/src/pocketmine/network/protocol/AddEntityPacket.php +++ b/src/pocketmine/network/protocol/AddEntityPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class AddEntityPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/AddItemEntityPacket.php b/src/pocketmine/network/protocol/AddItemEntityPacket.php index fadf84ee5..c2786ad94 100644 --- a/src/pocketmine/network/protocol/AddItemEntityPacket.php +++ b/src/pocketmine/network/protocol/AddItemEntityPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class AddItemEntityPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/AddMobPacket.php b/src/pocketmine/network/protocol/AddMobPacket.php index e0ce55383..317ac43d5 100644 --- a/src/pocketmine/network/protocol/AddMobPacket.php +++ b/src/pocketmine/network/protocol/AddMobPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + use pocketmine\utils\Binary; class AddMobPacket extends DataPacket{ diff --git a/src/pocketmine/network/protocol/AddPaintingPacket.php b/src/pocketmine/network/protocol/AddPaintingPacket.php index 1cb292ebe..d0272d002 100644 --- a/src/pocketmine/network/protocol/AddPaintingPacket.php +++ b/src/pocketmine/network/protocol/AddPaintingPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class AddPaintingPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/AddPlayerPacket.php b/src/pocketmine/network/protocol/AddPlayerPacket.php index 7137be69a..4b38a62b6 100644 --- a/src/pocketmine/network/protocol/AddPlayerPacket.php +++ b/src/pocketmine/network/protocol/AddPlayerPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + use pocketmine\utils\Binary; class AddPlayerPacket extends DataPacket{ diff --git a/src/pocketmine/network/protocol/AdventureSettingsPacket.php b/src/pocketmine/network/protocol/AdventureSettingsPacket.php index 8c4de6e73..0be53f7c6 100644 --- a/src/pocketmine/network/protocol/AdventureSettingsPacket.php +++ b/src/pocketmine/network/protocol/AdventureSettingsPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class AdventureSettingsPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/AnimatePacket.php b/src/pocketmine/network/protocol/AnimatePacket.php index fa17c317d..6e4eca5db 100644 --- a/src/pocketmine/network/protocol/AnimatePacket.php +++ b/src/pocketmine/network/protocol/AnimatePacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class AnimatePacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/ChatPacket.php b/src/pocketmine/network/protocol/ChatPacket.php index 94f27a922..d1ba748d5 100644 --- a/src/pocketmine/network/protocol/ChatPacket.php +++ b/src/pocketmine/network/protocol/ChatPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class ChatPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/ContainerClosePacket.php b/src/pocketmine/network/protocol/ContainerClosePacket.php index 23859a5fe..fa7f39c57 100644 --- a/src/pocketmine/network/protocol/ContainerClosePacket.php +++ b/src/pocketmine/network/protocol/ContainerClosePacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class ContainerClosePacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/ContainerOpenPacket.php b/src/pocketmine/network/protocol/ContainerOpenPacket.php index b2f78492c..aad724b05 100644 --- a/src/pocketmine/network/protocol/ContainerOpenPacket.php +++ b/src/pocketmine/network/protocol/ContainerOpenPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class ContainerOpenPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/ContainerSetContentPacket.php b/src/pocketmine/network/protocol/ContainerSetContentPacket.php index 713fdf6c3..ca8f438c0 100644 --- a/src/pocketmine/network/protocol/ContainerSetContentPacket.php +++ b/src/pocketmine/network/protocol/ContainerSetContentPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class ContainerSetContentPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/ContainerSetDataPacket.php b/src/pocketmine/network/protocol/ContainerSetDataPacket.php index 9f68827bb..1ef7777c3 100644 --- a/src/pocketmine/network/protocol/ContainerSetDataPacket.php +++ b/src/pocketmine/network/protocol/ContainerSetDataPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class ContainerSetDataPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/ContainerSetSlotPacket.php b/src/pocketmine/network/protocol/ContainerSetSlotPacket.php index dce05fdb6..4998d9fc8 100644 --- a/src/pocketmine/network/protocol/ContainerSetSlotPacket.php +++ b/src/pocketmine/network/protocol/ContainerSetSlotPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + use pocketmine\item\Item; class ContainerSetSlotPacket extends DataPacket{ diff --git a/src/pocketmine/network/protocol/DataPacket.php b/src/pocketmine/network/protocol/DataPacket.php index a42f64c03..c83e259fe 100644 --- a/src/pocketmine/network/protocol/DataPacket.php +++ b/src/pocketmine/network/protocol/DataPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + use pocketmine\item\Item; use pocketmine\utils\Binary; @@ -106,7 +108,7 @@ abstract class DataPacket extends \stdClass{ } protected function getShort($signed = true){ - return Binary::readShort($this->get(2), $signed); + return $signed ? Binary::readSignedShort($this->get(2)) : Binary::readShort($this->get(2)); } protected function putShort($v){ @@ -180,7 +182,7 @@ abstract class DataPacket extends \stdClass{ } protected function getString(){ - return $this->get($this->getShort(false)); + return $this->get($this->getShort()); } protected function putString($v){ diff --git a/src/pocketmine/network/protocol/DropItemPacket.php b/src/pocketmine/network/protocol/DropItemPacket.php index 83f57a1df..908b0094b 100644 --- a/src/pocketmine/network/protocol/DropItemPacket.php +++ b/src/pocketmine/network/protocol/DropItemPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class DropItemPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/EntityDataPacket.php b/src/pocketmine/network/protocol/EntityDataPacket.php index 78ed32963..3b0063821 100644 --- a/src/pocketmine/network/protocol/EntityDataPacket.php +++ b/src/pocketmine/network/protocol/EntityDataPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class EntityDataPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/EntityEventPacket.php b/src/pocketmine/network/protocol/EntityEventPacket.php index 40530f0a5..335612adf 100644 --- a/src/pocketmine/network/protocol/EntityEventPacket.php +++ b/src/pocketmine/network/protocol/EntityEventPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class EntityEventPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/ExplodePacket.php b/src/pocketmine/network/protocol/ExplodePacket.php index f3ff0062c..287cbd957 100644 --- a/src/pocketmine/network/protocol/ExplodePacket.php +++ b/src/pocketmine/network/protocol/ExplodePacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class ExplodePacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/FullChunkDataPacket.php b/src/pocketmine/network/protocol/FullChunkDataPacket.php index e596457a2..bb9ef5baf 100644 --- a/src/pocketmine/network/protocol/FullChunkDataPacket.php +++ b/src/pocketmine/network/protocol/FullChunkDataPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class FullChunkDataPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/HurtArmorPacket.php b/src/pocketmine/network/protocol/HurtArmorPacket.php index e99c40aa3..53b65da40 100644 --- a/src/pocketmine/network/protocol/HurtArmorPacket.php +++ b/src/pocketmine/network/protocol/HurtArmorPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class HurtArmorPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/InteractPacket.php b/src/pocketmine/network/protocol/InteractPacket.php index 679dcaa44..d0b209780 100644 --- a/src/pocketmine/network/protocol/InteractPacket.php +++ b/src/pocketmine/network/protocol/InteractPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class InteractPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/LevelEventPacket.php b/src/pocketmine/network/protocol/LevelEventPacket.php index 912960ba0..cf2f36b5e 100644 --- a/src/pocketmine/network/protocol/LevelEventPacket.php +++ b/src/pocketmine/network/protocol/LevelEventPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class LevelEventPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/LoginPacket.php b/src/pocketmine/network/protocol/LoginPacket.php index ee8b98f4e..43eeef9d4 100644 --- a/src/pocketmine/network/protocol/LoginPacket.php +++ b/src/pocketmine/network/protocol/LoginPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class LoginPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/LoginStatusPacket.php b/src/pocketmine/network/protocol/LoginStatusPacket.php index 6bfb3fb87..e3e92d3e9 100644 --- a/src/pocketmine/network/protocol/LoginStatusPacket.php +++ b/src/pocketmine/network/protocol/LoginStatusPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class LoginStatusPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/MessagePacket.php b/src/pocketmine/network/protocol/MessagePacket.php index da9849028..6704adadb 100644 --- a/src/pocketmine/network/protocol/MessagePacket.php +++ b/src/pocketmine/network/protocol/MessagePacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class MessagePacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/MoveEntityPacket.php b/src/pocketmine/network/protocol/MoveEntityPacket.php index 254a67bb9..cf7adf99e 100644 --- a/src/pocketmine/network/protocol/MoveEntityPacket.php +++ b/src/pocketmine/network/protocol/MoveEntityPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class MoveEntityPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/MovePlayerPacket.php b/src/pocketmine/network/protocol/MovePlayerPacket.php index 08f618ee6..16aa83be0 100644 --- a/src/pocketmine/network/protocol/MovePlayerPacket.php +++ b/src/pocketmine/network/protocol/MovePlayerPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class MovePlayerPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/PlayerActionPacket.php b/src/pocketmine/network/protocol/PlayerActionPacket.php index 7083ac53d..22d76159a 100644 --- a/src/pocketmine/network/protocol/PlayerActionPacket.php +++ b/src/pocketmine/network/protocol/PlayerActionPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class PlayerActionPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/PlayerArmorEquipmentPacket.php b/src/pocketmine/network/protocol/PlayerArmorEquipmentPacket.php index 12b2b5b45..493e74c69 100644 --- a/src/pocketmine/network/protocol/PlayerArmorEquipmentPacket.php +++ b/src/pocketmine/network/protocol/PlayerArmorEquipmentPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class PlayerArmorEquipmentPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/PlayerEquipmentPacket.php b/src/pocketmine/network/protocol/PlayerEquipmentPacket.php index ef49395ce..a2c88f846 100644 --- a/src/pocketmine/network/protocol/PlayerEquipmentPacket.php +++ b/src/pocketmine/network/protocol/PlayerEquipmentPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class PlayerEquipmentPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/RemoveBlockPacket.php b/src/pocketmine/network/protocol/RemoveBlockPacket.php index e38a61d8d..4b9348958 100644 --- a/src/pocketmine/network/protocol/RemoveBlockPacket.php +++ b/src/pocketmine/network/protocol/RemoveBlockPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class RemoveBlockPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/RemoveEntityPacket.php b/src/pocketmine/network/protocol/RemoveEntityPacket.php index a6e0bdd9f..fc414eb4a 100644 --- a/src/pocketmine/network/protocol/RemoveEntityPacket.php +++ b/src/pocketmine/network/protocol/RemoveEntityPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class RemoveEntityPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/RemovePlayerPacket.php b/src/pocketmine/network/protocol/RemovePlayerPacket.php index 1f621244c..bcf539fac 100644 --- a/src/pocketmine/network/protocol/RemovePlayerPacket.php +++ b/src/pocketmine/network/protocol/RemovePlayerPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class RemovePlayerPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/RespawnPacket.php b/src/pocketmine/network/protocol/RespawnPacket.php index 7dd6086ea..9943a86f7 100644 --- a/src/pocketmine/network/protocol/RespawnPacket.php +++ b/src/pocketmine/network/protocol/RespawnPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class RespawnPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/RotateHeadPacket.php b/src/pocketmine/network/protocol/RotateHeadPacket.php index f47d05a5a..0b93a3613 100644 --- a/src/pocketmine/network/protocol/RotateHeadPacket.php +++ b/src/pocketmine/network/protocol/RotateHeadPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class RotateHeadPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/SendInventoryPacket.php b/src/pocketmine/network/protocol/SendInventoryPacket.php index 443a4f6e2..3133af325 100644 --- a/src/pocketmine/network/protocol/SendInventoryPacket.php +++ b/src/pocketmine/network/protocol/SendInventoryPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class SendInventoryPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/SetEntityDataPacket.php b/src/pocketmine/network/protocol/SetEntityDataPacket.php index 3e6091f0b..50bf6abff 100644 --- a/src/pocketmine/network/protocol/SetEntityDataPacket.php +++ b/src/pocketmine/network/protocol/SetEntityDataPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + use pocketmine\utils\Binary; class SetEntityDataPacket extends DataPacket{ diff --git a/src/pocketmine/network/protocol/SetEntityMotionPacket.php b/src/pocketmine/network/protocol/SetEntityMotionPacket.php index 16e76eedd..d73433b98 100644 --- a/src/pocketmine/network/protocol/SetEntityMotionPacket.php +++ b/src/pocketmine/network/protocol/SetEntityMotionPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class SetEntityMotionPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/SetHealthPacket.php b/src/pocketmine/network/protocol/SetHealthPacket.php index 2f9cc81fb..33f2038b3 100644 --- a/src/pocketmine/network/protocol/SetHealthPacket.php +++ b/src/pocketmine/network/protocol/SetHealthPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class SetHealthPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/SetSpawnPositionPacket.php b/src/pocketmine/network/protocol/SetSpawnPositionPacket.php index 785b9b553..371e72a36 100644 --- a/src/pocketmine/network/protocol/SetSpawnPositionPacket.php +++ b/src/pocketmine/network/protocol/SetSpawnPositionPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class SetSpawnPositionPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/SetTimePacket.php b/src/pocketmine/network/protocol/SetTimePacket.php index 670f0e204..d51ab23df 100644 --- a/src/pocketmine/network/protocol/SetTimePacket.php +++ b/src/pocketmine/network/protocol/SetTimePacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + use pocketmine\level\Level; diff --git a/src/pocketmine/network/protocol/StartGamePacket.php b/src/pocketmine/network/protocol/StartGamePacket.php index dcf652b66..459dce4f7 100644 --- a/src/pocketmine/network/protocol/StartGamePacket.php +++ b/src/pocketmine/network/protocol/StartGamePacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class StartGamePacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/TakeItemEntityPacket.php b/src/pocketmine/network/protocol/TakeItemEntityPacket.php index 6dee90837..1e4dddba0 100644 --- a/src/pocketmine/network/protocol/TakeItemEntityPacket.php +++ b/src/pocketmine/network/protocol/TakeItemEntityPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class TakeItemEntityPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/TileEventPacket.php b/src/pocketmine/network/protocol/TileEventPacket.php index 8c461c7a8..2f127c2ff 100644 --- a/src/pocketmine/network/protocol/TileEventPacket.php +++ b/src/pocketmine/network/protocol/TileEventPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class TileEventPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/UnknownPacket.php b/src/pocketmine/network/protocol/UnknownPacket.php index 93ac17343..9cdae867a 100644 --- a/src/pocketmine/network/protocol/UnknownPacket.php +++ b/src/pocketmine/network/protocol/UnknownPacket.php @@ -22,6 +22,8 @@ namespace pocketmine\network\protocol; +#include + class UnknownPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/UnloadChunkPacket.php b/src/pocketmine/network/protocol/UnloadChunkPacket.php index 1a4ee0c3b..9d78f6d0c 100644 --- a/src/pocketmine/network/protocol/UnloadChunkPacket.php +++ b/src/pocketmine/network/protocol/UnloadChunkPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class UnloadChunkPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/UpdateBlockPacket.php b/src/pocketmine/network/protocol/UpdateBlockPacket.php index f4aeb81bf..68d6743aa 100644 --- a/src/pocketmine/network/protocol/UpdateBlockPacket.php +++ b/src/pocketmine/network/protocol/UpdateBlockPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class UpdateBlockPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/UseItemPacket.php b/src/pocketmine/network/protocol/UseItemPacket.php index d198d9e4e..7392fbf68 100644 --- a/src/pocketmine/network/protocol/UseItemPacket.php +++ b/src/pocketmine/network/protocol/UseItemPacket.php @@ -21,6 +21,8 @@ namespace pocketmine\network\protocol; +#include + class UseItemPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/utils/Binary.php b/src/pocketmine/utils/Binary.php index 528d614df..6d9eb49e6 100644 --- a/src/pocketmine/utils/Binary.php +++ b/src/pocketmine/utils/Binary.php @@ -228,24 +228,28 @@ class Binary{ } /** - * Reads a 16-bit signed/unsigned big-endian number + * Reads a 16-bit unsigned big-endian number * - * @param $str - * @param bool $signed + * @param $str * * @return int */ - public static function readShort($str, $signed = true){ - $unpacked = unpack("n", $str)[1]; + public static function readShort($str){ + return unpack("n", $str)[1]; + } - if($signed){ - if(PHP_INT_SIZE === 8){ - return $unpacked << 48 >> 48; - }else{ - return $unpacked << 16 >> 16; - } + /** + * Reads a 16-bit signed big-endian number + * + * @param $str + * + * @return int + */ + public static function readSignedShort($str){ + if(PHP_INT_SIZE === 8){ + return unpack("n", $str)[1] << 48 >> 48; }else{ - return $unpacked; + return unpack("n", $str)[1] << 16 >> 16; } } @@ -261,24 +265,28 @@ class Binary{ } /** - * Reads a 16-bit signed/unsigned little-endian number + * Reads a 16-bit unsigned little-endian number * * @param $str - * @param bool $signed * * @return int */ - public static function readLShort($str, $signed = true){ - $unpacked = unpack("v", $str)[1]; + public static function readLShort($str){ + return unpack("v", $str)[1]; + } - if($signed){ - if(PHP_INT_SIZE === 8){ - return $unpacked << 48 >> 48; - }else{ - return $unpacked << 16 >> 16; - } + /** + * Reads a 16-bit signed little-endian number + * + * @param $str + * + * @return int + */ + public static function readSignedLShort($str){ + if(PHP_INT_SIZE === 8){ + return unpack("v", $str)[1] << 48 >> 48; }else{ - return $unpacked; + return unpack("v", $str)[1] << 16 >> 16; } } @@ -361,7 +369,7 @@ class Binary{ $value = "0"; for($i = 0; $i < 8; $i += 2){ $value = bcmul($value, "65536", 0); - $value = bcadd($value, self::readShort(substr($x, $i, 2), false), 0); + $value = bcadd($value, self::readShort(substr($x, $i, 2)), 0); } if(bccomp($value, "9223372036854775807") == 1){ diff --git a/src/raklib b/src/raklib index a15d851da..1eba22678 160000 --- a/src/raklib +++ b/src/raklib @@ -1 +1 @@ -Subproject commit a15d851daa87698499a1485e37e76422cfb3f0c4 +Subproject commit 1eba2267876ba8e9a00380f2ae9e05dff9eb0ec8 From 6e8e2a79ddde71df4ab43b76c5353a9557672b21 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 30 Oct 2014 14:52:11 +0100 Subject: [PATCH 49/61] Fixed Event name being null --- src/pocketmine/event/Event.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/event/Event.php b/src/pocketmine/event/Event.php index e58950086..1a5bf2198 100644 --- a/src/pocketmine/event/Event.php +++ b/src/pocketmine/event/Event.php @@ -50,7 +50,7 @@ abstract class Event{ * @return string */ final public function getEventName(){ - return $this->eventName != null ? get_class($this) : $this->eventName; + return $this->eventName === null ? get_class($this) : $this->eventName; } /** From 57d1847c505b72cc26af973519f4ea967d885217 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 30 Oct 2014 16:02:48 +0100 Subject: [PATCH 50/61] Updated to receive new optimizations --- .../command/defaults/SetWorldSpawnCommand.php | 3 +- src/pocketmine/entity/Entity.php | 6 +- src/pocketmine/entity/FallingSand.php | 6 +- src/pocketmine/level/Explosion.php | 3 +- src/pocketmine/level/Level.php | 1 + src/pocketmine/math/Vector3.php | 100 +++++++++--------- src/pocketmine/utils/BlockIterator.php | 3 +- 7 files changed, 65 insertions(+), 57 deletions(-) diff --git a/src/pocketmine/command/defaults/SetWorldSpawnCommand.php b/src/pocketmine/command/defaults/SetWorldSpawnCommand.php index d65b45fbe..462735857 100644 --- a/src/pocketmine/command/defaults/SetWorldSpawnCommand.php +++ b/src/pocketmine/command/defaults/SetWorldSpawnCommand.php @@ -46,7 +46,8 @@ class SetWorldSpawnCommand extends VanillaCommand{ if(count($args) === 0){ if($sender instanceof Player){ $level = $sender->getLevel(); - $pos = Vector3::cloneVector($sender)->round(); + $pos = Vector3::cloneVector($sender); + $pos = $pos->round(); }else{ $sender->sendMessage(TextFormat::RED . "You can only perform this command as a player"); diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 92dbcd320..68df97f32 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -776,7 +776,8 @@ abstract class Entity extends Location implements Metadatable{ } public function isInsideOfWater(){ - $block = $this->level->getBlock(Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z)->floor()); + $pos = Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z); + $block = $this->level->getBlock($pos->floor()); if($block instanceof Water){ $f = ($block->y + 1) - ($block->getFluidHeightPercent() - 0.1111111); @@ -787,7 +788,8 @@ abstract class Entity extends Location implements Metadatable{ } public function isInsideOfSolid(){ - $block = $this->level->getBlock(Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z)->floor()); + $pos = Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z); + $block = $this->level->getBlock($pos->floor()); $bb = $block->getBoundingBox(); diff --git a/src/pocketmine/entity/FallingSand.php b/src/pocketmine/entity/FallingSand.php index b73464793..857339816 100644 --- a/src/pocketmine/entity/FallingSand.php +++ b/src/pocketmine/entity/FallingSand.php @@ -90,7 +90,8 @@ class FallingSand extends Entity{ if(!$this->dead){ if($this->ticksLived === 1){ - $block = $this->level->getBlock($pos = Vector3::cloneVector($this)->floor()); + $pos = Vector3::cloneVector($this); + $block = $this->level->getBlock($pos->floor()); if($block->getID() != $this->blockId){ $this->kill(); return true; @@ -109,7 +110,8 @@ class FallingSand extends Entity{ $this->motionY *= 1 - $this->drag; $this->motionZ *= $friction; - $pos = Vector3::cloneVector($this)->floor(); + $pos = Vector3::cloneVector($this); + $pos = $pos->floor(); if($this->onGround){ $this->kill(); diff --git a/src/pocketmine/level/Explosion.php b/src/pocketmine/level/Explosion.php index 3a5632a28..f3a34c923 100644 --- a/src/pocketmine/level/Explosion.php +++ b/src/pocketmine/level/Explosion.php @@ -130,7 +130,8 @@ class Explosion{ public function explodeB(){ $send = []; - $source = Vector3::cloneVector($this->source)->floor(); + $source = Vector3::cloneVector($this->source); + $source = $source->floor(); $yield = (1 / $this->size) * 100; if($this->what instanceof Entity){ diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index ac85f4652..576266bad 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -95,6 +95,7 @@ use pocketmine\utils\LevelException; use pocketmine\utils\ReversePriorityQueue; use pocketmine\utils\TextFormat; +#include class Level implements ChunkManager, Metadatable{ diff --git a/src/pocketmine/math/Vector3.php b/src/pocketmine/math/Vector3.php index 3384c5bc5..b79091930 100644 --- a/src/pocketmine/math/Vector3.php +++ b/src/pocketmine/math/Vector3.php @@ -24,8 +24,8 @@ namespace pocketmine\math; class Vector3{ /** @var Vector3[] */ - private static $vectorList = []; - private static $nextVector = 0; + public static $vectorList = []; + public static $nextVector = 0; const SIDE_DOWN = 0; const SIDE_UP = 1; @@ -45,15 +45,15 @@ class Vector3{ } public static function clearVectors(){ - self::$nextVector = 0; - self::$vectorList = []; + Vector3::$nextVector = 0; + Vector3::$vectorList = []; } public static function clearVectorList(){ - if(self::$nextVector > 65536){ - self::clearVectors(); + if(Vector3::$nextVector > 65536){ + Vector3::clearVectors(); }else{ - self::$nextVector = 0; + Vector3::$nextVector = 0; } } @@ -65,11 +65,11 @@ class Vector3{ * @return Vector3 */ public static function createVector($x, $y, $z){ - if(self::$nextVector >= count(self::$vectorList)){ - self::$vectorList[] = new Vector3(0, 0, 0); + if(Vector3::$nextVector >= count(Vector3::$vectorList)){ + Vector3::$vectorList[] = new Vector3(0, 0, 0); } - return self::$vectorList[self::$nextVector++]->setComponents($x, $y, $z); + return Vector3::$vectorList[Vector3::$nextVector++]->setComponents($x, $y, $z); } /** @@ -78,11 +78,11 @@ class Vector3{ * @return Vector3 */ public static function cloneVector(Vector3 $vector){ - if(self::$nextVector >= count(self::$vectorList)){ - self::$vectorList[] = new Vector3(0, 0, 0); + if(Vector3::$nextVector >= count(Vector3::$vectorList)){ + Vector3::$vectorList[] = new Vector3(0, 0, 0); } - return self::$vectorList[self::$nextVector++]->setComponents($vector->x, $vector->y, $vector->z); + return Vector3::$vectorList[Vector3::$nextVector++]->setComponents($vector->x, $vector->y, $vector->z); } public function getX(){ @@ -138,9 +138,9 @@ class Vector3{ */ public function add($x, $y = 0, $z = 0){ if($x instanceof Vector3){ - return self::createVector($this->x + $x->x, $this->y + $x->y, $this->z + $x->z); + return Vector3::createVector($this->x + $x->x, $this->y + $x->y, $this->z + $x->z); }else{ - return self::createVector($this->x + $x, $this->y + $y, $this->z + $z); + return Vector3::createVector($this->x + $x, $this->y + $y, $this->z + $z); } } @@ -160,46 +160,46 @@ class Vector3{ } public function multiply($number){ - return self::createVector($this->x * $number, $this->y * $number, $this->z * $number); + return Vector3::createVector($this->x * $number, $this->y * $number, $this->z * $number); } public function divide($number){ - return self::createVector($this->x / $number, $this->y / $number, $this->z / $number); + return Vector3::createVector($this->x / $number, $this->y / $number, $this->z / $number); } public function ceil(){ - return self::createVector((int) ($this->x + 1), (int) ($this->y + 1), (int) ($this->z + 1)); + return Vector3::createVector((int) ($this->x + 1), (int) ($this->y + 1), (int) ($this->z + 1)); } public function floor(){ $x = (int) $this->x; $y = (int) $this->y; $z = (int) $this->z; - return new Vector3($this->x >= $x ? $x : $x - 1, $this->y >= $y ? $y : $y - 1, $this->z >= $z ? $z : $z - 1); + return Vector3::createVector($this->x >= $x ? $x : $x - 1, $this->y >= $y ? $y : $y - 1, $this->z >= $z ? $z : $z - 1); } public function round(){ - return new Vector3(round($this->x), round($this->y), round($this->z)); + return Vector3::createVector(round($this->x), round($this->y), round($this->z)); } public function abs(){ - return new Vector3(abs($this->x), abs($this->y), abs($this->z)); + return Vector3::createVector(abs($this->x), abs($this->y), abs($this->z)); } public function getSide($side, $step = 1){ switch((int) $side){ - case self::SIDE_DOWN: - return self::createVector($this->x, $this->y - $step, $this->z); - case self::SIDE_UP: - return self::createVector($this->x, $this->y + $step, $this->z); - case self::SIDE_NORTH: - return self::createVector($this->x, $this->y, $this->z - $step); - case self::SIDE_SOUTH: - return self::createVector($this->x, $this->y, $this->z + $step); - case self::SIDE_WEST: - return self::createVector($this->x - $step, $this->y, $this->z); - case self::SIDE_EAST: - return self::createVector($this->x + $step, $this->y, $this->z); + case Vector3::SIDE_DOWN: + return Vector3::createVector($this->x, $this->y - $step, $this->z); + case Vector3::SIDE_UP: + return Vector3::createVector($this->x, $this->y + $step, $this->z); + case Vector3::SIDE_NORTH: + return Vector3::createVector($this->x, $this->y, $this->z - $step); + case Vector3::SIDE_SOUTH: + return Vector3::createVector($this->x, $this->y, $this->z + $step); + case Vector3::SIDE_WEST: + return Vector3::createVector($this->x - $step, $this->y, $this->z); + case Vector3::SIDE_EAST: + return Vector3::createVector($this->x + $step, $this->y, $this->z); default: return $this; } @@ -207,18 +207,18 @@ class Vector3{ public static function getOppositeSide($side){ switch((int) $side){ - case self::SIDE_DOWN: - return self::SIDE_UP; - case self::SIDE_UP: - return self::SIDE_DOWN; - case self::SIDE_NORTH: - return self::SIDE_SOUTH; - case self::SIDE_SOUTH: - return self::SIDE_NORTH; - case self::SIDE_WEST: - return self::SIDE_EAST; - case self::SIDE_EAST: - return self::SIDE_WEST; + case Vector3::SIDE_DOWN: + return Vector3::SIDE_UP; + case Vector3::SIDE_UP: + return Vector3::SIDE_DOWN; + case Vector3::SIDE_NORTH: + return Vector3::SIDE_SOUTH; + case Vector3::SIDE_SOUTH: + return Vector3::SIDE_NORTH; + case Vector3::SIDE_WEST: + return Vector3::SIDE_EAST; + case Vector3::SIDE_EAST: + return Vector3::SIDE_WEST; default: return -1; } @@ -259,7 +259,7 @@ class Vector3{ return $this->divide($len); } - return self::createVector(0, 0, 0); + return Vector3::createVector(0, 0, 0); } public function dot(Vector3 $v){ @@ -267,7 +267,7 @@ class Vector3{ } public function cross(Vector3 $v){ - return self::createVector( + return Vector3::createVector( $this->y * $v->z - $this->z * $v->y, $this->z * $v->x - $this->x * $v->z, $this->x * $v->y - $this->y * $v->x @@ -297,7 +297,7 @@ class Vector3{ if($f < 0 or $f > 1){ return null; }else{ - return self::createVector($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f); + return Vector3::createVector($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f); } } @@ -324,7 +324,7 @@ class Vector3{ if($f < 0 or $f > 1){ return null; }else{ - return self::createVector($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f); + return Vector3::createVector($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f); } } @@ -351,7 +351,7 @@ class Vector3{ if($f < 0 or $f > 1){ return null; }else{ - return self::createVector($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f); + return Vector3::createVector($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f); } } diff --git a/src/pocketmine/utils/BlockIterator.php b/src/pocketmine/utils/BlockIterator.php index aec0705ce..402e40a48 100644 --- a/src/pocketmine/utils/BlockIterator.php +++ b/src/pocketmine/utils/BlockIterator.php @@ -71,7 +71,8 @@ class BlockIterator implements \Iterator{ $secondPosition = 0; $thirdPosition = 0; - $startBlock = $this->level->getBlock(Vector3::createVector($startClone->x, $startClone->y, $startClone->z)->floor()); + $pos = Vector3::createVector($startClone->x, $startClone->y, $startClone->z); + $startBlock = $this->level->getBlock($pos->floor()); if($this->getXLength($direction) > $mainDirection){ $this->mainFace = $this->getXFace($direction); From 09a01be7094ccfbfb52b53e40ba230f48d0bfc32 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 30 Oct 2014 16:32:57 +0100 Subject: [PATCH 51/61] Added ifndef for NBT Binary --- src/pocketmine/nbt/NBT.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/nbt/NBT.php b/src/pocketmine/nbt/NBT.php index 3f112564f..3f77c81a7 100644 --- a/src/pocketmine/nbt/NBT.php +++ b/src/pocketmine/nbt/NBT.php @@ -38,9 +38,13 @@ use pocketmine\nbt\tag\NamedTAG; use pocketmine\nbt\tag\Short; use pocketmine\nbt\tag\String; use pocketmine\nbt\tag\Tag; -use pocketmine\utils\Binary; use pocketmine\utils\Utils; +#ifndef COMPILE +use pocketmine\utils\Binary; +#endif + + #include /** From 9a65279c6a0ad32d2de0a2d5f6c3b172b483a536 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 30 Oct 2014 16:41:11 +0100 Subject: [PATCH 52/61] Added ifndef for packets Binary --- src/pocketmine/network/protocol/AddMobPacket.php | 2 ++ src/pocketmine/network/protocol/AddPlayerPacket.php | 2 ++ src/pocketmine/network/protocol/DataPacket.php | 2 ++ src/pocketmine/network/protocol/SetEntityDataPacket.php | 2 ++ 4 files changed, 8 insertions(+) diff --git a/src/pocketmine/network/protocol/AddMobPacket.php b/src/pocketmine/network/protocol/AddMobPacket.php index 317ac43d5..2f1d054a8 100644 --- a/src/pocketmine/network/protocol/AddMobPacket.php +++ b/src/pocketmine/network/protocol/AddMobPacket.php @@ -23,7 +23,9 @@ namespace pocketmine\network\protocol; #include +#ifndef COMPILE use pocketmine\utils\Binary; +#endif class AddMobPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/AddPlayerPacket.php b/src/pocketmine/network/protocol/AddPlayerPacket.php index 4b38a62b6..17c0f252e 100644 --- a/src/pocketmine/network/protocol/AddPlayerPacket.php +++ b/src/pocketmine/network/protocol/AddPlayerPacket.php @@ -23,7 +23,9 @@ namespace pocketmine\network\protocol; #include +#ifndef COMPILE use pocketmine\utils\Binary; +#endif class AddPlayerPacket extends DataPacket{ public static $pool = []; diff --git a/src/pocketmine/network/protocol/DataPacket.php b/src/pocketmine/network/protocol/DataPacket.php index c83e259fe..fc175c28d 100644 --- a/src/pocketmine/network/protocol/DataPacket.php +++ b/src/pocketmine/network/protocol/DataPacket.php @@ -24,7 +24,9 @@ namespace pocketmine\network\protocol; #include use pocketmine\item\Item; +#ifndef COMPILE use pocketmine\utils\Binary; +#endif abstract class DataPacket extends \stdClass{ diff --git a/src/pocketmine/network/protocol/SetEntityDataPacket.php b/src/pocketmine/network/protocol/SetEntityDataPacket.php index 50bf6abff..a3239816c 100644 --- a/src/pocketmine/network/protocol/SetEntityDataPacket.php +++ b/src/pocketmine/network/protocol/SetEntityDataPacket.php @@ -23,7 +23,9 @@ namespace pocketmine\network\protocol; #include +#ifndef COMPILE use pocketmine\utils\Binary; +#endif class SetEntityDataPacket extends DataPacket{ public static $pool = []; From 6a4259bf241beb306beaaa1f0c88175c04bec831 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 30 Oct 2014 17:04:19 +0100 Subject: [PATCH 53/61] Updated RakLib --- src/raklib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/raklib b/src/raklib index 1eba22678..3281abd57 160000 --- a/src/raklib +++ b/src/raklib @@ -1 +1 @@ -Subproject commit 1eba2267876ba8e9a00380f2ae9e05dff9eb0ec8 +Subproject commit 3281abd57aa15333ae78d8976bc2835b44574fcb From fd46c7112077964b88795fb7a2d3b36d7050a1bc Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 30 Oct 2014 17:18:43 +0100 Subject: [PATCH 54/61] Updated RakLib --- src/raklib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/raklib b/src/raklib index 3281abd57..b8b6bec56 160000 --- a/src/raklib +++ b/src/raklib @@ -1 +1 @@ -Subproject commit 3281abd57aa15333ae78d8976bc2835b44574fcb +Subproject commit b8b6bec561768816a2f4acff07c2ccceda3d123a From 92eb5cb0b8e133c249449834eb64dbafa4fc029d Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 30 Oct 2014 17:56:58 +0100 Subject: [PATCH 55/61] Added LE Triad methods --- src/pocketmine/utils/Binary.php | 22 ++++++++++++++++++++++ src/raklib | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/utils/Binary.php b/src/pocketmine/utils/Binary.php index 6d9eb49e6..e18ba5f17 100644 --- a/src/pocketmine/utils/Binary.php +++ b/src/pocketmine/utils/Binary.php @@ -55,6 +55,28 @@ class Binary{ return substr(pack("N", $value), 1); } + /** + * Reads a 3-byte little-endian number + * + * @param $str + * + * @return mixed + */ + public static function readLTriad($str){ + return unpack("V", $str . "\x00")[1]; + } + + /** + * Writes a 3-byte little-endian number + * + * @param $value + * + * @return string + */ + public static function writeLTriad($value){ + return substr(pack("N", $value), 0, -1); + } + /** * Writes a coded metadata string * TODO: Replace and move this to entity diff --git a/src/raklib b/src/raklib index b8b6bec56..a0e5de5b8 160000 --- a/src/raklib +++ b/src/raklib @@ -1 +1 @@ -Subproject commit b8b6bec561768816a2f4acff07c2ccceda3d123a +Subproject commit a0e5de5b8e2198d4f7e0329fcf60650252a1e91d From 2424c8a76ccef3cc16ea457f253f90cdee5f4b83 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 30 Oct 2014 19:44:05 +0100 Subject: [PATCH 56/61] Update RakLib, possible fix for notifyACK --- src/pocketmine/network/RakLibInterface.php | 2 ++ src/raklib | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/network/RakLibInterface.php b/src/pocketmine/network/RakLibInterface.php index c01c50a7f..8950733ef 100644 --- a/src/pocketmine/network/RakLibInterface.php +++ b/src/pocketmine/network/RakLibInterface.php @@ -230,6 +230,8 @@ class RakLibInterface implements ServerInstance, SourceInterface{ $pk->reliability = 2; if($needACK === true){ $pk->identifierACK = $this->identifiersACK[$identifier]++; + }else{ + $pk->identifierACK = null; } $this->interface->sendEncapsulated($identifier, $pk, ($needACK === true ? RakLib::FLAG_NEED_ACK : 0) | ($immediate === true ? RakLib::PRIORITY_IMMEDIATE : RakLib::PRIORITY_NORMAL)); diff --git a/src/raklib b/src/raklib index a0e5de5b8..fd94d78ea 160000 --- a/src/raklib +++ b/src/raklib @@ -1 +1 @@ -Subproject commit a0e5de5b8e2198d4f7e0329fcf60650252a1e91d +Subproject commit fd94d78ea1fbd1395fc79779b7805bdf1784ba12 From 673b867ee8d4b71c5f3494151b4aefe7ae933623 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 30 Oct 2014 20:05:40 +0100 Subject: [PATCH 57/61] Fixed players not loading chunks when stuck on a unloaded chunk --- src/pocketmine/Player.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 539edb762..29d3ab302 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1070,6 +1070,9 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $chunk = $this->level->getChunk($this->newPosition->x >> 4, $this->newPosition->z >> 4); if(!($chunk instanceof FullChunk) or !$chunk->isGenerated()){ $revert = true; + $this->nextChunkOrderRun = 0; + }else{ + $this->chunk = $chunk; } } } @@ -2587,6 +2590,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->airTicks = 300; $this->fallDistance = 0; $this->orderChunks(); + $this->nextChunkOrderRun = 0; $this->forceMovement = $pos; $this->newPosition = $pos; From 7ab3c57b0039f26a874bc726da3a89a3865c8a2b Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 30 Oct 2014 22:06:07 +0100 Subject: [PATCH 58/61] Optimized networking code & AxisAlignedBB --- src/pocketmine/Player.php | 4 +- src/pocketmine/block/Fence.php | 2 +- src/pocketmine/entity/Entity.php | 6 +-- src/pocketmine/math/AxisAlignedBB.php | 12 ++--- .../network/protocol/DataPacket.php | 44 ++++++++++++++++++- src/pocketmine/utils/Binary.php | 2 +- 6 files changed, 55 insertions(+), 15 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 29d3ab302..968b39182 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -748,7 +748,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ if($this->connected === false){ return false; } - $this->server->getPluginManager()->callEvent($ev = DataPacketSendEvent::createEvent($this, $packet)); + $this->server->getPluginManager()->callEvent($ev = $packet->getSendEvent($this)); if($ev->isCancelled()){ return false; } @@ -1288,7 +1288,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ return; } - $this->server->getPluginManager()->callEvent($ev = DataPacketReceiveEvent::createEvent($this, $packet)); + $this->server->getPluginManager()->callEvent($ev = $packet->getReceiveEvent($this)); if($ev->isCancelled()){ return; } diff --git a/src/pocketmine/block/Fence.php b/src/pocketmine/block/Fence.php index a9abe1551..a3575d44c 100644 --- a/src/pocketmine/block/Fence.php +++ b/src/pocketmine/block/Fence.php @@ -48,7 +48,7 @@ class Fence extends Transparent{ $this->y, $this->z + $f2, $this->x + $f1, - $this->y + 1, //TODO: check this, add extra bounding box + $this->y + 1, $this->z + $f3 ); } diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 68df97f32..645ec0c33 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -776,8 +776,7 @@ abstract class Entity extends Location implements Metadatable{ } public function isInsideOfWater(){ - $pos = Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z); - $block = $this->level->getBlock($pos->floor()); + $block = $this->level->getBlock(Vector3::createVector(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z))); if($block instanceof Water){ $f = ($block->y + 1) - ($block->getFluidHeightPercent() - 0.1111111); @@ -788,8 +787,7 @@ abstract class Entity extends Location implements Metadatable{ } public function isInsideOfSolid(){ - $pos = Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z); - $block = $this->level->getBlock($pos->floor()); + $block = $this->level->getBlock(Vector3::createVector(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z))); $bb = $block->getBoundingBox(); diff --git a/src/pocketmine/math/AxisAlignedBB.php b/src/pocketmine/math/AxisAlignedBB.php index c871036b2..b3ba52801 100644 --- a/src/pocketmine/math/AxisAlignedBB.php +++ b/src/pocketmine/math/AxisAlignedBB.php @@ -26,8 +26,8 @@ class AxisAlignedBB{ /** @var AxisAlignedBB[] */ - private static $boundingBoxes = []; - private static $nextBoundingBox = 0; + public static $boundingBoxes = []; + public static $nextBoundingBox = 0; public $minX; public $minY; @@ -126,11 +126,11 @@ class AxisAlignedBB{ $maxZ += $z; } - return self::getBoundingBoxFromPool($minX, $minY, $minZ, $maxX, $maxY, $maxZ); + return AxisAlignedBB::getBoundingBoxFromPool($minX, $minY, $minZ, $maxX, $maxY, $maxZ); } public function grow($x, $y, $z){ - return self::getBoundingBoxFromPool($this->minX - $x, $this->minY - $y, $this->minZ - $z, $this->maxX + $x, $this->maxY + $y, $this->maxZ + $z); + return AxisAlignedBB::getBoundingBoxFromPool($this->minX - $x, $this->minY - $y, $this->minZ - $z, $this->maxX + $x, $this->maxY + $y, $this->maxZ + $z); } public function expand($x, $y, $z){ @@ -156,7 +156,7 @@ class AxisAlignedBB{ } public function shrink($x, $y, $z){ - return self::getBoundingBoxFromPool($this->minX + $x, $this->minY + $y, $this->minZ + $z, $this->maxX - $x, $this->maxY - $y, $this->maxZ - $z); + return AxisAlignedBB::getBoundingBoxFromPool($this->minX + $x, $this->minY + $y, $this->minZ + $z, $this->maxX - $x, $this->maxY - $y, $this->maxZ - $z); } public function contract($x, $y, $z){ @@ -181,7 +181,7 @@ class AxisAlignedBB{ } public function getOffsetBoundingBox($x, $y, $z){ - return self::getBoundingBoxFromPool($this->minX + $x, $this->minY + $y, $this->minZ + $z, $this->maxX + $x, $this->maxY + $y, $this->maxZ + $z); + return AxisAlignedBB::getBoundingBoxFromPool($this->minX + $x, $this->minY + $y, $this->minZ + $z, $this->maxX + $x, $this->maxY + $y, $this->maxZ + $z); } public function calculateXOffset(AxisAlignedBB $bb, $x){ diff --git a/src/pocketmine/network/protocol/DataPacket.php b/src/pocketmine/network/protocol/DataPacket.php index fc175c28d..c99377a45 100644 --- a/src/pocketmine/network/protocol/DataPacket.php +++ b/src/pocketmine/network/protocol/DataPacket.php @@ -23,17 +23,27 @@ namespace pocketmine\network\protocol; #include -use pocketmine\item\Item; #ifndef COMPILE use pocketmine\utils\Binary; #endif +use pocketmine\event\server\DataPacketSendEvent; +use pocketmine\event\server\DataPacketReceiveEvent; +use pocketmine\item\Item; +use pocketmine\Player; + + abstract class DataPacket extends \stdClass{ /** @var DataPacket[] */ public static $pool = []; public static $next = 0; + /** @var DataPacketSendEvent */ + private $sendEvent = null; + /** @var DataPacketReceiveEvent */ + private $receiveEvent = null; + public static function getFromPool(){ if(static::$next >= count(static::$pool)){ static::$pool[] = new static; @@ -48,6 +58,38 @@ abstract class DataPacket extends \stdClass{ static::$next = 0; } + /** + * @param Player $player + * + * @return DataPacketReceiveEvent + */ + public function getReceiveEvent(Player $player){ + if($this->receiveEvent === null){ + $this->receiveEvent = new DataPacketReceiveEvent($player, $this); + }else{ + $this->receiveEvent->setCancelled(false); + $this->receiveEvent->__construct($player, $this); + } + + return $this->receiveEvent; + } + + /** + * @param Player $player + * + * @return DataPacketSendEvent + */ + public function getSendEvent(Player $player){ + if($this->sendEvent === null){ + $this->sendEvent = new DataPacketSendEvent($player, $this); + }else{ + $this->sendEvent->setCancelled(false); + $this->sendEvent->__construct($player, $this); + } + + return $this->sendEvent; + } + private $offset = 0; public $buffer = ""; public $isEncoded = false; diff --git a/src/pocketmine/utils/Binary.php b/src/pocketmine/utils/Binary.php index e18ba5f17..395dca2b0 100644 --- a/src/pocketmine/utils/Binary.php +++ b/src/pocketmine/utils/Binary.php @@ -74,7 +74,7 @@ class Binary{ * @return string */ public static function writeLTriad($value){ - return substr(pack("N", $value), 0, -1); + return substr(pack("V", $value), 0, -1); } /** From f66944368db7e07938b60c0fdfe3a906066c5991 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 30 Oct 2014 22:06:23 +0100 Subject: [PATCH 59/61] Update RakLib --- src/raklib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/raklib b/src/raklib index fd94d78ea..9d4f0ea7c 160000 --- a/src/raklib +++ b/src/raklib @@ -1 +1 @@ -Subproject commit fd94d78ea1fbd1395fc79779b7805bdf1784ba12 +Subproject commit 9d4f0ea7c58e34883fb8a6057894e2b4920fd7d3 From 8f0527832f70a764868984985abd9b03ac582639 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 30 Oct 2014 22:15:19 +0100 Subject: [PATCH 60/61] Removed extra AxisAlignedBB generation on Door and Trapdoor --- src/pocketmine/block/Door.php | 24 ++++++++++++------------ src/pocketmine/block/Trapdoor.php | 10 ++++------ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/pocketmine/block/Door.php b/src/pocketmine/block/Door.php index 674ce94e0..4c7c1e02c 100644 --- a/src/pocketmine/block/Door.php +++ b/src/pocketmine/block/Door.php @@ -73,7 +73,7 @@ abstract class Door extends Transparent{ if($j === 0){ if($flag){ if(!$flag1){ - $bb = AxisAlignedBB::getBoundingBoxFromPool( + $bb->setBounds( $this->x, $this->y, $this->z, @@ -82,7 +82,7 @@ abstract class Door extends Transparent{ $this->z + $f ); }else{ - $bb = AxisAlignedBB::getBoundingBoxFromPool( + $bb->setBounds( $this->x, $this->y, $this->z + 1 - $f, @@ -92,7 +92,7 @@ abstract class Door extends Transparent{ ); } }else{ - $bb = AxisAlignedBB::getBoundingBoxFromPool( + $bb->setBounds( $this->x, $this->y, $this->z, @@ -104,7 +104,7 @@ abstract class Door extends Transparent{ }elseif($j === 1){ if($flag){ if(!$flag1){ - $bb = AxisAlignedBB::getBoundingBoxFromPool( + $bb->setBounds( $this->x + 1 - $f, $this->y, $this->z, @@ -113,7 +113,7 @@ abstract class Door extends Transparent{ $this->z + 1 ); }else{ - $bb = AxisAlignedBB::getBoundingBoxFromPool( + $bb->setBounds( $this->x, $this->y, $this->z, @@ -123,7 +123,7 @@ abstract class Door extends Transparent{ ); } }else{ - $bb = AxisAlignedBB::getBoundingBoxFromPool( + $bb->setBounds( $this->x, $this->y, $this->z, @@ -135,7 +135,7 @@ abstract class Door extends Transparent{ }elseif($j === 2){ if($flag){ if(!$flag1){ - $bb = AxisAlignedBB::getBoundingBoxFromPool( + $bb->setBounds( $this->x, $this->y, $this->z + 1 - $f, @@ -144,7 +144,7 @@ abstract class Door extends Transparent{ $this->z + 1 ); }else{ - $bb = AxisAlignedBB::getBoundingBoxFromPool( + $bb->setBounds( $this->x, $this->y, $this->z, @@ -154,7 +154,7 @@ abstract class Door extends Transparent{ ); } }else{ - $bb = AxisAlignedBB::getBoundingBoxFromPool( + $bb->setBounds( $this->x + 1 - $f, $this->y, $this->z, @@ -166,7 +166,7 @@ abstract class Door extends Transparent{ }elseif($j === 3){ if($flag){ if(!$flag1){ - $bb = AxisAlignedBB::getBoundingBoxFromPool( + $bb->setBounds( $this->x, $this->y, $this->z, @@ -175,7 +175,7 @@ abstract class Door extends Transparent{ $this->z + 1 ); }else{ - $bb = AxisAlignedBB::getBoundingBoxFromPool( + $bb->setBounds( $this->x + 1 - $f, $this->y, $this->z, @@ -185,7 +185,7 @@ abstract class Door extends Transparent{ ); } }else{ - $bb = AxisAlignedBB::getBoundingBoxFromPool( + $bb->setBounds( $this->x, $this->y, $this->z + 1 - $f, diff --git a/src/pocketmine/block/Trapdoor.php b/src/pocketmine/block/Trapdoor.php index a706e9cb6..619bcd8d7 100644 --- a/src/pocketmine/block/Trapdoor.php +++ b/src/pocketmine/block/Trapdoor.php @@ -43,8 +43,6 @@ class Trapdoor extends Transparent{ $f = 0.1875; - $bb = null; - if(($damage & 0x08) > 0){ $bb = AxisAlignedBB::getBoundingBoxFromPool( $this->x, @@ -67,7 +65,7 @@ class Trapdoor extends Transparent{ if(($damage & 0x04) > 0){ if(($damage & 0x03) === 0){ - $bb = AxisAlignedBB::getBoundingBoxFromPool( + $bb->setBounds( $this->x, $this->y, $this->z + 1 - $f, @@ -76,7 +74,7 @@ class Trapdoor extends Transparent{ $this->z + 1 ); }elseif(($damage & 0x03) === 1){ - $bb = AxisAlignedBB::getBoundingBoxFromPool( + $bb->setBounds( $this->x, $this->y, $this->z, @@ -85,7 +83,7 @@ class Trapdoor extends Transparent{ $this->z + $f ); }if(($damage & 0x03) === 2){ - $bb = AxisAlignedBB::getBoundingBoxFromPool( + $bb->setBounds( $this->x + 1 - $f, $this->y, $this->z, @@ -94,7 +92,7 @@ class Trapdoor extends Transparent{ $this->z + 1 ); }if(($damage & 0x03) === 3){ - $bb = AxisAlignedBB::getBoundingBoxFromPool( + $bb->setBounds( $this->x, $this->y, $this->z, From f72d7284b9421e4696ebf60eef392867c79e5368 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 30 Oct 2014 23:13:25 +0100 Subject: [PATCH 61/61] Added EncapsulatedPacket reuse on broadcast --- src/pocketmine/Server.php | 3 ++ .../network/CachedEncapsulatedPacket.php | 33 +++++++++++++++++++ src/pocketmine/network/RakLibInterface.php | 28 ++++++++++++---- 3 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 src/pocketmine/network/CachedEncapsulatedPacket.php diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 21f829b0f..5a3d46b56 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -1720,6 +1720,9 @@ class Server{ foreach($players as $player){ $player->dataPacket($packet); } + if(isset($packet->__encapsulatedPacket)){ + unset($packet->__encapsulatedPacket); + } } diff --git a/src/pocketmine/network/CachedEncapsulatedPacket.php b/src/pocketmine/network/CachedEncapsulatedPacket.php new file mode 100644 index 000000000..0ddcff4b7 --- /dev/null +++ b/src/pocketmine/network/CachedEncapsulatedPacket.php @@ -0,0 +1,33 @@ +internalData === null ? ($this->internalData = parent::toBinary($internal)) : $this->internalData; + } +} \ No newline at end of file diff --git a/src/pocketmine/network/RakLibInterface.php b/src/pocketmine/network/RakLibInterface.php index 8950733ef..3619ed05c 100644 --- a/src/pocketmine/network/RakLibInterface.php +++ b/src/pocketmine/network/RakLibInterface.php @@ -222,17 +222,31 @@ class RakLibInterface implements ServerInstance, SourceInterface{ public function putPacket(Player $player, DataPacket $packet, $needACK = false, $immediate = false){ if(isset($this->identifiers[$player])){ $identifier = $this->identifiers[$player]; + $pk = null; if(!$packet->isEncoded){ $packet->encode(); + unset($packet->__encapsulatedPacket); + }elseif(!$needACK){ + if(!isset($packet->__encapsulatedPacket)){ + $packet->__encapsulatedPacket = new CachedEncapsulatedPacket; + $packet->__encapsulatedPacket->identifierACK = null; + $packet->__encapsulatedPacket->buffer = $packet->buffer; + $packet->__encapsulatedPacket->reliability = 2; + } + $pk = $packet->__encapsulatedPacket; } - $pk = EncapsulatedPacket::getPacketFromPool(); - $pk->buffer = $packet->buffer; - $pk->reliability = 2; - if($needACK === true){ - $pk->identifierACK = $this->identifiersACK[$identifier]++; - }else{ - $pk->identifierACK = null; + + if($pk === null){ + $pk = EncapsulatedPacket::getPacketFromPool(); + $pk->buffer = $packet->buffer; + $pk->reliability = 2; + if($needACK === true){ + $pk->identifierACK = $this->identifiersACK[$identifier]++; + }else{ + $pk->identifierACK = null; + } } + $this->interface->sendEncapsulated($identifier, $pk, ($needACK === true ? RakLib::FLAG_NEED_ACK : 0) | ($immediate === true ? RakLib::PRIORITY_IMMEDIATE : RakLib::PRIORITY_NORMAL)); return $pk->identifierACK;