Skip to content

Recursive menu on close #205

@BrandPVP

Description

@BrandPVP
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?

Activity

TacoError

TacoError commented on Apr 4, 2023

@TacoError

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

Muqsit commented on Apr 9, 2023

@Muqsit
Owner

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 commented on Jun 28, 2025

@Muqsit
Owner

Your code snippet should work now. The new delay strategy adopted in InvMenu v4.7.0 f7f1beb takes care of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Muqsit@TacoError@BrandPVP

        Issue actions

          Recursive menu on close · Issue #205 · Muqsit/InvMenu