From 55e3b9ed91138dfbd28cca9f100f0c4802736845 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 12 Feb 2020 16:35:57 +0000 Subject: [PATCH] InventoryManager: avoid feedback loop when closing inventory --- src/network/mcpe/InventoryManager.php | 10 ++++++++++ src/network/mcpe/handler/InGamePacketHandler.php | 9 ++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/network/mcpe/InventoryManager.php b/src/network/mcpe/InventoryManager.php index 7c8731f4a..1348e8a5f 100644 --- a/src/network/mcpe/InventoryManager.php +++ b/src/network/mcpe/InventoryManager.php @@ -137,6 +137,16 @@ class InventoryManager{ } } + public function onClientRemoveWindow(int $id) : void{ + if($id === $this->lastInventoryNetworkId){ + unset($this->windowMap[$id]); + unset($this->initiatedSlotChanges[$id]); + $this->player->removeCurrentWindow(); + }else{ + $this->session->getLogger()->debug("Attempted to close inventory with network ID $id, but current is $this->lastInventoryNetworkId"); + } + } + public function syncSlot(Inventory $inventory, int $slot) : void{ $windowId = $this->getWindowId($inventory); if($windowId !== null){ diff --git a/src/network/mcpe/handler/InGamePacketHandler.php b/src/network/mcpe/handler/InGamePacketHandler.php index eac748203..045e48bc3 100644 --- a/src/network/mcpe/handler/InGamePacketHandler.php +++ b/src/network/mcpe/handler/InGamePacketHandler.php @@ -496,14 +496,9 @@ class InGamePacketHandler extends PacketHandler{ return true; } - $window = $this->player->getCurrentWindow(); - if($window !== null and $packet->windowId === $this->session->getInvManager()->getCurrentWindowId()){ - $this->player->removeCurrentWindow(); - return true; - } + $this->session->getInvManager()->onClientRemoveWindow($packet->windowId); - $this->session->getLogger()->debug("Attempted to close inventory with network ID $packet->windowId, but current is " . $this->session->getInvManager()->getCurrentWindowId()); - return false; + return true; } public function handlePlayerHotbar(PlayerHotbarPacket $packet) : bool{