Player: call InventoryCloseEvent after doing the necessary business

closes #4626

this does change the behaviour of getCurrentWindow() during InventoryCloseEvent, but no one should be using that anyway, since InventoryCloseEvent->getInventory() exists.
This commit is contained in:
Dylan K. Taylor 2022-05-21 19:23:05 +01:00
parent 02cf6ae46c
commit 1181b13b5d
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -2502,14 +2502,14 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
public function removeCurrentWindow() : void{ public function removeCurrentWindow() : void{
$this->doCloseInventory(); $this->doCloseInventory();
if($this->currentWindow !== null){ if($this->currentWindow !== null){
(new InventoryCloseEvent($this->currentWindow, $this))->call(); $currentWindow = $this->currentWindow;
$this->logger->debug("Closing inventory " . get_class($this->currentWindow) . "#" . spl_object_id($this->currentWindow)); $this->logger->debug("Closing inventory " . get_class($this->currentWindow) . "#" . spl_object_id($this->currentWindow));
$this->currentWindow->onClose($this); $this->currentWindow->onClose($this);
if(($inventoryManager = $this->getNetworkSession()->getInvManager()) !== null){ if(($inventoryManager = $this->getNetworkSession()->getInvManager()) !== null){
$inventoryManager->onCurrentWindowRemove(); $inventoryManager->onCurrentWindowRemove();
} }
$this->currentWindow = null; $this->currentWindow = null;
(new InventoryCloseEvent($currentWindow, $this))->call();
} }
} }