InvMenu icon indicating copy to clipboard operation
InvMenu copied to clipboard

Recursive menu on close

Open BrandPVP opened this issue 1 year ago • 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?

BrandPVP avatar Mar 26 '23 12:03 BrandPVP

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.

TacoError avatar Apr 04 '23 02:04 TacoError

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);

Muqsit avatar Apr 09 '23 13:04 Muqsit