diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 7d44ed42d..82b4cb221 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2594,7 +2594,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, $this->sendData($this->getViewers()); $this->networkSession->syncAdventureSettings($this); - $this->sendAllInventories(); + $this->networkSession->syncAllInventoryContents(); $this->spawnToAll(); $this->scheduleUpdate(); @@ -2878,10 +2878,11 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, } } - public function sendAllInventories(){ - foreach($this->windowIndex as $networkId => $inventory){ - $inventory->sendContents($this); - } + /** + * @return Inventory[] + */ + public function getAllWindows() : array{ + return $this->windowIndex; } public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue) : void{ diff --git a/src/pocketmine/network/mcpe/NetworkSession.php b/src/pocketmine/network/mcpe/NetworkSession.php index b2327c587..4b7ee563c 100644 --- a/src/pocketmine/network/mcpe/NetworkSession.php +++ b/src/pocketmine/network/mcpe/NetworkSession.php @@ -819,6 +819,12 @@ class NetworkSession{ } } + public function syncAllInventoryContents() : void{ + foreach($this->player->getAllWindows() as $inventory){ + $this->syncInventoryContents($inventory); + } + } + public function syncInventoryData(Inventory $inventory, int $propertyId, int $value) : void{ $windowId = $this->player->getWindowId($inventory); if($windowId !== ContainerIds::NONE){ diff --git a/src/pocketmine/network/mcpe/handler/InGameSessionHandler.php b/src/pocketmine/network/mcpe/handler/InGameSessionHandler.php index 619482037..6393e48e6 100644 --- a/src/pocketmine/network/mcpe/handler/InGameSessionHandler.php +++ b/src/pocketmine/network/mcpe/handler/InGameSessionHandler.php @@ -158,7 +158,7 @@ class InGameSessionHandler extends SessionHandler{ public function handleInventoryTransaction(InventoryTransactionPacket $packet) : bool{ if($this->player->isSpectator()){ - $this->player->sendAllInventories(); + $this->session->syncAllInventoryContents(); return true; } @@ -167,7 +167,7 @@ class InGameSessionHandler extends SessionHandler{ if($packet->trData instanceof NormalTransactionData){ $result = $this->handleNormalTransaction($packet->trData); }elseif($packet->trData instanceof MismatchTransactionData){ - $this->player->sendAllInventories(); + $this->session->syncAllInventoryContents(); $result = true; }elseif($packet->trData instanceof UseItemTransactionData){ $result = $this->handleUseItemTransaction($packet->trData); @@ -178,7 +178,7 @@ class InGameSessionHandler extends SessionHandler{ } if(!$result){ - $this->player->sendAllInventories(); + $this->session->syncAllInventoryContents(); } return $result; } diff --git a/src/pocketmine/network/mcpe/handler/PreSpawnSessionHandler.php b/src/pocketmine/network/mcpe/handler/PreSpawnSessionHandler.php index 1d69a38d0..3659a55b9 100644 --- a/src/pocketmine/network/mcpe/handler/PreSpawnSessionHandler.php +++ b/src/pocketmine/network/mcpe/handler/PreSpawnSessionHandler.php @@ -91,7 +91,7 @@ class PreSpawnSessionHandler extends SessionHandler{ $this->player->sendPotionEffects($this->player); $this->player->sendData($this->player); - $this->player->sendAllInventories(); + $this->session->syncAllInventoryContents(); $this->player->getInventory()->sendCreativeContents(); $this->player->getInventory()->sendHeldItem($this->player); $this->session->queueCompressed($this->server->getCraftingManager()->getCraftingDataPacket());