Solved EntityDamageByEntityEnvent Error

Discussion in 'Plugin Development' started by Christian210x, May 4, 2017.

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

    Christian210x

    when i'm a spectator i try to damage a player thats play a game and it give me this error. trying to solve it...

    error:
    https://gyazo.com/f6926490b1f4e023430e4394169897ab

    Code:
    Code:
                if (event.getDamager() instanceof Player
                        && event.getEntity() instanceof Player) {
                    Player attacker = (Player) event.getDamager();
                    Player victim = (Player) event.getEntity();
                    Random random = new Random();
                    int per = random.nextInt(100);
                    per += 1;
                    if(attacker.getItemInHand().equals(null) || attacker.getItemInHand().equals(Material.AIR)) return;
                    if(attacker.getItemInHand().getItemMeta().equals(items.PIERCING.getItemMeta())) {    //this is line where error occurs
                        if (attacker.getItemInHand().getItemMeta().getDisplayName().equals("§ePiercingBlade")) {
                            if (per <= 50) {
                            } else if (per >= 51) {
                                attacker.sendMessage("§7You pierced §6" + victim.getName() + " §7armor!");
                                victim.sendMessage("§7Your armor has been §cpierced §7by §6" + attacker.getName() + "§7!");
                                victim.setHealth(victim.getHealth() - 3);
                            }
                        }
                    }
                }
     
  2. Offline

    yPedx

    @Christian210x
    Do you want this to happen? (damage a player in spectator mode) if not, check the gamemode first.
     
  3. Offline

    messageofdeath

    Make sure this line does not return Null.
    items.PIERCING.getItemMeta()

    If that doesn't work make sure this doesn't return null.
    attacker.getItemInHand().getItemMeta()
     
  4. Offline

    Christian210x

    No they are in adventure mode.
    @yPedx

    OK I'll try something when I get off work. Thanks guys
    @messageofdeath
     
Thread Status:
Not open for further replies.

Share This Page