Solved Heal on death event

Discussion in 'Spigot Plugin Development' started by MrDienns, May 3, 2017.

Thread Status:
Not open for further replies.
  1. Hi Spigoters,

    I am making a plugin that allows a full custom hp system without adding any extra hearts. It's working perfectly fine but I had a question.

    When the player dies, I reset the player's HP to full before he even spawns. This was a slight mistake but I figured I could make it into a nice death animation instead.

    Question: Will healing the player on a death event cause unexpected issues?

    Now you may be asking "how can this cause unexpected issues? What can possibly happen?". Well. This is what happened an hour ago:
  2. You could use an EntityDamageEvent and check if the health is like 0.0001, because you can't undo death, and restore the health and do whatever. This is what I did for my 1vs1 plugin.
    • Agree Agree x 2
    • Useful Useful x 1
  3. I have a KitPvP plugin that does something similar to this, except it respawns them with a delay.

    What works for me is on PlayerDeathEvent, you set them to creative mode and then set their health to 20. Then it puts them in a sort of temporary spectator mode by enabling flight, applying upward velocity, giving blindness for 21 ticks, and hiding their entity.
    2 seconds later it respawns them.

    If you want the method I'll give it.

    I've experienced no half-dead errors with this method.

    EDIT: Another way is to use EntityDamageByEntityEvent and check if player.getHealth - event.getFinalDamage() is less than or equal to 0 and if it is, cancel the event and respawn the player.
    • Useful Useful x 1
  4. If you want to share your fancy delayed respawn method, that'd be sweet. I'm working on some custom death animation so I may get some inspiration :p
  5. Setting their health back to twenty and teleporting them back to spawn (or wherever, even just to reset their orientation) seems to work more than sufficiently in all of the plugins I've made that do this. 3 of which are on servers and constantly being used and I've yet to find an issue like that lol
  6. I think there is a player#spigot()#respawn() method, this respawns the user, I've used this before and works fine.
    • Agree Agree x 1
  7. Just to be sure I'll just use the damage event and check if the player would have a health of 0.0, if so, I'll trigger my custom death things.

    You did not read the thread at all did you
  8. This is the exact code I use taken from my private FFA, UHCSimulator, and Duels plugins and used in the PlayerDeathEvent for all 3 :p

    Code (Text):

                victim.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 20, 2));
    The reason I give them slowness is the velocity will still be there when they teleport and it ensures the dont go flying when they are teleported.
    • Useful Useful x 1
  9. As far as I am aware there are no negative side effects of settings a users health to the maximum in the EntityDamageEvent or in the EntityDeathEvent. From my experience both should work although if you are using the EntityDamageEvent than you might be be canceling the event causeing other plugins who use this event to not function, (think of custom death messages etc). I am not fully aware if these other events will be skipped. As of my testing this does not happen. Btw if you check for (if (event.getEntity().getHealth() - event.getFinalDamage() <= 0.0)) you should be fine.
    To answer your question, it should have no negative side effects if you are using any of these events or if you cancel them.

    Hope I answered your question,

    • Useful Useful x 1
  10. Sure thing. In this case I am using EntityHider (An Entity hiding library by Comphenix found here), but you could also just use the .hidePlayer() method.

    Code (Text):
        public void deathThing(PlayerDeathEvent event) {

            Player player = event.getEntity();


            player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 0));
            player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 21, 0));


            for (Player players : Bukkit.getServer().getOnlinePlayers()) {
                plugin.hideEntity(players, player);


            plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
                public void run() {
            }, 20L * 2);
    • Useful Useful x 1
  11. stop them from dying, and keep them from dying. just count this as a death and do what you want after
  12. This was actually a fix to Your issue, reading docs isn't hard; No need to assy about my reply; However this is the bukkit community..
  13. It wasn't an answer to my question :p

    I wasn't asking how to respawn a user: I was asking if healing a user in a death event would cause unexpected things. Nothing more nothing less :p
    Anyhow it's solved now so I'll mark it as solved.
Thread Status:
Not open for further replies.