PlayerDeathEvent Bug

Discussion in 'Plugin Development' started by Compressions, Jun 29, 2013.

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

    Compressions

    Hello, I have noticed a bug with PlayerDeathEvent, and was wondering if someone could help me in solving this issue. Either I am doing something wrong, or it is a bug; I don't know which. Well, here it goes. Whenever I call the player that died and the killer in a scenario such as this:
    Code:
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent e) {
            Player dead = e.getEntity();
            Player killer = e.getEntity().getKiller();
                if (!p.requests.isEmpty()) {
                    if (p.requests.get(dead.getName()) != null || p.requests.get(killer.getName()) != null) {
                        p.requests.clear();
                        p.inProgress = false;
                }
            }
        }
    A simple line like this:
    Code:
    killer.sendMessage("debug");
    Will cause an NPE. Does anyone know why, and how to fix it?
    Thanks in advance and I appreciate any help!
     
  2. Offline

    r0306

    Compressions
    You need to check if the cause of the player's death is actually by another player. Right now, you're sending a message to the killer (which could be any entity and not just a player) without adding a safety check so of course it will throw a NPE if the player died by a mob or anything that cannot receive the message.

    Code:
    if (killer != null)
    {
      //do a barrel roll
    }
     
  3. Offline

    Compressions

    r0306 I have used this check and the same error persists.
     
Thread Status:
Not open for further replies.

Share This Page