diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index e0485e1ab..662c4ba02 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -207,8 +207,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ protected $xuid = ""; protected $windowCnt = 2; - /** @var \SplObjectStorage */ - protected $windows; + /** @var int[] */ + protected $windows = []; /** @var Inventory[] */ protected $windowIndex = []; /** @var bool[] */ @@ -685,7 +685,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ */ public function __construct(SourceInterface $interface, $clientID, string $ip, int $port){ $this->interface = $interface; - $this->windows = new \SplObjectStorage(); $this->perm = new PermissibleBase($this); $this->namedtag = new CompoundTag(); $this->server = Server::getInstance(); @@ -3327,7 +3326,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } $this->removeAllWindows(true); - $this->windows = null; + $this->windows = []; $this->windowIndex = []; $this->cursorInventory = null; $this->craftingGrid = null; @@ -3723,13 +3722,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ * @return int */ public function getWindowId(Inventory $inventory) : int{ - if($this->windows->contains($inventory)){ - /** @var int $id */ - $id = $this->windows[$inventory]; - return $id; - } - - return ContainerIds::NONE; + return $this->windows[spl_object_hash($inventory)] ?? ContainerIds::NONE; } /** @@ -3765,7 +3758,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $cnt = $forceId; } $this->windowIndex[$cnt] = $inventory; - $this->windows->attach($inventory, $cnt); + $this->windows[spl_object_hash($inventory)] = $cnt; if($inventory->open($this)){ if($isPermanent){ $this->permanentWindows[$cnt] = true; @@ -3787,15 +3780,14 @@ 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($this->windows->contains($inventory)){ + if(isset($this->windows[$hash = spl_object_hash($inventory)])){ /** @var int $id */ - $id = $this->windows[$inventory]; + $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()); } - $this->windows->detach($this->windowIndex[$id]); - unset($this->windowIndex[$id]); - unset($this->permanentWindows[$id]); + + unset($this->windows[$hash], $this->windowIndex[$id], $this->permanentWindows[$id]); } $inventory->close($this);