1.16.5 Auto respawn player

Discussion in 'Spigot Plugin Development' started by Griboed, Jul 28, 2021.

  1. Hi. I am trying to respawn a player after death using this code

    Code (Text):
        public void onDeath(PlayerDeathEvent event)
            getServer().getScheduler().runTaskLater(this, () -> {
            }, 1L);
    It working. But if the player has a minimap mod, then his death waypoint does not appear. What packet should be sent to the client so that he understands that the player is dead?
    P.S: sorry for my English
    #1 Griboed, Jul 28, 2021
    Last edited: Jul 28, 2021
  2. You could try putting this
    inside a BukkitTask and running it some ticks later
  3. There is a gamerule for that it is called InstantRespawn or DoInstantRespawn just set it to true
  4. Not available on versions before snapshot 19w36a
  5. But this thread is marked as 1.16.5 and not 1.14.

    OnTopic: Maybe tell us the mod name. Normally the 1 tick delay should be more than enough for a proper minimap mod to recognize the death location.
  6. Mod JourneyMap
  7. You might do something else for that, you can listen to a EntityDamageEvent and calculate if the player's health-damage is below zero, like so:
    Code (Java):
        public void onDeath(EntityDamageEvent e){
            if(!(e.getEntity() instanceof Player)) return;

            Player p = (Player) e.getEntity();

            if(p.getHealth()-e.getFinalDamage() > 0) return; //if damage does not make the player dead, return

            if(p.getBedSpawnLocation() == null)
                p.teleport(p.getWorld().getSpawnLocation()); //not sure if spawn radius works here.
  8. There’s also a packet you can send that acts the same as someone clicking the respawn button when they die.

    Code (Java):
    ((CraftPlayer) player).getHandle().playerConnection.a(new PacketPlayInClientCommand(PacketPlayInClientCommand.EnumClientCommand.PERFORM_RESPAWN));
    • Agree Agree x 1
  9. p.spigot().respawn();
    • Funny Funny x 2
  10. What a useless answer. Did you even the original post lmao
  11. No, no, no, NOT Task. This effectively delays the function of the Death Event.
    Use a Bukkit Runnable to re-spawn the player.
    eg player isDead, runLater(1), respawn player.
  12. That‘s the same thing lol
  13. No, it is not.
    Dead is disconnect.
    Respawn is reconnect.
  14. Why would someone use a runnable when there are events?

    Also „dead“ is not disconnect. Dead is dead. And respawn also has nothing to do with reconnecting
  15. This method is used in Hypixel, but if you would like to see the death screen for a duration of a tick then you should just call a bukkit runnable.
    #15 parpar8090, Aug 6, 2021
    Last edited: Aug 6, 2021