1.8.8 Use ArmorEquipEvent

Discussion in 'Spigot Plugin Development' started by ZBLL, Jun 26, 2021.

Thread Status:
Not open for further replies.
  1. How do I use the ArmorEquipEvent, hosted here? Normally I would import such things with Maven, but I don't see how would I do it there. There's also a main class that I don't want to import (probably), since it extends JavaPlugin.
    #1 ZBLL, Jun 26, 2021
    Last edited: Jun 27, 2021
  2. If the project doesn't import anything into maven, the only way is to copy the code. Excluding main class
  3. So apparently I have to register ArmorListener and DispenserArmorListener, but ArmorListener requires an argument of List<String>... Oh my god.
  4. Just add the code to your project then create an event that uses the ArmorEquipEvent. Then you can access when a player puts on new armor or removes old armor. I used it for a custom enchant plugin and it works great!
  5. I have copied the files to my project. And do I have to register ArmorListener and DispenserArmorListener or I don't?
  6. Yes you do, in my case I just removed the list from the class and the constructor and also deleted lines 115 through 123 (in ArmorListener class ofc)
  7. So these are the lines that you want me to remove:
    Code (Java):

        if(e.getClickedBlock() != null && e.getAction() == Action.RIGHT_CLICK_BLOCK && !player.isSneaking()){// Having both of these checks is useless, might as well do it though.
            // Some blocks have actions when you right click them which stops the client from equipping the armor in hand.
            Material mat = e.getClickedBlock().getType();
            for(String s : blockedMaterials){
                if(mat.name().equalsIgnoreCase(s)) return;
    May you tell me why?
    Also, according to you I should make a constructor like this:
    Code (Java):

    public ArmorListener(){}
    Am I right?
  8. Because the author of the library wanted to allow devs/admins to have a blacklist of materials so the armor equip event wouldn't fire for those materials, for example a leather helmet, or a pumpkin (I think so at least, that's what I understand judging from the code, don't quote me) so if you don't want an item black list you just remvoe that part of the code.

    EDIT: Wrong. After reading the code again it is to prevent the event triggering when a player right clicks any block whose type is in the given list, for example if you right click a furnace or a door when holding an armor piece. Do your test and check if you actually need to do these checks or not. If you decide you want to check for clicked block's type I'd suggest you hardcode a list of strings from the library's config

    Yup, or just remove it because that's exactly equal to the default constructor
    #12 lelesape, Jun 27, 2021
    Last edited: Jun 27, 2021
  9. I just made a default constructor and it works. Thanks!
    • Friendly Friendly x 1
Thread Status:
Not open for further replies.