Check For Armor

Discussion in 'Plugin Development' started by zakarls, Jun 15, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    zakarls

    I am trying to check if a player has a full set of a certain type of armor and give them a certain potion effect based on the type they are wearing. Here is my code so far but it does not seem to work. The plugin loads in the server and does not throw any errors but nothing happens when I put a full set of armor on.
    Code:
    @EventHandler
        public void onInventoryEdit(InventoryInteractEvent event){
            Player player = (Player) event.getWhoClicked();
            PlayerInventory inv = event.getWhoClicked().getInventory();
            if(inv.getHelmet() == new ItemStack(Material.LEATHER_HELMET,1) &&inv.getChestplate() ==new ItemStack(Material.LEATHER_CHESTPLATE,1)&&
                    inv.getLeggings() == new ItemStack(Material.LEATHER_LEGGINGS,1)&&inv.getBoots() == new ItemStack(Material.LEATHER_BOOTS,1)){
                player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 100000, 2));
    }
     
  2. Offline

    caderape

    @zakarls This is the first time i see this event used.
    I'm not sure this is the best way to do it. You should check InventoryClickEvent and the slot clicked, for see if the armor is modified. And be carreful, armor can be null.

    note: When u check itemstack like that, the name, the description, the durability affect.
     
  3. Offline

    zakarls

    @caderape
    What if I want it to check for the itemstack but the durability doesnt matter
     
Thread Status:
Not open for further replies.

Share This Page