Solved Disabling respawn screen?

Discussion in 'Plugin Development' started by rocket138, Dec 18, 2013.

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

    rocket138

    I'm working on a skywars plugin, (almost done!) and I've run into an issue.
    I need players to return to the lobby on death, but so far they only do on respawn. I know there is some sort of packet thing that you can use to cause players to respawn, but all of the ways of tried it simply do not work. I don't know if it was changed for 1.7.2 or what, but I simply cannot force players to instantly respawn. I do not want them to lose items with a damage event, but an actually script to be ran on the PlayerDeathEvent, any help?

    Edit:
    TL;DR: ((CraftPlayer) player).getHandle().playerConnection.(new PacketPlayOutRespawn());
    What do I put after playerConnection. ?
     
  2. Offline

    Bartoke

    Just teleport the player when he enters the void (when his y is negative), so he doesn't actually have to die

    Or check in an EntityDamageEvent if the player's damage cause is VOID, so you know he's falling in the void, cancel that and teleport him back.
     
  3. Offline

    calebbfmv

    rocket138
    There is a packet about repsawning, Packet20NamedEntitySpawn
    Something along those lines..
     
  4. Offline

    Deleted user

    calebbfmv Bartoke rocket138
    Bartoke, that would work, but you can also use PacketPlayInClientCommand

    calebbfmv, no. That's not for respawning. That's for spawning in entities. Also, packet names changed
     
  5. Offline

    Ultimate_n00b

    It's Packet 205 for 1.6 and below, Packet PlayInClientCommand for 1.7.
     
  6. Offline

    rocket138

    Players don't always die from the void in SkyWars, and that would prevent players from dropping items...
     
  7. Just do an OnPlayerDeathEvent
    and in it, set the player's health to 20, and tp them to a stored location. This bypasses the respawn screen, and there is no respawn event that runs. So you will have to have whatever normally happens on PlayerRespawn in here, but I suspect that should be no issue. This also generally causes less lag.
     
  8. Offline

    rocket138

    I did this, but then when they join the world that they died in again, they die again instantly and get teleported out.
     
  9. Offline

    xTrollxDudex

    rocket138
    10 second google search c'mon, use those resources:
    PHP:
    Bukkit.getScheduler().scheduleSyncDelayedTask(pluginInstance, new Runnable() {
                @
    Override
                
    public void run() {
                    ((
    CraftPlayerplayer).getHandle().playerConnection.a(new PacketPlayOutRespawn());
                }
     
  10. Offline

    rocket138

    "10 seconds google search c'mon, use those resources:"
    Um, yeah I tried that and it just flat out doesn't work...
    The error is on the playerConnection.a "the method a(PacketPlayInSteerVehicle) in the type PlayerConnection is not applicable for the arguments (PacketPlayOutRespawn)"

    I figured it out:
    ((CraftPlayer) player).getHandle().playerConnection.a(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN));

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  11. Offline

    xTrollxDudex

    Most of it is correct at least
     
  12. Offline

    BlueMustache

    rocket138
    If your right, than why doesn't this work?
    Code:java
    1. public void respawnThem(Player p) {
    2. CraftHumanEntity human = (CraftHumanEntity)p;
    3. EntityPlayer nms = (EntityPlayer)human.getHandle();
    4. nms.playerConnection.a(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN));
    5. }
     
  13. Offline

    thapengwin

    Use EntityDamageEvent, check if the health - damage is less than or equal to zero, if so then heal and teleport the player where you need to.
     
  14. Offline

    Aqua

    Code:
    ((CraftPlayer)p).getHandle().playerConnection.a(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN));
    Uses these imports (1.7.9):
    Code:
    import net.minecraft.server.v1_7_R3.EnumClientCommand;
    import net.minecraft.server.v1_7_R3.PacketPlayInClientCommand;
    import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
     
  15. Offline

    garbagemule

    There is no need to use NMS for something that can be done entirely in the Bukkit API. Teleporting the player and setting their health > 0 in the death event will prevent them from dying, and the death screen will not appear.

    Edit: Oh god, didn't realize this thread was necro'ed. Well done BlueMustache
     
    AdamQpzm likes this.
  16. garbagemule Have to admit, though, that such methods usually do not take into account things such as the armour and enchantments on it, which can definitely be annoying. Nothing stopping someone from handling that themselves, though, I suppose.
     
  17. Offline

    garbagemule

    AdamQpzm
    Listening for PlayerDeathEvent and calling teleport and setHealth, no need to take armor and enchantments into account at all.
     
  18. garbagemule Isn't that what causes the alive-but-looking-alive graphical glitch?
     
  19. Offline

    garbagemule

    AdamQpzm
    I don't know what you're talking about, but no, no glitch results from that method. I've been using it in MobArena for over two years now, and it's working just fine.
     
  20. garbagemule Only managed to find one image of it:

    Edit: Well that didn't work. Link.
     
  21. Offline

    MineStein

    garbagemule AdamQpzm We might want to stop talking about this, this thread is already solved. If anyone had any more questions, just private message or create a thread for it.
     
  22. Offline

    garbagemule

    AdamQpzm
    Never seen that happen before, and the proposed method doesn't trigger it.
     
  23. Offline

    Garris0n

    garbagemule, AdamQpzm is right. It can cause some annoying visual bugs and other stuff because the game isn't designed for it.

    I've seen it happen when playing with it before, no idea how you've avoided it.
     
  24. Offline

    garbagemule

    Garris0n
    Like I said, I've never seen it. There may be other, related things that trigger it, but simply teleporting and setting health does not.
     
  25. Offline

    Garris0n

    Just setting health does, teleporting is irrelevant.

    Anyway, having an argument about it is pointless. It does happen, even if you've never noticed it before. There's probably some way to avoid it (perhaps sending some packet to refresh the player), but then you may as well use the packet method in the first place.
     
  26. Offline

    garbagemule

    Garris0n
    Teleporting is clearly not irrelevant if it prevents the glitch.
     
  27. Offline

    Garris0n

    Perhaps it forces some sort of refresh. I haven't really ever bothered to see what causes it, so I don't know.

    Regardless, there are other issues with that method, such as screwing up other plugins that use the death event, and predicting whether the player will die. But, if you want to use it, whatever.
     
  28. Offline

    garbagemule

    Garris0n
    Choose your poison, I guess. Anything's better than NMS :p
     
  29. Offline

    Kilovice

    The one that I use (which works incredibly well) this insures that the player spawns in correctly
    Code:java
    1. new BukkitRunnable(){
    2. @Override
    3. public void run(){
    4. ((CraftPlayer)event.getEntity()).getHandle().playerConnection.a(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN));
    5. }
    6. }.runTaskLater(Main.getPlugin(), 1);
     
  30. Offline

    BlueMustache

    Aqua
    Wow thanks!
    Haven't tested, but I didn't know you could still import CraftPlayer. Thanks!

    all
    Also, sorry for reopening a closed thread. I know it's kind of like dancing on a grave, but, it is crucial to my plugin, that they are literally respawned!
     
Thread Status:
Not open for further replies.

Share This Page