Problem description. I use InventoryTransactionEvent and I check if player click the item with id 264, server send message to player, but when server send message is duplicated. How to reproduce the bug. Use my code: public function transactionEvent(\pocketmine\event\inventory\InventoryTransactionEvent $e){ foreach($e->getTransaction()->getTransactions() as $transaction){ foreach($e->getTransaction()->getInventories() as $inv){ if($inv->getHolder() instanceof \pocketmine\Player) $p = $inv->getHolder(); elseif($inv->getHolder() instanceof \pocketmine\tile\Chest) $chest = $inv->getHolder(); if($transaction->getTargetItem()->getId() == 264){ $p->sendMessage("message"); }}}}
PHP: public function transactionEvent(\pocketmine\event\inventory\InventoryTransactionEvent $e){foreach($e->getTransaction()->getTransactions() as $transaction){foreach($e->getTransaction()->getInventories() as $inv){if($inv->getHolder() instanceof \pocketmine\Player) $p = $inv->getHolder();elseif($inv->getHolder() instanceof \pocketmine\tile\Chest) $chest = $inv->getHolder();if($transaction->getTargetItem()->getId() == 264){$p->sendMessage("message");}}}}
Just add break; below the $p->sendMessage("message");. I'm not sure why you foreach the inventories, but you probably have your reasons.
It's my understanding that when you take an item from a chest, 2 transactions are made. 1) The item is removed from the Chest, 2) The item is added to the Player's inventory. So when you foreach and check if the target item has a specific ID, your message is sent twice.