PlayerRespawnEvent + setHealt() ?!

Discussion in 'Plugin Development' started by recon88, May 28, 2012.

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

    recon88

    Why this doesn't work? The player is still respawning with full health.

    Code:
            @EventHandler
            public void onPlayerRespawn(PlayerRespawnEvent event) {
              Player player = event.getPlayer();
              player.setHealth(2);
              }
        }
     
  2. Offline

    CorrieKay

    the player isnt technically alive at that point, i think.
     
  3. Offline

    recon88

    Is there any workaround for that or would a delay work?
    Or is there another event?
     
  4. Offline

    r0306

    recon88
    You can add the players to a list on death. Then, in a player move event, check if the player is contained in the list and if it is, set their health to 2 and remove them from the list. Or, you can schedule a delayed task on player respawn which sets their health to 2.
     
    suckycomedian likes this.
  5. Offline

    recon88

    It works, but there's a little problem with the PlayerMoveEvent.
    If you are going to die and you keep walking, you will just skip the deathscreen.
    Ofcourse you will die, but you insta-spawn at the position you died.
     
  6. Offline

    r0306

    recon88
    Oh lol. Ok then try this.
    Code:
    if (!player.isDead()) {
    player.setHealth(2);
    }
     
  7. Offline

    recon88

    r0306
    Yep that's what I'm looking for =)
     
  8. Wait, it's possible to skip the screen server side? Could you provide me with a code example how you did that? :)

    //EDIT: Nevermind, I figured it out:
    Code:java
    1. @EventHandler
    2. public void instantRespawn(PlayerDeathEvent event)
    3. {
    4. plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Respawner(event.getPlayer));
    5. }
    6.  
    7. private class Respawner implements Runnable
    8. {
    9. private final Player player;
    10.  
    11. private Respawner(Player player)
    12. {
    13. this.player = player;
    14. }
    15.  
    16. public void run()
    17. {
    18. if(player.isDead())
    19. player.setHealth(20);
    20. }
    21. }
     
Thread Status:
Not open for further replies.

Share This Page