diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index f7c69bae..49dd9788 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -298,6 +298,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { this.commandHandler.registerCommand(new SpawnCommand(this)); // Dangerous Commands this.commandHandler.registerCommand(new UnloadCommand(this)); + this.commandHandler.registerCommand(new LoadCommand(this)); this.commandHandler.registerCommand(new RemoveCommand(this)); this.commandHandler.registerCommand(new DeleteCommand(this)); this.commandHandler.registerCommand(new ConfirmCommand(this)); diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java b/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java index f1f2e77b..b4a4f160 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java @@ -51,6 +51,15 @@ public interface MVWorldManager { */ public boolean unloadWorld(String name, boolean safely); + /** + * Loads the world. Only use this if the world has been unloaded with {@link removeWorldFromList(String)}. + * + * @param name The name of the world to load + * + * @return True if success, false if failure. + */ + public boolean loadWorld(String name); + /** * Test if a given chunk generator is valid. * diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/LoadCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/LoadCommand.java new file mode 100644 index 00000000..662da4e3 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/LoadCommand.java @@ -0,0 +1,37 @@ +/****************************************************************************** + * Multiverse 2 Copyright (c) the Multiverse Team 2011. * + * Multiverse 2 is licensed under the BSD License. * + * For more information please check the README.md file included * + * with this project. * + ******************************************************************************/ + +package com.onarandombox.MultiverseCore.commands; + +import com.onarandombox.MultiverseCore.MultiverseCore; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.permissions.PermissionDefault; + +import java.util.List; + +public class LoadCommand extends MultiverseCommand { + + public LoadCommand(MultiverseCore plugin) { + super(plugin); + this.setName("Load World"); + this.setCommandUsage("/mv load" + ChatColor.GREEN + " {WORLD}"); + this.setArgRange(1, 1); + this.addKey("mvload"); + this.addKey("mv load"); + this.setPermission("multiverse.core.load", "Loads a world into Multiverse.", PermissionDefault.OP); + } + + @Override + public void runCommand(CommandSender sender, List args) { + if (this.plugin.getMVWorldManager().loadWorld(args.get(0))) { + sender.sendMessage("World Loaded!"); + } else { + sender.sendMessage("Error trying to load world!"); + } + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java b/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java index 0ac6af83..90132909 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java @@ -140,12 +140,12 @@ public class WorldManager implements MVWorldManager { public boolean removeWorldFromConfig(String name) { if (this.configWorlds.getProperty("worlds." + name) != null) { removeWorldFromList(name); - this.plugin.log(Level.INFO, "World " + name + " was removed from config.yml"); + this.plugin.log(Level.INFO, "World '" + name + "' was removed from config.yml"); this.configWorlds.removeProperty("worlds." + name); this.configWorlds.save(); return true; } else { - this.plugin.log(Level.INFO, "World " + name + " was already removed from config.yml"); + this.plugin.log(Level.INFO, "World '" + name + "' was already removed from config.yml"); } return false; } @@ -160,7 +160,7 @@ public class WorldManager implements MVWorldManager { if (this.worlds.containsKey(name)) { this.worlds.remove(name); - this.plugin.log(Level.INFO, "World " + name + " was unloaded from memory."); + this.plugin.log(Level.INFO, "World '" + name + "' was unloaded from memory."); this.unloadWorld(name, true); return true; } else if (this.plugin.getServer().getWorld(name) != null) { @@ -171,6 +171,31 @@ public class WorldManager implements MVWorldManager { } return false; } + + public boolean loadWorld(String name) { + // Check if the World is already loaded + if (this.worlds.containsKey(name)) { + return true; + } + + // Grab all the Worlds from the Config. + List worldKeys = this.configWorlds.getKeys("worlds"); + + // Check that the list is not null and that the config contains the world + if ((worldKeys != null) && (worldKeys.contains(name))) { + // Grab the initial values from the config file. + String environment = this.configWorlds.getString("worlds." + name + ".environment", "NORMAL"); // Grab the Environment as a String. + String seedString = this.configWorlds.getString("worlds." + name + ".seed", ""); + String generatorString = this.configWorlds.getString("worlds." + name + ".generator"); + + addWorld(name, this.plugin.getEnvFromString(environment), seedString, generatorString); + + return true; + } + else { + return false; + } + } public Boolean deleteWorld(String name) {