Solved Problem with InventoryClickEvent

Discussion in 'Spigot Plugin Development' started by Toloxus, Jul 1, 2018.

Thread Status:
Not open for further replies.
  1. Hi guys i have a problem with this code. I want to InventoryClickEvent was fired when item goes into armor slot.

    Code (Java):
        EnumSet<Material> armors = EnumSet.of(
                Material.LEATHER_HELMET, Material.LEATHER_CHESTPLATE, Material.LEATHER_LEGGINGS, Material.LEATHER_BOOTS, Material.CHAINMAIL_HELMET,
                Material.CHAINMAIL_CHESTPLATE, Material.CHAINMAIL_LEGGINGS, Material.CHAINMAIL_BOOTS, Material.IRON_HELMET, Material.IRON_CHESTPLATE,
                Material.IRON_LEGGINGS, Material.IRON_BOOTS, Material.GOLD_HELMET, Material.GOLD_CHESTPLATE, Material.GOLD_LEGGINGS, Material.GOLD_BOOTS,
                Material.DIAMOND_HELMET, Material.DIAMOND_CHESTPLATE, Material.DIAMOND_LEGGINGS, Material.DIAMOND_BOOTS);
     
        @EventHandler
        public void playerInteract(PlayerInteractEvent e)
        {
            if((e.getAction() == Action.RIGHT_CLICK_AIR)||(e.getAction() == Action.RIGHT_CLICK_BLOCK))
            {
                if(e.getItem() == null)return;
                if(!armors.contains(e.getItem().getType()))
                {
                    return;
                }
                Player p = e.getPlayer();      
                Bukkit.getScheduler().runTaskLater(main.plugin, () -> checkArmor(p), 1);
            }
        }
     
        @EventHandler
        public void invClick(InventoryClickEvent e)
        {
            if(e.getCurrentItem() == null && e.getCurrentItem().getType() == Material.AIR && e.getCursor() == null)return;
       
            if((armors.contains(e.getCurrentItem().getType())) || (armors.contains(e.getCursor().getType())) || (e.isShiftClick()) ||
                    (e.getCurrentItem() == null && armors.contains(e.getCursor().getType())))
            {
                if (e.getSlotType().equals(SlotType.ARMOR))
                {
                    Player p = (Player) e.getWhoClicked();
                    Bukkit.getScheduler().runTaskLater(main.plugin, () -> checkArmor(p), 1);
                }
            }
        }
     
        public void checkArmor(Player p)
        {
            p.sendMessage("Debug shit");
        }
     
    #1 Toloxus, Jul 1, 2018
    Last edited: Jul 1, 2018
Thread Status:
Not open for further replies.