ok so am using EntityInventoryChangeEvent to make a CrateKey plugin , now when a player taps a glass pane the event is cancelled which means they can't do anything with that item, but the item also removes , how can i make the item not remove but still players can't touch it or put it into their inventory? PHP: public function onWin(EntityInventoryChangeEvent $event){ $p = $event->getEntity(); $win = $event->getNewItem(); if($win->getId() === 102 and $win->getCustomName() === ""){ if($p instanceof Player){ $item = Item::get(103, 0, 1)->setCustomName(""); $event->setNewItem($item); $event->setCancelled(true); } } }
The item is still in the inventory, the item just goes invisible after you cancel the event. Just get the items slot & reset the item back in the slot
So InventoryTransactionEvent, PHP: public function onTransaction(InventoryTransactionEvent $event){ $transactions = $event->getTransaction()->getTransactions(); $inventories = $event->getTransaction()->getInventories(); foreach($transactions as $trans){ foreach($inventories as $invs){ if($invs instanceof PlayerInventory){ $item = $trans->getTargetItem(); if($item->getId() === 102 and $item->getCustomName() === ""){ $event->setCancelled(true); } } } }} Learn what this does to understand, then continue.