This is how I use it on my plugin: PHP: public function onInvTrans(InventoryTransactionEvent $event){$chest = null;$player = null;$transa = $event->getTransaction()->getTransactions();$int = $event->getTransaction()->getInventories(); foreach ($transa as $t) { foreach ($int as $inst) { $inst = $inst->getHolder(); if ($inst instanceof Player) { $player = $inst; } if ($inst instanceof Chest) { $chest = $inst; }}$trans = $t;} if($chest == null || $player == null) return;} That's how you get the player and the chest of the event. To get the item which was transfered: PHP: $item = $event->getTargetItem(); More API functions you can look up here: https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/inventory/Transaction.php https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/inventory/TransactionGroup.php
I'm not using an IDE too, but that's no excuse for bad code formatting. You should always have proper formatted code, it can save you days of searching for errors
And it can gain you more people willing to read your code. JuStLiKeNoBoDyWaNtStOrEaDtExTwRiTtEnLiKeThIs.
So somthing like this? PHP: public function onTrans(InventoryTransactionEvent $ev){ $chest = null; $player = null; $trans = $ev->getTransaction()->getTransactions(); $int = $ev->getTransatctions()->getInventorys(); foreach($trans as $t){{ foreach($int as $inst){ $inst = $inst->getHolder(); if($inst instanceof Player){ $player = $inst; } if($inst instanceof Hopper){ $hopper = $inst; } } $trans = $t; $item = $ev->getTargetItem(); if($item->getId() == 377){ $player->sendMessage(c::BOLD.c::DARK_PURPLE."(!)".c::RESET.c::DARK_AQUA." Comming soon"); } } }
What editor are you using? Proper ones help you with formating, and some can even format it for you, while not being an IDE. Formatting is totally simple: Always add one level of indentation in one scope. When the scope ends, go one level back.
i disagree there no issue with unformatted code but ununified indents/inconsistent code style not everyone have the luxury to have an IDE but i agree to correct bad practice on term of code
This happens evertime I open the inventory [05:21:24] [Server thread/CRITICAL]: "Could not pass event 'pocketmine\event\inventory\InventoryTransactionEvent' to 'BuyCraft_Addon v0.1': Call to undefined method pocketmine\event\inventory\InventoryTransactionEvent::getTransatctions() on RoyalMCPE\BuyCraftAddon\Main [05:21:24] [Server thread/CRITICAL]: Error: "Call to undefined method pocketmine\event\inventory\InventoryTransactionEvent::getTransatctions()" (EXCEPTION) in "/plugins/BuyCraftAddon_v0.1/src/RoyalMCPE/BuyCraftAddon/Main" at line 69
Just in case you're unaware, there was a typo in InventoryTransactionEvent::getTransatctions(). It should be InventoryTransactionEvent::getTransactions().