1.16.x Armor equip event

Discussion in 'Spigot Plugin Development' started by Lukacizek, May 4, 2021 at 6:43 PM.

  1. Does anyone know how to make an action happen when a player equips/disequips a certain armor piece
     
  2. Would say PlayerArmorChangeEvent but that's not a spigot api thing. :D
     
  3. You could check in the interact event, if he rightclicked, and than get the item in players hand, and check if it is a armor piece
     
  4. Expanding on this, what I did was to check for Interact event, then run check for armour 1 tick later. If you don't check 1 tick later, you will not get the updated value.
     
  5. Can anyone send me the code im junior at java
     
  6. Would this work:
    @EventHandler
    public void onWear(InventoryClickEvent e) {
    Player p = (Player) e.getWhoClicked();
    if (p instanceof Player) {
    if (utils.checkSet(p, "Superior Armor")) {
    p.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, -1, 1));
    } else if (!utils.checkSet(p, "Superior Armor")) {
    p.removePotionEffect(PotionEffectType.INCREASE_DAMAGE);
    }
    }
    }
     
  7. As explained in the Javadocs: "This event is called when a player clicks in an inventory."
    https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/inventory/InventoryClickEvent.html
    This would fire when the player clicks the armor, not necessarily wearing it.

    I would check each time InventoryMoveItemEvent and PlayerInteractEvent for the slots 100-103(armor slots), get their ItemStack, and check if they equal the armor you want.

    Let me know if it helps!
     
  8. Please use the SpigotMC feature, to paste code. Click on the + if you send a message, than on code, than paste your code there.
     
    • Winner Winner x 1
  9. You need to listen for InventoryClickEvent, InventoryDragEvent, PlayerInteractEvent (Holding in hand and right-clicking armor), and if you also want to include dispensers BlockDispenseArmorEvent.
     
  10. Strahan

    Benefactor

    This is the real answer.

    Don't reinvent the wheel. His armor equip event works very well.
     
  11. This is a little bit different, but what I do on my plugin is that instead of listening to other inventory thingy event, I just listen to InventoryCloseEvent and loop on armor contents to check which armor got equip or disequip, downside is that it won't detect players that equips armor using right click until they open > close their inventory, to fix this just do a PlayerInteractEvent, see if the item in main hand is armor.