Player Equip Armor Listener?

Is there a Listener for when a player equips a type of armor(specifically boots)

I am currently trying to set a players fly data if they are wearing a set of boots with specific lore according to them

public void onBootsEquipEvent(ChangeEntityEquipmentEvent.TargetPlayer e, @First Player player){

    player = e.getCause().last(Player.class).get();
    player.sendMessage(Text.of(TextColors.BLACK, "FIRED EVENT"));
    Optional<ItemStack> optionalStack = player.getBoots();
    Optional<FlyingData> optFlying = player.get(FlyingData.class);
    boolean isFlying = optFlying.isPresent() && optFlying.get().flying().get();
        ItemStack item = optionalStack.get();
                List<Text> lore = item.get(Keys.ITEM_LORE).get();
                for(int i = 0; i < lore.size();i++){


I also realized that I should check if the cause is a player. as I am testing the code and it wont be the final product I didn’t bother

Well, you would use the event you’re using, and then check if getItemStack has an EquipmentProperty for EquipmentTypes.BOOTS.

Other items of note:

  • The point of the event filter (@First Player player) is that it is an argument to the method. You don’t assign to it, you just use it.
    • On that note, the last is usually the opposite of what you want, which would be the first.
  • The player may or may not be the cause, but he will always be the result of getTargetEntity.
  • Rather than doing the Keys.ITEM_LORE lookup twice, you could just store the Optional and use it both times, and save some time and memory.
  • You could also just as easily check Keys.IS_FLYING instead of the thing with FlyingData.
  • A foreach loop is usually faster than a for loop, especially given that a get call may take varying amounts of processing depending on what implementation of List is used.

Hmmm… I’m still having trouble getting the event to even fire… I feel like im missing something really obvious and im sorry if i am… Here are my classes that im using

main class

listener class

So what you’re saying is that it doesn’t send you the message FIRED EVENT?

Also, I cannot help but notice that only one of my recommendations was followed. The most important one I would say is the one I started out with, especially given that it’s unlikely that the code will work without it.

I was and am still going to implement/follow your Recommendations. I was just still having trouble getting the event to fire in the first place

You happen to have a point. It does not appear to be implemented even in 1.12.

Alrighty! thanks for the information :slight_smile: Il try and implement your recommendations in mind when creating diffrent stuff