Solved Break armor after durability is 0

Discussion in 'Plugin Development' started by Billythekidzz, Dec 15, 2014.

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

    Billythekidzz

    So I have a plugin that manually damages pieces of armor:
    Every 5 seconds, boots.setDurability((short) (boots.getDurability() + 1));
    The damaging works, but the item doesn't break after it's max durability has been breached. How would I make the armor break? Is there a way to get the max durability of the armor?
     
  2. Offline

    Luke_Lax

    ChipDev likes this.
  3. Offline

    Coopah

    @Billythekidzz
    I assume your using a repeating task that degrades the armor each 5 seconds? So add a check in this if the armor piece is equal to 0 and if it is then remove the armor piece that has broken :)
     
  4. Offline

    Billythekidzz

    @Luke_Lax
    @Coopah
    Correct me if I'm wrong, but when getdurability returns 0 that means the armor is full health? And a higher durability means the armor has taken more hits. Problem is when the durability is high enough for the armor piece to be destroyed, armor health keeps going into the negative. How do I get it destroyed?
     
  5. Offline

    Coopah

    @Billythekidzz
    Maybe but it was just a example of what you can do.
    As I said before, check if the durability gets to a certain number, google the correct ones by seeing the durability of the armor. Then in your repeating task do a check. If durability = something something then get the inventory and remove the armor by doing removeItem.
     
    Feindbild likes this.
  6. Offline

    Billythekidzz

    @Coopah
    I was thinking about doing that, but that would take ages due to there being 4 pieces of armor, then each type of material having a different durability. That's why I asked if there was such a thing as checking max durability or a faster method of doing this.
     
  7. Offline

    Coopah

    @Billythekidzz
    It would take like 30 lines of code, it isn't much lol.
     
  8. Offline

    SuperOriginal

  9. Offline

    Billythekidzz

    Alright, I did it. Just for future reference for others who want getMaxDurability(),

    Code:
    public double getMaxHelmetDurability(Player player){
            PlayerInventory inv = player.getInventory();
            double var = 0d;
            if(inv.getHelmet() != null){
                ItemStack armor = inv.getHelmet();
                if(armor.getType() == Material.CHAINMAIL_HELMET){
                    var = 166d;
                }
                if(armor.getType() == Material.LEATHER_HELMET){
                    var = 56d;
                }
                if(armor.getType() == Material.GOLD_HELMET){
                    var = 78d;
                }
                if(armor.getType() == Material.IRON_HELMET){
                    var = 166d;
                }
                if(armor.getType() == Material.DIAMOND_HELMET){
                    var = 364d;
                }
            }else{
                var = 0d;
            }
            return var;
        }   
        public double getMaxChestplateDurability(Player player){
            PlayerInventory inv = player.getInventory();
            double var = 0d;
            if(inv.getChestplate() != null){
                ItemStack armor = inv.getChestplate();
                if(armor.getType() == Material.CHAINMAIL_CHESTPLATE){
                    var = 241d;
                }
                if(armor.getType() == Material.LEATHER_CHESTPLATE){
                    var = 81d;
                }
                if(armor.getType() == Material.GOLD_CHESTPLATE){
                    var = 113d;
                }
                if(armor.getType() == Material.IRON_CHESTPLATE){
                    var = 241d;
                }
                if(armor.getType() == Material.DIAMOND_CHESTPLATE){
                    var = 529d;
                }
            }else{
                var = 0d;
            }
            return var;
        }
        public double getMaxLeggingsDurability(Player player){
            PlayerInventory inv = player.getInventory();
            double var = 0d;
            if(inv.getLeggings() != null){
                ItemStack armor = inv.getLeggings();
                if(armor.getType() == Material.CHAINMAIL_LEGGINGS){
                    var = 226d;
                }
                if(armor.getType() == Material.LEATHER_LEGGINGS){
                    var = 76d;
                }
                if(armor.getType() == Material.GOLD_LEGGINGS){
                    var = 106d;
                }
                if(armor.getType() == Material.IRON_LEGGINGS){
                    var = 226d;
                }
                if(armor.getType() == Material.DIAMOND_LEGGINGS){
                    var = 496d;
                }
            }else{
                var = 0d;
            }
            return var;
        }
        public double getMaxBootsDurability(Player player){
            PlayerInventory inv = player.getInventory();
            double var = 0d;
            if(inv.getBoots() != null){
                ItemStack armor = inv.getBoots();
                if(armor.getType() == Material.CHAINMAIL_BOOTS){
                    var = 196d;
                }
                if(armor.getType() == Material.LEATHER_BOOTS){
                    var = 66d;
                }
                if(armor.getType() == Material.GOLD_BOOTS){
                    var = 92d;
                }
                if(armor.getType() == Material.IRON_BOOTS){
                    var = 196d;
                }
                if(armor.getType() == Material.DIAMOND_BOOTS){
                    var = 430d;
                }
            }else{
                var = 0d;
            }
            return var;
        }
    
     
  10. Offline

    SuperOriginal

    @Billythekidzz Or you can ignore my post and go the long way I guess.
     
Thread Status:
Not open for further replies.

Share This Page