Solved New auto-respawn method

Discussion in 'Plugin Development' started by VortexGmer, Mar 20, 2015.

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

    VortexGmer

    Well I know there are some old respawn methods but...
    They are old and don't work!
    So I've got the player death event but how do I call and send packet205clientcommand to the player and make them immediately respawn?
     
  2. @VortexGmer You could listen for the damage event and if their health will be <= 0 then set their health to full, teleport and do whatever else.
     
  3. Offline

    VortexGmer

    Yes but this is already gone in the community and I don't see this as an answer, It will totally MESS UP my minigame plugins
     
  4. Offline

    TehHypnoz

    I have also been look how to do this for a while without using NMS and found this (sorry for spoonfeed):

    Code:
    @EventHandler
        public void onPlayerDeath(PlayerDeathEvent e) {
            final Player p = e.getEntity();
            new BukkitRunnable() {
                public void run() {
                   try {
                       Object nmsPlayer = p.getClass().getMethod("getHandle").invoke(p);
                       Object packet = Class.forName(nmsPlayer.getClass().getPackage().getName() + ".PacketPlayInClientCommand").newInstance();
                       Class<?> enumClass = Class.forName(nmsPlayer.getClass().getPackage().getName() + ".EnumClientCommand");
            
                       for(Object ob : enumClass.getEnumConstants()){
                           if(ob.toString().equals("PERFORM_RESPAWN")){
                               packet = packet.getClass().getConstructor(enumClass).newInstance(ob);
                           }
                       }
            
                       Object con = nmsPlayer.getClass().getField("playerConnection").get(nmsPlayer);
                       con.getClass().getMethod("a", packet.getClass()).invoke(con, packet);
                   }
                   catch(Throwable t){
                       t.printStackTrace();
                   }
                }
            }.runTaskLater(plugin, 1);
        }
    
     
    sgavster likes this.
  5. Offline

    VortexGmer

    Just saying... That code doesn't work, It doesn't even let the user's respawn! When you press the respawn button it goes gray and back to blue and doesnt respawn you, forget about instant!

    ZOMG I have another method in my server that set's the player health to max and I just realized that ot instantly respawn the player XD just for others make a bukkit runnable and inside for(Player p : Bukkit.getonlineplayers()){
    player.sethealth(Whatever);
    }

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Mar 20, 2015
  6. Offline

    TehHypnoz

    Works for me, are you getting any errors?

    Btw, you shouldn't use the method where you just change the players health, because that's kinda glitchy and doesnt always work.
     
  7. Offline

    ItsMattHogan

    I know a way of doing it that doesn't use NMS. I'll post it tomorrow when I'm at my main PC :)

    btw, I do know it's solved.. just thought I'd share it anyway
     
  8. Offline

    VortexGmer

    Sure why nott?
     
Thread Status:
Not open for further replies.

Share This Page