@EventHandler
public void inventoryClick(InventoryClickEvent event) {
Inventory inventory = event.getInventory();
if (!didPlayerClickOwnInventory((Player) event.getWhoClicked(), inventory))
return;
ItemStack item = event.getCurrentItem();
Player player = (Player) inventory.getHolder();
ItemStack cursor = event.getCursor();
if (event.getSlotType() == InventoryType.SlotType.ARMOR) {
if (item != null && item.getType() != Material.AIR
&& (cursor == null || cursor.getType() == Material.AIR || isArmor(cursor))) {
if (playerUnequipsArmorEvent(player, item, "INVENTORY")) {
event.setCancelled(true);
return;
}
}
if (cursor != null && cursor.getType() != Material.AIR && isArmor(cursor)) {
if (playerEquipsArmorEvent(player, cursor, "INVENTORY")) {
event.setCancelled(true);
return;
}
}
}
else if (event.getClick().isShiftClick() && item != null && isArmor(item)) {
ItemStack currentItem = player.getInventory().getArmorContents()[getArmorTypeNumber(item)];
if (currentItem == null || currentItem.getType() == Material.AIR) {
if (playerEquipsArmorEvent(player, item, "INVENTORY")) {
event.setCancelled(true);
return;
}
}