Solved Canceling PlayerDeathEvent by setHealth(20D) works in API 1.13.2 Dec 2018 but not in 1.13.2 Jan 2019

Discussion in 'Spigot Plugin Development' started by Zame, Jan 12, 2019.


    I am very confused atm.

    I made a plugin and achieved to "cancel" the PlayerDeathEvent by setting the health of the victim back to 20.
    It all works well.
    But today I was using the latest 1.13.2 spigot.jar on my server (server running it) and it didn't work.
    The victim was still alive for other players but the client of the victim was in the respawn screen.

    I tested the new plugin where I was using this method on a server that was running the 1.13.2 spigot.jar from december 2018 an everything worked fine.

    Idk if it should be like that or if that is a bug in spigot api or an error on my side.

    I know I could simply do all the stuff in the EntityDamageByEntityEvent but it worked before the other way so I thought I should open a thread to talk about that.

    Here is my code that works fine on a server running dec 2018 spigot but not on a server running jan 2019 spigot:

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

            Player dead = event.getEntity();


    #1 Zame, Jan 12, 2019
    Last edited: Jan 12, 2019
  2. Why dead.setHealth(20D); and not dead.setHealth(20);?
    Ohhh and please answer my question
  3. Since the event is not cancellable, it sounds like you'd need to use the the EntityDamageEvent and check if the entity being damaged is a Player and whether or not the final damage would result in the player's death.

    As to why this behaviour was changed, I cannot answer.

    The D stands for double and is perfectly acceptable.

    The event does not implement Cancellable and thus cannot be cancelled.
    • Agree Agree x 1
    • Informative Informative x 1
  4. Welp didnt realise that
  5. Haha. You should know you can't
    #setCancelled(true); in PlayerDeathEvent.
    As said before. My code works on a server running Dec 2018 API but not on a server running the JAN 2019 API.
  6. I know I can do that but It works on a server running DEC 2018 API
  7. Well, like i said i didnt realise that, apologies. I'm used to cancelling events all the time. It's fine to correct me, but please keep it respectful.
    • Like Like x 1
  8. No prob. Everbody learns new stuff
  9. As far as I can tell, the event is not supposed to be cancellable. So it might have been considered a bug that setting the player's health to 20 would (effectively) cancel it.
    But that's just me speculating.

    I did...
  10. The weird thing is. In the latest API is also "cancels" the event. The Player is still alive for other players and himself but he is in the respawn screen
  11. There might be a packet you could stop from being sent to stop that from happening, but I'm not entirely sure which one that would be.
  12. I know that there is this
    Code (Text):
    ((CraftPlayer)player).getHandle().playerConnection.a(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN));
    But didn't work and wasn't my prio atm
  13. Just catch the damage event, check if damage >= to health, and if so, cancel it. It probably doesn't work in 1.13 because setHealth is a sloppy way of stopping death, and the death event was never intended for something like that. If it was, they would've made it cancellable.
    • Informative Informative x 1
  14. As mentioned above, I know that I could do that I just want to know why it works in the older API (month old) and not anymore (january)? And hopefully a fix for that
  15. Check the spigot source and find the difference
  16. Try this

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

            Player dead = event.getEntity().getName;


    • Funny Funny x 1
    • Optimistic Optimistic x 1
    • Creative Creative x 1
  17. md_5

    Administrator Developer

    I'd be somewhat surprised if there really was a change between December and January that causes this.

    Anyway you need to find the exact build that introduced this bug.

    When you run buildtools you will see it prints out a build number, currently 2046.

    You can pass this number to --rev to get a specific version.

    Go back and find the last working version, and then open a bug report using the issues link above.

    Actually now that I think about it, I'm almost certain this commit is what changed it:

    Basically fixes a long time Spigot bug where players never saw death messages on their client game over screen.

    The best fix imo is to not try and revive players in the death event (its a miracle this doesn't cause other obscure bugs), but rather to not allow the killing blow in the first place (EntityDamageEvent).

    I'm a bit hesitant to make PlayerDeathEvent cancellable, because it doesn't seem to me like it has well defined behaviour as to what happens if you cancel it. For example what should it set the player's health to if you cancel the event? Because if the health isn't set back to a positive number they'll just get stuck in a death loop and/or glitched state.
    • Agree Agree x 2
    • Informative Informative x 1
  18. Thanks for the anwser.

    A methode to make death cancelable would be to so #setCancle(bool, double);
    so you cancle the event and set the health. If double is below 0 it throws an exception.

    Might not be the best solution but maybe you guys think about it
  19. First of all, thank you. second your code is a bit wrong. and I also posted my code that works on an older build

Share This Page