What’s the most efficient way to get all the enchantments of a player as like the all armor enchantments and enchantments on the item the player is currently holding.
Fair warning. This is example code. I don't recommend copying it. through the Player class, use getArmorInventory() to get the armor slots, then use the getAll() or whatever the equivalent function is to get an array output of the items in the slots. next loop through each of their enchantments and add them to an array variable. To get the item in the player's hand, go through the Player class to getInventory() to the the actual inventory. Then, get use the getItemInHand() function to get the item in hand. This description is shown in the following code. $list is the output enchantment list PHP: foreach($player->getArmorInventory()->getAll() as $item) { foreach($item->getEnchantments() as $Enchantment) { $list[] = $enchantment; }}foreach($player->getInventory()->getItemInHand()->getEnchantments() as $enchantment) { $list[] = $enchantment;}
That's what I do right now but I'm asking if there's any other way. A way that I can cache the enchantments.
save the enchantment instance to a private array in the class you are doing your comparison? then update on inventory transaction event (good luck with that though)