Implemented per world setting to keep the spawn in memory or not.

This commit is contained in:
Rigby 2011-07-27 00:24:27 +01:00 committed by EvilSeph
parent 6ae23e3f03
commit 4117d6b65e
5 changed files with 48 additions and 22 deletions

View File

@ -49,7 +49,7 @@ public class ChunkProviderServer implements IChunkProvider {
int l = j * 16 + 8 - chunkcoordinates.z; int l = j * 16 + 8 - chunkcoordinates.z;
short short1 = 128; short short1 = 128;
if (k < -short1 || k > short1 || l < -short1 || l > short1) { if (k < -short1 || k > short1 || l < -short1 || l > short1 || !(this.world.keepSpawnInMemory)) { // CraftBukkit - added 'this.world.keepSpawnInMemory'
this.unloadQueue.add(i, j); // CraftBukkit this.unloadQueue.add(i, j); // CraftBukkit
} }
} }

View File

@ -234,6 +234,7 @@ public class MinecraftServer implements Runnable, ICommandListener {
// if (l == 0 || this.propertyManager.getBoolean("allow-nether", true)) { // if (l == 0 || this.propertyManager.getBoolean("allow-nether", true)) {
WorldServer worldserver = this.worlds.get(l); WorldServer worldserver = this.worlds.get(l);
log.info("Preparing start region for level " + l + " (Seed: " + worldserver.getSeed() + ")"); log.info("Preparing start region for level " + l + " (Seed: " + worldserver.getSeed() + ")");
if (worldserver.getWorld().getKeepSpawnInMemory()) {
// CraftBukkit end // CraftBukkit end
ChunkCoordinates chunkcoordinates = worldserver.getSpawn(); ChunkCoordinates chunkcoordinates = worldserver.getSpawn();
@ -260,7 +261,7 @@ public class MinecraftServer implements Runnable, ICommandListener {
} }
} }
} }
// } // CraftBukkit } // CraftBukkit
} }
// CraftBukkit start // CraftBukkit start

View File

@ -83,6 +83,7 @@ public class World implements IBlockAccess {
// CraftBukkit start // CraftBukkit start
private final CraftWorld world; private final CraftWorld world;
public boolean pvpMode; public boolean pvpMode;
public boolean keepSpawnInMemory = true;
public ChunkGenerator generator; public ChunkGenerator generator;
Chunk lastChunkAccessed; Chunk lastChunkAccessed;
int lastXAccessed = Integer.MIN_VALUE; int lastXAccessed = Integer.MIN_VALUE;

View File

@ -485,6 +485,7 @@ public final class CraftServer implements Server {
pluginManager.callEvent(new WorldInitEvent(internal.getWorld())); pluginManager.callEvent(new WorldInitEvent(internal.getWorld()));
System.out.print("Preparing start region for level " + (console.worlds.size() -1) + " (Seed: " + internal.getSeed() + ")"); System.out.print("Preparing start region for level " + (console.worlds.size() -1) + " (Seed: " + internal.getSeed() + ")");
if (internal.getWorld().getKeepSpawnInMemory()) {
short short1 = 196; short short1 = 196;
long i = System.currentTimeMillis(); long i = System.currentTimeMillis();
for (int j = -short1; j <= short1; j += 16) { for (int j = -short1; j <= short1; j += 16) {
@ -511,6 +512,7 @@ public final class CraftServer implements Server {
} }
} }
} }
}
pluginManager.callEvent(new WorldLoadEvent(internal.getWorld())); pluginManager.callEvent(new WorldLoadEvent(internal.getWorld()));
return internal.getWorld(); return internal.getWorld();
} }

View File

@ -783,4 +783,26 @@ public class CraftWorld implements World {
public int getMaxHeight() { public int getMaxHeight() {
return 128; return 128;
} }
public boolean getKeepSpawnInMemory() {
return world.keepSpawnInMemory;
}
public void setKeepSpawnInMemory(boolean keepLoaded) {
world.keepSpawnInMemory = keepLoaded;
// Grab the worlds spawn chunk
ChunkCoordinates chunkcoordinates = this.world.getSpawn();
int chunkCoordX = chunkcoordinates.x >> 4;
int chunkCoordZ = chunkcoordinates.z >> 4;
// Cycle through the 25x25 Chunks around it to load/unload the chunks.
for (int x = -12; x <= 12; x++) {
for (int z = -12; z <= 12; z++) {
if (keepLoaded) {
loadChunk(chunkCoordX + x, chunkCoordZ + z);
} else {
unloadChunk(chunkCoordX + x, chunkCoordZ + z);
}
}
}
}
} }