Solved Credits For Kills Console Error

Discussion in 'Plugin Development' started by IZeusI, Jan 6, 2015.

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

    IZeusI

    I started on a new addition to my PvP plugin, I wanted to add essentials economy for kills. This was simple enough to make, and works perfectly. However, I can't seem to understand why the console spits out an error message if a player is killed via a command, or via the console. I definitely know the plugin works and the player death event is registered correctly as when one player kills another, credits are awarded. Any suggestions? Thanks.

    Error:
    http://pastebin.com/D1z7gSsJ
    Code:
    Code:
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent e){
            if (e.getEntity().getPlayer() instanceof Player){
                Player p = e.getEntity().getPlayer();
                Player k = e.getEntity().getKiller();
                if (!(k.getName() == p.getName())){
                    if (k.getPlayer() instanceof Player){
                        Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), ("eco give "+k.getName()+ "10"));
                        k.sendMessage(ChatColor.AQUA+"You Have Been Given 10 Credits For Killing "+ChatColor.GREEN+p.getName()+ChatColor.AQUA+"!");
                        e.setDeathMessage(ChatColor.BLUE+p.getName()+ChatColor.GREEN+" Has Been Rekt By "+ChatColor.RED+k.getName()+ChatColor.GREEN+", Y2eZpZ?");
                    }
                    return;
                }
            }
        }
    
     
  2. Offline

    ColonelHedgehog

    "k" will sometimes return null, because it can't be assumed that another Entity killed the player all the time. Try putting in a conditional that triggers the rest of the code iff k != null.
     
    IZeusI likes this.
  3. Offline

    IZeusI

    Worked perfectly, thanks a lot!
     
Thread Status:
Not open for further replies.

Share This Page