Healing items

Discussion in 'Plugin Development' started by ChucknorisSR, Jun 26, 2015.

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


    So I am coding a kitpvp server and I want no items/armor to take durability damage. So I used this code:
        public void onDamage(EntityDamageByEntityEvent e) {
            if (e.getDamager() instanceof Player) {
                Player killer = (Player) e.getDamager();
                    killer.getItemInHand().setDurability((short) 1); 
            }else if(e.getEntity() instanceof Player){
                ItemStack[] armor = ((Player) e.getEntity()).getInventory().getArmorContents();
                for(ItemStack i : armor){
        public void onBowDamage(EntityShootBowEvent e) {
            if (e.getEntity() instanceof Player) {
                e.getBow().setDurability((short) 1);
    But for some reason the armor heals but the bow and sword don't.
  2. Offline


    I notice you put '(short) 1); on the bow and then you put '(short) 0); on the armor, could that be why?
  3. Offline


    You probably just want to use if, not else if.

    In your code if a player is being attacked by a zombie, his armor will heal, but not if he is being attacked by another player.
  4. Offline


    Like @MnMaxon already said Java checks first if the damager is an instance of a player. If it's true it returns and doesn't even check your else if statement. Just remove the "else", so it checks both.
Thread Status:
Not open for further replies.

Share This Page