Having probs with getEntity() in PlayerDeathEvent

Discussion in 'Plugin Development' started by Th3Rokaz, Jan 19, 2017.

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

    Th3Rokaz

    by the title u know what the problem is so check my code

    public void onPlayerDeath(PlayerDeathEvent event) {
    Player player = .getEntity();
    Entity killer = player.getKiller();

    if(!(killer instanceof Player)){
    EntityType type = killer.getType();

    switch(type) {
    case BLAZE:
    break;
    default:
    break;
    }
    } else if (killer instanceof Player) {
    event.setDeathMessage();
    }
    }
     
  2. Offline

    Zombie_Striker

    Please don't do this. Not only is the title too short/ does not have enough details to know what is happening, you should always explain what the problem is in your main post.

    Because you had a vague description in the title, I do not know what the problem is. What is your probem?

    If the player dies of fall damage/ suffocation/ anything where another entity is not involved, killer will be null. Null check before you use it,
     
  3. Offline

    Th3Rokaz

    okay event.getEntity is marking red idk why oh and setDeathMessage to

    The method getEntity() is undefined for the type PlayerDeathEvent
    The method setDeathMessage() is undefined for the type PlayerDeathEvent


    btw my code again:

    Code:
    @EventHandler(priority = EventPriority.MONITOR)
        public void onPlayerDeath(PlayerDeathEvent event) {
           Player player = event.getEntity();
           Player killer = player.getKiller();
           if (killer != null) {
           if(!(killer instanceof Player)){
               EntityType type = killer.getType();
        
               switch(type) {
                   case BLAZE:
                       break;
                default:
                    break;
               }
           } else if (killer instanceof Player) {
              event.setDeathMessage();
           }
        } else {
          
        }
        }
     
    Last edited by a moderator: Jan 20, 2017
  4. Offline

    DoggyCode™

    If your IDE is marking it red, that means your bracket formatting is probs messed up. And setDeathMessage requires a parameter input (String), which is also probs why your IDE marked it as an error in your code.
     
  5. Offline

    Sethburster

  6. Offline

    Th3Rokaz

    my code now

    @EventHandler(priority = EventPriority.MONITOR)
    public void onPlayerDeath(PlayerDeathEvent event) {
    Player player = event.getEntity();
    Entity killer = player.getKiller();
    if (killer != null) {
    if(!(killer instanceof Player)){
    EntityType type = killer.getType();

    switch(type) {
    case BLAZE:
    break;
    default:
    break;
    }
    } else if (killer instanceof Player) {
    event.setDeathMessage("s");
    }
    } else {

    }
    }

    }
    so what should i do

    ">
    oh did you read my errors

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
Thread Status:
Not open for further replies.

Share This Page