1.16.5 Armor equip event

Discussion in 'Spigot Plugin Development' started by Lukacizek, May 4, 2021.

  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. Would this work:
    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")) {
  6. As explained in the Javadocs: "This event is called when a player clicks in an inventory."
    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!
  7. 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
  8. You need to listen for InventoryClickEvent, InventoryDragEvent, PlayerInteractEvent (Holding in hand and right-clicking armor), and if you also want to include dispensers BlockDispenseArmorEvent.
  9. Strahan


    This is the real answer.

    Don't reinvent the wheel. His armor equip event works very well.
    • Agree Agree x 1
  10. 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.
  11. I think I used it in 1.16.2 without problems.
  12. No hopes for those API-s none of them work on 1.16.5 i just hate the fact that no one wants to make one that works for 1.16.5
  13. Strahan


    Works fine for me under 1.16.5

    EDIT: Wellll.... the plugin is using 1.16.5 in the buildpath, but I just realized my server's Spigot is older. I'll update and try again.
  14. Im literally gonna end up paying 1k$ on fiver for one that works on 1.16.5
  15. Strahan


    OK, tried it again with Spigot server, client and plugin all native on 1.16.5 and worked flawlessly.

    What is happening for you that makes you believe they aren't 1.16.5 compatible?

    PS: $1000 USD is major overpricing for this functionality.
  16. Well even if they are i cant chech the armor name which i need it says some stupid "required boolean"
  17. Strahan


    That's less than helpful. Post your actual code.