From ef816c0a52f4655aa0a9ffff065aa24b74a1e208 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 27 Jan 2018 11:00:08 +0000 Subject: [PATCH] Player: Fixed window ID of closing inventory always being -1 reported by @Muqsit, thank you sir --- src/pocketmine/Player.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 2d8814978..5ebe1e9b8 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -3773,17 +3773,18 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ * @throws \BadMethodCallException if trying to remove a fixed inventory window without the `force` parameter as true */ public function removeWindow(Inventory $inventory, bool $force = false){ - if(isset($this->windows[$hash = spl_object_hash($inventory)])){ - /** @var int $id */ - $id = $this->windows[$hash]; - if(!$force and isset($this->permanentWindows[$id])){ - throw new \BadMethodCallException("Cannot remove fixed window $id (" . get_class($inventory) . ") from " . $this->getName()); - } + $id = $this->windows[$hash = spl_object_hash($inventory)] ?? null; - unset($this->windows[$hash], $this->windowIndex[$id], $this->permanentWindows[$id]); + if($id !== null and !$force and isset($this->permanentWindows[$id])){ + throw new \BadMethodCallException("Cannot remove fixed window $id (" . get_class($inventory) . ") from " . $this->getName()); } $inventory->close($this); + + unset($this->windows[$hash]); + if($id !== null){ + unset($this->windowIndex[$id], $this->permanentWindows[$id]); + } } /**