From 0b19d626323931d3ac71152f1faf654ddf10d7ab Mon Sep 17 00:00:00 2001
From: Zach Brown <1254957+zachbr@users.noreply.github.com>
Date: Fri, 17 Mar 2017 00:04:34 -0500
Subject: [PATCH] Make sure the entity is still added to the world

---
 ...plicate-alive-entity-on-second-world.patch | 65 ++++++++++++++-----
 1 file changed, 50 insertions(+), 15 deletions(-)

diff --git a/Spigot-Server-Patches/Fix-a-duplicate-alive-entity-on-second-world.patch b/Spigot-Server-Patches/Fix-a-duplicate-alive-entity-on-second-world.patch
index d1becbc061..ae5c0ee3b0 100644
--- a/Spigot-Server-Patches/Fix-a-duplicate-alive-entity-on-second-world.patch
+++ b/Spigot-Server-Patches/Fix-a-duplicate-alive-entity-on-second-world.patch
@@ -5,24 +5,59 @@ Subject: [PATCH] Fix a duplicate alive entity on second world
 
 
 diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
-index 0e1d9817..4cabdd7a 100644
+index 0e1d9817..92ba4fcb 100644
 --- a/src/main/java/net/minecraft/server/Entity.java
 +++ b/src/main/java/net/minecraft/server/Entity.java
 @@ -0,0 +0,0 @@ public abstract class Entity implements ICommandListener {
              // CraftBukkit end */
-             // CraftBukkit start - Ensure chunks are loaded in case TravelAgent is not used which would initially cause chunks to load during find/create
-             // minecraftserver.getPlayerList().changeWorld(this, j, worldserver, worldserver1);
-+            this.dead = true; // Paper - Mark entity as dead before we actually move it to the new world
-             worldserver1.getMinecraftServer().getPlayerList().repositionEntity(this, exit, portal);
-             // worldserver.entityJoinedWorld(this, false); // Handled in repositionEntity
-             // CraftBukkit end
-@@ -0,0 +0,0 @@ public abstract class Entity implements ICommandListener {
-                 // CraftBukkit end
-             }
  
--            this.dead = true;
-+            //this.dead = true; // Paper - Moved this up to ensure that the entity is dead when it's placed on the new world
-             this.world.methodProfiler.b();
-             worldserver.m();
-             worldserver1.m();
+             this.world.kill(this);
+-            this.dead = false;
++            //this.dead = false; // Paper - Mark entity as dead before we actually move it to the new world
+             this.world.methodProfiler.a("reposition");
+             /* CraftBukkit start - Handled in calculateTarget
+             BlockPosition blockposition;
+diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
+index a9d59bbf..a83a3054 100644
+--- a/src/main/java/net/minecraft/server/PlayerList.java
++++ b/src/main/java/net/minecraft/server/PlayerList.java
+@@ -0,0 +0,0 @@ public abstract class PlayerList {
+         entityplayer.playerConnection.sendPacket(new PacketPlayOutRespawn(entityplayer.dimension, entityplayer.world.getDifficulty(), entityplayer.world.getWorldData().getType(), entityplayer.playerInteractManager.getGameMode()));
+         this.f(entityplayer);
+         worldserver.removeEntity(entityplayer);
+-        entityplayer.dead = false;
++        //entityplayer.dead = false; // Paper - He's dead jim - Handle players the same way we do all entities
+         this.changeWorld(entityplayer, j, worldserver, worldserver1);
+         this.a(entityplayer, worldserver);
+         entityplayer.playerConnection.a(entityplayer.locX, entityplayer.locY, entityplayer.locZ, entityplayer.yaw, entityplayer.pitch);
+@@ -0,0 +0,0 @@ public abstract class PlayerList {
+ 
+         worldserver.methodProfiler.a("moving");
+         entity.setPositionRotation(exit.getX(), exit.getY(), exit.getZ(), exit.getYaw(), exit.getPitch());
+-        if (entity.isAlive()) {
++        //if (entity.isAlive()) { // Paper - The entity will be dead, that's okay
+             worldserver.entityJoinedWorld(entity, false);
+-        }
++        //} // Paper
+         /*
+         if (entity.dimension == -1) {
+             d0 = MathHelper.a(d0 / 8.0D, worldserver1.getWorldBorder().b() + 16.0D, worldserver1.getWorldBorder().d() - 16.0D);
+@@ -0,0 +0,0 @@ public abstract class PlayerList {
+             d0 = (double) MathHelper.clamp((int) d0, -29999872, 29999872);
+             d1 = (double) MathHelper.clamp((int) d1, -29999872, 29999872);
+             */
+-            if (entity.isAlive()) {
++            //if (entity.isAlive()) { // Paper - The entity will be dead, that's okay
+                 // entity.setPositionRotation(d0, entity.locY, d1, entity.yaw, entity.pitch);
+                 // worldserver1.getTravelAgent().a(entity, f);
+                 if (portal) {
+@@ -0,0 +0,0 @@ public abstract class PlayerList {
+                 }
+                 // worldserver1.addEntity(entity);
+                 worldserver1.entityJoinedWorld(entity, false);
+-            }
++            //} // Paper
+ 
+             worldserver.methodProfiler.b();
+         }
 --
\ No newline at end of file