Disables death screen on death

Discussion in 'Spigot Plugin Development' started by suitinacow, Jul 10, 2015.

  1. I need to disable the death screen when a player re-spawns.. Any idea on how to do this?
     
  2. Listen to when they get damaged, and if their health-damage<0 do what ever it is you need to do.

    Or when they die have a BukkitRunnable that after a tick set their health back to 20
     
    #2 Bimmr, Jul 10, 2015
    Last edited: Jul 10, 2015
    • Like Like x 1
  3. thanks, ill try this and tell you what happens
     
  4. Wouldn't the Death Packet still be sent right when a Player's health hits 0.0? You're probably better off using ProtocolLib to cancel the death screen
     
    • Like Like x 1
    • Agree Agree x 1
  5. I believe you can still set their health to 20, and it'll work. although you'd have to test. I remember seeing this being posted somewhere else.
     
    • Like Like x 1
  6. Maybe, but I'm just basing it off of reason. When you die on a server, right when your health hits 0 you see the death animation and the screen. So if you wait a second you're basically healing a player that is viewed by the server as dead. The server won't even handle that correctly until the client sends a respawn packet.
     
    • Like Like x 1
    • Like Like x 1
  7. What I do is on a playerdeathevent schedule a delayed task of 1 tick and then set their health to 20.0
     
    • Like Like x 1
  8. Wouldn't that still cause them to see a flash of the death screen for like .5 seconds?
     
    • Like Like x 1
  9. Well in technical terms that's 10 ticks :p. You can actually try it without the delay, but 1 tick is very unnoticeable.
     
    • Like Like x 1
  10. Yeah, I was just curious (Everything I posted above was just pure hunches on how I understand the client <-> server communications. If your version does work without flashing the screen, that would be better than using ProtcolLib or packets because it won't break. Unless Mojang decides to mess with health again..
     
    • Like Like x 1
  11. I followed most of what you guys said and made a simple block of code here and im not sure if it's supposed to be like this since it does absolutely nothing when I die. it doesnt teleport me nor regain my hearts

    Code (Text):
    @EventHandler
        public void damage(final PlayerDeathEvent event){
            try{
                if(event.getEntity() instanceof Player){
                    Player player = (Player) event.getEntity();
                    if(player.getHealth() < 0)
                    {
                        player.setHealth(20);
                        player.teleport(pluginHandler.getSpawn(player.getWorld()));
                    }
                }
            }catch (Exception x){
                x.printStackTrace();              
            }  
        }
     
  12. Fixed it, i just changed
    Code (Text):
    if(player.getHealth() < 0)
    to
    Code (Text):
    if(player.getHealth() < .1)
     
  13. you could also go for if(player.getHealth() <= 0) (or =< I always forget which way it's arround.
    It would make it a little bit cleaner wouldnt it?
     
  14. or just use
    player.spigot().respawn(); to insta respawn them? It happens really fast. The death screen doesnt even show.
     
  15. Or, you could just listen for an EntityDamageEvent then check if the event damage is greater than or equal to the player's current health. Then, cancel the event, set their health back to 20 and do whatever it is you need to do.
     
  16. player.isDead() ???
     
  17. That checks if they're dead.
     
  18. I know, and with the code posted here:
    Code (Text):
    @EventHandler
        public void damage(final PlayerDeathEvent event){
            try{
                if(event.getEntity() instanceof Player){
                    Player player = (Player) event.getEntity();
                    if(player.getHealth() < 0)
                    {
                        player.setHealth(20);
                        player.teleport(pluginHandler.getSpawn(player.getWorld()));
                    }
                }
            }catch (Exception x){
                x.printStackTrace();              
            }  
        }
    the player is dead, so instead of checking if the heath is less then 0, you can just check if they are dead.
     
    • Agree Agree x 1
  19. Ah thx.. but then i'd have to force them to drop all of their stuff in the inventory and armor, and exp.. i used these methods but they dont work??
    Code (Text):

                        player.setFireTicks(0);
                        event.setDroppedExp((int) player.getExp());                  
                        player.getInventory().clear();
                        player.getActivePotionEffects().clear();