Skipping respawn screen without packets

Discussion in 'Plugin Development' started by glasseater, Dec 21, 2014.

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

    glasseater

    Hey guys,

    As the title says, I am trying to skip the respawn screen. However, I was wondering if there was a way to do it without packets. Any help is appreciated. I have tried setting their health to 20 and sending them to the spawn but that did not work.

    Kind Regards,

    Glass
     
  2. Offline

    Slash9211

    Did you get there health, tp to spawn cords, set health? In that order?
     
  3. Offline

    Konato_K

    There is no way to do this without packets or NMS.

    Also, as far I know, setting their health to 20 in the PlayerDeathEvent can break stuff.
     
  4. Offline

    glasseater

  5. Offline

    API_Tutorials

  6. Offline

    Skionz

  7. Offline

    BrentHogeling

    @glasseater You need to use packets as automating the death event could miss out some vital stuff, as well as that other plugins which listen for a death event won't fire IIRC.
     
  8. Offline

    mrgreen33gamer

    @glasseater I use my respawn code with PACKETS. Because @Skionz said: Packets are fun!

    #SpoonFeeding Here you go, sir! This code will INSTANTLY respawn them:

    Code:java
    1.  
    2. new BukkitRunnable() {
    3. public void run() {
    4. try {
    5. Object nmsPlayer = player.getClass()
    6. .getMethod("getHandle", new Class[0])
    7. .invoke(player, new Object[0]);
    8. Object packet = Class.forName(
    9. nmsPlayer.getClass().getPackage().getName()
    10. + ".PacketPlayInClientCommand")
    11. .newInstance();
    12. Class<?> enumClass = Class.forName(nmsPlayer.getClass()
    13. .getPackage().getName()
    14. + ".EnumClientCommand");
    15. for (Object ob : enumClass.getEnumConstants()) {
    16. if (ob.toString().equals("PERFORM_RESPAWN")) {
    17. packet = packet.getClass()
    18. .getConstructor(new Class[] { enumClass })
    19. .newInstance(new Object[] { ob });
    20. }
    21. }
    22. Object con = nmsPlayer.getClass()
    23. .getField("playerConnection").get(nmsPlayer);
    24. con.getClass()
    25. .getMethod("a", new Class[] { packet.getClass() })
    26. .invoke(con, new Object[] { packet });
    27. } catch (Throwable t) {
    28. t.printStackTrace();
    29. }
    30. }
    31. }.runTaskTimer(plugin, 0L, 10L);
    32.  
     
    Skionz and pookeythekid like this.
  9. Offline

    Konato_K

    @mrgreen33gamer If we are going to spoon feed then I'm going to give something easier

    Code:
    public void respawnPlayer(Player player)
    { if(player.isDead())
      { ((CraftServer)Bukkit.getServer()).getHandle().moveToWorld(((CraftPlayer)player).getHandle(), 0, false);
      }
    }
    
    This is NMS and of course, this does not have reflection, much spoon such feed.
     
  10. Offline

    Bloxcraft

    I use this method on my server:

    on player death
    make new respawn event + call it
    set player health to their max health
    teleport to event's respawn location
    reset the player (remove potion effects, set fire ticks to 0, set velocity to none, etc)
     
  11. Offline

    mrgreen33gamer

    @Konato_K That doesn't cancel the respawn screen. It just teleports them to a world... Silly u!
     
  12. Offline

    Konato_K

    @mrgreen33gamer Test it, it does respawn them, actually, that's the code the server runs after receiving the respawn packet.
     
  13. Offline

    mrgreen33gamer

    @Konato_K Came here to help. Not to test YOUR code.
     
  14. Offline

    mythbusterma

    @mrgreen33gamer

    You criticise his code as not working, and when he tells you it does work, you tell him that you're not here to test his code. Please, don't post if you don't know what you're talking about, or can't even be told you're wrong when you call someone out in error.
     
  15. Offline

    glasseater

    @Konato_K I have tried packets quite a few times. With no luck. Does it have to be on 1.8? Because I am using 1.7.9
     
  16. Offline

    Skionz

    @glasseater You can use any version although I believe the classes were renamed in 1.6 or 1.7.
     
  17. Offline

    Konato_K

    @glasseater The code I put has been tested in all 1.7 versions (1_7_R1 to 1_7_R4), I don't know if there are changes in the namespace of 1_8_R1 so I don't know if it works in 1.8, but it works fine in 1.7
     
  18. Offline

    Noahz123

    Yes, use this if you want to lag your server to oblivion.
     
  19. Offline

    jusjus112

    You can just easy set the player his health to max, and dont let them die?
    Thats what the title says "Without packets"?
     
  20. Offline

    glasseater

  21. Offline

    nuno1212sss

    @glasseater Not that hard, check for EntityDamageEvent and check if their health - the final damage of the event is less than 0 if it is, cancel the event, reset the player(Max health, max food, no potions, etc...) and drop all his stuff, about exp I don't know what the drop amount loss is but here have some #SpoonFeed
    Code:
    @EventHandler
        public void onDamagee(EntityDamageEvent e){
            if(!(e.getEntity() instanceof Player)) return;
                if((((Player) e.getEntity()).getHealth()-e.getFinalDamage())<=0){
                    Player p = (Player) e.getEntity();
    Inventory i = p.getInventory();
    for(ItemStack in : i.getContents()){
    if(in!=null &&in.getType() != Material.AIR)
    p.getWorld().dropItem(p.getLocation(), in);
    }
    p.getInventory().clear();
    for(ItemStack ar : p.getInventory().getArmorContents()){
    if(ar != null &&ar.getType() != Material.AIR)
    p.getWorld().dropItem(p.getLocation(),ar);
    }
    p.getInventory().setArmorContents(new ItemStack[4]);
                    e.setCancelled(true);
                    return;
            }
        }
    There is no player reset there, but it isn't that hard xD
     
    Lionhard likes this.
  22. Offline

    Noahz123

    I'd also like to state that this code segment is from a person named Minecrell and it has been floating around the internet for well over a year now. I took the first two lines, put it into google, and found it as the second result.
     
  23. @nuno1212sss DOn't know if it works, but it is definitelly a nice way. :D LIKE!
     
  24. Offline

    1Rogue

    Everyone is suggesting solutions with non-bukkit (yes that includes craftbukkit) code when it's really as simple as:

    Code:java
    1. @EventHandler
    2. public void onDamage(EntityDamageEvent event) {
    3. if (event.getEntityType() == EntityType.PLAYER) {
    4. if (event.getCause() != DamageCause.ENTITY_ATTACK
    5. && event.getCause() != DamageCause.PROJECTILE) { //Use EntityDamageByEntityEvent for resolution here
    6. Player p = (Player) event.getEntity();
    7. if (event.getDamage() >= p.getHealth()
    8. && p.getGameMode() != GameMode.CREATIVE) {
    9. //dead - teleport or handle
    10. event.setDamage(0);
    11. event.setCancelled(true);
    12. }
    13. }
    14. }
    15. }


    Don't forget to drop their inventories upon death!
     
  25. Offline

    glasseater

    @1Rogue That does not work either.
     
  26. Offline

    1Rogue

    It won't work for entity attacks and projectiles if you blindly copy/pasted it, as noted in the code "Use EntityDamageByEntityEvent for resolution here".
     
  27. Offline

    glasseater

    @1Rogue I know. It doesn't work though :/
     
  28. Offline

    1Rogue

    How is it not working? How did you interpret this in your code? I can assure you that it works having used it for implementations before, so somewhere there's something else mixed up here.
     
  29. Offline

    glasseater

    @1Rogue Does it work on 1.7? Maybe that. Although I don't see why it wouldn't. It still takes them to the respawn screen.
     
  30. Offline

    1Rogue

    I used the EntityDamageEvent, not the PlayerDeathEvent. In english what that code will do is cancel any damage that results in a death if the following conditions are met:

    • Target is a player
    • Cause of death was not a projectile or another entity attacking them
    • The player is not in creative
     
Thread Status:
Not open for further replies.

Share This Page