1.16.5 How to take item durability

Discussion in 'Spigot Plugin Development' started by StTrigger, Jul 18, 2021 at 6:53 PM.

  1. So basicly i have a loop and i need to take one item durability every cycle.

    P.S: i dont need an itemstack, i just need an item in the helmet slot to brake
     
    #1 StTrigger, Jul 18, 2021 at 6:53 PM
    Last edited: Jul 18, 2021 at 6:58 PM
  2. Can you describe a little more what you mean by "one item durability"? Does this only apply to items that have durability (armor, swords, tools, etc.)? Do you want to take off one durability as in from its total durability?
     
  3. i need to add 1 damage,
     
  4. oh. i fixed that but i have an. another question.

    My code:
    Code (Java):
    if (isBombActivated()) Bukkit.getOnlinePlayers().forEach(p -> {
                        if (p.getLocation().getY() >= 70 && !isSimilar(p.getInventory().getHelmet(),hazmat)) {
                            p.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 20, 2));
                            p.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, 20, 2));
                            p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20, 2));
                            p.addPotionEffect(new PotionEffect(PotionEffectType.HARM, 20, 2));
                            p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60, 2));
                        } else if (p.getLocation().getY() >= 60 && !isSimilar(p.getInventory().getHelmet(),hazmat)) {
                            p.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 20, 2));
                            p.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, 20, 2));
                            p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20, 2));
                            p.addPotionEffect(new PotionEffect(PotionEffectType.HARM, 20, 1));
                            p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60, 2));
                        } else if (p.getLocation().getY() >= 50 && !isSimilar(p.getInventory().getHelmet(),hazmat)) {
                            p.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 20, 1));
                            p.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, 20, 2));
                            p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20, 2));
                        } else if (p.getLocation().getY() >= 40 && !isSimilar(p.getInventory().getHelmet(),hazmat)) {
                            p.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 20, 1));
                            p.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, 20, 1));
                            p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20, 2));
                        } else if (p.getLocation().getY() >= 30 && !isSimilar(p.getInventory().getHelmet(),hazmat)) {
                            p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20, 1));
                            p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20, 1));
                        } else if (p.getLocation().getY() >= 20 && !isSimilar(p.getInventory().getHelmet(),hazmat)) {
                            p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20, 1));
                        } else if (p.getLocation().getY() >= 20 && isSimilar(p.getInventory().getHelmet(),hazmat)) {
                            Damageable meta = (Damageable) p.getInventory().getHelmet().getItemMeta();
                            meta.setDamage(meta.getDamage() + 1);
                            p.getInventory().getHelmet().setItemMeta((ItemMeta) meta);
                        }
                    });
                }
            }.runTaskTimer(this,1,19);
    its taking one durability but then item stops to being the "hazmat" itemstack cuz of changed meta...
    do you know how to fix that?
     
  5. When you change the item durability the isSimilar method think that is other item. Try:
    Code (Java):
    if (p.getInventory.getHelmet().getItemMeta().equals(hazmat.getItemMeta()){
    //do stuff
     
    or try check if the helmet name is equal for the "hazmat" name
     
    • Agree Agree x 1