From 9e14435dbb13966542236a35525f1ee913288e1b Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sat, 30 May 2015 23:59:24 +0200 Subject: [PATCH] Moved network ids to constants, improved some entity methods, more performance --- src/pocketmine/Player.php | 69 +++++++--- src/pocketmine/Server.php | 4 +- src/pocketmine/entity/Entity.php | 123 +++++++++--------- src/pocketmine/entity/Human.php | 4 +- .../event/player/PlayerChatEvent.php | 4 +- src/pocketmine/level/Level.php | 29 ++++- src/pocketmine/network/Network.php | 2 +- src/pocketmine/network/RakLibInterface.php | 12 +- .../network/protocol/AddEntityPacket.php | 7 +- .../network/protocol/AddItemEntityPacket.php | 7 +- .../network/protocol/AddPaintingPacket.php | 7 +- .../network/protocol/AddPlayerPacket.php | 9 +- .../protocol/AdventureSettingsPacket.php | 7 +- .../network/protocol/AnimatePacket.php | 7 +- .../network/protocol/BatchPacket.php | 7 +- .../network/protocol/ContainerClosePacket.php | 7 +- .../network/protocol/ContainerOpenPacket.php | 7 +- .../protocol/ContainerSetContentPacket.php | 7 +- .../protocol/ContainerSetDataPacket.php | 7 +- .../protocol/ContainerSetSlotPacket.php | 7 +- .../network/protocol/DataPacket.php | 10 +- .../network/protocol/DisconnectPacket.php | 7 +- .../network/protocol/DropItemPacket.php | 7 +- .../network/protocol/EntityEventPacket.php | 8 +- .../network/protocol/ExplodePacket.php | 7 +- .../network/protocol/FullChunkDataPacket.php | 7 +- .../network/protocol/HurtArmorPacket.php | 7 +- .../network/protocol/InteractPacket.php | 7 +- .../network/protocol/LevelEventPacket.php | 7 +- .../network/protocol/LoginPacket.php | 7 +- .../network/protocol/MobEffectPacket.php | 7 +- .../network/protocol/MoveEntityPacket.php | 7 +- .../network/protocol/MovePlayerPacket.php | 7 +- .../network/protocol/PlayStatusPacket.php | 8 +- .../network/protocol/PlayerActionPacket.php | 7 +- .../protocol/PlayerArmorEquipmentPacket.php | 7 +- .../protocol/PlayerEquipmentPacket.php | 7 +- .../network/protocol/RemoveBlockPacket.php | 7 +- .../network/protocol/RemoveEntityPacket.php | 7 +- .../network/protocol/RemovePlayerPacket.php | 7 +- .../network/protocol/RespawnPacket.php | 7 +- .../network/protocol/SetDifficultyPacket.php | 7 +- .../network/protocol/SetEntityDataPacket.php | 7 +- .../network/protocol/SetEntityLinkPacket.php | 7 +- .../protocol/SetEntityMotionPacket.php | 7 +- .../network/protocol/SetHealthPacket.php | 7 +- .../protocol/SetSpawnPositionPacket.php | 7 +- .../network/protocol/SetTimePacket.php | 7 +- .../network/protocol/StartGamePacket.php | 7 +- .../network/protocol/TakeItemEntityPacket.php | 7 +- .../network/protocol/TextPacket.php | 7 +- .../network/protocol/TileEntityDataPacket.php | 7 +- .../network/protocol/TileEventPacket.php | 7 +- .../network/protocol/UnknownPacket.php | 46 ------- .../network/protocol/UpdateBlockPacket.php | 7 +- .../network/protocol/UseItemPacket.php | 7 +- src/raklib | 2 +- src/spl | 2 +- 58 files changed, 197 insertions(+), 436 deletions(-) delete mode 100644 src/pocketmine/network/protocol/UnknownPacket.php diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 21d2ff20d..0c2c297d5 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -159,8 +159,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade protected $sendIndex = 0; - protected $moveToSend = []; - protected $motionToSend = []; + protected $moveToSend; + protected $motionToSend; /** @var Vector3 */ public $speed = null; @@ -502,11 +502,16 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->spawnThreshold = (int) $this->server->getProperty("chunk-sending.spawn-threshold", 56); $this->spawnPosition = null; $this->gamemode = $this->server->getGamemode(); - $this->setLevel($this->server->getDefaultLevel(), true); + $this->setLevel($this->server->getDefaultLevel()); $this->viewDistance = $this->server->getViewDistance(); $this->newPosition = new Vector3(0, 0, 0); $this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0); + $this->motionToSend = new SetEntityMotionPacket(); + $this->moveToSend = new MoveEntityPacket(); + $this->motionToSend->setChannel(Network::CHANNEL_MOVEMENT); + $this->moveToSend->setChannel(Network::CHANNEL_MOVEMENT); + $this->uuid = Utils::dataToUUID($ip, $port, $clientID); $this->creationTime = microtime(true); @@ -1168,11 +1173,40 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } public function addEntityMotion($entityId, $x, $y, $z){ - $this->motionToSend[$entityId] = [$entityId, $x, $y, $z]; + $this->motionToSend->entities[$entityId] = [$entityId, $x, $y, $z]; } public function addEntityMovement($entityId, $x, $y, $z, $yaw, $pitch, $headYaw = null){ - $this->moveToSend[$entityId] = [$entityId, $x, $y, $z, $yaw, $headYaw === null ? $yaw : $headYaw, $pitch]; + $this->moveToSend->entities[$entityId] = [$entityId, $x, $y, $z, $yaw, $headYaw === null ? $yaw : $headYaw, $pitch]; + } + + public function setDataProperty($id, $type, $value){ + if(parent::setDataProperty($id, $type, $value)){ + $this->sendData([$this], [$id => $this->dataProperties[$id]]); + return true; + } + + return false; + } + + protected function checkGroundState($movX, $movY, $movZ, $dx, $dy, $dz){ + if(!$this->onGround or $movY != 0){ + $bb = clone $this->boundingBox; + $bb->maxY = $bb->minY + 0.5; + $bb->minY -= 1; + if(count($this->level->getCollisionBlocks($bb, true)) > 0){ + $this->onGround = true; + }else{ + $this->onGround = false; + } + } + $this->isCollided = $this->onGround; + } + + protected function checkBlockCollision(){ + foreach($this->getBlocksAround() as $block){ + $block->onEntityCollide($this); + } } protected function checkNearEntities($tickDiff){ @@ -1418,7 +1452,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade }else{ if(!$this->allowFlight and $this->inAirTicks > 10 and !$this->isSleeping() and $this->getDataProperty(self::DATA_NO_AI) !== 1){ $expectedVelocity = (-$this->gravity) / $this->drag - ((-$this->gravity) / $this->drag) * exp(-$this->drag * ($this->inAirTicks - $this->startAirTicks)); - $diff = sqrt(abs($this->speed->y - $expectedVelocity)); + $diff = ($this->speed->y - $expectedVelocity) ** 2; if(!$this->hasEffect(Effect::JUMP) and $diff > 0.6 and $expectedVelocity < $this->speed->y and !$this->server->getAllowFlight()){ if($this->inAirTicks < 100){ @@ -1442,19 +1476,17 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->sendNextChunk(); } - if(count($this->moveToSend) > 0){ - $pk = new MoveEntityPacket(); - $pk->entities = $this->moveToSend; - $this->batchDataPacket($pk->setChannel(Network::CHANNEL_MOVEMENT)); - $this->moveToSend = []; + if(count($this->moveToSend->entities) > 0){ + $this->dataPacket($this->moveToSend); + $this->moveToSend->entities = []; + $this->moveToSend->isEncoded = false; } - if(count($this->motionToSend) > 0){ - $pk = new SetEntityMotionPacket(); - $pk->entities = $this->motionToSend; - $this->batchDataPacket($pk->setChannel(Network::CHANNEL_MOVEMENT)); - $this->motionToSend = []; + if(count($this->motionToSend->entities) > 0){ + $this->dataPacket($this->motionToSend); + $this->motionToSend->entities = []; + $this->motionToSend->isEncoded = false; } if(count($this->batchedPackets) > 0){ @@ -1496,7 +1528,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return; } - if($packet->pid() === ProtocolInfo::BATCH_PACKET){ + if($packet::NETWORK_ID === ProtocolInfo::BATCH_PACKET){ /** @var BatchPacket $packet */ $this->server->getNetwork()->processBatch($packet, $this); return; @@ -1507,7 +1539,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return; } - switch($packet->pid()){ + switch($packet::NETWORK_ID){ case ProtocolInfo::LOGIN_PACKET: if($this->loggedIn){ break; @@ -3097,7 +3129,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->resetFallDistance(); - $this->orderChunks(); $this->nextChunkOrderRun = 0; $this->newPosition = null; } diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 63617af9a..24f390b13 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -1408,7 +1408,7 @@ class Server{ public function addOp($name){ $this->operators->set(strtolower($name), true); - if(($player = $this->getPlayerExact($name)) instanceof Player){ + if(($player = $this->getPlayerExact($name)) !== null){ $player->recalculatePermissions(); } $this->operators->save(true); @@ -1420,7 +1420,7 @@ class Server{ public function removeOp($name){ $this->operators->remove(strtolower($name)); - if(($player = $this->getPlayerExact($name)) instanceof Player){ + if(($player = $this->getPlayerExact($name)) !== null){ $player->recalculatePermissions(); } $this->operators->save(); diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index fb925c59f..a91476b3c 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -129,6 +129,9 @@ abstract class Entity extends Location implements Metadatable{ protected $lastDamageCause = null; + /** @var Block[] */ + private $blocksAround = []; + public $lastX = null; public $lastY = null; public $lastZ = null; @@ -198,6 +201,7 @@ abstract class Entity extends Location implements Metadatable{ /** @var \pocketmine\event\TimingsHandler */ protected $timings; + protected $isPlayer = false; public function __construct(FullChunk $chunk, Compound $nbt){ @@ -207,6 +211,8 @@ abstract class Entity extends Location implements Metadatable{ $this->timings = Timings::getEntityTimings($this); + $this->isPlayer = $this instanceof Player; + $this->temporalVector = new Vector3(); if($this->eyeHeight === null){ @@ -537,7 +543,7 @@ abstract class Entity extends Location implements Metadatable{ * @param array $data Properly formatted entity data, defaults to everything */ public function sendData($player, array $data = null){ - if($player instanceof Player){ + if(!is_array($player)){ $player = [$player]; } @@ -757,13 +763,13 @@ abstract class Entity extends Location implements Metadatable{ Timings::$timerEntityBaseTick->startTiming(); //TODO: check vehicles + $this->blocksAround = null; $this->justCreated = false; - $isPlayer = $this instanceof Player; if(!$this->isAlive()){ $this->removeAllEffects(); $this->despawnFromAll(); - if(!$isPlayer){ + if(!$this->isPlayer){ $this->close(); } @@ -844,10 +850,8 @@ abstract class Entity extends Location implements Metadatable{ $this->lastYaw = $this->yaw; $this->lastPitch = $this->pitch; - if(!($this instanceof Player)){ - foreach($this->hasSpawned as $player){ - $player->addEntityMovement($this->id, $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch, $this->yaw); - } + foreach($this->hasSpawned as $player){ + $player->addEntityMovement($this->id, $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch, $this->yaw); } } @@ -859,12 +863,6 @@ abstract class Entity extends Location implements Metadatable{ foreach($this->hasSpawned as $player){ $player->addEntityMotion($this->id, $this->motionX, $this->motionY, $this->motionZ); } - - if($this instanceof Player){ - $this->motionX = 0; - $this->motionY = 0; - $this->motionZ = 0; - } } } @@ -893,7 +891,7 @@ abstract class Entity extends Location implements Metadatable{ ++$this->deadTicks; if($this->deadTicks >= 10){ $this->despawnFromAll(); - if(!($this instanceof Player)){ + if(!$this->isPlayer){ $this->close(); } } @@ -1076,11 +1074,9 @@ abstract class Entity extends Location implements Metadatable{ Timings::$entityMoveTimer->startTiming(); - $axisalignedbb = clone $this->boundingBox; - $newBB = $this->boundingBox->getOffsetBoundingBox($dx, $dy, $dz); - $list = $this->level->getCollisionCubes($this, $newBB->grow(-0.01, -0.01, -0.01), false); + $list = $this->level->getCollisionCubes($this, $newBB, false); if(count($list) === 0){ $this->boundingBox = $newBB; @@ -1119,7 +1115,7 @@ abstract class Entity extends Location implements Metadatable{ if($this->keepMovement){ $this->boundingBox->offset($dx, $dy, $dz); $this->setPosition($this->temporalVector->setComponents(($this->boundingBox->minX + $this->boundingBox->maxX) / 2, $this->boundingBox->minY, ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2)); - $this->onGround = $this instanceof Player ? true : false; + $this->onGround = $this->isPlayer ? true : false; return true; }else{ @@ -1243,24 +1239,7 @@ abstract class Entity extends Location implements Metadatable{ $this->checkChunks(); - if($this instanceof Player){ - if(!$this->onGround or $movY != 0){ - $bb = clone $this->boundingBox; - $bb->maxY = $bb->minY + 0.5; - $bb->minY -= 1; - if(count($this->level->getCollisionBlocks($bb)) > 0){ - $this->onGround = true; - }else{ - $this->onGround = false; - } - } - $this->isCollided = $this->onGround; - }else{ - $this->isCollidedVertically = $movY != $dy; - $this->isCollidedHorizontally = ($movX != $dx or $movZ != $dz); - $this->isCollided = ($this->isCollidedHorizontally or $this->isCollidedVertically); - $this->onGround = ($movY != $dy and $movY < 0); - } + $this->checkGroundState($movX, $movY, $movZ, $dx, $dy, $dz); $this->updateFallState($dy, $this->onGround); if($movX != $dx){ @@ -1284,32 +1263,48 @@ abstract class Entity extends Location implements Metadatable{ } } - protected function checkBlockCollision(){ - $minX = Math::floorFloat($this->boundingBox->minX + 0.001); - $minY = Math::floorFloat($this->boundingBox->minY + 0.001); - $minZ = Math::floorFloat($this->boundingBox->minZ + 0.001); - $maxX = Math::ceilFloat($this->boundingBox->maxX - 0.001); - $maxY = Math::ceilFloat($this->boundingBox->maxY - 0.001); - $maxZ = Math::ceilFloat($this->boundingBox->maxZ - 0.001); + protected function checkGroundState($movX, $movY, $movZ, $dx, $dy, $dz){ + $this->isCollidedVertically = $movY != $dy; + $this->isCollidedHorizontally = ($movX != $dx or $movZ != $dz); + $this->isCollided = ($this->isCollidedHorizontally or $this->isCollidedVertically); + $this->onGround = ($movY != $dy and $movY < 0); + } - $vector = new Vector3(0, 0, 0); - $v = new Vector3(0, 0, 0); + public function getBlocksAround(){ + if($this->blocksAround === null){ + $minX = Math::floorFloat($this->boundingBox->minX); + $minY = Math::floorFloat($this->boundingBox->minY); + $minZ = Math::floorFloat($this->boundingBox->minZ); + $maxX = Math::ceilFloat($this->boundingBox->maxX); + $maxY = Math::ceilFloat($this->boundingBox->maxY); + $maxZ = Math::ceilFloat($this->boundingBox->maxZ); - 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->hasEntityCollision()){ - $block->onEntityCollide($this); - if(!($this instanceof Player)){ - $block->addVelocityToEntity($this, $vector); + $this->blocksAround = []; + + for($z = $minZ; $z <= $maxZ; ++$z){ + for($x = $minX; $x <= $maxX; ++$x){ + for($y = $minY; $y <= $maxY; ++$y){ + $block = $this->level->getBlock($this->temporalVector->setComponents($x, $y, $z)); + if($block->hasEntityCollision()){ + $this->blocksAround[] = $block; } } } } } - if(!($this instanceof Player) and $vector->lengthSquared() > 0){ + return $this->blocksAround; + } + + protected function checkBlockCollision(){ + $vector = new Vector3(0, 0, 0); + + foreach($this->getBlocksAround() as $block){ + $block->onEntityCollide($this); + $block->addVelocityToEntity($this, $vector); + } + + if($vector->lengthSquared() > 0){ $vector = $vector->normalize(); $d = 0.014; $this->motionX += $vector->x * $d; @@ -1508,21 +1503,19 @@ abstract class Entity extends Location implements Metadatable{ * @param int $id * @param int $type * @param mixed $value + * + * @return bool */ public function setDataProperty($id, $type, $value){ - if($this->getDataProperty($id) !== $value){ - $this->dataProperties[$id] = [$type, $value]; + if($this->getDataProperty($id) !== $value){ + $this->dataProperties[$id] = [$type, $value]; - $targets = $this->hasSpawned; - if($this instanceof Player){ - if(!$this->spawned){ - return; - } - $targets[] = $this; - } + $this->sendData($this->hasSpawned, [$id => $this->dataProperties[$id]]); - $this->sendData($targets, [$id => $this->dataProperties[$id]]); - } + return true; + } + + return false; } /** diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index a167cdec0..28e2e78fe 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -115,7 +115,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ public function getDrops(){ $drops = []; - if($this->inventory instanceof PlayerInventory){ + if($this->inventory !== null){ foreach($this->inventory->getContents() as $item){ $drops[] = $item; } @@ -128,7 +128,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ parent::saveNBT(); $this->namedtag->Inventory = new Enum("Inventory", []); $this->namedtag->Inventory->setTagType(NBT::TAG_Compound); - if($this->inventory instanceof PlayerInventory){ + if($this->inventory !== null){ for($slot = 0; $slot < 9; ++$slot){ $hotbarSlot = $this->inventory->getHotbarSlotIndex($slot); if($hotbarSlot !== -1){ diff --git a/src/pocketmine/event/player/PlayerChatEvent.php b/src/pocketmine/event/player/PlayerChatEvent.php index b9939bca0..c04cd5e66 100644 --- a/src/pocketmine/event/player/PlayerChatEvent.php +++ b/src/pocketmine/event/player/PlayerChatEvent.php @@ -76,9 +76,7 @@ class PlayerChatEvent extends PlayerEvent implements Cancellable{ * @param Player $player */ public function setPlayer(Player $player){ - if($player instanceof Player){ - $this->player = $player; - } + $this->player = $player; } public function getFormat(){ diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 5480c34a9..f4df36a49 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -988,10 +988,11 @@ class Level implements ChunkManager, Metadatable{ /** * @param AxisAlignedBB $bb + * @param bool $targetFirst * * @return Block[] */ - public function getCollisionBlocks(AxisAlignedBB $bb){ + public function getCollisionBlocks(AxisAlignedBB $bb, $targetFirst = false){ $minX = Math::floorFloat($bb->minX); $minY = Math::floorFloat($bb->minY); $minZ = Math::floorFloat($bb->minZ); @@ -1001,17 +1002,31 @@ class Level implements ChunkManager, Metadatable{ $collides = []; - for($z = $minZ; $z <= $maxZ; ++$z){ - for($x = $minX; $x <= $maxX; ++$x){ - for($y = $minY; $y <= $maxY; ++$y){ - $block = $this->getBlock($this->temporalVector->setComponents($x, $y, $z)); - if($block->getId() !== 0 and $block->collidesWithBB($bb)){ - $collides[] = $block; + if($targetFirst){ + for($z = $minZ; $z <= $maxZ; ++$z){ + for($x = $minX; $x <= $maxX; ++$x){ + for($y = $minY; $y <= $maxY; ++$y){ + $block = $this->getBlock($this->temporalVector->setComponents($x, $y, $z)); + if($block->getId() !== 0 and $block->collidesWithBB($bb)){ + return [$block]; + } + } + } + } + }else{ + for($z = $minZ; $z <= $maxZ; ++$z){ + for($x = $minX; $x <= $maxX; ++$x){ + for($y = $minY; $y <= $maxY; ++$y){ + $block = $this->getBlock($this->temporalVector->setComponents($x, $y, $z)); + if($block->getId() !== 0 and $block->collidesWithBB($bb)){ + $collides[] = $block; + } } } } } + return $collides; } diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index 8e2b7ed36..b6264413d 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -220,7 +220,7 @@ class Network{ try{ while($offset < $len){ if(($pk = $this->getPacket(ord($str{$offset++}))) !== null){ - if($pk->pid() === Info::BATCH_PACKET){ + if($pk::NETWORK_ID === Info::BATCH_PACKET){ throw new \InvalidStateException("Invalid BatchPacket inside BatchPacket"); } $pk->setBuffer($str, $offset); diff --git a/src/pocketmine/network/RakLibInterface.php b/src/pocketmine/network/RakLibInterface.php index e7fd672a1..341ef62ff 100644 --- a/src/pocketmine/network/RakLibInterface.php +++ b/src/pocketmine/network/RakLibInterface.php @@ -25,7 +25,6 @@ use pocketmine\event\player\PlayerCreationEvent; use pocketmine\network\protocol\DataPacket; use pocketmine\network\protocol\Info as ProtocolInfo; use pocketmine\network\protocol\Info; -use pocketmine\network\protocol\UnknownPacket; use pocketmine\Player; use pocketmine\Server; use pocketmine\utils\MainLogger; @@ -136,8 +135,10 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{ try{ if($packet->buffer !== ""){ $pk = $this->getPacket($packet->buffer); - $pk->decode(); - $this->players[$identifier]->handleDataPacket($pk); + if($pk !== null){ + $pk->decode(); + $this->players[$identifier]->handleDataPacket($pk); + } } }catch(\Exception $e){ if(\pocketmine\DEBUG > 1 and isset($pk)){ @@ -216,7 +217,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{ $pk = $packet->__encapsulatedPacket; } - if(!$immediate and !$needACK and $packet->pid() !== ProtocolInfo::BATCH_PACKET + if(!$immediate and !$needACK and $packet::NETWORK_ID !== ProtocolInfo::BATCH_PACKET and Network::$BATCH_THRESHOLD >= 0 and strlen($packet->buffer) >= Network::$BATCH_THRESHOLD){ $this->server->batchPackets([$player], [$packet], true, $packet->getChannel()); @@ -251,8 +252,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{ $pid = ord($buffer{0}); if(($data = $this->network->getPacket($pid)) === null){ - $data = new UnknownPacket(); - $data->packetID = $pid; + return null; } $data->setBuffer($buffer, 1); diff --git a/src/pocketmine/network/protocol/AddEntityPacket.php b/src/pocketmine/network/protocol/AddEntityPacket.php index 8f70184c8..f4e683578 100644 --- a/src/pocketmine/network/protocol/AddEntityPacket.php +++ b/src/pocketmine/network/protocol/AddEntityPacket.php @@ -29,8 +29,7 @@ use pocketmine\utils\Binary; #endif class AddEntityPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::ADD_ENTITY_PACKET; public $eid; public $type; @@ -45,10 +44,6 @@ class AddEntityPacket extends DataPacket{ public $metadata; public $links = []; - public function pid(){ - return Info::ADD_ENTITY_PACKET; - } - public function decode(){ } diff --git a/src/pocketmine/network/protocol/AddItemEntityPacket.php b/src/pocketmine/network/protocol/AddItemEntityPacket.php index dca5ca13a..86509e5b0 100644 --- a/src/pocketmine/network/protocol/AddItemEntityPacket.php +++ b/src/pocketmine/network/protocol/AddItemEntityPacket.php @@ -25,8 +25,7 @@ namespace pocketmine\network\protocol; class AddItemEntityPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::ADD_ITEM_ENTITY_PACKET; public $eid; public $item; @@ -37,10 +36,6 @@ class AddItemEntityPacket extends DataPacket{ public $speedY; public $speedZ; - public function pid(){ - return Info::ADD_ITEM_ENTITY_PACKET; - } - public function decode(){ } diff --git a/src/pocketmine/network/protocol/AddPaintingPacket.php b/src/pocketmine/network/protocol/AddPaintingPacket.php index f104442ef..7b2276185 100644 --- a/src/pocketmine/network/protocol/AddPaintingPacket.php +++ b/src/pocketmine/network/protocol/AddPaintingPacket.php @@ -25,8 +25,7 @@ namespace pocketmine\network\protocol; class AddPaintingPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::ADD_PAINTING_PACKET; public $eid; public $x; @@ -35,10 +34,6 @@ class AddPaintingPacket extends DataPacket{ public $direction; public $title; - public function pid(){ - return Info::ADD_PAINTING_PACKET; - } - public function decode(){ } diff --git a/src/pocketmine/network/protocol/AddPlayerPacket.php b/src/pocketmine/network/protocol/AddPlayerPacket.php index f1cc2c2af..5e3154875 100644 --- a/src/pocketmine/network/protocol/AddPlayerPacket.php +++ b/src/pocketmine/network/protocol/AddPlayerPacket.php @@ -29,10 +29,7 @@ use pocketmine\utils\Binary; #endif class AddPlayerPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; - - + const NETWORK_ID = Info::ADD_PLAYER_PACKET; public $clientID; public $username; @@ -52,10 +49,6 @@ class AddPlayerPacket extends DataPacket{ public $slim = false; public $skin = null; - public function pid(){ - return Info::ADD_PLAYER_PACKET; - } - public function decode(){ } diff --git a/src/pocketmine/network/protocol/AdventureSettingsPacket.php b/src/pocketmine/network/protocol/AdventureSettingsPacket.php index 0be53f7c6..b07d03ee3 100644 --- a/src/pocketmine/network/protocol/AdventureSettingsPacket.php +++ b/src/pocketmine/network/protocol/AdventureSettingsPacket.php @@ -25,15 +25,10 @@ namespace pocketmine\network\protocol; class AdventureSettingsPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::ADVENTURE_SETTINGS_PACKET; public $flags; - public function pid(){ - return Info::ADVENTURE_SETTINGS_PACKET; - } - public function decode(){ } diff --git a/src/pocketmine/network/protocol/AnimatePacket.php b/src/pocketmine/network/protocol/AnimatePacket.php index 721132e20..f6d5ba624 100644 --- a/src/pocketmine/network/protocol/AnimatePacket.php +++ b/src/pocketmine/network/protocol/AnimatePacket.php @@ -25,16 +25,11 @@ namespace pocketmine\network\protocol; class AnimatePacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::ANIMATE_PACKET; public $action; public $eid; - public function pid(){ - return Info::ANIMATE_PACKET; - } - public function decode(){ $this->action = $this->getByte(); $this->eid = $this->getLong(); diff --git a/src/pocketmine/network/protocol/BatchPacket.php b/src/pocketmine/network/protocol/BatchPacket.php index 513837878..ee3cb78a0 100644 --- a/src/pocketmine/network/protocol/BatchPacket.php +++ b/src/pocketmine/network/protocol/BatchPacket.php @@ -25,15 +25,10 @@ namespace pocketmine\network\protocol; class BatchPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::BATCH_PACKET; public $payload; - public function pid(){ - return Info::BATCH_PACKET; - } - public function decode(){ $size = $this->getInt(); $this->payload = $this->get($size); diff --git a/src/pocketmine/network/protocol/ContainerClosePacket.php b/src/pocketmine/network/protocol/ContainerClosePacket.php index fa7f39c57..4f8913f71 100644 --- a/src/pocketmine/network/protocol/ContainerClosePacket.php +++ b/src/pocketmine/network/protocol/ContainerClosePacket.php @@ -25,15 +25,10 @@ namespace pocketmine\network\protocol; class ContainerClosePacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::CONTAINER_CLOSE_PACKET; public $windowid; - public function pid(){ - return Info::CONTAINER_CLOSE_PACKET; - } - public function decode(){ $this->windowid = $this->getByte(); } diff --git a/src/pocketmine/network/protocol/ContainerOpenPacket.php b/src/pocketmine/network/protocol/ContainerOpenPacket.php index aad724b05..5b5923adc 100644 --- a/src/pocketmine/network/protocol/ContainerOpenPacket.php +++ b/src/pocketmine/network/protocol/ContainerOpenPacket.php @@ -25,8 +25,7 @@ namespace pocketmine\network\protocol; class ContainerOpenPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::CONTAINER_OPEN_PACKET; public $windowid; public $type; @@ -35,10 +34,6 @@ class ContainerOpenPacket extends DataPacket{ public $y; public $z; - public function pid(){ - return Info::CONTAINER_OPEN_PACKET; - } - public function decode(){ } diff --git a/src/pocketmine/network/protocol/ContainerSetContentPacket.php b/src/pocketmine/network/protocol/ContainerSetContentPacket.php index 626192c11..108008965 100644 --- a/src/pocketmine/network/protocol/ContainerSetContentPacket.php +++ b/src/pocketmine/network/protocol/ContainerSetContentPacket.php @@ -25,8 +25,7 @@ namespace pocketmine\network\protocol; class ContainerSetContentPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::CONTAINER_SET_CONTENT_PACKET; const SPECIAL_INVENTORY = 0; const SPECIAL_ARMOR = 0x78; @@ -37,10 +36,6 @@ class ContainerSetContentPacket extends DataPacket{ public $slots = []; public $hotbar = []; - public function pid(){ - return Info::CONTAINER_SET_CONTENT_PACKET; - } - public function clean(){ $this->slots = []; $this->hotbar = []; diff --git a/src/pocketmine/network/protocol/ContainerSetDataPacket.php b/src/pocketmine/network/protocol/ContainerSetDataPacket.php index 1ef7777c3..750accdce 100644 --- a/src/pocketmine/network/protocol/ContainerSetDataPacket.php +++ b/src/pocketmine/network/protocol/ContainerSetDataPacket.php @@ -25,17 +25,12 @@ namespace pocketmine\network\protocol; class ContainerSetDataPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::CONTAINER_SET_DATA_PACKET; public $windowid; public $property; public $value; - public function pid(){ - return Info::CONTAINER_SET_DATA_PACKET; - } - public function decode(){ } diff --git a/src/pocketmine/network/protocol/ContainerSetSlotPacket.php b/src/pocketmine/network/protocol/ContainerSetSlotPacket.php index 4998d9fc8..244aba979 100644 --- a/src/pocketmine/network/protocol/ContainerSetSlotPacket.php +++ b/src/pocketmine/network/protocol/ContainerSetSlotPacket.php @@ -26,18 +26,13 @@ namespace pocketmine\network\protocol; use pocketmine\item\Item; class ContainerSetSlotPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::CONTAINER_SET_SLOT_PACKET; public $windowid; public $slot; /** @var Item */ public $item; - public function pid(){ - return Info::CONTAINER_SET_SLOT_PACKET; - } - public function decode(){ $this->windowid = $this->getByte(); $this->slot = $this->getShort(); diff --git a/src/pocketmine/network/protocol/DataPacket.php b/src/pocketmine/network/protocol/DataPacket.php index ff71f1c57..5c67267ba 100644 --- a/src/pocketmine/network/protocol/DataPacket.php +++ b/src/pocketmine/network/protocol/DataPacket.php @@ -32,19 +32,23 @@ use pocketmine\item\Item; abstract class DataPacket extends \stdClass{ - private $offset = 0; + const NETWORK_ID = 0; + + public $offset = 0; public $buffer = ""; public $isEncoded = false; private $channel = 0; - abstract public function pid(); + public function pid(){ + return $this::NETWORK_ID; + } abstract public function encode(); abstract public function decode(); protected function reset(){ - $this->buffer = chr($this->pid()); + $this->buffer = chr($this::NETWORK_ID); $this->offset = 0; } diff --git a/src/pocketmine/network/protocol/DisconnectPacket.php b/src/pocketmine/network/protocol/DisconnectPacket.php index 5a83bd7d5..1b1a5d40a 100644 --- a/src/pocketmine/network/protocol/DisconnectPacket.php +++ b/src/pocketmine/network/protocol/DisconnectPacket.php @@ -25,15 +25,10 @@ namespace pocketmine\network\protocol; class DisconnectPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::DISCONNECT_PACKET; public $message; - public function pid(){ - return Info::DISCONNECT_PACKET; - } - public function decode(){ $this->message = $this->getString(); } diff --git a/src/pocketmine/network/protocol/DropItemPacket.php b/src/pocketmine/network/protocol/DropItemPacket.php index 2e7d12b0a..afdd0310f 100644 --- a/src/pocketmine/network/protocol/DropItemPacket.php +++ b/src/pocketmine/network/protocol/DropItemPacket.php @@ -25,17 +25,12 @@ namespace pocketmine\network\protocol; class DropItemPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::DROP_ITEM_PACKET; public $eid; public $unknown; public $item; - public function pid(){ - return Info::DROP_ITEM_PACKET; - } - public function decode(){ $this->eid = $this->getLong(); $this->unknown = $this->getByte(); diff --git a/src/pocketmine/network/protocol/EntityEventPacket.php b/src/pocketmine/network/protocol/EntityEventPacket.php index 8c5777fb3..f41bc6589 100644 --- a/src/pocketmine/network/protocol/EntityEventPacket.php +++ b/src/pocketmine/network/protocol/EntityEventPacket.php @@ -25,6 +25,7 @@ namespace pocketmine\network\protocol; class EntityEventPacket extends DataPacket{ + const NETWORK_ID = Info::ENTITY_EVENT_PACKET; const HURT_ANIMATION = 2; const DEATH_ANIMATION = 3; @@ -42,16 +43,9 @@ class EntityEventPacket extends DataPacket{ const AMBIENT_SOUND = 16; const RESPAWN = 17; - public static $pool = []; - public static $next = 0; - public $eid; public $event; - public function pid(){ - return Info::ENTITY_EVENT_PACKET; - } - public function decode(){ $this->eid = $this->getLong(); $this->event = $this->getByte(); diff --git a/src/pocketmine/network/protocol/ExplodePacket.php b/src/pocketmine/network/protocol/ExplodePacket.php index 287cbd957..6b0f660d5 100644 --- a/src/pocketmine/network/protocol/ExplodePacket.php +++ b/src/pocketmine/network/protocol/ExplodePacket.php @@ -25,8 +25,7 @@ namespace pocketmine\network\protocol; class ExplodePacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::EXPLODE_PACKET; public $x; public $y; @@ -34,10 +33,6 @@ class ExplodePacket extends DataPacket{ public $radius; public $records = []; - public function pid(){ - return Info::EXPLODE_PACKET; - } - public function clean(){ $this->records = []; return parent::clean(); diff --git a/src/pocketmine/network/protocol/FullChunkDataPacket.php b/src/pocketmine/network/protocol/FullChunkDataPacket.php index 5b70e43e0..619485212 100644 --- a/src/pocketmine/network/protocol/FullChunkDataPacket.php +++ b/src/pocketmine/network/protocol/FullChunkDataPacket.php @@ -25,17 +25,12 @@ namespace pocketmine\network\protocol; class FullChunkDataPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::FULL_CHUNK_DATA_PACKET; public $chunkX; public $chunkZ; public $data; - public function pid(){ - return Info::FULL_CHUNK_DATA_PACKET; - } - public function decode(){ } diff --git a/src/pocketmine/network/protocol/HurtArmorPacket.php b/src/pocketmine/network/protocol/HurtArmorPacket.php index 53b65da40..2f5896c87 100644 --- a/src/pocketmine/network/protocol/HurtArmorPacket.php +++ b/src/pocketmine/network/protocol/HurtArmorPacket.php @@ -25,15 +25,10 @@ namespace pocketmine\network\protocol; class HurtArmorPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::HURT_ARMOR_PACKET; public $health; - public function pid(){ - return Info::HURT_ARMOR_PACKET; - } - public function decode(){ } diff --git a/src/pocketmine/network/protocol/InteractPacket.php b/src/pocketmine/network/protocol/InteractPacket.php index 91dc3880c..86221c8ee 100644 --- a/src/pocketmine/network/protocol/InteractPacket.php +++ b/src/pocketmine/network/protocol/InteractPacket.php @@ -25,17 +25,12 @@ namespace pocketmine\network\protocol; class InteractPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::INTERACT_PACKET; public $action; public $eid; public $target; - public function pid(){ - return Info::INTERACT_PACKET; - } - public function decode(){ $this->action = $this->getByte(); $this->target = $this->getLong(); diff --git a/src/pocketmine/network/protocol/LevelEventPacket.php b/src/pocketmine/network/protocol/LevelEventPacket.php index 1a56943ac..d34bc3225 100644 --- a/src/pocketmine/network/protocol/LevelEventPacket.php +++ b/src/pocketmine/network/protocol/LevelEventPacket.php @@ -25,8 +25,7 @@ namespace pocketmine\network\protocol; class LevelEventPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::LEVEL_EVENT_PACKET; public $evid; public $x; @@ -34,10 +33,6 @@ class LevelEventPacket extends DataPacket{ public $z; public $data; - public function pid(){ - return Info::LEVEL_EVENT_PACKET; - } - public function decode(){ } diff --git a/src/pocketmine/network/protocol/LoginPacket.php b/src/pocketmine/network/protocol/LoginPacket.php index 7ef9ff0c5..2d5151282 100644 --- a/src/pocketmine/network/protocol/LoginPacket.php +++ b/src/pocketmine/network/protocol/LoginPacket.php @@ -25,8 +25,7 @@ namespace pocketmine\network\protocol; class LoginPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::LOGIN_PACKET; public $username; public $protocol1; @@ -36,10 +35,6 @@ class LoginPacket extends DataPacket{ public $slim = false; public $skin = null; - public function pid(){ - return Info::LOGIN_PACKET; - } - public function decode(){ $this->username = $this->getString(); $this->protocol1 = $this->getInt(); diff --git a/src/pocketmine/network/protocol/MobEffectPacket.php b/src/pocketmine/network/protocol/MobEffectPacket.php index 5040c8682..f38112551 100644 --- a/src/pocketmine/network/protocol/MobEffectPacket.php +++ b/src/pocketmine/network/protocol/MobEffectPacket.php @@ -25,8 +25,7 @@ namespace pocketmine\network\protocol; class MobEffectPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::MOB_EFFECT_PACKET; const EVENT_ADD = 1; const EVENT_MODIFY = 2; @@ -39,10 +38,6 @@ class MobEffectPacket extends DataPacket{ public $particles = true; public $duration; - public function pid(){ - return Info::MOB_EFFECT_PACKET; - } - public function decode(){ } diff --git a/src/pocketmine/network/protocol/MoveEntityPacket.php b/src/pocketmine/network/protocol/MoveEntityPacket.php index 12e865c5b..81a8afb83 100644 --- a/src/pocketmine/network/protocol/MoveEntityPacket.php +++ b/src/pocketmine/network/protocol/MoveEntityPacket.php @@ -25,18 +25,13 @@ namespace pocketmine\network\protocol; class MoveEntityPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::MOVE_ENTITY_PACKET; // eid, x, y, z, yaw, pitch /** @var array[] */ public $entities = []; - public function pid(){ - return Info::MOVE_ENTITY_PACKET; - } - public function clean(){ $this->entities = []; return parent::clean(); diff --git a/src/pocketmine/network/protocol/MovePlayerPacket.php b/src/pocketmine/network/protocol/MovePlayerPacket.php index 165c8239f..d5f5b4785 100644 --- a/src/pocketmine/network/protocol/MovePlayerPacket.php +++ b/src/pocketmine/network/protocol/MovePlayerPacket.php @@ -25,8 +25,7 @@ namespace pocketmine\network\protocol; class MovePlayerPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::MOVE_PLAYER_PACKET; public $eid; public $x; @@ -38,10 +37,6 @@ class MovePlayerPacket extends DataPacket{ public $mode = 0; public $onGround; - public function pid(){ - return Info::MOVE_PLAYER_PACKET; - } - public function clean(){ $this->teleport = false; return parent::clean(); diff --git a/src/pocketmine/network/protocol/PlayStatusPacket.php b/src/pocketmine/network/protocol/PlayStatusPacket.php index ca9ec3c0d..4ce67ea37 100644 --- a/src/pocketmine/network/protocol/PlayStatusPacket.php +++ b/src/pocketmine/network/protocol/PlayStatusPacket.php @@ -25,21 +25,15 @@ namespace pocketmine\network\protocol; class PlayStatusPacket extends DataPacket{ + const NETWORK_ID = Info::PLAY_STATUS_PACKET; const LOGIN_SUCCESS = 0; const LOGIN_FAILED_CLIENT = 1; const LOGIN_FAILED_SERVER = 2; const PLAYER_SPAWN = 3; - - public static $pool = []; - public static $next = 0; public $status; - public function pid(){ - return Info::PLAY_STATUS_PACKET; - } - public function decode(){ } diff --git a/src/pocketmine/network/protocol/PlayerActionPacket.php b/src/pocketmine/network/protocol/PlayerActionPacket.php index 4d16ca796..b44061a16 100644 --- a/src/pocketmine/network/protocol/PlayerActionPacket.php +++ b/src/pocketmine/network/protocol/PlayerActionPacket.php @@ -25,8 +25,7 @@ namespace pocketmine\network\protocol; class PlayerActionPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::PLAYER_ACTION_PACKET; public $eid; public $action; @@ -35,10 +34,6 @@ class PlayerActionPacket extends DataPacket{ public $z; public $face; - public function pid(){ - return Info::PLAYER_ACTION_PACKET; - } - public function decode(){ $this->eid = $this->getLong(); $this->action = $this->getInt(); diff --git a/src/pocketmine/network/protocol/PlayerArmorEquipmentPacket.php b/src/pocketmine/network/protocol/PlayerArmorEquipmentPacket.php index 5cdad7cd1..7df9f98b2 100644 --- a/src/pocketmine/network/protocol/PlayerArmorEquipmentPacket.php +++ b/src/pocketmine/network/protocol/PlayerArmorEquipmentPacket.php @@ -25,16 +25,11 @@ namespace pocketmine\network\protocol; class PlayerArmorEquipmentPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::PLAYER_ARMOR_EQUIPMENT_PACKET; public $eid; public $slots = []; - public function pid(){ - return Info::PLAYER_ARMOR_EQUIPMENT_PACKET; - } - public function decode(){ $this->eid = $this->getLong(); $this->slots[0] = $this->getByte(); diff --git a/src/pocketmine/network/protocol/PlayerEquipmentPacket.php b/src/pocketmine/network/protocol/PlayerEquipmentPacket.php index 98619f059..32ab69160 100644 --- a/src/pocketmine/network/protocol/PlayerEquipmentPacket.php +++ b/src/pocketmine/network/protocol/PlayerEquipmentPacket.php @@ -25,8 +25,7 @@ namespace pocketmine\network\protocol; class PlayerEquipmentPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::PLAYER_EQUIPMENT_PACKET; public $eid; public $item; @@ -34,10 +33,6 @@ class PlayerEquipmentPacket extends DataPacket{ public $slot; public $selectedSlot; - public function pid(){ - return Info::PLAYER_EQUIPMENT_PACKET; - } - public function decode(){ $this->eid = $this->getLong(); $this->item = $this->getShort(); diff --git a/src/pocketmine/network/protocol/RemoveBlockPacket.php b/src/pocketmine/network/protocol/RemoveBlockPacket.php index c0c9b4992..2f503f11e 100644 --- a/src/pocketmine/network/protocol/RemoveBlockPacket.php +++ b/src/pocketmine/network/protocol/RemoveBlockPacket.php @@ -25,18 +25,13 @@ namespace pocketmine\network\protocol; class RemoveBlockPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::REMOVE_BLOCK_PACKET; public $eid; public $x; public $y; public $z; - public function pid(){ - return Info::REMOVE_BLOCK_PACKET; - } - public function decode(){ $this->eid = $this->getLong(); $this->x = $this->getInt(); diff --git a/src/pocketmine/network/protocol/RemoveEntityPacket.php b/src/pocketmine/network/protocol/RemoveEntityPacket.php index 8757dcf78..f4b5b4c91 100644 --- a/src/pocketmine/network/protocol/RemoveEntityPacket.php +++ b/src/pocketmine/network/protocol/RemoveEntityPacket.php @@ -25,15 +25,10 @@ namespace pocketmine\network\protocol; class RemoveEntityPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::REMOVE_ENTITY_PACKET; public $eid; - public function pid(){ - return Info::REMOVE_ENTITY_PACKET; - } - public function decode(){ } diff --git a/src/pocketmine/network/protocol/RemovePlayerPacket.php b/src/pocketmine/network/protocol/RemovePlayerPacket.php index 5f8f4600b..ef903f604 100644 --- a/src/pocketmine/network/protocol/RemovePlayerPacket.php +++ b/src/pocketmine/network/protocol/RemovePlayerPacket.php @@ -25,16 +25,11 @@ namespace pocketmine\network\protocol; class RemovePlayerPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::REMOVE_PLAYER_PACKET; public $eid; public $clientID; - public function pid(){ - return Info::REMOVE_PLAYER_PACKET; - } - public function decode(){ } diff --git a/src/pocketmine/network/protocol/RespawnPacket.php b/src/pocketmine/network/protocol/RespawnPacket.php index 903c7e02f..ee8121c90 100644 --- a/src/pocketmine/network/protocol/RespawnPacket.php +++ b/src/pocketmine/network/protocol/RespawnPacket.php @@ -25,17 +25,12 @@ namespace pocketmine\network\protocol; class RespawnPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::RESPAWN_PACKET; public $x; public $y; public $z; - public function pid(){ - return Info::RESPAWN_PACKET; - } - public function decode(){ $this->x = $this->getFloat(); $this->y = $this->getFloat(); diff --git a/src/pocketmine/network/protocol/SetDifficultyPacket.php b/src/pocketmine/network/protocol/SetDifficultyPacket.php index 9608c3b72..23179171d 100644 --- a/src/pocketmine/network/protocol/SetDifficultyPacket.php +++ b/src/pocketmine/network/protocol/SetDifficultyPacket.php @@ -25,15 +25,10 @@ namespace pocketmine\network\protocol; class SetDifficultyPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::SET_DIFFICULTY_PACKET; public $difficulty; - public function pid(){ - return Info::SET_DIFFICULTY_PACKET; - } - public function decode(){ $this->difficulty = $this->getInt(); } diff --git a/src/pocketmine/network/protocol/SetEntityDataPacket.php b/src/pocketmine/network/protocol/SetEntityDataPacket.php index 539a5082d..ae7b89175 100644 --- a/src/pocketmine/network/protocol/SetEntityDataPacket.php +++ b/src/pocketmine/network/protocol/SetEntityDataPacket.php @@ -29,16 +29,11 @@ use pocketmine\utils\Binary; #endif class SetEntityDataPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::SET_ENTITY_DATA_PACKET; public $eid; public $metadata; - public function pid(){ - return Info::SET_ENTITY_DATA_PACKET; - } - public function decode(){ } diff --git a/src/pocketmine/network/protocol/SetEntityLinkPacket.php b/src/pocketmine/network/protocol/SetEntityLinkPacket.php index ad73f1486..8533fae82 100644 --- a/src/pocketmine/network/protocol/SetEntityLinkPacket.php +++ b/src/pocketmine/network/protocol/SetEntityLinkPacket.php @@ -25,17 +25,12 @@ namespace pocketmine\network\protocol; class SetEntityLinkPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::SET_ENTITY_LINK_PACKET; public $from; public $to; public $type; - public function pid(){ - return Info::SET_ENTITY_LINK_PACKET; - } - public function decode(){ } diff --git a/src/pocketmine/network/protocol/SetEntityMotionPacket.php b/src/pocketmine/network/protocol/SetEntityMotionPacket.php index e96ae6d50..aa7dbe02f 100644 --- a/src/pocketmine/network/protocol/SetEntityMotionPacket.php +++ b/src/pocketmine/network/protocol/SetEntityMotionPacket.php @@ -25,18 +25,13 @@ namespace pocketmine\network\protocol; class SetEntityMotionPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::SET_ENTITY_MOTION_PACKET; // eid, motX, motY, motZ /** @var array[] */ public $entities = []; - public function pid(){ - return Info::SET_ENTITY_MOTION_PACKET; - } - public function clean(){ $this->entities = []; return parent::clean(); diff --git a/src/pocketmine/network/protocol/SetHealthPacket.php b/src/pocketmine/network/protocol/SetHealthPacket.php index 15b42b066..60fd1687c 100644 --- a/src/pocketmine/network/protocol/SetHealthPacket.php +++ b/src/pocketmine/network/protocol/SetHealthPacket.php @@ -25,15 +25,10 @@ namespace pocketmine\network\protocol; class SetHealthPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::SET_HEALTH_PACKET; public $health; - public function pid(){ - return Info::SET_HEALTH_PACKET; - } - public function decode(){ $this->health = $this->getInt(); } diff --git a/src/pocketmine/network/protocol/SetSpawnPositionPacket.php b/src/pocketmine/network/protocol/SetSpawnPositionPacket.php index 371e72a36..14090b671 100644 --- a/src/pocketmine/network/protocol/SetSpawnPositionPacket.php +++ b/src/pocketmine/network/protocol/SetSpawnPositionPacket.php @@ -25,17 +25,12 @@ namespace pocketmine\network\protocol; class SetSpawnPositionPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::SET_SPAWN_POSITION_PACKET; public $x; public $z; public $y; - public function pid(){ - return Info::SET_SPAWN_POSITION_PACKET; - } - public function decode(){ } diff --git a/src/pocketmine/network/protocol/SetTimePacket.php b/src/pocketmine/network/protocol/SetTimePacket.php index d51ab23df..841f55b8e 100644 --- a/src/pocketmine/network/protocol/SetTimePacket.php +++ b/src/pocketmine/network/protocol/SetTimePacket.php @@ -27,16 +27,11 @@ namespace pocketmine\network\protocol; use pocketmine\level\Level; class SetTimePacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::SET_TIME_PACKET; public $time; public $started = true; - public function pid(){ - return Info::SET_TIME_PACKET; - } - public function decode(){ } diff --git a/src/pocketmine/network/protocol/StartGamePacket.php b/src/pocketmine/network/protocol/StartGamePacket.php index 5f3fcce91..fe1b92a70 100644 --- a/src/pocketmine/network/protocol/StartGamePacket.php +++ b/src/pocketmine/network/protocol/StartGamePacket.php @@ -25,8 +25,7 @@ namespace pocketmine\network\protocol; class StartGamePacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::START_GAME_PACKET; public $seed; public $generator; @@ -39,10 +38,6 @@ class StartGamePacket extends DataPacket{ public $y; public $z; - public function pid(){ - return Info::START_GAME_PACKET; - } - public function decode(){ } diff --git a/src/pocketmine/network/protocol/TakeItemEntityPacket.php b/src/pocketmine/network/protocol/TakeItemEntityPacket.php index cdc8fe648..09b0f2c0c 100644 --- a/src/pocketmine/network/protocol/TakeItemEntityPacket.php +++ b/src/pocketmine/network/protocol/TakeItemEntityPacket.php @@ -25,16 +25,11 @@ namespace pocketmine\network\protocol; class TakeItemEntityPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::TAKE_ITEM_ENTITY_PACKET; public $target; public $eid; - public function pid(){ - return Info::TAKE_ITEM_ENTITY_PACKET; - } - public function decode(){ } diff --git a/src/pocketmine/network/protocol/TextPacket.php b/src/pocketmine/network/protocol/TextPacket.php index a289e7152..fcd994717 100644 --- a/src/pocketmine/network/protocol/TextPacket.php +++ b/src/pocketmine/network/protocol/TextPacket.php @@ -25,8 +25,7 @@ namespace pocketmine\network\protocol; class TextPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::TEXT_PACKET; const TYPE_RAW = 0; const TYPE_CHAT = 1; @@ -39,10 +38,6 @@ class TextPacket extends DataPacket{ public $message; public $parameters = []; - public function pid(){ - return Info::TEXT_PACKET; - } - public function decode(){ $this->type = $this->getByte(); switch($this->type){ diff --git a/src/pocketmine/network/protocol/TileEntityDataPacket.php b/src/pocketmine/network/protocol/TileEntityDataPacket.php index e8f4bd888..853d50934 100644 --- a/src/pocketmine/network/protocol/TileEntityDataPacket.php +++ b/src/pocketmine/network/protocol/TileEntityDataPacket.php @@ -25,18 +25,13 @@ namespace pocketmine\network\protocol; class TileEntityDataPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::TILE_ENTITY_DATA_PACKET; public $x; public $y; public $z; public $namedtag; - public function pid(){ - return Info::TILE_ENTITY_DATA_PACKET; - } - public function decode(){ $this->x = $this->getInt(); $this->y = $this->getByte(); diff --git a/src/pocketmine/network/protocol/TileEventPacket.php b/src/pocketmine/network/protocol/TileEventPacket.php index 2f127c2ff..b46d2b5ec 100644 --- a/src/pocketmine/network/protocol/TileEventPacket.php +++ b/src/pocketmine/network/protocol/TileEventPacket.php @@ -25,8 +25,7 @@ namespace pocketmine\network\protocol; class TileEventPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::TILE_EVENT_PACKET; public $x; public $y; @@ -34,10 +33,6 @@ class TileEventPacket extends DataPacket{ public $case1; public $case2; - public function pid(){ - return Info::TILE_EVENT_PACKET; - } - public function decode(){ } diff --git a/src/pocketmine/network/protocol/UnknownPacket.php b/src/pocketmine/network/protocol/UnknownPacket.php deleted file mode 100644 index 9cdae867a..000000000 --- a/src/pocketmine/network/protocol/UnknownPacket.php +++ /dev/null @@ -1,46 +0,0 @@ - - - -class UnknownPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; - - public $packetID = -1; - - public function pid(){ - return $this->packetID; - } - - public function decode(){ - - } - - public function encode(){ - - } - -} \ No newline at end of file diff --git a/src/pocketmine/network/protocol/UpdateBlockPacket.php b/src/pocketmine/network/protocol/UpdateBlockPacket.php index 465bca1db..e7d398de3 100644 --- a/src/pocketmine/network/protocol/UpdateBlockPacket.php +++ b/src/pocketmine/network/protocol/UpdateBlockPacket.php @@ -25,8 +25,7 @@ namespace pocketmine\network\protocol; class UpdateBlockPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::UPDATE_BLOCK_PACKET; const FLAG_NONE = 0b0000; const FLAG_NEIGHBORS = 0b0001; @@ -39,10 +38,6 @@ class UpdateBlockPacket extends DataPacket{ public $records = []; //x, z, y, blockId, blockData, flags - public function pid(){ - return Info::UPDATE_BLOCK_PACKET; - } - public function decode(){ } diff --git a/src/pocketmine/network/protocol/UseItemPacket.php b/src/pocketmine/network/protocol/UseItemPacket.php index ead8d5237..316d879e9 100644 --- a/src/pocketmine/network/protocol/UseItemPacket.php +++ b/src/pocketmine/network/protocol/UseItemPacket.php @@ -25,8 +25,7 @@ namespace pocketmine\network\protocol; class UseItemPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; + const NETWORK_ID = Info::USE_ITEM_PACKET; public $x; public $y; @@ -42,10 +41,6 @@ class UseItemPacket extends DataPacket{ public $posY; public $posZ; - public function pid(){ - return Info::USE_ITEM_PACKET; - } - public function decode(){ $this->x = $this->getInt(); $this->y = $this->getInt(); diff --git a/src/raklib b/src/raklib index 675c7b0c9..88c47ff3e 160000 --- a/src/raklib +++ b/src/raklib @@ -1 +1 @@ -Subproject commit 675c7b0c98645c1c63505bcb94e8556412124e67 +Subproject commit 88c47ff3eca89dd369c9a4d575d40a777bda4ac8 diff --git a/src/spl b/src/spl index 0bea1c5d4..d59c0f673 160000 --- a/src/spl +++ b/src/spl @@ -1 +1 @@ -Subproject commit 0bea1c5d4003a3d0a8a38a9c2192bf9dcfc26f46 +Subproject commit d59c0f673455f02b2620853f3fa6290d63ffd960