Auto-Respawn

Discussion in 'Plugin Development' started by naorpeled, Mar 17, 2013.

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

    naorpeled

    I have a PvP server and I dont know how to do that a player will respawn without the respawn button
     
  2. Offline

    Nitnelave

    That's tricky... You would have to listen to the EntityDamageEvent, see if the player dies or not, if he does then you have to cancel the event, and basically make him die yourself. By that I mean that you have to drop his inventory, drop half of his experience, restore him to full health, and teleport him to the spawn point.
     
  3. Offline

    Tirelessly

    Code:java
    1.  
    2. String tv = Bukkit.getVersion();
    3. int index = tv.indexOf("(MC: ")+5;
    4. int end = tv.indexOf(")", index);
    5. String version = tv.substring(index, end);
    6. try
    7. {
    8. Class packet = Class.forName("net.minecraft.server.v"+version.replace(".", "_") +".Packet205ClientCommand");
    9. Object name = packet.getConstructor(new Class[0]).newInstance(new Object[0]);
    10. Field a = packet.getDeclaredField("a");
    11. a.setAccessible(true);
    12. a.set(name, 1);
    13. Object nmsPlayer = Class.forName("org.bukkit.craftbukkit.v"+version.replace(".", "_")+".entity.CraftPlayer").getMethod("getHandle", new Class[0])
    14. .invoke(e.getEntity(), new Object[0]);
    15. Field con = Class.forName("net.minecraft.server.v"+version.replace(".", "_") +".EntityPlayer").getDeclaredField("playerConnection");
    16. con.setAccessible(true);
    17. Object handle = con.get(nmsPlayer);
    18. packet.getDeclaredMethod("handle", Class.forName("net.minecraft.server.v"+version.replace(".", "_") +".Connection"))
    19. .invoke(name, handle);
    20. }
    21. catch(Exception ex)
    22. {
    23. ex.printStackTrace();
    24. }
    25.  

    Credit to fireblast709
     
    GrandmaJam likes this.
  4. Offline

    Nitnelave

    Oh, the terrible way to bypass the bukkit security check... You know, if they added it, there are some reasons.
     
  5. Offline

    Tirelessly

    I don't really care, tbh. If they want to make it more work to update plugins that use craftbukkit code then they need to add things like this to the API.
     
  6. Offline

    naorpeled

    Can you please make me a plugin for it?
    I know its a big favor but I have errors.
    and Auro-Respawn = No Respawn button just automatic respawn.= ( Like McPvP)
     
  7. Offline

    fireblast709

    Just note that the code does not work anymore due a change in the package names. You can parse the name though
     
  8. Offline

    naorpeled

    Can someone just give me the code for no respawn button please.
    I know its on the PlayerDeathEvent event
     
  9. Offline

    Tirelessly

    I did?
     
  10. Offline

    Nitnelave

    There is no PlayerDeathEvent... There is EntityDeathEvent, but it does not have anything like what you require.
     
  11. Offline

    njb_said

    Instant Respawn? Thats easy.
    On playerdeathevent.
    Set the players health to 20
    Clear potions.
    Set food to 20
    Set fireticks to 0
    Teleport them to a spawnpoint

    Simple :D
    Example:
    main.techge3ks.com (in the kitpvp)
     
  12. Offline

    RingOfStorms

    Yea this is the worst way to do this, packets are a much safer and better way. So many plugins use the playerDeathEvent and if you mess with it like this, about 75% of plugins will not work in the intended way.
     
  13. Offline

    HelGod

    I do have the code for this, i am currently not on my computer but when i get on i will edit my post and put it in
     
    naorpeled likes this.
  14. Offline

    dillyg10

    I swear, I just saw a post on this in this section.... comon man read. And, don't copy and paste code from Bukkit.... you have to interpret what the devs say, and write your own code.

    BTW, listen to what njb_said said (lol).
    psuedo code:
    onDeath{
    player.setHealth(20);
    }
    //Profit^
     
  15. Offline

    AstramG

    Teleport them to the spawnpoint when they die, it works in one of my plugins :).
     
  16. Offline

    dillyg10

    wha..
     
  17. Offline

    AstramG

    Just listen to when they die, and once they do. Teleport them to their spawnpoints, it works fine.
     
  18. Offline

    dillyg10

    If you don't set the health to 20... than can be very buggy. Especially if the server starts to lag!

    What do you mean it "doesn't work".

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  19. Offline

    naorpeled

    it doesent tp you when you die... and it doesent remove the potion effects...
     
  20. Offline

    TomTheDeveloper

    Did you register that event in onEnable?
     
  21. Offline

    naorpeled

  22. Offline

    RingOfStorms

    Again, doing the set to 20 hp and just teleporting is one of the worst methods of doing this. So many plugins use teh death event and if you just stop it from happening I bet you that so many plugins will break with yours. Learn how to use packets and do it safely.

    Or simply use a plugin that has been made here.

    In his plugin he uses packets and so the death event still goes normally.

    This is how it is done.
    Code:java
    1.  
    2. Packet205ClientCommand packet = new Packet205ClientCommand();
    3. packet.a = 1;
    4. ((CraftPlayer)player).getHandle().playerConnection.a(packet);
    5.  


    It is so much easier to do this than to do all of the hp crap anyways.

    ondeath () {
    //code above
    }
     
    bobacadodl, Bone008 and Knaxel like this.
  23. Offline

    naorpeled

    How do I learn about packets?
    and can you please explain me how to put that packet?
     
  24. Offline

    RingOfStorms

    .. the code is literally right there, if you can't figure out copy and paste then I think you need to go to some java basics.
     
  25. Offline

    HelGod

    Code:java
    1.  
    2. public class NoRespawn implements Listener {
    3.  
    4. private Main plugin;
    5.  
    6. public NoRespawn(Main plugin) {
    7. this.plugin = plugin;
    8. }
    9.  
    10. @EventHandler
    11. public void onD(PlayerDeathEvent e) {
    12. final Player player = e.getEntity();
    13. Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    14. @Override
    15. public void run() {
    16. Packet205ClientCommand packet = new Packet205ClientCommand();
    17. packet.a = 1;
    18. ((CraftPlayer) player).getHandle().playerConnection.a(packet);
    19. }
    20. }, 0);
    21. }
    22. }
    23.  


    That is the code i use
     
  26. Offline

    RingOfStorms

    Why use a delayed task with a delay of zero...

    Code:java
    1.  
    2. @EventHandler
    3. public void death (PlayerDeathEvent e) {
    4. Packet205ClientCommand packet = new Packet205ClientCommand();
    5. packet.a = 1;
    6. ((CraftPlayer) e.getEntity()).getHandle().playerConnection.sendPacket(packet);
    7. }
    8.  


    Literally all you need.
     
  27. Offline

    naorpeled

    My code is Complete....
    With no packets....
    it was easy I was just stupid
     
  28. Offline

    HelGod

    I really don't know, lol
     
  29. What you could do would have a bukkit runnable that would loop through all the online players (every 1 tick), and if they have 1 health, //do your code.
     
Thread Status:
Not open for further replies.

Share This Page