InventoryManager: avoid feedback loop when closing inventory

This commit is contained in:
Dylan K. Taylor 2020-02-12 16:35:57 +00:00
parent b108fb61bf
commit 55e3b9ed91
2 changed files with 12 additions and 7 deletions

View File

@ -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){

View File

@ -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{