Solved Giving potion effects if a certain item is in hand

Discussion in 'Plugin Development' started by MasterNiitro, Jul 30, 2016.

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

    MasterNiitro

    Hi,
    Im trying to give a potion effect if a player is holding a certain item and hitting another player..
    But when i hit my friend it won't give him the potion effect

    Code:
    @EventHandler
        public void onAttack(EntityDamageByEntityEvent e) {
           
            Player defender = null;
           
            if(e.getEntity() instanceof Player)
               defender = (Player) e.getEntity();
           
            if(defender.getItemInHand().equals(Commands.DaiSpada.spada)) {
                defender.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 500, 1));
            }
        }
    
     
  2. Offline

    SuperSniper

    Did you register the event?
     
  3. Offline

    ArsenArsen

    NullPointerException!
    Add else return; to
    And as mentioned before check is the event registered. Check if getItemInHand does not return null, and use isSimlar, or even better compare the names and lores.
     
    Zombie_Striker likes this.
  4. Offline

    MasterNiitro

    ok thank you all gonna try now..
     
Thread Status:
Not open for further replies.

Share This Page