How to create the listener, so it works? I tried several ways to create the InventoryTransactionEvent, but everytime it only worked for windows 10 players... This is my code: PHP: public function onInventoryTransaction(InventoryTransactionEvent $event) { $trans = $event->getTransaction()->getActions(); foreach($trans as $t) { $inv = $t->getInventory(); if($inv instanceof ChestInventory) { foreach($inv->getViewers() as $assumed) { if($assumed instanceof Player) { $p = $assumed; $cinv = $inv; $action = $t; break; } } } if($inv == null) return; $e->setCancelled(); $item = $action->getTargetItem(); if($item->getName() === "Test") { $sender->sendMessage("Whats this"); } } }
See how InvMenu does it https://github.com/Muqsit/InvMenu/b...431c/src/muqsit/invmenu/EventListener.php#L60 $inventoryAction->getSourceItem() is the item the player clicks in the chest inventory and $playerAction->getSourceItem() is the item the player puts in the chest inventory. Also, note. The code you're using is a very old code I wrote for ChestShop, it's only compatible with ALPHA7 or ALPHA9.
I had same bug, there are problem with two actions, at the android works first, and at the windows works second. You can get functional action by target item id. PHP: public function onInventoryTransaction(InventoryTransactionEvent $event) { $trans = $event->getTransaction()->getActions(); foreach($trans as $t) { $inv = $t->getInventory(); if($inv instanceof ChestInventory) { foreach($inv->getViewers() as $assumed) { if($assumed instanceof Player && $t->getTargetItem()->getId() !== 0) { $p = $assumed; $cinv = $inv; $action = $t; break; } } } if($inv == null) return; $event->setCancelled(); $item = $action->getTargetItem(); if($item->getName() === "Test") { $event->getPlayer()->sendMessage("Whats this"); } } }