Player: Fixed window ID of closing inventory always being -1

reported by @Muqsit, thank you sir
This commit is contained in:
Dylan K. Taylor 2018-01-27 11:00:08 +00:00
parent 3e35bc38e2
commit ef816c0a52

View File

@ -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]);
}
}
/**