From 4377f7fede13664a3b9b911e7b94f0e24d22fd0d Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Mon, 12 Feb 2018 08:59:32 +1100 Subject: [PATCH] SPIGOT-3813: Player.setHealth not reliable in conjunction with attribute API By: md_5 --- paper-server/nms-patches/EntityLiving.patch | 2 +- .../java/org/bukkit/craftbukkit/entity/CraftPlayer.java | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/paper-server/nms-patches/EntityLiving.patch b/paper-server/nms-patches/EntityLiving.patch index 1fd9494f40..1521d5c8d5 100644 --- a/paper-server/nms-patches/EntityLiving.patch +++ b/paper-server/nms-patches/EntityLiving.patch @@ -257,7 +257,7 @@ + player.setRealHealth(f); + } + -+ this.datawatcher.set(EntityLiving.HEALTH, Float.valueOf(player.getScaledHealth())); ++ player.updateScaledHealth(); + return; + } + // CraftBukkit end diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 20059b9456..1866d5210f 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -1382,9 +1382,12 @@ public class CraftPlayer extends CraftHumanEntity implements Player { injectScaledMaxHealth(set, true); + // SPIGOT-3813: Attributes before health + if (getHandle().playerConnection != null) { + getHandle().playerConnection.sendPacket(new PacketPlayOutUpdateAttributes(getHandle().getId(), set)); + sendHealthUpdate(); + } getHandle().getDataWatcher().set(EntityLiving.HEALTH, (float) getScaledHealth()); - sendHealthUpdate(); - getHandle().playerConnection.sendPacket(new PacketPlayOutUpdateAttributes(getHandle().getId(), set)); getHandle().maxHealthCache = getMaxHealth(); }