How can I cancell InventoryTransactionEvent, when player change hotbar item? For example, I would like, that clock always were in first Invntory bar slot. Something like this? PHP: public function onSlotChange(InventoryTransactionEvent $event) { $newItem = null; $player = null; $transactions = $event->getQueue()->getTransactions(); foreach ($transactions as $tr){ if ($tr->getTargetItem() instanceof Item) $newItem = $tr->getTargetItem(); if ($tr->getInventory() instanceof PlayerInventory) $player = $tr->getInventory()->getHolder(); } if ($player != null && $newItem != null){ $lastItem = $player->getInventory()->getItemInHand(); if ($lastItem->getId() == 347 && $newItem->getId() != 347){ //compas $event->setCancelled(); } }}
Ops, event is works. I.e items don't drop, but items remove from Invntory bar, and appear in player inventory ;C