Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive menu on close #205

Open
BrandPVP opened this issue Mar 26, 2023 · 2 comments
Open

Recursive menu on close #205

BrandPVP opened this issue Mar 26, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@BrandPVP
Copy link
Contributor

$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?

@TacoError
Copy link

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
Copy link
Owner

Muqsit commented Apr 9, 2023

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 Muqsit added the bug Something isn't working label Apr 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants