Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 12:30:06 +01:00
213 Zeilen
7.9 KiB
Diff
213 Zeilen
7.9 KiB
Diff
--- a/net/minecraft/server/ChunkProviderServer.java
|
|
+++ b/net/minecraft/server/ChunkProviderServer.java
|
|
@@ -14,10 +14,17 @@
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
+// CraftBukkit start
|
|
+import org.bukkit.Server;
|
|
+import org.bukkit.craftbukkit.chunkio.ChunkIOExecutor;
|
|
+import org.bukkit.craftbukkit.util.LongHashSet;
|
|
+import org.bukkit.event.world.ChunkUnloadEvent;
|
|
+// CraftBukkit end
|
|
+
|
|
public class ChunkProviderServer implements IChunkProvider {
|
|
|
|
private static final Logger a = LogManager.getLogger();
|
|
- private final Set<Long> unloadQueue = Sets.newHashSet();
|
|
+ public final LongHashSet unloadQueue = new LongHashSet(); // CraftBukkit - LongHashSet
|
|
public final ChunkGenerator chunkGenerator;
|
|
private final IChunkLoader chunkLoader;
|
|
public final Long2ObjectMap<Chunk> chunks = new Long2ObjectOpenHashMap(8192);
|
|
@@ -35,7 +42,14 @@
|
|
|
|
public void unload(Chunk chunk) {
|
|
if (this.world.worldProvider.c(chunk.locX, chunk.locZ)) {
|
|
- this.unloadQueue.add(Long.valueOf(ChunkCoordIntPair.a(chunk.locX, chunk.locZ)));
|
|
+ // CraftBukkit start
|
|
+ this.unloadQueue.add(chunk.locX, chunk.locZ);
|
|
+
|
|
+ Chunk c = chunks.get(ChunkCoordIntPair.a(chunk.locX, chunk.locZ));
|
|
+ if (c != null) {
|
|
+ c.mustSave = true;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
chunk.d = true;
|
|
}
|
|
|
|
@@ -69,19 +83,68 @@
|
|
Chunk chunk = this.getLoadedChunkAt(i, j);
|
|
|
|
if (chunk == null) {
|
|
- chunk = this.loadChunk(i, j);
|
|
+ // CraftBukkit start
|
|
+ ChunkRegionLoader loader = null;
|
|
+
|
|
+ if (this.chunkLoader instanceof ChunkRegionLoader) {
|
|
+ loader = (ChunkRegionLoader) this.chunkLoader;
|
|
+ }
|
|
+ if (loader != null && loader.chunkExists(world, i, j)) {
|
|
+ chunk = ChunkIOExecutor.syncChunkLoad(world, loader, this, i, j);
|
|
+ }
|
|
+ /* chunk = this.loadChunk(i, j);
|
|
if (chunk != null) {
|
|
this.chunks.put(ChunkCoordIntPair.a(i, j), chunk);
|
|
chunk.addEntities();
|
|
chunk.loadNearby(this, this.chunkGenerator);
|
|
}
|
|
+ */
|
|
+ // CraftBukkit end
|
|
}
|
|
|
|
return chunk;
|
|
}
|
|
|
|
public Chunk getChunkAt(int i, int j) {
|
|
+ return getChunkAt(i, j, null);
|
|
+ }
|
|
+
|
|
+ public Chunk getChunkAt(int i, int j, Runnable runnable) {
|
|
+ return getChunkAt(i, j, runnable, true);
|
|
+ }
|
|
+
|
|
+ public Chunk getChunkAt(int i, int j, Runnable runnable, boolean generate) {
|
|
+ Chunk chunk = chunks.get(ChunkCoordIntPair.a(i, j));
|
|
+ ChunkRegionLoader loader = null;
|
|
+
|
|
+ if (this.chunkLoader instanceof ChunkRegionLoader) {
|
|
+ loader = (ChunkRegionLoader) this.chunkLoader;
|
|
+
|
|
+ }
|
|
+ // We can only use the queue for already generated chunks
|
|
+ if (chunk == null && loader != null && loader.chunkExists(world, i, j)) {
|
|
+ if (runnable != null) {
|
|
+ ChunkIOExecutor.queueChunkLoad(world, loader, this, i, j, runnable);
|
|
+ return null;
|
|
+ } else {
|
|
+ chunk = ChunkIOExecutor.syncChunkLoad(world, loader, this, i, j);
|
|
+ }
|
|
+ } else if (chunk == null && generate) {
|
|
+ chunk = originalGetChunkAt(i, j);
|
|
+ }
|
|
+
|
|
+ // If we didn't load the chunk async and have a callback run it now
|
|
+ if (runnable != null) {
|
|
+ runnable.run();
|
|
+ }
|
|
+
|
|
+ return chunk;
|
|
+ }
|
|
+
|
|
+ public Chunk originalGetChunkAt(int i, int j) {
|
|
Chunk chunk = this.getOrLoadChunkAt(i, j);
|
|
+ boolean newChunk = false;
|
|
+ // CraftBukkit end
|
|
|
|
if (chunk == null) {
|
|
long k = ChunkCoordIntPair.a(i, j);
|
|
@@ -97,9 +160,37 @@
|
|
crashreportsystemdetails.a("Generator", (Object) this.chunkGenerator);
|
|
throw new ReportedException(crashreport);
|
|
}
|
|
+ newChunk = true; // CraftBukkit
|
|
|
|
this.chunks.put(k, chunk);
|
|
chunk.addEntities();
|
|
+
|
|
+ // CraftBukkit start
|
|
+ Server server = world.getServer();
|
|
+ if (server != null) {
|
|
+ /*
|
|
+ * If it's a new world, the first few chunks are generated inside
|
|
+ * the World constructor. We can't reliably alter that, so we have
|
|
+ * no way of creating a CraftWorld/CraftServer at that point.
|
|
+ */
|
|
+ server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkLoadEvent(chunk.bukkitChunk, newChunk));
|
|
+ }
|
|
+
|
|
+ // 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.getLoadedChunkAt(chunk.locX + x, chunk.locZ + z);
|
|
+ if (neighbor != null) {
|
|
+ neighbor.setNeighborLoaded(-x, -z);
|
|
+ chunk.setNeighborLoaded(x, z);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ // CraftBukkit end
|
|
chunk.loadNearby(this, this.chunkGenerator);
|
|
}
|
|
|
|
@@ -146,10 +237,12 @@
|
|
|
|
public boolean a(boolean flag) {
|
|
int i = 0;
|
|
- ArrayList arraylist = Lists.newArrayList(this.chunks.values());
|
|
|
|
- for (int j = 0; j < arraylist.size(); ++j) {
|
|
- Chunk chunk = (Chunk) arraylist.get(j);
|
|
+ // CraftBukkit start
|
|
+ Iterator iterator = this.chunks.values().iterator();
|
|
+ while (iterator.hasNext()) {
|
|
+ Chunk chunk = (Chunk) iterator.next();
|
|
+ // CraftBukkit end
|
|
|
|
if (flag) {
|
|
this.saveChunkNOP(chunk);
|
|
@@ -174,22 +267,41 @@
|
|
|
|
public boolean unloadChunks() {
|
|
if (!this.world.savingDisabled) {
|
|
- if (!this.unloadQueue.isEmpty()) {
|
|
- Iterator iterator = this.unloadQueue.iterator();
|
|
-
|
|
- for (int i = 0; i < 100 && iterator.hasNext(); iterator.remove()) {
|
|
- Long olong = (Long) iterator.next();
|
|
- Chunk chunk = (Chunk) this.chunks.get(olong);
|
|
+ // CraftBukkit start
|
|
+ Server server = this.world.getServer();
|
|
+ for (int i = 0; i < 100 && !this.unloadQueue.isEmpty(); ++i) {
|
|
+ long chunkcoordinates = this.unloadQueue.popFirst();
|
|
+ Chunk chunk = this.chunks.get(chunkcoordinates);
|
|
+ if (chunk == null) continue;
|
|
+
|
|
+ ChunkUnloadEvent event = new ChunkUnloadEvent(chunk.bukkitChunk);
|
|
+ server.getPluginManager().callEvent(event);
|
|
+ if (!event.isCancelled()) {
|
|
|
|
- if (chunk != null && chunk.d) {
|
|
+ if (chunk != null) {
|
|
chunk.removeEntities();
|
|
this.saveChunk(chunk);
|
|
this.saveChunkNOP(chunk);
|
|
- this.chunks.remove(olong);
|
|
- ++i;
|
|
+ this.chunks.remove(chunkcoordinates); // CraftBukkit
|
|
+ }
|
|
+
|
|
+ // 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.getLoadedChunkAt(chunk.locX + x, chunk.locZ + z);
|
|
+ if (neighbor != null) {
|
|
+ neighbor.setNeighborUnloaded(-x, -z);
|
|
+ chunk.setNeighborUnloaded(x, z);
|
|
+ }
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
+ // CraftBukkit end
|
|
|
|
this.chunkLoader.a();
|
|
}
|