Hey all, I want help please. I want to to make it so when I pick up a item from a virtual inventory (meaning I created a tile) it closes the window and sends a message. I have tried everything looked at other people plugins but never actually worked. Please guys can you provide me some code?
Yes, I can. PHP: public function onInventoryTransaction(InventoryTransactionEvent $event){ $chest = null; $player = null; $oldItemPlayer = null; $newItemPlayer = null; $oldItemChest = null; $newItemChest = null; $chestSlot = null; $playerSlot = null; $viewers = []; foreach($event->getTransaction()->getInventories() as $inventory){ if($inventory->getHolder() instanceof Player){ $player = $inventory->getHolder(); }else{ $chest = $inventory->getHolder(); $viewers = $inventory->getViewers(); } } foreach($event->getTransaction()->getAction() as $transaction){ if($oldItemChest === null and $newItemChest === null){ $oldItemChest = $transaction->getSourceItem(); $newItemChest = $transaction->getTargetItem(); }else{ $oldItemPlayer = $transaction->getSourceItem(); $newItemPlayer = $transaction->getTargetItem(); } if($chestSlot !== null){ $playerSlot = $transaction->getSlot(); }else{ $chestSlot = $transaction->getSlot(); } } if($player !== null and $chest !== null and $oldItemPlayer !== null and $newItemPlayer !== null and $oldItemChest !== null and $newItemChest !== null and $chestSlot !== null and $playerSlot !== null){ $action = $oldItemChest->getCount() > $newItemChest->getCount();//true if player take an item $diff = $action ? $oldItemChest->getCount() - $newItemChest->getCount() : $newItemChest->getCount() - $oldItemChest->getCount(); //TODO } }
You have to change PHP: $event->getTransaction()->getTransactions() to PHP: $event->getTransaction()->getActions() There was a API change
Thanks, I'm correct it. I just use only packets and not know about it. But update is really useless, many plugins who authors inactive won't work. And users of this plugins will spaming in this forum that plugins aren't works. Facepalm, PMMP
So, what do i do so when i pick up the bucket it closes the window and just send a message saying "hello" how would i do this code?
if($oldItemChest->getId() === Item::BUCKET){ $player->closeWindow($chest->getInventory()); $player->sendMessage("hello"); }
Thats wrong... it should be PHP: if($oldItemChest->getId() === 325){$player->closeWindow($chest->getInventory());$player->sendMessage("hello");}
Both ways are right (well they are mostly the same anyway). However @themestl 's way seems better. It tells the reader that the item we're talking about is a bucket.