From 463e6dac068859faf37b1d9a76a3f069ee3a820a Mon Sep 17 00:00:00 2001
From: Zach Brown <1254957+zachbr@users.noreply.github.com>
Date: Tue, 11 Sep 2018 17:38:57 -0400
Subject: [PATCH] Ensure entity is always dying before Death Event

Prior to this it was possible for plugins to put the server into a never
ending recursive loop until it eventually killed itself.

Fixes GH-1432
---
 .gitignore                                       | 1 +
 Spigot-Server-Patches/Improve-death-events.patch | 5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore
index 9712169add..3ef869c1ac 100644
--- a/.gitignore
+++ b/.gitignore
@@ -34,6 +34,7 @@ work/Spigot-Server
 work/Spigot-API
 work/*.jar
 work/test-server
+work/ForgeFlower
 
 # Mac filesystem dust
 .DS_Store/
diff --git a/Spigot-Server-Patches/Improve-death-events.patch b/Spigot-Server-Patches/Improve-death-events.patch
index f5f776fdfc..14d749ec63 100644
--- a/Spigot-Server-Patches/Improve-death-events.patch
+++ b/Spigot-Server-Patches/Improve-death-events.patch
@@ -69,7 +69,7 @@ index dca497072..454c1e7d0 100644
      }
  
 diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
-index 14637be49..dec4b442c 100644
+index 14637be49..5ccd3ea6f 100644
 --- a/src/main/java/net/minecraft/server/EntityLiving.java
 +++ b/src/main/java/net/minecraft/server/EntityLiving.java
 @@ -0,0 +0,0 @@ public abstract class EntityLiving extends Entity {
@@ -140,7 +140,7 @@ index 14637be49..dec4b442c 100644
  
 -            this.aU = true;
 -            this.getCombatTracker().g();
-+            //this.aU = true;
++            this.aU = true; // Paper - Always set at start, unset later if cancelled - GH-1432
 +            //this.getCombatTracker().g();
 +
 +            org.bukkit.event.entity.EntityDeathEvent deathEvent = null;
@@ -178,6 +178,7 @@ index 14637be49..dec4b442c 100644
 +                this.setDying(true);
 +                this.world.broadcastEntityEffect(this, (byte) 3);
 +            } else {
++                this.setDying(false); // Paper - reset if cancelled
 +                this.setHealth((float) deathEvent.getReviveHealth());
 +            }
 +            // Paper end