From 532e229c28a8a0c8bd4f910352a0647180ce1772 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sun, 20 Mar 2016 00:35:02 -0400 Subject: [PATCH] handle NaN health/absorb values and repair bad data Undoes damage from Damage API bugs --- ...th-absorb-values-and-repair-bad-data.patch | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Spigot-Server-Patches/0097-handle-NaN-health-absorb-values-and-repair-bad-data.patch diff --git a/Spigot-Server-Patches/0097-handle-NaN-health-absorb-values-and-repair-bad-data.patch b/Spigot-Server-Patches/0097-handle-NaN-health-absorb-values-and-repair-bad-data.patch new file mode 100644 index 0000000000..f36e946911 --- /dev/null +++ b/Spigot-Server-Patches/0097-handle-NaN-health-absorb-values-and-repair-bad-data.patch @@ -0,0 +1,60 @@ +From e1be9ab34e3afe58f661278015309c564c953717 Mon Sep 17 00:00:00 2001 +From: Aikar +Date: Sun, 27 Sep 2015 01:18:02 -0400 +Subject: [PATCH] handle NaN health/absorb values and repair bad data + + +diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java +index 3e92dcc..cef1117 100644 +--- a/src/main/java/net/minecraft/server/EntityLiving.java ++++ b/src/main/java/net/minecraft/server/EntityLiving.java +@@ -457,7 +457,13 @@ public abstract class EntityLiving extends Entity { + } + + public void a(NBTTagCompound nbttagcompound) { +- this.setAbsorptionHearts(nbttagcompound.getFloat("AbsorptionAmount")); ++ // Paper start - jvm keeps optimizing the setter ++ float absorptionAmount = nbttagcompound.getFloat("AbsorptionAmount"); ++ if (Float.isNaN(absorptionAmount)) { ++ absorptionAmount = 0; ++ } ++ this.setAbsorptionHearts(absorptionAmount); ++ // Paper end + if (nbttagcompound.hasKeyOfType("Attributes", 9) && this.world != null && !this.world.isClientSide) { + GenericAttributes.a(this.getAttributeMap(), nbttagcompound.getList("Attributes", 10)); + } +@@ -742,6 +748,10 @@ public abstract class EntityLiving extends Entity { + } + + public void setHealth(float f) { ++ // Paper start ++ if (Float.isNaN(f)) { f = getMaxHealth(); if (this.valid) { ++ System.err.println("[NAN-HEALTH] " + getName() + " had NaN health set"); ++ } } // Paper end + // CraftBukkit start - Handle scaled health + if (this instanceof EntityPlayer) { + org.bukkit.craftbukkit.entity.CraftPlayer player = ((EntityPlayer) this).getBukkitEntity(); +@@ -2084,7 +2094,7 @@ public abstract class EntityLiving extends Entity { + } + + public void setAbsorptionHearts(float f) { +- if (f < 0.0F) { ++ if (f < 0.0F || Float.isNaN(f)) { // Paper + f = 0.0F; + } + +diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +index b2b2bf4..4bcfe96 100644 +--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java ++++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +@@ -1371,6 +1371,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { + } + + public void setRealHealth(double health) { ++ if (Double.isNaN(health)) {return;} // Paper + this.health = health; + } + +-- +2.7.4 +