Why isn't this working? O.o

Discussion in 'Spigot Plugin Development' started by valaiyar, May 26, 2017.

  1. Code (Text):
    Player player = (Player) e.getEntity();
            switch (player.getLastDamageCause().getCause()) {
            case FALL:
                player.sendMessage("fall");
                return;
            case PROJECTILE:
                player.sendMessage("projectile");
                if (e.getEntity().getLastDamageCause().getEntity() instanceof Arrow) {
                    Arrow arrow = (Arrow) player.getKiller();
                    if (arrow.getShooter() instanceof Player) {
                        player.sendMessage("arrow from another player");
                        return;
                    }
                 
                }
            case ENTITY_ATTACK:
                if (e.getEntity().getLastDamageCause().getEntity() instanceof Player) {
                    Player killer = (Player) e.getEntity().getLastDamageCause().getEntity();
                    player.sendMessage("hit from another player");
                    return;
                }
            default:
                player.sendMessage("damage");
                return;
        }
    For some reason the arrow check isn't working, and the entity_attack works when shooting arrow.
     
  2. ScarabCoder

    ScarabCoder Retired Resource Staff
    Retired

    If it's Entity Attack, you could try checking if the entity was an Arrow/Projectile or a Player, then work from there.