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

Can't open inventory after InvMenu inventory close #116

Closed
CupidonSauce173 opened this issue Dec 15, 2020 · 3 comments
Closed

Can't open inventory after InvMenu inventory close #116

CupidonSauce173 opened this issue Dec 15, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@CupidonSauce173
Copy link

CupidonSauce173 commented Dec 15, 2020

After the player interact with an item in the InvMenu inventory, it sends them to a form (from FormAPI) but then the inventories doesn't show up (normal player inventory & InvMenu inventory)

Here's the code

public function sendChest(Player $player, string $shop){
    $menu = InvMenu::create(InvMenu::TYPE_DOUBLE_CHEST);
    $menu->setName($shop);
    $menu->readonly();
    $inventory = $menu->getInventory();
    $items = Shop::getShopItems('Armor');
    /** @var Item $item */
    foreach ($items as $item){
        $data = $item->getLore();
        $inventory->addItem($item->setLore(["Price: $data[0]", "Stored: $data[2]", "Shop ID: $data[3]", "ChestSlot: $data[1]"]));
    }
    $menu->setListener(function (InvMenuTransaction $invMenuTransaction) use ($shop) : InvMenuTransactionResult{
        $invMenuTransaction->getPlayer()->removeWindow($invMenuTransaction->getAction()->getInventory());
        $itemTakenOut = $invMenuTransaction->getItemClicked();
        return $invMenuTransaction->discard()->then(function (Player $player) use ($shop, $invMenuTransaction, $itemTakenOut): void{
            if(!$itemTakenOut->isNull()){
                $this->onBuy($itemTakenOut, $player, $shop);
            }
        });
    });
    $menu->send($player);
}
@CupidonSauce173
Copy link
Author

If the player doesn't interact with anything and just manually closes the inventory, then they will be able to open their inventory again. It's only when they do interact with something.

@Muqsit Muqsit added the bug Something isn't working label Dec 15, 2020
@Muqsit
Copy link
Owner

Muqsit commented Dec 15, 2020

See if it works if you remove this line:

$invMenuTransaction->getPlayer()->removeWindow($invMenuTransaction->getAction()->getInventory());

Edit: Nevermind, I thought onBuy was sending an inventory. Try with the InvCrashFix plugin (https://github.com/Muqsit/InvCrashFix).

@CupidonSauce173
Copy link
Author

Perfect, it worked.

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

2 participants