Sadly Spigot does not have an event for checking when a Player is changing armor.
Arnuh put a good base with his project, but there were still a lot of bugs.
This plugin should be bug free and working properly, but if you still find some
please report them. Thank you!
The events handle when a player
- Equip or unequip item in opened inventory through
- Click
- Double click (collect to cursor)
- Shift-click
- Drop item (Q)
- Hotswap with hotbar(1-9) or with second hand(F)
- Dragged item
- Equip item through hotbar right-click
- Equip item by Dispenser
- Unequip when Player dies
- Unequip when armor item breaks
It could be that some things changed in newer versions.
As said before if you find bugs please report them. Thank you!
All armor events of this plugin are Cancellable
. The ArmorAction
gives you info
how the armor was equipped or unequipped. When checking in which slot the item
was equipped or unequipped use the getArmorSlot()
method.
This event is called when a Player is equipping armor.
In this example we give the Player the jump boost effect when he equips iron boots.
@EventHandler
private void onArmorEquipEvent(ArmorEquipEvent e) {
if (e.getItem().getType() == Material.IRON_BOOTS) {
PotionEffect effect = new PotionEffect(PotionEffectType.JUMP, 1000000, 2);
e.getPlayer().addPotionEffect(effect);
}
...
}
This event is called when a Player is fully unequipping an item out of the armor
slot. This means it will only be called when the armor slot is empty. In example,
you custom equipped a stack (64 items) of dirt on the boots slot and take half of it,
it will not count as an unequip event.
And here we remove the jump boost effect when the Player unequips iron boots.
@EventHandler
private void onArmorUnequipEvent(ArmorUnequipEvent e) {
if (e.getAction() == ArmorAction.DEATH) return;
if (e.getItem().getType() == Material.IRON_BOOTS) {
e.getPlayer().removePotionEffect(PotionEffectType.JUMP);
}
...
}
Have fun coding ❤️🦊