Solved item durability failing

Discussion in 'Plugin Development' started by DatCookiez, Jan 14, 2015.

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

    DatCookiez

    Hey guys, I have this ItemStack and an EntityDamageByEntityEvent and at the moment I'm using this Diamond Sword to give poison on hit. Everything works as it's supposed to, but once the sword gets damaged, the code no longer works. I've tried getting the itemDurability() and checking if it's <= 9999 but it still doesn't work.

    Code:
    Random rand = new Random();
            int hit = rand.nextInt(100);
            if (hit <= 100){
                if (e.getDamager() instanceof Player){
                    if (e.getEntity() instanceof Player){
                        if (p.getItemInHand().equals(sword)){
                                v.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 20*2, 1));
                                    }
                                }
                            }
                        }
    Any ideas?
     
  2. Offline

    Skionz

  3. Offline

    DatCookiez

    @Skionz ?
    Code:
    if (p.getItemInHand().equals(sword.getType().name())){
     
  4. Offline

    Skionz

    @DatCookiez An ItemStack will never equal a String.
     
  5. Offline

    DatCookiez

    @Skionz
    Could I please have an example ?
     
  6. Offline

    Skionz

  7. Offline

    nverdier

    @Skionz I think he's asking how you would do it...


    @DatCookiez Get the name of the ItemStack, and check if it equals whatever you want! Simple as that/
     
  8. Offline

    DatCookiez

    @nverdier
    if (p.getItemInHand().equals(sword.getItemMeta().equals(swordMeta))){

    I'm not quite sure what to do.. I've tried a lot of things, could you please help?

    (BUMP)
     
  9. Offline

    ColonelHedgehog

    He's saying you need to check for the name of the item, to see if it's the type of item a sword is.

    Assuming sword is a Material, you'd use something more like:

    p.getItemInHand().getType() == sword.getType()
     
  10. Offline

    DatCookiez

    @ColonelHedgehog
    Thank you, I was on the right track, just didn't finished the last sword.getTyepe();
     
Thread Status:
Not open for further replies.

Share This Page