From 7271e5cfb80f8283a26c270c85d2314d648d10f1 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Tue, 28 Jun 2011 17:53:26 -0600 Subject: [PATCH] Started Purge Cmd. Moved Queued cmds to CmdMgr --- .../MultiverseCore/MultiverseCore.java | 64 ++----------------- .../command/CommandManager.java | 55 ++++++++++++++++ .../command/commands/ConfirmCommand.java | 2 +- .../command/commands/DeleteCommand.java | 2 +- .../command/commands/MVPurge.java | 42 ------------ .../command/commands/PurgeCommand.java | 51 +++++++++++++++ 6 files changed, 114 insertions(+), 102 deletions(-) delete mode 100644 src/com/onarandombox/MultiverseCore/command/commands/MVPurge.java create mode 100644 src/com/onarandombox/MultiverseCore/command/commands/PurgeCommand.java diff --git a/src/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/com/onarandombox/MultiverseCore/MultiverseCore.java index 61fca8e6..b3c83123 100644 --- a/src/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -94,8 +94,6 @@ public class MultiverseCore extends JavaPlugin { // HashMap to contain information relating to the Players. public HashMap playerSessions = new HashMap(); - // List to hold commands that require approval - public List queuedCommands = new ArrayList(); @Override public void onLoad() { @@ -315,7 +313,7 @@ public class MultiverseCore extends JavaPlugin { List worldKeys = this.configWorlds.getKeys("worlds"); // Force the worlds to be loaded, ie don't just load new worlds. - if(forceLoad) { + if (forceLoad) { this.worlds.clear(); } @@ -340,11 +338,10 @@ public class MultiverseCore extends JavaPlugin { } // Ensure that the worlds created by the default server were loaded into MV, useful for first time runs - //count += loadDefaultWorlds(); + // count += loadDefaultWorlds(); // TODO: This was taken out because some people don't want nether! Instead show a message to people who have MVImport // and tell them to do MVImports for their worlds! - // Simple Output to the Console to show how many Worlds were loaded. log(Level.INFO, count + " - World(s) loaded."); } @@ -403,7 +400,7 @@ public class MultiverseCore extends JavaPlugin { ChunkGenerator customGenerator = getChunkGenerator(generatorName, generatorID, name); if (customGenerator == null && generator != null && !generator.isEmpty()) { - if(!pluginExists(generatorName)) { + if (!pluginExists(generatorName)) { log(Level.WARNING, "Could not find plugin: " + generatorName); } else { log(Level.WARNING, "Found plugin: " + generatorName + ", but did not find generatorID: " + generatorID); @@ -589,8 +586,8 @@ public class MultiverseCore extends JavaPlugin { * @param msg */ public void log(Level level, String msg) { - log.log(level, "[Multiverse-Core] " + msg); - debugLog.log(level, "[Multiverse-Core] " + msg); + log.log(level, this.tag + " " + msg); + debugLog.log(level, this.tag + " " + msg); } /** @@ -663,56 +660,7 @@ public class MultiverseCore extends JavaPlugin { // TODO: Find out where to put these next 3 methods! I just stuck them here for now --FF - /** - * - */ - public void queueCommand(CommandSender sender, String commandName, String methodName, String[] args, Class[] paramTypes, String success, String fail) { - cancelQueuedCommand(sender); - this.queuedCommands.add(new QueuedCommand(methodName, args, paramTypes, sender, Calendar.getInstance(), this, success, fail)); - sender.sendMessage("The command " + ChatColor.RED + commandName + ChatColor.WHITE + " has been halted due to the fact that it could break something!"); - sender.sendMessage("If you still wish to execute " + ChatColor.RED + commandName + ChatColor.WHITE); - sender.sendMessage("please type: " + ChatColor.GREEN + "/mvconfirm"); - sender.sendMessage(ChatColor.GREEN + "/mvconfirm" + ChatColor.WHITE + " will only be available for 10 seconds."); - } - - /** - * Tries to fire off the command - * - * @param sender - * @return - */ - public boolean confirmQueuedCommand(CommandSender sender) { - for (QueuedCommand com : this.queuedCommands) { - if (com.getSender().equals(sender)) { - if (com.execute()) { - sender.sendMessage(com.getSuccess()); - return true; - } else { - sender.sendMessage(com.getFail()); - return false; - } - } - } - return false; - } - - /** - * Cancels(invalidates) a command that has been requested. This is called when a user types something other than 'yes' or when they try to queue a second command Queuing a second command will delete the first command entirely. - * - * @param sender - */ - public void cancelQueuedCommand(CommandSender sender) { - QueuedCommand c = null; - for (QueuedCommand com : this.queuedCommands) { - if (com.getSender().equals(sender)) { - c = com; - } - } - if (c != null) { - // Each person is allowed at most one queued command. - this.queuedCommands.remove(c); - } - } + public Collection getMVWorlds() { return this.worlds.values(); diff --git a/src/com/onarandombox/MultiverseCore/command/CommandManager.java b/src/com/onarandombox/MultiverseCore/command/CommandManager.java index 17d15700..88d188a2 100644 --- a/src/com/onarandombox/MultiverseCore/command/CommandManager.java +++ b/src/com/onarandombox/MultiverseCore/command/CommandManager.java @@ -9,6 +9,7 @@ package com.onarandombox.MultiverseCore.command; import java.util.ArrayList; +import java.util.Calendar; import java.util.List; import org.bukkit.ChatColor; @@ -23,6 +24,9 @@ public class CommandManager { protected List commands; private MultiverseCore plugin; + // List to hold commands that require approval + public List queuedCommands = new ArrayList(); + public CommandManager(MultiverseCore plugin) { this.commands = new ArrayList(); this.plugin = plugin; @@ -140,4 +144,55 @@ public class CommandManager { } return returnVal.replace("\"", ""); } + + /** + * + */ + public void queueCommand(CommandSender sender, String commandName, String methodName, String[] args, Class[] paramTypes, String success, String fail) { + cancelQueuedCommand(sender); + this.queuedCommands.add(new QueuedCommand(methodName, args, paramTypes, sender, Calendar.getInstance(), this.plugin, success, fail)); + sender.sendMessage("The command " + ChatColor.RED + commandName + ChatColor.WHITE + " has been halted due to the fact that it could break something!"); + sender.sendMessage("If you still wish to execute " + ChatColor.RED + commandName + ChatColor.WHITE); + sender.sendMessage("please type: " + ChatColor.GREEN + "/mvconfirm"); + sender.sendMessage(ChatColor.GREEN + "/mvconfirm" + ChatColor.WHITE + " will only be available for 10 seconds."); + } + + /** + * Tries to fire off the command + * + * @param sender + * @return + */ + public boolean confirmQueuedCommand(CommandSender sender) { + for (QueuedCommand com : this.queuedCommands) { + if (com.getSender().equals(sender)) { + if (com.execute()) { + sender.sendMessage(com.getSuccess()); + return true; + } else { + sender.sendMessage(com.getFail()); + return false; + } + } + } + return false; + } + + /** + * Cancels(invalidates) a command that has been requested. This is called when a user types something other than 'yes' or when they try to queue a second command Queuing a second command will delete the first command entirely. + * + * @param sender + */ + public void cancelQueuedCommand(CommandSender sender) { + QueuedCommand c = null; + for (QueuedCommand com : this.queuedCommands) { + if (com.getSender().equals(sender)) { + c = com; + } + } + if (c != null) { + // Each person is allowed at most one queued command. + this.queuedCommands.remove(c); + } + } } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ConfirmCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ConfirmCommand.java index f2d26b44..fb0ffb3f 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ConfirmCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ConfirmCommand.java @@ -22,7 +22,7 @@ public class ConfirmCommand extends BaseCommand { @Override public void execute(CommandSender sender, String[] args) { - this.plugin.confirmQueuedCommand(sender); + this.plugin.getCommandManager().confirmQueuedCommand(sender); } } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/DeleteCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/DeleteCommand.java index ef5e11d7..65087e58 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/DeleteCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/DeleteCommand.java @@ -23,7 +23,7 @@ public class DeleteCommand extends BaseCommand { @Override public void execute(CommandSender sender, String[] args) { Class paramTypes[] = {String.class}; - this.plugin.queueCommand(sender, "mvdelete", "deleteWorld", args, paramTypes, "World Deleted!", "World was not deleted!"); + this.plugin.getCommandManager().queueCommand(sender, "mvdelete", "deleteWorld", args, paramTypes, "World Deleted!", "World was not deleted!"); } } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/MVPurge.java b/src/com/onarandombox/MultiverseCore/command/commands/MVPurge.java deleted file mode 100644 index 1ae445f6..00000000 --- a/src/com/onarandombox/MultiverseCore/command/commands/MVPurge.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.onarandombox.MultiverseCore.command.commands; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.command.BaseCommand; -import com.onarandombox.utils.PurgeWorlds; - -public class MVPurge extends BaseCommand { - - public MVPurge(MultiverseCore plugin) { - super(plugin); - } - - @Override - public void execute(CommandSender sender, String[] args) { -// if (!(args.length > 0)) { -// return fal; -// } -// -// if (!(sender instanceof Player)) { -// sender.sendMessage("This command needs to be used from inside the game!"); -// return true; -// } -// -// Player p = (Player) sender; -// List creatures = new ArrayList(); -// -// for (String creature : args[0].toUpperCase().split(",")) { -// creatures.add(creature); -// } -// -// new PurgeWorlds(plugin).purge(sender, p.getWorld(), creatures); -// -// return true; - } - -} diff --git a/src/com/onarandombox/MultiverseCore/command/commands/PurgeCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/PurgeCommand.java new file mode 100644 index 00000000..43e677e2 --- /dev/null +++ b/src/com/onarandombox/MultiverseCore/command/commands/PurgeCommand.java @@ -0,0 +1,51 @@ +package com.onarandombox.MultiverseCore.command.commands; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.command.BaseCommand; +import com.onarandombox.utils.PurgeWorlds; + +public class PurgeCommand extends BaseCommand { + + public PurgeCommand(MultiverseCore plugin) { + super(plugin); + this.name = "Purge the world "; + this.description = "Removed the specified type of mob from the specified world."; + this.usage = "/mvpurge" + ChatColor.GOLD + " [WORLD|all] " + ChatColor.GREEN + "{all|animals|monsters|MOBNAME}"; + this.minArgs = 1; + this.maxArgs = 2; + this.identifiers.add("mvpurge"); + this.permission = "multiverse.world.purge"; + this.requiresOp = true; + } + + @Override + public void execute(CommandSender sender, String[] args) { + Player p = null; + if(sender instanceof Player) { + p = (Player) sender; + } + if (args.length == 1 && p == null) { + sender.sendMessage("This command requires a WORLD when being run from the console!"); + sender.sendMessage(this.usage); + return; + } + + List creatures = new ArrayList(); + + for (String creature : args[0].toUpperCase().split(",")) { + creatures.add(creature); + } + + new PurgeWorlds(plugin).purge(sender, p.getWorld(), creatures); + + return; + } + +}