Getting Damage cause

Discussion in 'Plugin Development' started by VictoryShot, May 6, 2014.

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

    VictoryShot

    Hello I want custom death message for each damaage cause. One thing they dont work! Here is my code so far only the top one works but not the Lava one.
    Code:java
    1. @EventHandler
    2. public void onKill(PlayerDeathEvent e){
    3. String killed = e.getEntity().getName();
    4. String killer = e.getEntity().getKiller().getName();
    5. e.setDeathMessage(ChatColor.AQUA + "[" + ChatColor.RED + "KitPvP" + ChatColor.AQUA + "]: " + ChatColor.YELLOW + killed + " has been slain by " + killer);
    6. Bukkit.broadcastMessage(ChatColor.AQUA + "[KitPVP]: " + ChatColor.RED + killer + " Killed " + killed);
    7. if(e.getEntity().getLastDamageCause().getCause() == DamageCause.LAVA) {
    8. Player p = e.getEntity();
    9. p.sendMessage("u died in lava test");
    10.  
    11. }
    12. }


    Error in console:

    http://pastebin.com/Rz9CUdDg

    Please help
     
  2. Offline

    scorbin60943

    You cant assume that the cause of death is a entity and that the killer is a player.
     
  3. Offline

    VictoryShot

    Is this post suppose to help me?
     
  4. Offline

    scorbin60943

    dont want to make it too easy for ya. :p Have you tried debugging? I believe the problem is with
    • String killer = e.getEntity().getKiller().getName();"
    Play with it a little. You need to add null check to make sure that the value you are getting exits. See what you can do from there
     
  5. Offline

    coasterman10

    There is a chance that a player's killer returns null. You can solve this by doing a null check.
     
Thread Status:
Not open for further replies.

Share This Page