hey , how can i do Inventory Transactions , i want the player to hit a clock in a chest inventory and get a chain armor piece.
Transactions can be a bit confusing. You can listen for InventoryTransactionEvent, then do event->getTransaction()->getTransactions(), because the event is confusing like that. You can foreach the transactions, then get the inventory, the target item, etc. You will learn more by looking in the source or by reading the API docs. I also may be wrong on this, so feel free to check me.
There was a plugin named ChestShop made by @Muqsit , he showed a really good way to do InventoryTransactionEvent PHP: public function onTransaction(InventoryTransactionEvent $event){ $transactions = $event->getTransaction()->getTransactions(); $player = null; $chestinv = null; $action = null; foreach($transactions as $transaction){ if(($inv = $transaction->getInventory()) instanceof CustomChestInventory){ foreach($inv->getViewers() as $assumed){ if($assumed instanceof Player){ $player = $assumed; $chestinv = $inv; $action = $transaction; break 2; } } } } /* * $player => Player interacting with the GUI. * $chestinv => The chest's inventory. * $action => BaseTransaction|Transaction|SimpleTransactionGroup */ if($chestinv === null) return; // code }
am kinda confused on what todo on code , PHP: if($player->getInventory()->getTargetItem() === ITEM::CLOCK){\\?