Player Death Event

Discussion in 'Plugin Development' started by KrazyFlow, Aug 12, 2014.

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

    KrazyFlow

    I have been developing a plugin for a short while now to get used to java and learn more about the language. I am trying to add a bounty command to it all. So far I have the command working fine but I have had a problem with play death events for when one player kills another. I have the code I am trying here:

    Code:java
    1. @EventHandler
    2. public void onPlayerKill(PlayerDeathEvent e){
    3.  
    4. Player deadPlayer = e.getEntity();
    5.  
    6. Player killer = e.getEntity().getKiller();
    7.  
    8. if(killer instanceof Player && deadPlayer instanceof Player){
    9.  
    10. Player player = (Player) killer;
    11.  
    12. int killcount = configGetter.getConfig().getInt(player.getName() + "playerkills");
    13. int money = configGetter.getConfig().getInt(player.getName() + "money");
    14. int playermoney = configGetter.getConfig().getInt("playermoney");
    15.  
    16. configGetter.getConfig().set(player.getName() + "playerkills", killcount + 1);
    17. configGetter.getConfig().set(player.getName() + "money", money + playermoney);
    18.  
    19. player.sendMessage(ChatColor.BLUE + "Nice you just slaughtered " + deadPlayer);
    20. deadPlayer.sendMessage(ChatColor.RED + "Better luck next time...");
    21. Bukkit.getServer().broadcastMessage(ChatColor.BOLD + "" + ChatColor.RED + "Watch out! " + player + " just murdered " + deadPlayer);
    22. }
    23. }


    But nothing happens when a player has been killed. no message or anything. Any help will be appreciated.
     
  2. KrazyFlow Debug the code to see which parts are executed.
     
  3. Offline

    Skionz

    is it registered?

    EDIT: Also change this to deadPlayer.getName()
    Code:
     player.sendMessage(ChatColor.BLUE + "Nice you just slaughtered " + deadPlayer.getName());
     
  4. Offline

    KrazyFlow

    AdamQpzm

    But it only has one if statement to be executed on the player death.

    Skionz

    Also what do you mean by registered? (I'm a slight noob with java)
     
  5. Offline

    TheDarkLord197

    KrazyFlow You must register your listeners for them to actually work. If you haven't already put it there, This should be in your onEnable method, in your Main class.
    Code:java
    1. getServer().getPluginManager.registerEvents(new NameOfListenerClass(), this);


    Edit: Nevermind
     
Thread Status:
Not open for further replies.

Share This Page