From 6a374be73752b0d6317ac6e1dfdf1cea312cbacd Mon Sep 17 00:00:00 2001
From: Thinkofdeath <thinkofdeath@spigotmc.org>
Date: Sun, 15 Mar 2015 21:11:15 +0000
Subject: [PATCH] Fix possible tick list syncing issue

---
 nms-patches/WorldServer.patch | 52 +++++++++++++++++++++++------------
 1 file changed, 35 insertions(+), 17 deletions(-)

diff --git a/nms-patches/WorldServer.patch b/nms-patches/WorldServer.patch
index 6efc04a326..2bc8ad14bf 100644
--- a/nms-patches/WorldServer.patch
+++ b/nms-patches/WorldServer.patch
@@ -1,5 +1,5 @@
---- /home/matt/mc-dev-private//net/minecraft/server/WorldServer.java	2015-03-11 10:15:29.143595382 +0000
-+++ src/main/java/net/minecraft/server/WorldServer.java	2015-03-11 10:15:29.147595381 +0000
+--- /home/matt/mc-dev-private//net/minecraft/server/WorldServer.java	2015-03-15 21:11:07.596380090 +0000
++++ src/main/java/net/minecraft/server/WorldServer.java	2015-03-15 21:11:07.600380090 +0000
 @@ -16,11 +16,23 @@
  import org.apache.logging.log4j.LogManager;
  import org.apache.logging.log4j.Logger;
@@ -316,7 +316,25 @@
                  }
  
                  this.methodProfiler.a("cleaning");
-@@ -508,6 +673,7 @@
+@@ -477,7 +642,9 @@
+         for (int i = 0; i < 2; ++i) {
+             Iterator iterator;
+ 
++            boolean remove = false; // CraftBukkit
+             if (i == 0) {
++                remove = true; // CraftBukkit
+                 iterator = this.M.iterator();
+             } else {
+                 iterator = this.V.iterator();
+@@ -492,6 +659,7 @@
+ 
+                 if (blockposition.getX() >= structureboundingbox.a && blockposition.getX() < structureboundingbox.d && blockposition.getZ() >= structureboundingbox.c && blockposition.getZ() < structureboundingbox.f) {
+                     if (flag) {
++                        if (remove) // CraftBukkit
+                         this.L.remove(nextticklistentry);
+                         iterator.remove();
+                     }
+@@ -508,6 +676,7 @@
          return arraylist;
      }
  
@@ -324,7 +342,7 @@
      public void entityJoinedWorld(Entity entity, boolean flag) {
          if (!this.getSpawnAnimals() && (entity instanceof EntityAnimal || entity instanceof EntityWaterAnimal)) {
              entity.die();
-@@ -519,6 +685,7 @@
+@@ -519,6 +688,7 @@
  
          super.entityJoinedWorld(entity, flag);
      }
@@ -332,7 +350,7 @@
  
      private boolean getSpawnNPCs() {
          return this.server.getSpawnNPCs();
-@@ -531,13 +698,43 @@
+@@ -531,13 +701,43 @@
      protected IChunkProvider k() {
          IChunkLoader ichunkloader = this.dataManager.createChunkLoader(this.worldProvider);
  
@@ -377,7 +395,7 @@
          for (int k1 = 0; k1 < this.h.size(); ++k1) {
              TileEntity tileentity = (TileEntity) this.h.get(k1);
              BlockPosition blockposition = tileentity.getPosition();
-@@ -546,6 +743,8 @@
+@@ -546,6 +746,8 @@
                  arraylist.add(tileentity);
              }
          }
@@ -386,7 +404,7 @@
  
          return arraylist;
      }
-@@ -609,6 +808,23 @@
+@@ -609,6 +811,23 @@
              int j = this.worldProvider.getSeaLevel();
              int k = 0;
  
@@ -410,7 +428,7 @@
              if (blockposition != null) {
                  i = blockposition.getX();
                  k = blockposition.getZ();
-@@ -618,7 +834,7 @@
+@@ -618,7 +837,7 @@
  
              int l = 0;
  
@@ -419,7 +437,7 @@
                  i += random.nextInt(64) - random.nextInt(64);
                  k += random.nextInt(64) - random.nextInt(64);
                  ++l;
-@@ -657,6 +873,7 @@
+@@ -657,6 +876,7 @@
  
      public void save(boolean flag, IProgressUpdate iprogressupdate) throws ExceptionWorldConflict {
          if (this.chunkProvider.canSave()) {
@@ -427,7 +445,7 @@
              if (iprogressupdate != null) {
                  iprogressupdate.a("Saving level");
              }
-@@ -667,7 +884,8 @@
+@@ -667,7 +887,8 @@
              }
  
              this.chunkProvider.saveChunks(flag, iprogressupdate);
@@ -437,7 +455,7 @@
              Iterator iterator = arraylist.iterator();
  
              while (iterator.hasNext()) {
-@@ -698,8 +916,12 @@
+@@ -698,8 +919,12 @@
          this.worldData.k(this.getWorldBorder().getWarningTime());
          this.worldData.b(this.getWorldBorder().j());
          this.worldData.e(this.getWorldBorder().i());
@@ -451,7 +469,7 @@
      }
  
      protected void a(Entity entity) {
-@@ -731,8 +953,16 @@
+@@ -731,8 +956,16 @@
      }
  
      public boolean strikeLightning(Entity entity) {
@@ -469,7 +487,7 @@
              return true;
          } else {
              return false;
-@@ -744,10 +974,20 @@
+@@ -744,10 +977,20 @@
      }
  
      public Explosion createExplosion(Entity entity, double d0, double d1, double d2, float f, boolean flag, boolean flag1) {
@@ -490,7 +508,7 @@
          if (!flag1) {
              explosion.clearBlocks();
          }
-@@ -793,7 +1033,8 @@
+@@ -793,7 +1036,8 @@
                  BlockActionData blockactiondata = (BlockActionData) iterator.next();
  
                  if (this.a(blockactiondata)) {
@@ -500,7 +518,7 @@
                  }
              }
  
-@@ -816,6 +1057,7 @@
+@@ -816,6 +1060,7 @@
          boolean flag = this.S();
  
          super.p();
@@ -508,7 +526,7 @@
          if (this.o != this.p) {
              this.server.getPlayerList().a(new PacketPlayOutGameStateChange(7, this.p), this.worldProvider.getDimension());
          }
-@@ -834,6 +1076,21 @@
+@@ -834,6 +1079,21 @@
              this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(7, this.p));
              this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(8, this.r));
          }
@@ -530,7 +548,7 @@
  
      }
  
-@@ -862,10 +1119,17 @@
+@@ -862,10 +1122,17 @@
      }
  
      public void a(EnumParticle enumparticle, boolean flag, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6, int... aint) {