Solved Problem With Checking if Entity is dead and not a player.

Discussion in 'Plugin Development' started by tlm920, Jun 25, 2019.

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


    Hi all. I ran into some trouble today when I was checking if an entity is dead, and they are not a player. When I am in game and an entity dies, the entity is shown in console. But if I die, which I don't want it to display, it logs that craftplayer has died. Any ideas on how to fix this or what I am doing wrong?
    1. @EventHandler
    2. public void onMobDeath(EntityDeathEvent event) {
    3. // Location l = event.getEntity().getLocation(); (something I was going to setup later)
    4. Entity e = event.getEntity();
    6. if (e.isDead() || !(e instanceof Player)) {
    7."The entity is a " + e.getClass().getName());
    8. }
    9. }
    Last edited: Jun 25, 2019
  2. Offline


    Well, what your code is saying is that it will display the message if the entity is dead (which it should always be, since this is the death event) OR if the entity is not a player. The || is code for the OR operation. What you would have wanted to use instead is the && (AND) operator, but since the entity should always be dead, you should not even need that or that check.
    Kars likes this.
  3. Offline


    :eek: I feel like an idiot! I'm fairly new to Java syntax and thought || was and! Thanks for your reply, this helped me out a lot.:D
Thread Status:
Not open for further replies.

Share This Page