From 4117d6b65e22adbb0221113b089d6d6528fa33f2 Mon Sep 17 00:00:00 2001 From: Rigby Date: Wed, 27 Jul 2011 00:24:27 +0100 Subject: [PATCH] Implemented per world setting to keep the spawn in memory or not. --- .../minecraft/server/ChunkProviderServer.java | 2 +- .../net/minecraft/server/MinecraftServer.java | 7 ++-- src/main/java/net/minecraft/server/World.java | 1 + .../org/bukkit/craftbukkit/CraftServer.java | 38 ++++++++++--------- .../org/bukkit/craftbukkit/CraftWorld.java | 22 +++++++++++ 5 files changed, 48 insertions(+), 22 deletions(-) diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java index 0fa2b619f7..0b232fd13e 100644 --- a/src/main/java/net/minecraft/server/ChunkProviderServer.java +++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java @@ -49,7 +49,7 @@ public class ChunkProviderServer implements IChunkProvider { int l = j * 16 + 8 - chunkcoordinates.z; 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 } } diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java index ee8dee661c..a5d9d05c23 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -232,8 +232,9 @@ public class MinecraftServer implements Runnable, ICommandListener { // CraftBukkit start for (int l = 0; l < this.worlds.size(); ++l) { // if (l == 0 || this.propertyManager.getBoolean("allow-nether", true)) { - WorldServer worldserver = this.worlds.get(l); - log.info("Preparing start region for level " + l + " (Seed: " + worldserver.getSeed() + ")"); + WorldServer worldserver = this.worlds.get(l); + log.info("Preparing start region for level " + l + " (Seed: " + worldserver.getSeed() + ")"); + if (worldserver.getWorld().getKeepSpawnInMemory()) { // CraftBukkit end ChunkCoordinates chunkcoordinates = worldserver.getSpawn(); @@ -260,7 +261,7 @@ public class MinecraftServer implements Runnable, ICommandListener { } } } - // } // CraftBukkit + } // CraftBukkit } // CraftBukkit start diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java index aacbef13ee..63ea15884a 100644 --- a/src/main/java/net/minecraft/server/World.java +++ b/src/main/java/net/minecraft/server/World.java @@ -83,6 +83,7 @@ public class World implements IBlockAccess { // CraftBukkit start private final CraftWorld world; public boolean pvpMode; + public boolean keepSpawnInMemory = true; public ChunkGenerator generator; Chunk lastChunkAccessed; int lastXAccessed = Integer.MIN_VALUE; diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index c4a87b8079..670490d03a 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -485,29 +485,31 @@ public final class CraftServer implements Server { pluginManager.callEvent(new WorldInitEvent(internal.getWorld())); System.out.print("Preparing start region for level " + (console.worlds.size() -1) + " (Seed: " + internal.getSeed() + ")"); - short short1 = 196; - long i = System.currentTimeMillis(); - for (int j = -short1; j <= short1; j += 16) { - for (int k = -short1; k <= short1; k += 16) { - long l = System.currentTimeMillis(); + if (internal.getWorld().getKeepSpawnInMemory()) { + short short1 = 196; + long i = System.currentTimeMillis(); + for (int j = -short1; j <= short1; j += 16) { + for (int k = -short1; k <= short1; k += 16) { + long l = System.currentTimeMillis(); - if (l < i) { - i = l; - } + if (l < i) { + i = l; + } - if (l > i + 1000L) { - int i1 = (short1 * 2 + 1) * (short1 * 2 + 1); - int j1 = (j + short1) * (short1 * 2 + 1) + k + 1; + if (l > i + 1000L) { + int i1 = (short1 * 2 + 1) * (short1 * 2 + 1); + int j1 = (j + short1) * (short1 * 2 + 1) + k + 1; - System.out.println("Preparing spawn area for " + name + ", " + (j1 * 100 / i1) + "%"); - i = l; - } + System.out.println("Preparing spawn area for " + name + ", " + (j1 * 100 / i1) + "%"); + i = l; + } - ChunkCoordinates chunkcoordinates = internal.getSpawn(); - internal.chunkProviderServer.getChunkAt(chunkcoordinates.x + j >> 4, chunkcoordinates.z + k >> 4); + ChunkCoordinates chunkcoordinates = internal.getSpawn(); + internal.chunkProviderServer.getChunkAt(chunkcoordinates.x + j >> 4, chunkcoordinates.z + k >> 4); - while (internal.doLighting()) { - ; + while (internal.doLighting()) { + ; + } } } } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 74e48d6217..8cf3dd1bec 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -783,4 +783,26 @@ public class CraftWorld implements World { public int getMaxHeight() { 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); + } + } + } + } }