Hi, I am making a plugin that needs to check if a player has example a full diamond armor. PHP: if($player instanceof Player) { if ($armorCheck->getHelmet()->getCustomName() === "Helmet Of The Warrior" && $armorCheck->getChestplate()->getCustomName() === "Chestplate Of The Warrior" && $armorCheck->getLeggings()->getCustomName() === "Leggings Of The Warrior" && $armorCheck->getBoots()->getCustomName() === "Boots Of The Warrior") { //code } } But there is no event, I just want it to check when the player puts armor on it so I thought it would be in the EntityArmorChangeEvent so I wrote these lines in it and it doesn't work. probably because the second line was check if the new item had 4 different names at the same time (I was using the getNewItem() thingy. But I am wondering how to avoid the repeating task to know if a player has the "combo" of armor and check it directly when he wear armor. Thank you.
you can use InventoryTransactionEvent example PHP: <?phpnamespace Author/Plugin;use pocketmine\event\Listener;use pocketmine\item\Item;use pocketmine\player\Player;use pocketmine\event\inventory\InventoryTransactionEvent;use pocketmine\inventory\ArmorInventory;class EventListener implements Listener{ private $plugin; public function __construct(PluginMain $plugin){ $this->plugin = $plugin; } public function onTransaction(InventoryTransactionEvent $event){ if(!$event->getInventory() instanceof ArmorInventory) return; if(!$event->getInventory()->getHolder() instanceof Player) return; $boots = $event->getInventory()->getBoots(); if($boots->getName() == 'CustomName'){ //Do smth } }}?>?>
Call to undefined method pocketmine\inventory\transaction\InventoryTransaction::getInventory(); if I try with getInventories, it tells me that it tries to getBoots() on array.
But getInventory still a undefined mrthid for that event (I even just copedc pasted your code and it doesn't work
use this PHP: <?phpnamespace Author/Plugin;use pocketmine\event\Listener;use pocketmine\item\Item;use pocketmine\player\Player;use pocketmine\event\inventory\InventoryTransactionEvent;use pocketmine\inventory\ArmorInventory;use pocketmine\inventory\transaction\InventoryTransaction;class EventListener implements Listener{ private $plugin; public function __construct(PluginMain $plugin){ $this->plugin = $plugin; } public function onTransaction(InventoryTransactionEvent $event){ foreach($event->getTransactions()->getInventories() as $inventory){ if($inventory instanceof ArmorInventory){ $boots = $inventory->getInventory()->getBoots(); if($boots->getCustomName() == 'CustomName'){ //do smth } } } }}?> And you can use getActions and check if the inventory is instance of ArmorInventory anyway why are you trying to get Armor content?
Error: "Call to undefined method pocketmine\event\inventory\InventoryTransactionEvent::getTransactions()" I try to get it so if a player wear a certain armor (like if the player has TestHelmet, TestChesplate, TestLeggings and TestBoots, it gives him/her effects or just do something.
I guess using InventoryTransactionEvent for this case is a low-level move. It works but there's a lot you'd need to do to get to what EntityArmorChangeEvent already does. You are facing this issue because cancellable events are usually called before a change takes place (as they're supposed to). So, at the time the event gets called, the player still isn't wearing the new armor item. PHP: /** @var EntityArmorChangeEvent $event */$player = $event->getEntity();if($player instanceof Player){ $inventory = $player->getArmorInventory(); // $inventory contains the old armor} The event has $event->getSlot() and $event->getNewItem() that you can utilize to solve your issue. PHP: $inventory = $player->getArmorInventory();$new_armor = $inventory->getContents();$new_armor[$event->getSlot()] = $event->getNewItem();if(count($new_armor) === 4){ [$helmet, $chestplate, $leggings, $boots] = $new_armor; if($helmet->getCustomName() === ...){ // ... }}
So basically by using that if the player wear $helmet, $chestplate, $leggings and $boots, the code will run ?