diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index 6328360da3..204361799a 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -116,7 +116,9 @@ abstract class BaseInventory implements Inventory{ } if($send){ - $this->sendContents($this->getViewers()); + foreach($this->getViewers() as $viewer){ + $viewer->getNetworkSession()->syncInventoryContents($this); + } } } @@ -380,34 +382,9 @@ abstract class BaseInventory implements Inventory{ $listener->onSlotChange($this, $index); } if($send){ - $this->sendSlot($index, $this->getViewers()); - } - } - - /** - * @param Player|Player[] $target - */ - public function sendContents($target) : void{ - if($target instanceof Player){ - $target = [$target]; - } - - foreach($target as $player){ - $player->getNetworkSession()->syncInventoryContents($this); - } - } - - /** - * @param int $index - * @param Player|Player[] $target - */ - public function sendSlot(int $index, $target) : void{ - if($target instanceof Player){ - $target = [$target]; - } - - foreach($target as $player){ - $player->getNetworkSession()->syncInventorySlot($this, $index); + foreach($this->viewers as $viewer){ + $viewer->getNetworkSession()->syncInventorySlot($this, $index); + } } } diff --git a/src/pocketmine/inventory/ContainerInventory.php b/src/pocketmine/inventory/ContainerInventory.php index bc827dd760..ee8dfe7e00 100644 --- a/src/pocketmine/inventory/ContainerInventory.php +++ b/src/pocketmine/inventory/ContainerInventory.php @@ -49,7 +49,7 @@ abstract class ContainerInventory extends BaseInventory{ $who->sendDataPacket(ContainerOpenPacket::blockInv($windowId, $this->getNetworkType(), $holder->getFloorX(), $holder->getFloorY(), $holder->getFloorZ())); } - $this->sendContents($who); + $who->getNetworkSession()->syncInventoryContents($this); } protected function onClose(Player $who) : void{ diff --git a/src/pocketmine/inventory/Inventory.php b/src/pocketmine/inventory/Inventory.php index 8260b5943b..d393a3e25f 100644 --- a/src/pocketmine/inventory/Inventory.php +++ b/src/pocketmine/inventory/Inventory.php @@ -107,17 +107,6 @@ interface Inventory{ */ public function setContents(array $items, bool $send = true) : void; - /** - * @param Player|Player[] $target - */ - public function sendContents($target) : void; - - /** - * @param int $index - * @param Player|Player[] $target - */ - public function sendSlot(int $index, $target) : void; - /** * Checks if the inventory contains any Item with the same material data. * It will check id, amount, and metadata (if not null) diff --git a/src/pocketmine/inventory/PlayerInventory.php b/src/pocketmine/inventory/PlayerInventory.php index 206ad8660a..909fd3ff2e 100644 --- a/src/pocketmine/inventory/PlayerInventory.php +++ b/src/pocketmine/inventory/PlayerInventory.php @@ -137,12 +137,12 @@ class PlayerInventory extends BaseInventory{ if(!is_array($target)){ $target->sendDataPacket($pk); if($target === $this->getHolder()){ - $this->sendSlot($this->getHeldItemIndex(), $target); + $target->getNetworkSession()->syncInventorySlot($this, $this->getHeldItemIndex()); } }else{ $this->getHolder()->getWorld()->getServer()->broadcastPacket($target, $pk); if(in_array($this->getHolder(), $target, true)){ - $this->sendSlot($this->getHeldItemIndex(), $this->getHolder()); + $target->getNetworkSession()->syncInventorySlot($this, $this->getHeldItemIndex()); } } } diff --git a/src/pocketmine/inventory/transaction/InventoryTransaction.php b/src/pocketmine/inventory/transaction/InventoryTransaction.php index d57a9fa1f0..02158c22b3 100644 --- a/src/pocketmine/inventory/transaction/InventoryTransaction.php +++ b/src/pocketmine/inventory/transaction/InventoryTransaction.php @@ -282,7 +282,7 @@ class InventoryTransaction{ protected function sendInventories() : void{ foreach($this->inventories as $inventory){ - $inventory->sendContents($this->source); + $this->source->getNetworkSession()->syncInventoryContents($inventory); } } diff --git a/src/pocketmine/inventory/transaction/action/SlotChangeAction.php b/src/pocketmine/inventory/transaction/action/SlotChangeAction.php index 670c4cdb51..8cf2f5f4e3 100644 --- a/src/pocketmine/inventory/transaction/action/SlotChangeAction.php +++ b/src/pocketmine/inventory/transaction/action/SlotChangeAction.php @@ -27,7 +27,6 @@ use pocketmine\inventory\Inventory; use pocketmine\inventory\transaction\InventoryTransaction; use pocketmine\item\Item; use pocketmine\Player; -use function spl_object_id; /** * Represents an action causing a change in an inventory slot. @@ -110,9 +109,9 @@ class SlotChangeAction extends InventoryAction{ * @param Player $source */ public function onExecuteSuccess(Player $source) : void{ - $viewers = $this->inventory->getViewers(); - unset($viewers[spl_object_id($source)]); - $this->inventory->sendSlot($this->inventorySlot, $viewers); + foreach($this->inventory->getViewers() as $viewer){ + $viewer->getNetworkSession()->syncInventorySlot($this->inventory, $this->inventorySlot); + } } /** @@ -121,6 +120,6 @@ class SlotChangeAction extends InventoryAction{ * @param Player $source */ public function onExecuteFail(Player $source) : void{ - $this->inventory->sendSlot($this->inventorySlot, $source); + $source->getNetworkSession()->syncInventorySlot($this->inventory, $this->inventorySlot); } } diff --git a/src/pocketmine/network/mcpe/handler/InGameSessionHandler.php b/src/pocketmine/network/mcpe/handler/InGameSessionHandler.php index 6e1bd11c31..9323ccb0d5 100644 --- a/src/pocketmine/network/mcpe/handler/InGameSessionHandler.php +++ b/src/pocketmine/network/mcpe/handler/InGameSessionHandler.php @@ -339,7 +339,7 @@ class InGameSessionHandler extends SessionHandler{ switch($data->getActionType()){ case ReleaseItemTransactionData::ACTION_RELEASE: if(!$this->player->releaseHeldItem()){ - $this->player->getInventory()->sendContents($this->player); + $this->session->syncInventoryContents($this->player->getInventory()); } return true; case ReleaseItemTransactionData::ACTION_CONSUME: