From 4bf66910218177fd6e78f92cf385b3e423e3d25b Mon Sep 17 00:00:00 2001
From: Shane Freeder <theboyetronic@gmail.com>
Date: Fri, 11 Aug 2017 12:02:53 +0100
Subject: [PATCH] Update CB

---
 .../Chunk-Save-Reattempt.patch                |  4 +-
 .../Chunk-Save-Stats-Debug-Option.patch       |  2 +-
 .../Chunk-save-queue-improvements.patch       | 42 +++++++++----------
 .../Fix-Double-World-Add-issues.patch         |  2 +-
 ...vent-Auto-Save-if-Save-Queue-is-full.patch |  6 +--
 Spigot-Server-Patches/Timings-v2.patch        |  4 +-
 work/CraftBukkit                              |  2 +-
 7 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/Spigot-Server-Patches/Chunk-Save-Reattempt.patch b/Spigot-Server-Patches/Chunk-Save-Reattempt.patch
index b6400df967..581cd85c36 100644
--- a/Spigot-Server-Patches/Chunk-Save-Reattempt.patch
+++ b/Spigot-Server-Patches/Chunk-Save-Reattempt.patch
@@ -6,7 +6,7 @@ Subject: [PATCH] Chunk Save Reattempt
 We commonly have "Stream Closed" errors on chunk saving, so this code should re-try to save the chunk in the event of failure and hopefully prevent rollbacks.
 
 diff --git a/src/main/java/net/minecraft/server/ChunkRegionLoader.java b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
-index 8e91be4a1..721a3cd81 100644
+index cd976f09e..d1c13f00d 100644
 --- a/src/main/java/net/minecraft/server/ChunkRegionLoader.java
 +++ b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
 @@ -0,0 +0,0 @@ public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver {
@@ -28,7 +28,7 @@ index 8e91be4a1..721a3cd81 100644
                  synchronized (lock) { if (this.b.get(chunkcoordintpair) == nbttagcompound) { this.b.remove(chunkcoordintpair); } }// Paper - This will not equal if a newer version is still pending
  
 diff --git a/src/main/java/net/minecraft/server/RegionFile.java b/src/main/java/net/minecraft/server/RegionFile.java
-index 5f9678aad..ed840dbc9 100644
+index 6a92b5af8..5bcbd718f 100644
 --- a/src/main/java/net/minecraft/server/RegionFile.java
 +++ b/src/main/java/net/minecraft/server/RegionFile.java
 @@ -0,0 +0,0 @@ public class RegionFile {
diff --git a/Spigot-Server-Patches/Chunk-Save-Stats-Debug-Option.patch b/Spigot-Server-Patches/Chunk-Save-Stats-Debug-Option.patch
index 6e08eec16b..e2b40f19d5 100644
--- a/Spigot-Server-Patches/Chunk-Save-Stats-Debug-Option.patch
+++ b/Spigot-Server-Patches/Chunk-Save-Stats-Debug-Option.patch
@@ -55,7 +55,7 @@ index ef194312b..8fca62eec 100644
              return false;
          }
 diff --git a/src/main/java/net/minecraft/server/ChunkRegionLoader.java b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
-index ceef6e456..d275eb194 100644
+index 67753e0b1..ea91c0477 100644
 --- a/src/main/java/net/minecraft/server/ChunkRegionLoader.java
 +++ b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
 @@ -0,0 +0,0 @@ public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver {
diff --git a/Spigot-Server-Patches/Chunk-save-queue-improvements.patch b/Spigot-Server-Patches/Chunk-save-queue-improvements.patch
index 6f35390f90..f486f4563f 100644
--- a/Spigot-Server-Patches/Chunk-save-queue-improvements.patch
+++ b/Spigot-Server-Patches/Chunk-save-queue-improvements.patch
@@ -26,7 +26,7 @@ Then finally, Sleeping will by default be removed, but due to known issues with
 But if sleeps are to remain enabled, we at least lower the sleep interval so it doesn't have as much negative impact.
 
 diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
-index 9a6f87e59..873ffa77d 100644
+index 36689db74..3898ad8fa 100644
 --- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
 +++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
 @@ -0,0 +0,0 @@ public class PaperConfig {
@@ -41,7 +41,7 @@ index 9a6f87e59..873ffa77d 100644
 +    }
  }
 diff --git a/src/main/java/net/minecraft/server/ChunkRegionLoader.java b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
-index 6550686ee..17005d677 100644
+index cdb0b1342..cd976f09e 100644
 --- a/src/main/java/net/minecraft/server/ChunkRegionLoader.java
 +++ b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
 @@ -0,0 +0,0 @@ import java.util.List;
@@ -58,16 +58,12 @@ index 6550686ee..17005d677 100644
 +    private final Object lock = new Object(); // Paper - Chunk queue improvements
      private static final Logger a = LogManager.getLogger();
      private final Map<ChunkCoordIntPair, NBTTagCompound> b = Maps.newConcurrentMap();
--    private final Set<ChunkCoordIntPair> c = Collections.newSetFromMap(Maps.newConcurrentMap());
-+    //private final Set<ChunkCoordIntPair> c = Collections.newSetFromMap(Maps.newConcurrentMap()); // Paper - Chunk queue improvements
-     private final File d;
-     private final DataConverterManager e;
-     private boolean f;
+     // CraftBukkit
 @@ -0,0 +0,0 @@ public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver {
-     }
- 
      protected void a(ChunkCoordIntPair chunkcoordintpair, NBTTagCompound nbttagcompound) {
--        if (!this.c.contains(chunkcoordintpair)) {
+         // CraftBukkit
+         // if (!this.c.contains(chunkcoordintpair))
+-        {
 +        synchronized (lock) {  // Paper - Chunk queue improvements
              this.b.put(chunkcoordintpair, nbttagcompound);
          }
@@ -75,35 +71,39 @@ index 6550686ee..17005d677 100644
  
          FileIOThread.a().a(this);
      }
+@@ -0,0 +0,0 @@ public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver {
+     }
  
-     public boolean a() {
--        // CraftBukkit start
+     private synchronized boolean processSaveQueueEntry(boolean logCompletion) {
 -        Iterator<Map.Entry<ChunkCoordIntPair, NBTTagCompound>> iter = this.b.entrySet().iterator();
 -        if (!iter.hasNext()) {
--            // CraftBukkit end
++        // CraftBukkit start
 +        // Paper start - Chunk queue improvements
 +        QueuedChunk chunk = queue.poll();
 +        if (chunk == null) {
-+            // Paper - end
-             if (this.f) {
++        // Paper - end
+             if (logCompletion) {
+                 // CraftBukkit end
                  ChunkRegionLoader.a.info("ThreadedAnvilChunkStorage ({}): All chunks are saved", this.d.getName());
-             }
+@@ -0,0 +0,0 @@ public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver {
  
              return false;
          } else {
 -            // CraftBukkit start
 -            Map.Entry<ChunkCoordIntPair, NBTTagCompound> entry = iter.next();
--            iter.remove(); // Pop single entry
 -            ChunkCoordIntPair chunkcoordintpair = entry.getKey();
+-            NBTTagCompound nbttagcompound = entry.getValue();
 -            // CraftBukkit end
 +            ChunkCoordIntPair chunkcoordintpair = chunk.coords; // Paper - Chunk queue improvements
  
              boolean flag;
  
              try {
--                this.c.add(chunkcoordintpair);
--                NBTTagCompound nbttagcompound = (NBTTagCompound) entry.getValue(); // CraftBukkit
+-                // this.c.add(chunkcoordintpair);
+-                // NBTTagCompound nbttagcompound = (NBTTagCompound) this.b.remove(chunkcoordintpair);
+-                // CraftBukkit
 +                //this.c.add(chunkcoordintpair);
++                //NBTTagCompound nbttagcompound = (NBTTagCompound) entry.getValue(); // CraftBukkit // Paper - Chunk queue improvements
 +                NBTTagCompound nbttagcompound = chunk.compound; // Paper - Chunk queue improvements
  
                  if (nbttagcompound != null) {
@@ -116,8 +116,8 @@ index 6550686ee..17005d677 100644
  
                  flag = true;
              } finally {
--                this.c.remove(chunkcoordintpair);
-+                //this.c.remove(chunkcoordintpair); // Paper
+-                this.b.remove(chunkcoordintpair, nbttagcompound); // CraftBukkit
++                //this.b.remove(chunkcoordintpair, nbttagcompound); // CraftBukkit // Paper
              }
  
              return flag;
diff --git a/Spigot-Server-Patches/Fix-Double-World-Add-issues.patch b/Spigot-Server-Patches/Fix-Double-World-Add-issues.patch
index e8acc5e8b8..c53e3b8148 100644
--- a/Spigot-Server-Patches/Fix-Double-World-Add-issues.patch
+++ b/Spigot-Server-Patches/Fix-Double-World-Add-issues.patch
@@ -8,7 +8,7 @@ Vanilla will double add Spider Jockeys to the world, so ignore already added.
 Also add debug if something else tries to, and abort before world gets bad state
 
 diff --git a/src/main/java/net/minecraft/server/ChunkRegionLoader.java b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
-index 5e9879b89..cf0a8011d 100644
+index d1c13f00d..5f999d275 100644
 --- a/src/main/java/net/minecraft/server/ChunkRegionLoader.java
 +++ b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
 @@ -0,0 +0,0 @@ public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver {
diff --git a/Spigot-Server-Patches/Prevent-Auto-Save-if-Save-Queue-is-full.patch b/Spigot-Server-Patches/Prevent-Auto-Save-if-Save-Queue-is-full.patch
index bc17e3eeee..d7d9935ea1 100644
--- a/Spigot-Server-Patches/Prevent-Auto-Save-if-Save-Queue-is-full.patch
+++ b/Spigot-Server-Patches/Prevent-Auto-Save-if-Save-Queue-is-full.patch
@@ -7,7 +7,7 @@ If the save queue already has 50 (configurable) of chunks pending,
 then avoid processing auto save (which would add more)
 
 diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
-index efae01b1..70b498c7 100644
+index efae01b1d..70b498c7b 100644
 --- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
 +++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
 @@ -0,0 +0,0 @@ public class PaperWorldConfig {
@@ -23,7 +23,7 @@ index efae01b1..70b498c7 100644
      private void removeCorruptTEs() {
          removeCorruptTEs = getBoolean("remove-corrupt-tile-entities", false);
 diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
-index 39f0f5a1..19f10fed 100644
+index 067c53b12..ef194312b 100644
 --- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
 +++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
 @@ -0,0 +0,0 @@ public class ChunkProviderServer implements IChunkProvider {
@@ -51,7 +51,7 @@ index 39f0f5a1..19f10fed 100644
                  }
              }
 diff --git a/src/main/java/net/minecraft/server/ChunkRegionLoader.java b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
-index 6b5b5e91..ceef6e45 100644
+index 3ed762f05..e90d08b0d 100644
 --- a/src/main/java/net/minecraft/server/ChunkRegionLoader.java
 +++ b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
 @@ -0,0 +0,0 @@ public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver {
diff --git a/Spigot-Server-Patches/Timings-v2.patch b/Spigot-Server-Patches/Timings-v2.patch
index 2f50f4e33e..94ecd6bf99 100644
--- a/Spigot-Server-Patches/Timings-v2.patch
+++ b/Spigot-Server-Patches/Timings-v2.patch
@@ -514,7 +514,7 @@ index 9dcab42de..c1b0d6cea 100644
              this.chunkLoader.a(this.world, chunk);
          } catch (IOException ioexception) {
 diff --git a/src/main/java/net/minecraft/server/ChunkRegionLoader.java b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
-index 370f1418b..f4161b8ec 100644
+index 9655a3ceb..cdb0b1342 100644
 --- a/src/main/java/net/minecraft/server/ChunkRegionLoader.java
 +++ b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
 @@ -0,0 +0,0 @@ public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver {
@@ -607,7 +607,7 @@ index 6f63a5a1d..3b8425915 100644
              return waitable.get();
          } catch (java.util.concurrent.ExecutionException e) {
 diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
-index 6258cfd01..2b508a029 100644
+index c2da96eaf..6d47f384a 100644
 --- a/src/main/java/net/minecraft/server/Entity.java
 +++ b/src/main/java/net/minecraft/server/Entity.java
 @@ -0,0 +0,0 @@ import org.bukkit.block.BlockFace;
diff --git a/work/CraftBukkit b/work/CraftBukkit
index 27b8bf9116..963b19c599 160000
--- a/work/CraftBukkit
+++ b/work/CraftBukkit
@@ -1 +1 @@
-Subproject commit 27b8bf91169642a61f9cf888432cf018773d7df0
+Subproject commit 963b19c5995b14f8980a42f13b1bd693a5b411d1