From 87d4d4e1f42118386dcf2648a42992f01583523d Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sun, 29 Jan 2012 12:41:48 -0700 Subject: [PATCH] Allow generate-structures to be used per world --- .../MultiverseCore/api/MVWorldManager.java | 36 ++++++++++--------- .../commands/CreateCommand.java | 12 +++++-- .../commands/ImportCommand.java | 11 ++++-- .../MultiverseCore/commands/InfoCommand.java | 6 ++-- .../MultiverseCore/utils/WorldManager.java | 24 ++++++++----- 5 files changed, 56 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java b/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java index 023bf1b6..5492b77d 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java @@ -30,31 +30,35 @@ public interface MVWorldManager { /** * Add a new World to the Multiverse Setup. * - * @param name World Name - * @param env Environment Type - * @param seedString The seed in the form of a string. - * If the seed is a Long, - * it will be interpreted as such. - * @param type The Type of the world to be made. - * @param generator The Custom generator plugin to use. + * @param name World Name + * @param env Environment Type + * @param seedString The seed in the form of a string. + * If the seed is a Long, + * it will be interpreted as such. + * @param type The Type of the world to be made. + * @param generateStructures If true, this world will get NPC villages. + * @param generator The Custom generator plugin to use. * @return True if the world is added, false if not. */ - boolean addWorld(String name, Environment env, String seedString, WorldType type, String generator); + boolean addWorld(String name, Environment env, String seedString, WorldType type, boolean generateStructures, + String generator); /** * Add a new World to the Multiverse Setup. * - * @param name World Name - * @param env Environment Type - * @param seedString The seed in the form of a string. - * If the seed is a Long, - * it will be interpreted as such. - * @param type The Type of the world to be made. - * @param generator The Custom generator plugin to use. + * @param name World Name + * @param env Environment Type + * @param seedString The seed in the form of a string. + * If the seed is a Long, + * it will be interpreted as such. + * @param type The Type of the world to be made. + * @param generateStructures If true, this world will get NPC villages. + * @param generator The Custom generator plugin to use. * @param useSpawnAdjust If true, multiverse will search for a safe spawn. If not, It will not modify the level.dat. * @return True if the world is added, false if not. */ - boolean addWorld(String name, Environment env, String seedString, WorldType type, String generator, boolean useSpawnAdjust); + boolean addWorld(String name, Environment env, String seedString, WorldType type, boolean generateStructures, + String generator, boolean useSpawnAdjust); /** * Remove the world from the Multiverse list, from the diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java index ffc3533d..ee44febd 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java @@ -29,8 +29,8 @@ public class CreateCommand extends MultiverseCommand { public CreateCommand(MultiverseCore plugin) { super(plugin); this.setName("Create World"); - this.setCommandUsage("/mv create" + ChatColor.GREEN + " {NAME} {ENV}" + ChatColor.GOLD + " -s [SEED] -g [GENERATOR[:ID]] -t [WORLDTYPE] [-n]"); - this.setArgRange(2, 9); // SUPPRESS CHECKSTYLE: MagicNumberCheck + this.setCommandUsage("/mv create" + ChatColor.GREEN + " {NAME} {ENV}" + ChatColor.GOLD + " -s [SEED] -g [GENERATOR[:ID]] -t [WORLDTYPE] [-n] -a [true|false]"); + this.setArgRange(2, 11); // SUPPRESS CHECKSTYLE: MagicNumberCheck this.addKey("mvcreate"); this.addKey("mvc"); this.addKey("mv create"); @@ -51,6 +51,11 @@ public class CreateCommand extends MultiverseCommand { String env = args.get(1); String seed = CommandHandler.getFlag("-s", args); String generator = CommandHandler.getFlag("-g", args); + boolean allowStructures = true; + String structureString = CommandHandler.getFlag("-a", args); + if (structureString != null) { + allowStructures = Boolean.parseBoolean(structureString); + } String typeString = CommandHandler.getFlag("-t", args); boolean useSpawnAdjust = true; for (String s : args) { @@ -58,6 +63,7 @@ public class CreateCommand extends MultiverseCommand { useSpawnAdjust = false; } } + if (worldFile.exists() || this.worldManager.isMVWorld(worldName)) { sender.sendMessage(ChatColor.RED + "A Folder/World already exists with this name!"); sender.sendMessage(ChatColor.RED + "If you are confident it is a world you can import with /mvimport"); @@ -84,7 +90,7 @@ public class CreateCommand extends MultiverseCommand { Command.broadcastCommandMessage(sender, "Starting creation of world '" + worldName + "'..."); - if (this.worldManager.addWorld(worldName, environment, seed, type, generator, useSpawnAdjust)) { + if (this.worldManager.addWorld(worldName, environment, seed, type, allowStructures, generator, useSpawnAdjust)) { Command.broadcastCommandMessage(sender, "Complete!"); } else { Command.broadcastCommandMessage(sender, "FAILED."); diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java index 6e86179f..0a1b7131 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java @@ -33,8 +33,8 @@ public class ImportCommand extends MultiverseCommand { public ImportCommand(MultiverseCore plugin) { super(plugin); this.setName("Import World"); - this.setCommandUsage("/mv import" + ChatColor.GREEN + " {NAME} {ENV} " + ChatColor.GOLD + " -g [GENERATOR[:ID]] [-n] -t [TYPE]"); - this.setArgRange(1, 5); // SUPPRESS CHECKSTYLE: MagicNumberCheck + this.setCommandUsage("/mv import" + ChatColor.GREEN + " {NAME} {ENV} " + ChatColor.GOLD + " -g [GENERATOR[:ID]] [-n] -t [TYPE] -a [true|false]"); + this.setArgRange(1, 9); // SUPPRESS CHECKSTYLE: MagicNumberCheck this.addKey("mvimport"); this.addKey("mvim"); this.addKey("mv import"); @@ -129,6 +129,11 @@ public class ImportCommand extends MultiverseCommand { String generator = CommandHandler.getFlag("-g", args); String typeString = CommandHandler.getFlag("-t", args); + boolean allowStructures = true; + String structureString = CommandHandler.getFlag("-a", args); + if (structureString != null) { + allowStructures = Boolean.parseBoolean(structureString); + } boolean useSpawnAdjust = true; for (String s : args) { if (s.equalsIgnoreCase("-n")) { @@ -157,7 +162,7 @@ public class ImportCommand extends MultiverseCommand { if (worldFile.exists() && env != null) { Command.broadcastCommandMessage(sender, String.format("Starting import of world '%s'...", worldName)); - if (this.worldManager.addWorld(worldName, environment, null, type, generator, useSpawnAdjust)) + if (this.worldManager.addWorld(worldName, environment, null, type, allowStructures, generator, useSpawnAdjust)) Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Complete!"); else Command.broadcastCommandMessage(sender, ChatColor.RED + "Failed!"); diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java index c33b06ec..b92527eb 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java @@ -109,7 +109,8 @@ public class InfoCommand extends MultiverseCommand { message.add(new FancyMessage("World Name: ", world.getName(), colors)); message.add(new FancyMessage("World Alias: ", world.getColoredWorldString(), colors)); message.add(new FancyMessage("Game Mode: ", world.getGameMode().toString(), colors)); - message.add(new FancyMessage("World Type: ", world.getWorldType().toString(), colors)); + message.add(new FancyMessage("Difficulty: ", world.getDifficulty().toString(), colors)); + //message.add(new FancyMessage("Game Mode: ", StringUtils.capitalize(world.getGameMode().toString()), colors)); Location spawn = world.getSpawnLocation(); message.add(new FancyMessage("Spawn Location: ", plugin.getLocationManipulation().strCoords(spawn), colors)); @@ -135,7 +136,8 @@ public class InfoCommand extends MultiverseCommand { // Page 2 message = new ArrayList(); message.add(new FancyHeader("More World Settings", colors)); - message.add(new FancyMessage("Difficulty: ", world.getDifficulty().toString(), colors)); + message.add(new FancyMessage("World Type: ", world.getWorldType().toString(), colors)); + message.add(new FancyMessage("Structures: ", world.getCBWorld().canGenerateStructures() + "", colors)); message.add(new FancyMessage("Weather: ", world.isWeatherEnabled() + "", colors)); message.add(new FancyMessage("Players will get hungry: ", world.getHunger() + "", colors)); message.add(new FancyMessage("Keep spawn in memory: ", world.isKeepingSpawnInMemory() + "", colors)); diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java b/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java index 8d376248..3bc01374 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java @@ -84,15 +84,17 @@ public class WorldManager implements MVWorldManager { * {@inheritDoc} */ @Override - public boolean addWorld(String name, Environment env, String seedString, WorldType type, String generator) { - return this.addWorld(name, env, seedString, type, generator, true); + public boolean addWorld(String name, Environment env, String seedString, WorldType type, boolean generateStructures, + String generator) { + return this.addWorld(name, env, seedString, type, generateStructures, generator, true); } /** * {@inheritDoc} */ @Override - public boolean addWorld(String name, Environment env, String seedString, WorldType type, String generator, boolean useSpawnAdjust) { + public boolean addWorld(String name, Environment env, String seedString, WorldType type, boolean generateStructures, + String generator, boolean useSpawnAdjust) { plugin.log(Level.FINE, "Adding world with: " + name + ", " + env.toString() + ", " + seedString + ", " + type.toString() + ", " + generator); Long seed = null; WorldCreator c = new WorldCreator(name); @@ -111,6 +113,7 @@ public class WorldManager implements MVWorldManager { } c.environment(env); c.type(type); + c.generateStructures(generateStructures); World world; StringBuilder builder = new StringBuilder(); @@ -281,9 +284,10 @@ public class WorldManager implements MVWorldManager { String type = this.configWorlds.getString("worlds." + name + ".type", "NORMAL"); String seedString = this.configWorlds.getString("worlds." + name + ".seed", ""); String generatorString = this.configWorlds.getString("worlds." + name + ".generator"); + boolean generateStructures = this.configWorlds.getBoolean("worlds." + name + ".generatestructures", true); - addWorld(name, EnvironmentCommand.getEnvFromString(environment), seedString, - EnvironmentCommand.getWorldTypeFromString(type), generatorString); + this.addWorld(name, EnvironmentCommand.getEnvFromString(environment), seedString, + EnvironmentCommand.getWorldTypeFromString(type), generateStructures, generatorString); if (this.unloadedWorlds.contains(name)) { this.unloadedWorlds.remove(name); } @@ -469,9 +473,11 @@ public class WorldManager implements MVWorldManager { String name = w.getName(); if (!worldStrings.contains(name)) { if (this.defaultGens.containsKey(name)) { - this.addWorld(name, w.getEnvironment(), w.getSeed() + "", w.getWorldType(), this.defaultGens.get(name)); + this.addWorld(name, w.getEnvironment(), w.getSeed() + "", w.getWorldType(), + w.canGenerateStructures(), this.defaultGens.get(name)); } else { - this.addWorld(name, w.getEnvironment(), w.getSeed() + "", w.getWorldType(), null); + this.addWorld(name, w.getEnvironment(), w.getSeed() + "", w.getWorldType(), + w.canGenerateStructures(), null); } } @@ -545,6 +551,7 @@ public class WorldManager implements MVWorldManager { String environment = this.configWorlds.getString("worlds." + worldKey + ".environment", "NORMAL"); String type = this.configWorlds.getString("worlds." + worldKey + ".type", "NORMAL"); String seedString = this.configWorlds.getString("worlds." + worldKey + ".seed", null); + boolean generateStructures = this.configWorlds.getBoolean("worlds." + worldKey + ".generatestructures", true); if (seedString == null) { seedString = this.configWorlds.getLong("worlds." + worldKey + ".seed") + ""; } @@ -554,9 +561,8 @@ public class WorldManager implements MVWorldManager { this.plugin.log(Level.WARNING, "Found SKYLANDS world. Not importing automatically, as it won't work atm :("); continue; } - // TODO: UNCOMMENT BEFORE RELEASE addWorld(worldKey, EnvironmentCommand.getEnvFromString(environment), seedString, - EnvironmentCommand.getWorldTypeFromString(type), generatorString); + EnvironmentCommand.getWorldTypeFromString(type), generateStructures, generatorString); // Increment the world count count++;