Solved [HELP] PlayerDeathEvent doesn't work!

Discussion in 'Plugin Development' started by Steffion, May 13, 2012.

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


    Hello guys,
    I need help with my plugin :X!
    I call the PlayerDeathEvent but it gives not a reply!
    This is my code:
    package nl.Steffion.HungerRestore;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.player.PlayerRespawnEvent;
    public class HungerRestorePlayerListener implements Listener {
        public static HungerRestore plugin;
        public int hungerbar = 20;
        public HungerRestorePlayerListener(HungerRestore plugin) {
            HungerRestorePlayerListener.plugin = plugin;
        @EventHandler(priority = EventPriority.NORMAL)
        public void onPlayerDeath (PlayerDeathEvent event, Player player) {
            hungerbar = player.getFoodLevel();
            player.sendMessage("§c" + hungerbar);
    This is in the Player Listener. I tried it in the main class but it even won't work...
    Help please?
  2. Offline


    Try adding a logger inside of your event to see if it fired.
  3. Offline


    Did you register your listener?
    tomjw64 likes this.
  4. Offline


    dsmyth1915 I tried, No response....
    CorrieKay I did :eek:
    public final HungerRestorePlayerListener playerListener = new HungerRestorePlayerListener(this);
    //some code
    getServer().getPluginManager().registerEvents(playerListener, this);
    Btw i see now this in the console:
    16:45:44 [INFO] [HungerRestore] Enabling HungerRestore v1.0
    16:45:44 [INFO] HungerRestore by Steffion is now enabled.
    16:45:44 [SEVERE] Wrong method arguments used for event type registered
    16:45:44 [SEVERE] Wrong method arguments used for event type registered
    Some help :O?
  5. Code:
    public void onPlayerDeath (PlayerDeathEvent event, Player player) {
    The only arguments a method listening on an event can take is the event. You cannot add other arguments.
    Steffion likes this.
  6. Offline


    kumpelblase2 But if i want the players name how to get it? event.getPlayer().getName();?
  7. Offline


    kumpelblase2 Thank you! It works!
    Btw: player = event.getEntity();
    Is the right code :p
    I set this topic to Solved :D!
  8. since it's a player death event you can use event.getPlayer();
Thread Status:
Not open for further replies.

Share This Page