From 7f0126a364ee8a1419424dc09ca0cfc488236373 Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Wed, 22 Jun 2011 18:27:27 +0100 Subject: [PATCH] You may now set a generator to a default world using plugin.yml --- .../net/minecraft/server/MinecraftServer.java | 18 +++++++++--- .../org/bukkit/craftbukkit/CraftServer.java | 29 +++++++++++++++++++ 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java index 81e36680b2..00cd628cd8 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -24,7 +24,9 @@ import org.bukkit.craftbukkit.LoggerOutputStream; import org.bukkit.craftbukkit.command.ColouredConsoleSender; import org.bukkit.craftbukkit.scheduler.CraftScheduler; import org.bukkit.craftbukkit.util.ServerShutdownThread; +import org.bukkit.event.world.WorldInitEvent; import org.bukkit.event.world.WorldSaveEvent; +import org.bukkit.generator.ChunkGenerator; import org.bukkit.plugin.PluginLoadOrder; // CraftBukkit @@ -168,12 +170,14 @@ public class MinecraftServer implements Runnable, ICommandListener { for (int j = 0; j < (this.propertyManager.getBoolean("allow-nether", true) ? 2 : 1); ++j) { WorldServer world; int dimension = j == 0 ? 0 : -1; + String worldType = Environment.getEnvironment(dimension).toString().toLowerCase(); + String name = (dimension == 0) ? s : s + "_" + worldType; + + ChunkGenerator gen = server.getGenerator(name); if (j == 0) { - world = new WorldServer(this, new ServerNBTManager(new File("."), s, true), s, dimension, i, org.bukkit.World.Environment.getEnvironment(dimension), null); // CraftBukkit + world = new WorldServer(this, new ServerNBTManager(new File("."), s, true), s, dimension, i, org.bukkit.World.Environment.getEnvironment(dimension), gen); // CraftBukkit } else { - String worldType = Environment.getEnvironment(dimension).toString().toLowerCase(); - String name = s + "_" + worldType; String dim = "DIM-1"; File newWorld = new File(new File(name), dim); @@ -202,9 +206,15 @@ public class MinecraftServer implements Runnable, ICommandListener { } } - world = new SecondaryWorldServer(this, new ServerNBTManager(new File("."), name, true), name, dimension, i, worlds.get(0), org.bukkit.World.Environment.getEnvironment(dimension), null); // CraftBukkit + world = new SecondaryWorldServer(this, new ServerNBTManager(new File("."), name, true), name, dimension, i, worlds.get(0), org.bukkit.World.Environment.getEnvironment(dimension), gen); // CraftBukkit } + if (gen != null) { + world.getWorld().getPopulators().addAll(gen.getDefaultPopulators(world.getWorld())); + } + + server.getPluginManager().callEvent(new WorldInitEvent(world.getWorld())); + world.tracker = new EntityTracker(this, dimension); world.addIWorldAccess(new WorldManager(this, world)); world.spawnMonsters = this.propertyManager.getBoolean("spawn-monsters", true) ? 1 : 0; diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index a7cc8e4c73..86f7cf5539 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -576,4 +576,33 @@ public final class CraftServer implements Server { public boolean getOnlineMode() { return this.console.onlineMode; } + + public ChunkGenerator getGenerator(String world) { + ConfigurationNode node = configuration.getNode("worlds"); + ChunkGenerator result = null; + + if (node != null) { + node = node.getNode(world); + + if (node != null) { + String name = node.getString("generator"); + + if ((name != null) && (!name.isEmpty())) { + String[] split = name.split(":", 2); + String id = (split.length > 1) ? split[1] : null; + Plugin plugin = pluginManager.getPlugin(split[0]); + + if (plugin == null) { + getLogger().severe("Could not set generator for default world '" + world + "': Plugin '" + split[0] + "' does not exist"); + } else if (!plugin.isEnabled()) { + getLogger().severe("Could not set generator for default world '" + world + "': Plugin '" + split[0] + "' is not enabled yet (is it load:STARTUP?)"); + } else { + result = plugin.getDefaultWorldGenerator(world, id); + } + } + } + } + + return result; + } }