diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 47c6f95bc..6ee2f6ff5 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -1628,7 +1628,7 @@ abstract class Entity{ $pk->attributes = $this->attributeMap->getAll(); $pk->metadata = $this->getSyncedNetworkData(false); - $player->sendDataPacket($pk); + $player->getNetworkSession()->sendDataPacket($pk); } /** @@ -1670,7 +1670,7 @@ abstract class Entity{ $id = spl_object_id($player); if(isset($this->hasSpawned[$id])){ if($send){ - $player->sendDataPacket(RemoveActorPacket::create($this->id)); + $player->getNetworkSession()->sendDataPacket(RemoveActorPacket::create($this->id)); } unset($this->hasSpawned[$id]); } @@ -1762,11 +1762,11 @@ abstract class Entity{ if($p === $this){ continue; } - $p->sendDataPacket(clone $pk); + $p->getNetworkSession()->sendDataPacket(clone $pk); } if($this instanceof Player){ - $this->sendDataPacket($pk); + $this->getNetworkSession()->sendDataPacket($pk); } } diff --git a/src/entity/Human.php b/src/entity/Human.php index 203a85b6b..5876e1fd7 100644 --- a/src/entity/Human.php +++ b/src/entity/Human.php @@ -405,7 +405,7 @@ class Human extends Living implements ProjectileSource, InventoryHolder{ protected function sendSpawnPacket(Player $player) : void{ if(!($this instanceof Player)){ - $player->sendDataPacket(PlayerListPacket::add([PlayerListEntry::createAdditionEntry($this->uuid, $this->id, $this->getName(), $this->skin)])); + $player->getNetworkSession()->sendDataPacket(PlayerListPacket::add([PlayerListEntry::createAdditionEntry($this->uuid, $this->id, $this->getName(), $this->skin)])); } $pk = new AddPlayerPacket(); @@ -418,7 +418,7 @@ class Human extends Living implements ProjectileSource, InventoryHolder{ $pk->pitch = $this->location->pitch; $pk->item = $this->getInventory()->getItemInHand(); $pk->metadata = $this->getSyncedNetworkData(false); - $player->sendDataPacket($pk); + $player->getNetworkSession()->sendDataPacket($pk); //TODO: Hack for MCPE 1.2.13: DATA_NAMETAG is useless in AddPlayerPacket, so it has to be sent separately $this->sendData($player, [EntityMetadataProperties::NAMETAG => new StringMetadataProperty($this->getNameTag())]); @@ -426,7 +426,7 @@ class Human extends Living implements ProjectileSource, InventoryHolder{ $player->getNetworkSession()->onMobArmorChange($this); if(!($this instanceof Player)){ - $player->sendDataPacket(PlayerListPacket::remove([PlayerListEntry::createRemovalEntry($this->uuid)])); + $player->getNetworkSession()->sendDataPacket(PlayerListPacket::remove([PlayerListEntry::createRemovalEntry($this->uuid)])); } } diff --git a/src/entity/object/ItemEntity.php b/src/entity/object/ItemEntity.php index 354819eec..698c21d90 100644 --- a/src/entity/object/ItemEntity.php +++ b/src/entity/object/ItemEntity.php @@ -240,7 +240,7 @@ class ItemEntity extends Entity{ $pk->item = $this->getItem(); $pk->metadata = $this->getSyncedNetworkData(false); - $player->sendDataPacket($pk); + $player->getNetworkSession()->sendDataPacket($pk); } public function onCollideWithPlayer(Player $player) : void{ diff --git a/src/entity/object/Painting.php b/src/entity/object/Painting.php index 8e96e3982..b9276755b 100644 --- a/src/entity/object/Painting.php +++ b/src/entity/object/Painting.php @@ -159,7 +159,7 @@ class Painting extends Entity{ $pk->direction = self::FACING_TO_DATA[$this->facing]; $pk->title = $this->motive; - $player->sendDataPacket($pk); + $player->getNetworkSession()->sendDataPacket($pk); } /** diff --git a/src/inventory/transaction/CraftingTransaction.php b/src/inventory/transaction/CraftingTransaction.php index 8b710278f..26694e16b 100644 --- a/src/inventory/transaction/CraftingTransaction.php +++ b/src/inventory/transaction/CraftingTransaction.php @@ -167,6 +167,6 @@ class CraftingTransaction extends InventoryTransaction{ * So people don't whine about messy desync issues when someone cancels CraftItemEvent, or when a crafting * transaction goes wrong. */ - $this->source->sendDataPacket(ContainerClosePacket::create(ContainerIds::NONE)); + $this->source->getNetworkSession()->sendDataPacket(ContainerClosePacket::create(ContainerIds::NONE)); } } diff --git a/src/player/Player.php b/src/player/Player.php index 566118ea6..7b010146d 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -84,7 +84,6 @@ use pocketmine\nbt\tag\ListTag; use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\protocol\ActorEventPacket; use pocketmine\network\mcpe\protocol\AnimatePacket; -use pocketmine\network\mcpe\protocol\ClientboundPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\MovePlayerPacket; use pocketmine\network\mcpe\protocol\SetTitlePacket; @@ -1902,20 +1901,6 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, $this->getWorld()->dropItem($this->location->add(0, 1.3, 0), $item, $this->getDirectionVector()->multiply(0.4), 40); } - /** - * @param ClientboundPacket $packet - * @param bool $immediate - * - * @return bool - */ - public function sendDataPacket(ClientboundPacket $packet, bool $immediate = false) : bool{ - if(!$this->isConnected()){ - return false; - } - - return $this->networkSession->sendDataPacket($packet, $immediate); - } - /** * Adds a title text to the user's screen, with an optional subtitle. * @@ -1930,7 +1915,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, if($subtitle !== ""){ $this->sendSubTitle($subtitle); } - $this->sendDataPacket(SetTitlePacket::title($title)); + $this->networkSession->sendDataPacket(SetTitlePacket::title($title)); } /** @@ -1939,7 +1924,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, * @param string $subtitle */ public function sendSubTitle(string $subtitle) : void{ - $this->sendDataPacket(SetTitlePacket::subtitle($subtitle)); + $this->networkSession->sendDataPacket(SetTitlePacket::subtitle($subtitle)); } /** @@ -1948,21 +1933,21 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, * @param string $message */ public function sendActionBarMessage(string $message) : void{ - $this->sendDataPacket(SetTitlePacket::actionBarMessage($message)); + $this->networkSession->sendDataPacket(SetTitlePacket::actionBarMessage($message)); } /** * Removes the title from the client's screen. */ public function removeTitles(){ - $this->sendDataPacket(SetTitlePacket::clearTitle()); + $this->networkSession->sendDataPacket(SetTitlePacket::clearTitle()); } /** * Resets the title duration settings to defaults and removes any existing titles. */ public function resetTitles(){ - $this->sendDataPacket(SetTitlePacket::resetTitleOptions()); + $this->networkSession->sendDataPacket(SetTitlePacket::resetTitleOptions()); } /** @@ -1974,7 +1959,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, */ public function setTitleDuration(int $fadeIn, int $stay, int $fadeOut){ if($fadeIn >= 0 and $stay >= 0 and $fadeOut >= 0){ - $this->sendDataPacket(SetTitlePacket::setAnimationTimes($fadeIn, $stay, $fadeOut)); + $this->networkSession->sendDataPacket(SetTitlePacket::setAnimationTimes($fadeIn, $stay, $fadeOut)); } }