From f5d92d6b12dcc43cb9a05f2e16357ebe0d9fdc20 Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Tue, 1 Mar 2016 11:20:42 +1100
Subject: [PATCH] SPIGOT-1525: Fix worldborder set.

---
 nms-patches/World.patch | 69 +++++++++++++++++++++--------------------
 1 file changed, 36 insertions(+), 33 deletions(-)

diff --git a/nms-patches/World.patch b/nms-patches/World.patch
index 9e81b62588..6238ecad4b 100644
--- a/nms-patches/World.patch
+++ b/nms-patches/World.patch
@@ -75,15 +75,18 @@
          this.u = Lists.newArrayList(new IWorldAccess[] { this.t});
          this.L = Calendar.getInstance();
          this.scoreboard = new Scoreboard();
-@@ -69,6 +128,7 @@
+@@ -69,6 +128,10 @@
          this.worldProvider = worldprovider;
          this.isClientSide = flag;
          this.N = worldprovider.getWorldBorder();
-+        this.getServer().addWorld(this.world);  // CraftBukkit
++        // CraftBukkit start
++        this.N.world = (WorldServer) this;
++        this.getServer().addWorld(this.world);
++        // CraftBukkit end
      }
  
      public World b() {
-@@ -197,6 +257,27 @@
+@@ -197,6 +260,27 @@
      }
  
      public boolean setTypeAndData(BlockPosition blockposition, IBlockData iblockdata, int i) {
@@ -111,7 +114,7 @@
          if (!this.isValidLocation(blockposition)) {
              return false;
          } else if (!this.isClientSide && this.worldData.getType() == WorldType.DEBUG_ALL_BLOCK_STATES) {
-@@ -204,9 +285,23 @@
+@@ -204,9 +288,23 @@
          } else {
              Chunk chunk = this.getChunkAtWorldCoords(blockposition);
              Block block = iblockdata.getBlock();
@@ -135,7 +138,7 @@
                  return false;
              } else {
                  if (iblockdata.c() != iblockdata1.c() || iblockdata.d() != iblockdata1.d()) {
-@@ -215,6 +310,7 @@
+@@ -215,6 +313,7 @@
                      this.methodProfiler.b();
                  }
  
@@ -143,7 +146,7 @@
                  if ((i & 2) != 0 && (!this.isClientSide || (i & 4) == 0) && chunk.isReady()) {
                      this.notify(blockposition, iblockdata1, iblockdata, i);
                  }
-@@ -225,12 +321,35 @@
+@@ -225,12 +324,35 @@
                          this.updateAdjacentComparators(blockposition, block);
                      }
                  }
@@ -179,7 +182,7 @@
      public boolean setAir(BlockPosition blockposition) {
          return this.setTypeAndData(blockposition, Blocks.AIR.getBlockData(), 3);
      }
-@@ -264,6 +383,11 @@
+@@ -264,6 +386,11 @@
  
      public void update(BlockPosition blockposition, Block block) {
          if (this.worldData.getType() != WorldType.DEBUG_ALL_BLOCK_STATES) {
@@ -191,7 +194,7 @@
              this.applyPhysics(blockposition, block);
          }
  
-@@ -339,6 +463,17 @@
+@@ -339,6 +466,17 @@
              IBlockData iblockdata = this.getType(blockposition);
  
              try {
@@ -209,7 +212,7 @@
                  iblockdata.getBlock().doPhysics(this, blockposition, iblockdata, block);
              } catch (Throwable throwable) {
                  CrashReport crashreport = CrashReport.a(throwable, "Exception while updating neighbours");
-@@ -520,6 +655,17 @@
+@@ -520,6 +658,17 @@
      }
  
      public IBlockData getType(BlockPosition blockposition) {
@@ -227,7 +230,7 @@
          if (!this.isValidLocation(blockposition)) {
              return Blocks.AIR.getBlockData();
          } else {
-@@ -715,6 +861,13 @@
+@@ -715,6 +864,13 @@
      }
  
      public boolean addEntity(Entity entity) {
@@ -241,7 +244,7 @@
          int i = MathHelper.floor(entity.locX / 16.0D);
          int j = MathHelper.floor(entity.locZ / 16.0D);
          boolean flag = entity.attachedToPlayer;
-@@ -723,6 +876,34 @@
+@@ -723,6 +879,34 @@
              flag = true;
          }
  
@@ -276,7 +279,7 @@
          if (!flag && !this.isChunkLoaded(i, j, false)) {
              return false;
          } else {
-@@ -745,6 +926,7 @@
+@@ -745,6 +929,7 @@
              ((IWorldAccess) this.u.get(i)).a(entity);
          }
  
@@ -284,7 +287,7 @@
      }
  
      protected void c(Entity entity) {
-@@ -787,7 +969,15 @@
+@@ -787,7 +972,15 @@
              this.getChunkAt(i, j).b(entity);
          }
  
@@ -301,7 +304,7 @@
          this.c(entity);
      }
  
-@@ -1039,6 +1229,11 @@
+@@ -1039,6 +1232,11 @@
  
          for (i = 0; i < this.j.size(); ++i) {
              entity = (Entity) this.j.get(i);
@@ -313,7 +316,7 @@
  
              try {
                  ++entity.ticksLived;
-@@ -1087,8 +1282,10 @@
+@@ -1087,8 +1285,10 @@
          CrashReportSystemDetails crashreportsystemdetails1;
          CrashReport crashreport1;
  
@@ -326,7 +329,7 @@
              Entity entity1 = entity.by();
  
              if (entity1 != null) {
-@@ -1121,7 +1318,7 @@
+@@ -1121,7 +1321,7 @@
                      this.getChunkAt(j, l).b(entity);
                  }
  
@@ -335,7 +338,7 @@
                  this.c(entity);
              }
  
-@@ -1130,6 +1327,13 @@
+@@ -1130,6 +1330,13 @@
  
          this.methodProfiler.c("blockEntities");
          this.M = true;
@@ -349,7 +352,7 @@
          Iterator iterator = this.tileEntityListTick.iterator();
  
          while (iterator.hasNext()) {
-@@ -1162,11 +1366,13 @@
+@@ -1162,11 +1369,13 @@
          }
  
          this.M = false;
@@ -363,7 +366,7 @@
  
          this.methodProfiler.c("pendingBlockEntities");
          if (!this.b.isEmpty()) {
-@@ -1174,9 +1380,11 @@
+@@ -1174,9 +1383,11 @@
                  TileEntity tileentity1 = (TileEntity) this.b.get(i1);
  
                  if (!tileentity1.x()) {
@@ -375,7 +378,7 @@
  
                      if (this.isLoaded(tileentity1.getPosition())) {
                          Chunk chunk = this.getChunkAtWorldCoords(tileentity1.getPosition());
-@@ -1231,7 +1439,10 @@
+@@ -1231,7 +1442,10 @@
          int j = MathHelper.floor(entity.locZ);
          byte b0 = 32;
  
@@ -387,7 +390,7 @@
              entity.M = entity.locX;
              entity.N = entity.locY;
              entity.O = entity.locZ;
-@@ -1570,10 +1781,18 @@
+@@ -1570,10 +1784,18 @@
          }
      }
  
@@ -406,7 +409,7 @@
              TileEntity tileentity = null;
              int i;
              TileEntity tileentity1;
-@@ -1608,6 +1827,14 @@
+@@ -1608,6 +1830,14 @@
  
      public void setTileEntity(BlockPosition blockposition, TileEntity tileentity) {
          if (tileentity != null && !tileentity.x()) {
@@ -421,7 +424,7 @@
              if (this.M) {
                  tileentity.a(blockposition);
                  Iterator iterator = this.b.iterator();
-@@ -1762,6 +1989,14 @@
+@@ -1762,6 +1992,14 @@
                  }
  
                  this.o = MathHelper.a(this.o, 0.0F, 1.0F);
@@ -436,7 +439,7 @@
              }
          }
      }
-@@ -1893,7 +2128,10 @@
+@@ -1893,7 +2131,10 @@
      }
  
      public boolean c(EnumSkyBlock enumskyblock, BlockPosition blockposition) {
@@ -448,7 +451,7 @@
              return false;
          } else {
              int i = 0;
-@@ -2058,7 +2296,7 @@
+@@ -2058,7 +2299,7 @@
          while (iterator.hasNext()) {
              Entity entity = (Entity) iterator.next();
  
@@ -457,7 +460,7 @@
                  arraylist.add(entity);
              }
          }
-@@ -2073,7 +2311,7 @@
+@@ -2073,7 +2314,7 @@
          while (iterator.hasNext()) {
              Entity entity = (Entity) iterator.next();
  
@@ -466,7 +469,7 @@
                  arraylist.add(entity);
              }
          }
-@@ -2121,7 +2359,7 @@
+@@ -2121,7 +2362,7 @@
              }
          }
  
@@ -475,7 +478,7 @@
      }
  
      public Entity getEntity(int i) {
-@@ -2141,8 +2379,17 @@
+@@ -2141,8 +2382,17 @@
  
          while (iterator.hasNext()) {
              Entity entity = (Entity) iterator.next();
@@ -495,7 +498,7 @@
                  ++i;
              }
          }
-@@ -2151,12 +2398,18 @@
+@@ -2151,12 +2401,18 @@
      }
  
      public void a(Collection<Entity> collection) {
@@ -515,7 +518,7 @@
              this.b(entity);
          }
  
-@@ -2170,7 +2423,13 @@
+@@ -2170,7 +2426,13 @@
          IBlockData iblockdata = this.getType(blockposition);
          AxisAlignedBB axisalignedbb = flag ? null : block.getBlockData().d(this, blockposition);
  
@@ -530,7 +533,7 @@
      }
  
      public int K() {
-@@ -2270,6 +2529,11 @@
+@@ -2270,6 +2532,11 @@
  
          for (int i = 0; i < this.players.size(); ++i) {
              EntityHuman entityhuman1 = (EntityHuman) this.players.get(i);
@@ -542,7 +545,7 @@
  
              if ((IEntitySelector.d.apply(entityhuman1) || !flag) && (IEntitySelector.e.apply(entityhuman1) || flag)) {
                  double d5 = entityhuman1.e(d0, d1, d2);
-@@ -2433,6 +2697,16 @@
+@@ -2433,6 +2700,16 @@
  
      public void everyoneSleeping() {}
  
@@ -559,7 +562,7 @@
      public float h(float f) {
          return (this.p + (this.q - this.p) * f) * this.j(f);
      }
-@@ -2648,7 +2922,7 @@
+@@ -2648,7 +2925,7 @@
          int l = j * 16 + 8 - blockposition.getZ();
          short short0 = 128;