[HELP] AutoRespawn

Discussion in 'Spigot Plugin Development' started by Tauchet, May 7, 2015.

  1. Hello, how do I make a player it does not appear deaths screen, and what are autorespawn!
  2. I believe there is a respawn packet you must send the player.
  3. You could create a PlayerDeathEvent handler which checks if a player died. Then go player.Spigot().respawn() and cancel the death event. event.setCancelled(true);
    Good luck! If you are still having trouble, I will be happy to help.
    [Edit]: event.setCancelled(true); won't work. Just do player.Spigot().respawn();
    #3 gogobebe2, May 7, 2015
    Last edited: May 7, 2015
  4. GUYS NO
    Code (Text):
    public void onPlayerDeath(PlayerDeathEvent event){
    Edit: I meant, that is wrong.
    #5 connection_lost, May 7, 2015
    Last edited: May 7, 2015
  5. That's pretty much what I said. Idk what you mean by "GUYS NO".
    Ahh ok. Then you can just do it without cancelling. Should still work.
  6. No the player has not yet "died" until the event has run its route. Your handler is not the only one. You must wait a tick for the event completion before calling Player.Soigot#respawn ().
    • Agree Agree x 1
  7. I should be sorry for being VERY unclear :(
    • Friendly Friendly x 1
  8. Another option that I might annoy some people, isn't the best method and isnt very efficient is on the PlayerDeathEvent just clear the players inventory/clear drops (i dont remember which), set their health to 20, set their food level to 20, set their velocity to a new vector and teleport the player to a defined location

    This is also used so the player doesnt loose their levels
    • Agree Agree x 1
  9. In your case:
    PlayerDeathEvent is not cancellable. You need to stop the damage instead.
    Listen to EntityDamageEvent, prevent the lethal damage.
  10. I know i never said to cancel it but since the PlayerDeathEvent is called before the player actually dies, we are changing the players heath to their max health so it does "cancel" the event
  11. Another way you could auto respawn is, check when they get if their health will go below 0, if it does then send them to spawn and set their health to 20. You could use packets, etc but I prefer to just do that.
  12. I used to do that, but something like this happens: (jump to 1:38)

    Edit: This video is definitely not mine... I am just using it for demostration
  13. What usually causes that is when you dont reset their velocity
  14. True.
  15. Yes. I agree with you. And you could put all this logic in a new method that re-implements player.Spigot().respawn() except make it save the player data.
  16. It is not possible only with bukkit and did not appear event.getPlayer().Spigot().respawn();
  17. Here you go. This is a alternate way of doing it.
    This Has Instant Respawn Which means there is no 1 tick delay of a loading screen. like what spigot code does.
    There is no loading screen at all for this code. Recommend using this for KitPvP servers.
    Code (Text):
        public void onPlayerDeath(PlayerDeathEvent e){
            Player player = e.getEntity();
  18. You should set the player velocity to a new vector so they dont spawn moving at the same rate as they were when they died
    Example would be falling into the void, you are falling fast so when you respawn you will then die again from fall damage.
    • Agree Agree x 1
  19. I would Try that But I don't have a clue on how to do it