Skip to content

Commit 5e8483c

Browse files
committed
Ensure other forms of inventory close requests do not call listener during a pending dispatch
1 parent 767b718 commit 5e8483c

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/muqsit/invmenu/InvMenuEventHandler.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,13 @@ public function onInventoryClose(InventoryCloseEvent $event) : void{
8181

8282
$current = $session->current;
8383
if($current !== null && $event->getInventory() === $current->menu->getInventory()){
84-
$current?->graphic->remove($player);
84+
$current->graphic->remove($player);
8585
$session->current = null;
8686
}
8787
$session->network->wait(PlayerNetwork::DELAY_TYPE_ANIMATION_WAIT, static fn($success) => false);
88+
if($session->dispatcher !== null && $session->dispatcher->state === PlayerWindowDispatcher::STATE_SENDING && $session->dispatcher->info === $current){
89+
return;
90+
}
8891
$current?->menu->onClose($player);
8992
}
9093

src/muqsit/invmenu/session/PlayerSession.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ public function __construct(
2121
* @internal
2222
*/
2323
public function finalize() : void{
24+
$this->network->finalize();
25+
$this->dispatcher?->finalize(); // dispatcher finalized first, it has authority to nullify current
26+
$this->dispatcher = null;
2427
if($this->current !== null){
2528
$this->current->graphic->remove($this->player);
2629
$this->player->removeCurrentWindow();
30+
$this->current = null;
2731
}
28-
$this->network->finalize();
29-
$this->dispatcher?->finalize();
30-
$this->dispatcher = null;
3132
}
3233
}

0 commit comments

Comments
 (0)