2015-05-25 12:37:24 +02:00
|
|
|
--- a/net/minecraft/server/ChunkProviderServer.java
|
|
|
|
+++ b/net/minecraft/server/ChunkProviderServer.java
|
2016-11-17 02:41:03 +01:00
|
|
|
@@ -15,6 +15,11 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
|
|
|
|
+// CraftBukkit start
|
|
|
|
+import org.bukkit.craftbukkit.chunkio.ChunkIOExecutor;
|
|
|
|
+import org.bukkit.event.world.ChunkUnloadEvent;
|
|
|
|
+// CraftBukkit end
|
|
|
|
+
|
|
|
|
public class ChunkProviderServer implements IChunkProvider {
|
|
|
|
|
2016-02-29 22:32:46 +01:00
|
|
|
private static final Logger a = LogManager.getLogger();
|
2016-11-17 02:41:03 +01:00
|
|
|
@@ -70,19 +75,82 @@
|
2016-02-29 22:32:46 +01:00
|
|
|
Chunk chunk = this.getLoadedChunkAt(i, j);
|
|
|
|
|
|
|
|
if (chunk == null) {
|
|
|
|
+ // CraftBukkit start
|
|
|
|
+ ChunkRegionLoader loader = null;
|
|
|
|
+
|
|
|
|
+ if (this.chunkLoader instanceof ChunkRegionLoader) {
|
|
|
|
+ loader = (ChunkRegionLoader) this.chunkLoader;
|
|
|
|
+ }
|
2017-02-01 00:52:21 +01:00
|
|
|
+ if (loader != null && loader.a(i, j)) {
|
2016-02-29 22:32:46 +01:00
|
|
|
+ chunk = ChunkIOExecutor.syncChunkLoad(world, loader, this, i, j);
|
|
|
|
+ }
|
2016-06-12 04:28:08 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return chunk;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Nullable
|
|
|
|
+ public Chunk originalGetOrLoadChunkAt(int i, int j) {
|
|
|
|
+ // CraftBukkit end
|
|
|
|
+ Chunk chunk = this.getLoadedChunkAt(i, j);
|
|
|
|
+
|
|
|
|
+ if (chunk == null) {
|
|
|
|
chunk = this.loadChunk(i, j);
|
2016-02-29 22:32:46 +01:00
|
|
|
if (chunk != null) {
|
|
|
|
this.chunks.put(ChunkCoordIntPair.a(i, j), chunk);
|
2016-06-22 01:08:09 +02:00
|
|
|
chunk.addEntities();
|
|
|
|
- chunk.loadNearby(this, this.chunkGenerator);
|
|
|
|
+ chunk.loadNearby(this, this.chunkGenerator, false); // CraftBukkit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-29 22:32:46 +01:00
|
|
|
return chunk;
|
|
|
|
}
|
|
|
|
|
2016-05-22 03:36:38 +02:00
|
|
|
+ // CraftBukkit start
|
|
|
|
+ public Chunk getChunkIfLoaded(int x, int z) {
|
|
|
|
+ return chunks.get(ChunkCoordIntPair.a(x, z));
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
+
|
2016-02-29 22:32:46 +01:00
|
|
|
public Chunk getChunkAt(int i, int j) {
|
2016-05-15 14:14:47 +02:00
|
|
|
- Chunk chunk = this.getOrLoadChunkAt(i, j);
|
2014-11-25 22:32:16 +01:00
|
|
|
+ return getChunkAt(i, j, null);
|
|
|
|
+ }
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
+ public Chunk getChunkAt(int i, int j, Runnable runnable) {
|
2016-04-20 12:00:35 +02:00
|
|
|
+ return getChunkAt(i, j, runnable, true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Chunk getChunkAt(int i, int j, Runnable runnable, boolean generate) {
|
2016-05-22 03:36:38 +02:00
|
|
|
+ Chunk chunk = getChunkIfLoaded(i, j);
|
2014-11-25 22:32:16 +01:00
|
|
|
+ ChunkRegionLoader loader = null;
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
+ if (this.chunkLoader instanceof ChunkRegionLoader) {
|
|
|
|
+ loader = (ChunkRegionLoader) this.chunkLoader;
|
2016-02-29 22:32:46 +01:00
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
+ // We can only use the queue for already generated chunks
|
2017-02-01 00:52:21 +01:00
|
|
|
+ if (chunk == null && loader != null && loader.a(i, j)) {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ if (runnable != null) {
|
|
|
|
+ ChunkIOExecutor.queueChunkLoad(world, loader, this, i, j, runnable);
|
|
|
|
+ return null;
|
|
|
|
+ } else {
|
|
|
|
+ chunk = ChunkIOExecutor.syncChunkLoad(world, loader, this, i, j);
|
|
|
|
+ }
|
2016-04-20 12:00:35 +02:00
|
|
|
+ } else if (chunk == null && generate) {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ chunk = originalGetChunkAt(i, j);
|
|
|
|
+ }
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // If we didn't load the chunk async and have a callback run it now
|
|
|
|
+ if (runnable != null) {
|
|
|
|
+ runnable.run();
|
|
|
|
+ }
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
+ return chunk;
|
|
|
|
+ }
|
2016-02-29 22:32:46 +01:00
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
+ public Chunk originalGetChunkAt(int i, int j) {
|
2016-06-12 04:28:08 +02:00
|
|
|
+ Chunk chunk = this.originalGetOrLoadChunkAt(i, j);
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit end
|
|
|
|
|
|
|
|
if (chunk == null) {
|
2016-02-29 22:32:46 +01:00
|
|
|
long k = ChunkCoordIntPair.a(i, j);
|
2016-11-17 02:41:03 +01:00
|
|
|
@@ -101,7 +169,7 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2016-05-10 13:47:39 +02:00
|
|
|
this.chunks.put(k, chunk);
|
2014-11-25 22:32:16 +01:00
|
|
|
chunk.addEntities();
|
2016-06-22 01:08:09 +02:00
|
|
|
- chunk.loadNearby(this, this.chunkGenerator);
|
|
|
|
+ chunk.loadNearby(this, this.chunkGenerator, true); // CraftBukkit
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
|
|
|
|
2016-06-22 01:08:09 +02:00
|
|
|
return chunk;
|
2016-11-17 02:41:03 +01:00
|
|
|
@@ -147,10 +215,12 @@
|
2015-02-26 23:41:06 +01:00
|
|
|
|
2016-02-29 22:32:46 +01:00
|
|
|
public boolean a(boolean flag) {
|
2014-11-25 22:32:16 +01:00
|
|
|
int i = 0;
|
2016-05-10 13:47:39 +02:00
|
|
|
- ArrayList arraylist = Lists.newArrayList(this.chunks.values());
|
2015-02-26 23:41:06 +01:00
|
|
|
|
|
|
|
- for (int j = 0; j < arraylist.size(); ++j) {
|
|
|
|
- Chunk chunk = (Chunk) arraylist.get(j);
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start
|
|
|
|
+ Iterator iterator = this.chunks.values().iterator();
|
|
|
|
+ while (iterator.hasNext()) {
|
|
|
|
+ Chunk chunk = (Chunk) iterator.next();
|
|
|
|
+ // CraftBukkit end
|
|
|
|
|
|
|
|
if (flag) {
|
|
|
|
this.saveChunkNOP(chunk);
|
2016-11-17 02:41:03 +01:00
|
|
|
@@ -183,10 +253,12 @@
|
2016-05-11 07:34:16 +02:00
|
|
|
Chunk chunk = (Chunk) this.chunks.get(olong);
|
|
|
|
|
|
|
|
if (chunk != null && chunk.d) {
|
2016-06-22 01:08:09 +02:00
|
|
|
- chunk.removeEntities();
|
|
|
|
- this.saveChunk(chunk);
|
|
|
|
- this.saveChunkNOP(chunk);
|
|
|
|
- this.chunks.remove(olong);
|
|
|
|
+ // CraftBukkit start - move unload logic to own method
|
|
|
|
+ if (!unloadChunk(chunk, true)) {
|
2016-05-11 07:34:16 +02:00
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
2016-06-22 01:08:09 +02:00
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
2016-11-17 02:41:03 +01:00
|
|
|
@@ -198,6 +270,40 @@
|
2016-06-22 01:08:09 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // CraftBukkit start
|
|
|
|
+ public boolean unloadChunk(Chunk chunk, boolean save) {
|
2016-07-11 13:10:56 +02:00
|
|
|
+ ChunkUnloadEvent event = new ChunkUnloadEvent(chunk.bukkitChunk, save);
|
2016-06-22 01:08:09 +02:00
|
|
|
+ this.world.getServer().getPluginManager().callEvent(event);
|
|
|
|
+ if (event.isCancelled()) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
2016-07-11 13:10:56 +02:00
|
|
|
+ save = event.isSaveChunk();
|
2016-06-22 01:08:09 +02:00
|
|
|
+
|
|
|
|
+ // Update neighbor counts
|
|
|
|
+ for (int x = -2; x < 3; x++) {
|
|
|
|
+ for (int z = -2; z < 3; z++) {
|
|
|
|
+ if (x == 0 && z == 0) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Chunk neighbor = this.getChunkIfLoaded(chunk.locX + x, chunk.locZ + z);
|
|
|
|
+ if (neighbor != null) {
|
|
|
|
+ neighbor.setNeighborUnloaded(-x, -z);
|
|
|
|
+ chunk.setNeighborUnloaded(x, z);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Moved from unloadChunks above
|
|
|
|
+ chunk.removeEntities();
|
|
|
|
+ if (save) {
|
|
|
|
+ this.saveChunk(chunk);
|
|
|
|
+ this.saveChunkNOP(chunk);
|
|
|
|
+ }
|
|
|
|
+ this.chunks.remove(chunk.chunkKey);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
+
|
|
|
|
public boolean e() {
|
|
|
|
return !this.world.savingDisabled;
|
|
|
|
}
|