Muqsit/InvMenu

Recursive menu on close

BrandPVP opened this issue · 2 comments

$menu1 = InvMenu::create(InvMenu::TYPE_CHEST);
$menu1->setName("Menu");
$menu1->setInventoryCloseListener(function(Player $player, Inventory $inventory) use ($menu1){
	$menu1->send($player);
});
$menu1->send($player);

Is this not supposed to be working?

Make a delayed closure task that waits like 10 or something ticks before sending the next menu, you are sending it before the inventory actually fully closes the first on on the client side.

Muqsit commented

This is indeed a bug, sending menus during inventory close is intended to function properly. In the meantime, you may use the workaround provided by @TacoError:

$menu = InvMenu::create(InvMenu::TYPE_CHEST);
$menu->setInventoryCloseListener(function(Player $player, Inventory $inventory) use($menu, $plugin) : void{
	$plugin->getScheduler()->scheduleDelayedTask(new ClosureTask(function() use($player, $menu) : void{
		if($player->isConnected()){
			$menu->send($player);
		}
	}), 1);
});
$menu->send($player);