From fc9aa456dae588a3f820b6061df671fe01afcd99 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 9 Jul 2011 07:52:20 -0600 Subject: [PATCH 01/55] Rewritten commandManager --- .../MultiverseCore/MultiverseCore.java | 73 ++++---- .../MultiverseCore/command/BaseCommand.java | 96 +++++++++-- .../command/CommandManager.java | 158 +++++++++++++++--- .../command/commands/ModifyAddCommand.java | 38 ++--- .../command/commands/ModifyCommand.java | 1 + 5 files changed, 269 insertions(+), 97 deletions(-) diff --git a/src/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/com/onarandombox/MultiverseCore/MultiverseCore.java index a8e2d08f..d25dbef5 100644 --- a/src/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -2,6 +2,7 @@ package com.onarandombox.MultiverseCore; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -83,12 +84,12 @@ public class MultiverseCore extends JavaPlugin { public void onEnable() { // Output a little snippet to show it's enabled. this.log(Level.INFO, "- Version " + this.getDescription().getVersion() + " Enabled - By " + getAuthors()); - + // Setup all the Events the plugin needs to Monitor. this.registerEvents(); // Setup Permissions, we'll do an initial check for the Permissions plugin then fall back on isOP(). this.ph = new MVPermissions(this); - + this.bank = this.banker.loadEconPlugin(); // Setup the command manager this.commandManager = new CommandManager(this); @@ -118,7 +119,7 @@ public class MultiverseCore extends JavaPlugin { pm.registerEvent(Event.Type.PLAYER_KICK, this.playerListener, Priority.Highest, this); pm.registerEvent(Event.Type.PLAYER_RESPAWN, this.playerListener, Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Priority.Normal, this); - + pm.registerEvent(Event.Type.ENTITY_REGAIN_HEALTH, this.entityListener, Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Priority.Normal, this); // To Allow/Disallow PVP as well as EnableHealth. pm.registerEvent(Event.Type.CREATURE_SPAWN, this.entityListener, Priority.Normal, this); // To prevent all or certain animals/monsters from spawning. @@ -168,22 +169,22 @@ public class MultiverseCore extends JavaPlugin { */ private void registerCommands() { // Page 1 - this.commandManager.addCommand(new HelpCommand(this)); - this.commandManager.addCommand(new CoordCommand(this)); - this.commandManager.addCommand(new TeleportCommand(this)); - this.commandManager.addCommand(new ListCommand(this)); - this.commandManager.addCommand(new WhoCommand(this)); - this.commandManager.addCommand(new SetSpawnCommand(this)); - this.commandManager.addCommand(new CreateCommand(this)); - this.commandManager.addCommand(new ImportCommand(this)); - this.commandManager.addCommand(new SpawnCommand(this)); - this.commandManager.addCommand(new RemoveCommand(this)); - this.commandManager.addCommand(new DeleteCommand(this)); - this.commandManager.addCommand(new UnloadCommand(this)); - this.commandManager.addCommand(new ConfirmCommand(this)); - this.commandManager.addCommand(new InfoCommand(this)); - this.commandManager.addCommand(new ReloadCommand(this)); - + // this.commandManager.addCommand(new HelpCommand(this)); + // this.commandManager.addCommand(new CoordCommand(this)); + // this.commandManager.addCommand(new TeleportCommand(this)); + // this.commandManager.addCommand(new ListCommand(this)); + // this.commandManager.addCommand(new WhoCommand(this)); + // this.commandManager.addCommand(new SetSpawnCommand(this)); + // this.commandManager.addCommand(new CreateCommand(this)); + // this.commandManager.addCommand(new ImportCommand(this)); + // this.commandManager.addCommand(new SpawnCommand(this)); + // this.commandManager.addCommand(new RemoveCommand(this)); + // this.commandManager.addCommand(new DeleteCommand(this)); + // this.commandManager.addCommand(new UnloadCommand(this)); + // this.commandManager.addCommand(new ConfirmCommand(this)); + // this.commandManager.addCommand(new InfoCommand(this)); + // this.commandManager.addCommand(new ReloadCommand(this)); + this.commandManager.addCommand(new ModifyAddCommand(this)); this.commandManager.addCommand(new ModifySetCommand(this)); this.commandManager.addCommand(new ModifyRemoveCommand(this)); @@ -238,7 +239,7 @@ public class MultiverseCore extends JavaPlugin { } /** - * + * * @return */ private int loadDefaultWorlds() { @@ -262,9 +263,9 @@ public class MultiverseCore extends JavaPlugin { /** * Add a new World to the Multiverse Setup. - * + * * Isn't there a prettier way to do this??!!?!?! - * + * * @param name World Name * @param environment Environment Type */ @@ -347,7 +348,7 @@ public class MultiverseCore extends JavaPlugin { /** * Remove the world from the Multiverse list - * + * * @param name The name of the world to remove * @return True if success, false if failure. */ @@ -361,7 +362,7 @@ public class MultiverseCore extends JavaPlugin { /** * Remove the world from the Multiverse list and from the config - * + * * @param name The name of the world to remove * @return True if success, false if failure. */ @@ -374,7 +375,7 @@ public class MultiverseCore extends JavaPlugin { /** * Remove the world from the Multiverse list, from the config and deletes the folder - * + * * @param name The name of the world to remove * @return True if success, false if failure. */ @@ -389,7 +390,7 @@ public class MultiverseCore extends JavaPlugin { /** * Delete a folder Courtesy of: lithium3141 - * + * * @param file The folder to delete * @return true if success */ @@ -420,7 +421,7 @@ public class MultiverseCore extends JavaPlugin { /** * Grab the players session if one exists, otherwise create a session then return it. - * + * * @param player * @return */ @@ -435,7 +436,7 @@ public class MultiverseCore extends JavaPlugin { /** * Grab and return the Teleport class. - * + * * @return */ public MVTeleport getTeleporter() { @@ -462,12 +463,18 @@ public class MultiverseCore extends JavaPlugin { sender.sendMessage("This plugin is Disabled!"); return true; } - return this.commandManager.dispatch(sender, command, commandLabel, args); + System.out.print("Command executed!"); + System.out.print(command.getName()); + System.out.print(Arrays.toString(args)); + ArrayList allArgs = new ArrayList(Arrays.asList(args)); + allArgs.add(0, command.getName()); + return this.commandManager.dispatch(sender, allArgs); + // return this.commandManager.dispatch(sender, command, commandLabel, args); } /** * Print messages to the server Log as well as to our DebugLog. 'debugLog' is used to seperate Heroes information from the Servers Log Output. - * + * * @param level * @param msg */ @@ -478,7 +485,7 @@ public class MultiverseCore extends JavaPlugin { /** * Print messages to the Debug Log, if the servers in Debug Mode then we also wan't to print the messages to the standard Server Console. - * + * * @param level * @param msg */ @@ -491,7 +498,7 @@ public class MultiverseCore extends JavaPlugin { /** * Parse the Authors Array into a readable String with ',' and 'and'. - * + * * @return */ private String getAuthors() { @@ -522,7 +529,7 @@ public class MultiverseCore extends JavaPlugin { /** * This code should get moved somewhere more appropriate, but for now, it's here. - * + * * @param env * @return */ diff --git a/src/com/onarandombox/MultiverseCore/command/BaseCommand.java b/src/com/onarandombox/MultiverseCore/command/BaseCommand.java index aeff4f9e..06a2151f 100644 --- a/src/com/onarandombox/MultiverseCore/command/BaseCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/BaseCommand.java @@ -1,6 +1,7 @@ package com.onarandombox.MultiverseCore.command; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.bukkit.command.CommandSender; @@ -8,7 +9,7 @@ import org.bukkit.command.CommandSender; import com.onarandombox.MultiverseCore.MultiverseCore; public abstract class BaseCommand { - + protected MultiverseCore plugin; protected String name; protected String description; @@ -18,16 +19,17 @@ public abstract class BaseCommand { protected int minArgs; protected int maxArgs; protected List identifiers; - + public final String IN_GAME_COMMAND_MSG = "This command needs to be used as a Player in game."; - + public BaseCommand(MultiverseCore plugin) { this.identifiers = new ArrayList(); this.plugin = plugin; } - + public abstract void execute(CommandSender sender, String[] args); - + + @Deprecated public boolean validate(String name, String[] parsedArgs, StringBuilder identifier) { String match = this.matchIdentifier(name, parsedArgs); if (match != null) { @@ -42,9 +44,18 @@ public abstract class BaseCommand { } return false; } - + + public boolean validate(ArrayList args) { + int argsLength = args.size(); + if ((argsLength == -1 || argsLength >= this.minArgs) && (this.maxArgs == -1 || argsLength <= this.maxArgs)) { + return true; + } + return false; + } + + @Deprecated public String matchIdentifier(String input, String[] args) { - + String argsString = this.getArgsString(args); String lower = input.toLowerCase() + argsString; int index = -1; @@ -55,14 +66,58 @@ public abstract class BaseCommand { index = i; } } - + if (index != -1) { return this.identifiers.get(index); } else { return null; } } - + + public String getIdentifier(ArrayList allArgs) { + // Combines our args to a space seperated string + String argsString = this.getArgsString(allArgs); + + for (String s : this.identifiers) { + String identifier = s.toLowerCase(); + if (argsString.matches(identifier + "(\\s+.*|\\s*)")) { + return identifier; + } + } + return null; + } + + public ArrayList removeIdentifierArgs(ArrayList allArgs, String identifier) { + int identifierLength = identifier.split(" ").length; + for (int i = 0; i < identifierLength; i++) { + // Since we're pulling from the front, always remove the first element + allArgs.remove(0); + } + return allArgs; + } + + protected String[] removeRedundantArgs(String[] args, String command) { + System.out.print("Attempting to remove redundant args:"); + System.out.print(Arrays.toString(args)); + System.out.print(command); + String[] cmdSplit = command.split(" "); + // Start at cmdSplit[1], because 0 is the command name + int match = 0; + int i = 0; + while (i + 1 < cmdSplit.length && i < args.length && cmdSplit[i + 1].equalsIgnoreCase(args[i])) { + System.out.print("Found a match!"); + match = i + 1; + i++; + } + ArrayList newArgs = new ArrayList(); + for (int j = match; j < args.length; j++) { + newArgs.add(args[j]); + } + String[] mynewArr = {}; + return newArgs.toArray(mynewArr); + } + + @Deprecated private String getArgsString(String[] args) { String returnString = ""; for (String s : args) { @@ -70,33 +125,40 @@ public abstract class BaseCommand { } return returnString; } - + + private String getArgsString(ArrayList args) { + String returnString = ""; + for (String s : args) { + returnString += s + " "; + } + return returnString.substring(0, returnString.length() - 1); + } + public List getIdentifiers() { return this.identifiers; } - + public void setIdentifiers(List identifiers) { this.identifiers = identifiers; } - + public String getName() { return this.name; } - + public String getDescription() { return this.description; } - + public String getUsage() { return this.usage; } - + public boolean isOpRequired() { return this.requiresOp; } - + public String getPermission() { return this.permission; } - } diff --git a/src/com/onarandombox/MultiverseCore/command/CommandManager.java b/src/com/onarandombox/MultiverseCore/command/CommandManager.java index ead9d8a6..f495802c 100644 --- a/src/com/onarandombox/MultiverseCore/command/CommandManager.java +++ b/src/com/onarandombox/MultiverseCore/command/CommandManager.java @@ -9,8 +9,11 @@ package com.onarandombox.MultiverseCore.command; import java.util.ArrayList; +import java.util.Arrays; import java.util.Calendar; +import java.util.Iterator; import java.util.List; +import java.util.ListIterator; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -19,43 +22,88 @@ import org.bukkit.command.CommandSender; import com.onarandombox.MultiverseCore.MultiverseCore; 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; } - + + public boolean dispatch(CommandSender sender, ArrayList allArgs) { + ArrayList parsedArgs = parseAllQuotedStrings(allArgs); + String identifier = null; + + Iterator iterator = this.commands.iterator(); + BaseCommand foundCommand = null; + // This loop is pretty neat. It goes until either the iterator has no more + // Or until we find an identifier. When we do, we no longer iterate, and the + // value left in "foundCommand" is the command we found! + while (iterator.hasNext() && identifier == null) { + foundCommand = iterator.next(); + identifier = foundCommand.getIdentifier(parsedArgs); + if (identifier != null) { + // This method, removeIdentifierArgs mutates parsedArgs + foundCommand.removeIdentifierArgs(parsedArgs, identifier); + validateAndRunCommand(sender, parsedArgs, foundCommand); + } + } + return true; + } + + private void validateAndRunCommand(CommandSender sender, ArrayList parsedArgs, BaseCommand foundCommand) { + if (foundCommand.validate(parsedArgs)) { + if (this.plugin.ph.hasPermission(sender, foundCommand.getPermission(), foundCommand.isOpRequired())) { + foundCommand.execute(sender, parsedArgs.toArray(new String[parsedArgs.size()])); + } else { + sender.sendMessage("You do not have permission to use this command. (" + foundCommand.getPermission() + ")"); + } + } else { + sender.sendMessage(ChatColor.AQUA + "Command: " + ChatColor.WHITE + foundCommand.getName()); + sender.sendMessage(ChatColor.AQUA + "Description: " + ChatColor.WHITE + foundCommand.getDescription()); + sender.sendMessage(ChatColor.AQUA + "Usage: " + ChatColor.WHITE + foundCommand.getUsage()); + } + } + @Deprecated public boolean dispatch(CommandSender sender, Command command, String label, String[] args) { - + BaseCommand match = null; String[] trimmedArgs = null; StringBuilder identifier = new StringBuilder(); - + String[] finalArgs = null; + for (BaseCommand cmd : this.commands) { StringBuilder tmpIdentifier = new StringBuilder(); String[] tmpArgs = parseAllQuotedStrings(args); - + System.out.print("Before Args"); + System.out.print(Arrays.toString(tmpArgs)); if (match == null) { match = cmd.matchIdentifier(label, tmpArgs) == null ? null : cmd; + // If we have a valid match, then we want to remove any extraneous words. + // For example: /mvmodiy add is the name of a command, we want the command + // to never see the "add" + if (match != null) { + finalArgs = cmd.removeRedundantArgs(tmpArgs, cmd.matchIdentifier(label, tmpArgs)); + } } - - + + System.out.print("After Args"); + System.out.print(Arrays.toString(tmpArgs)); + if (match != null && cmd.validate(label, tmpArgs, tmpIdentifier) && tmpIdentifier.length() > identifier.length()) { identifier = tmpIdentifier; trimmedArgs = tmpArgs; } } - + if (match != null) { if (this.plugin.ph.hasPermission(sender, match.getPermission(), match.isOpRequired())) { - if (trimmedArgs != null) { - match.execute(sender, trimmedArgs); + if (finalArgs != null) { + match.execute(sender, finalArgs); } else { sender.sendMessage(ChatColor.AQUA + "Command: " + ChatColor.WHITE + match.getName()); sender.sendMessage(ChatColor.AQUA + "Description: " + ChatColor.WHITE + match.getDescription()); @@ -67,36 +115,37 @@ public class CommandManager { } return true; } - + public void addCommand(BaseCommand command) { this.commands.add(command); } - + public void removeCommand(BaseCommand command) { this.commands.remove(command); } - + @Deprecated public List getCommands() { return this.commands; } - + public List getCommands(CommandSender sender) { ArrayList playerCommands = new ArrayList(); - for(BaseCommand c : this.commands) { - if(this.plugin.ph.hasPermission(sender, c.permission, c.isOpRequired())) { + for (BaseCommand c : this.commands) { + if (this.plugin.ph.hasPermission(sender, c.permission, c.isOpRequired())) { playerCommands.add(c); } } return playerCommands; } - + /** * Combines all quoted strings * * @param args * @return */ + @Deprecated private String[] parseAllQuotedStrings(String[] args) { // TODO: Allow ' ArrayList newArgs = new ArrayList(); @@ -104,7 +153,7 @@ public class CommandManager { // we could have: "Fish dog" the man bear pig "lives today" and maybe "even tomorrow" or "the" next day int start = -1; for (int i = 0; i < args.length; i++) { - + // If we aren't looking for an end quote, and the first part of a string is a quote if (start == -1 && args[i].substring(0, 1).equals("\"")) { start = i; @@ -126,10 +175,10 @@ public class CommandManager { // ... then we want to close that quote and make that one arg. newArgs.add(parseQuotedString(args, start, args.length)); } - + return newArgs.toArray(new String[newArgs.size()]); } - + /** * Takes a string array and returns a combined string, excluding the stop position, including the start * @@ -138,6 +187,7 @@ public class CommandManager { * @param stop * @return */ + @Deprecated private String parseQuotedString(String[] args, int start, int stop) { String returnVal = args[start]; for (int i = start + 1; i < stop; i++) { @@ -145,8 +195,62 @@ public class CommandManager { } return returnVal.replace("\"", ""); } - - + + /** + * Combines all quoted strings + * + * @param args + * @return + */ + private ArrayList parseAllQuotedStrings(ArrayList args) { + // TODO: Allow ' + ArrayList newArgs = new ArrayList(); + // Iterate through all command params: + // we could have: "Fish dog" the man bear pig "lives today" and maybe "even tomorrow" or "the" next day + int start = -1; + for (int i = 0; i < args.size(); i++) { + + // If we aren't looking for an end quote, and the first part of a string is a quote + if (start == -1 && args.get(i).substring(0, 1).equals("\"")) { + start = i; + } + // Have to keep this seperate for one word quoted strings like: "fish" + if (start != -1 && args.get(i).substring(args.get(i).length() - 1, args.get(i).length()).equals("\"")) { + // Now we've found the second part of a string, let's parse the quoted one out + // Make sure it's i+1, we still want I included + newArgs.add(parseQuotedString(args, start, i + 1)); + // Reset the start to look for more! + start = -1; + } else if (start == -1) { + // This is a word that is NOT enclosed in any quotes, so just add it + newArgs.add(args.get(i)); + } + } + // If the string was ended but had an open quote... + if (start != -1) { + // ... then we want to close that quote and make that one arg. + newArgs.add(parseQuotedString(args, start, args.size())); + } + + return newArgs; + } + + /** + * Takes a string array and returns a combined string, excluding the stop position, including the start + * + * @param args + * @param start + * @param stop + * @return + */ + private String parseQuotedString(ArrayList args, int start, int stop) { + String returnVal = args.get(start); + for (int i = start + 1; i < stop; i++) { + returnVal += " " + args.get(i); + } + return returnVal.replace("\"", ""); + } + /** * Returns the given flag value * @@ -167,7 +271,7 @@ public class CommandManager { } return null; } - + /** * */ @@ -179,7 +283,7 @@ public class CommandManager { 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 * @@ -200,7 +304,7 @@ public class CommandManager { } 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. * diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ModifyAddCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ModifyAddCommand.java index 29a9a5c1..60eb6bcf 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ModifyAddCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ModifyAddCommand.java @@ -8,67 +8,65 @@ import com.onarandombox.MultiverseCore.MVWorld; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.command.BaseCommand; - - // This will contain all the properties that support the ADD/REMOVE // Anything not in here will only support the SET action public class ModifyAddCommand extends BaseCommand { - + public ModifyAddCommand(MultiverseCore plugin) { super(plugin); this.name = "Modify a World (Add a value)"; this.description = "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used"; this.usage = "/mvmodify " + ChatColor.GREEN + "ADD {VALUE} {PROPERTY}" + ChatColor.GOLD + " [WORLD] "; - this.minArgs = 3; - this.maxArgs = 4; + this.minArgs = 2; + this.maxArgs = 3; this.identifiers.add("mvmodify add"); this.permission = "multiverse.world.modify"; this.requiresOp = true; } - + @Override public void execute(CommandSender sender, String[] args) { // We NEED a world from the command line Player p = null; - if (!(sender instanceof Player)) { + if (sender instanceof Player) { p = (Player) sender; } - - if (args.length == 3 && p == null) { - sender.sendMessage("From the command line, WORLD is required."); + + if (args.length == 2 && p == null) { + sender.sendMessage(ChatColor.RED + "From the command line, WORLD is required."); sender.sendMessage(this.description); sender.sendMessage(this.usage); sender.sendMessage("Nothing changed."); return; } - + MVWorld world; - String value = args[1]; - String property = args[2]; - - if (args.length == 3) { + String value = args[0]; + String property = args[1]; + + if (args.length == 2) { world = this.plugin.getMVWorld(p.getWorld().getName()); } else { - world = this.plugin.getMVWorld(args[3]); + world = this.plugin.getMVWorld(args[2]); } - + if (world == null) { sender.sendMessage("That world does not exist!"); return; } - + if (!ModifyCommand.validateAction(Action.Add, property)) { sender.sendMessage("Sorry, you can't ADD to " + property); sender.sendMessage("Please visit our wiki for more information: URLGOESHERE FERNFERRET DON'T FORGET IT!"); return; } - + if (world.addToList(property, value)) { sender.sendMessage(value + " was added to " + property); } else { sender.sendMessage(value + " could not be added to " + property); } - + } } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ModifyCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ModifyCommand.java index b905e679..8b43d8bb 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ModifyCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ModifyCommand.java @@ -43,6 +43,7 @@ public class ModifyCommand extends BaseCommand { // ModifySetCommand // ModifyClearCommand } + protected static boolean validateAction(Action action, String property) { if (action == Action.Set) { try { From 29851679364a62218b12553d555467889f9bd69c Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 9 Jul 2011 08:33:18 -0600 Subject: [PATCH 02/55] Fixed Spacing, fixed Modify commands --- .../MultiverseCore/MultiverseCore.java | 36 +++--- .../MultiverseCore/command/BaseCommand.java | 70 +----------- .../command/CommandManager.java | 107 ------------------ .../command/commands/ConfirmCommand.java | 6 +- .../command/commands/CoordCommand.java | 2 +- .../command/commands/CreateCommand.java | 10 +- .../command/commands/DeleteCommand.java | 7 +- .../command/commands/EnvironmentCommand.java | 7 +- .../command/commands/HelpCommand.java | 5 +- .../command/commands/ImportCommand.java | 13 +-- .../command/commands/InfoCommand.java | 14 +-- .../command/commands/ListCommand.java | 14 +-- .../command/commands/ModifyAddCommand.java | 2 +- .../command/commands/ModifyClearCommand.java | 32 +++--- .../command/commands/ModifyCommand.java | 14 +-- .../command/commands/ModifyRemoveCommand.java | 38 ++++--- .../command/commands/ModifySetCommand.java | 32 +++--- .../command/commands/PurgeCommand.java | 12 +- .../command/commands/RemoveCommand.java | 4 +- .../command/commands/SetSpawnCommand.java | 5 +- .../command/commands/SpawnCommand.java | 6 +- .../command/commands/TeleportCommand.java | 17 ++- .../command/commands/UnloadCommand.java | 5 +- .../command/commands/WhoCommand.java | 21 ++-- 24 files changed, 147 insertions(+), 332 deletions(-) diff --git a/src/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/com/onarandombox/MultiverseCore/MultiverseCore.java index d25dbef5..32594cc3 100644 --- a/src/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -165,25 +165,25 @@ public class MultiverseCore extends JavaPlugin { } /** - * Register Multiverse-Core commands to DThielke's Command Manager. + * Register Multiverse-Core commands to Command Manager. */ private void registerCommands() { // Page 1 - // this.commandManager.addCommand(new HelpCommand(this)); - // this.commandManager.addCommand(new CoordCommand(this)); - // this.commandManager.addCommand(new TeleportCommand(this)); - // this.commandManager.addCommand(new ListCommand(this)); - // this.commandManager.addCommand(new WhoCommand(this)); - // this.commandManager.addCommand(new SetSpawnCommand(this)); - // this.commandManager.addCommand(new CreateCommand(this)); - // this.commandManager.addCommand(new ImportCommand(this)); - // this.commandManager.addCommand(new SpawnCommand(this)); - // this.commandManager.addCommand(new RemoveCommand(this)); - // this.commandManager.addCommand(new DeleteCommand(this)); - // this.commandManager.addCommand(new UnloadCommand(this)); - // this.commandManager.addCommand(new ConfirmCommand(this)); - // this.commandManager.addCommand(new InfoCommand(this)); - // this.commandManager.addCommand(new ReloadCommand(this)); + this.commandManager.addCommand(new HelpCommand(this)); + this.commandManager.addCommand(new CoordCommand(this)); + this.commandManager.addCommand(new TeleportCommand(this)); + this.commandManager.addCommand(new ListCommand(this)); + this.commandManager.addCommand(new WhoCommand(this)); + this.commandManager.addCommand(new SetSpawnCommand(this)); + this.commandManager.addCommand(new CreateCommand(this)); + this.commandManager.addCommand(new ImportCommand(this)); + this.commandManager.addCommand(new SpawnCommand(this)); + this.commandManager.addCommand(new RemoveCommand(this)); + this.commandManager.addCommand(new DeleteCommand(this)); + this.commandManager.addCommand(new UnloadCommand(this)); + this.commandManager.addCommand(new ConfirmCommand(this)); + this.commandManager.addCommand(new InfoCommand(this)); + this.commandManager.addCommand(new ReloadCommand(this)); this.commandManager.addCommand(new ModifyAddCommand(this)); this.commandManager.addCommand(new ModifySetCommand(this)); @@ -463,13 +463,9 @@ public class MultiverseCore extends JavaPlugin { sender.sendMessage("This plugin is Disabled!"); return true; } - System.out.print("Command executed!"); - System.out.print(command.getName()); - System.out.print(Arrays.toString(args)); ArrayList allArgs = new ArrayList(Arrays.asList(args)); allArgs.add(0, command.getName()); return this.commandManager.dispatch(sender, allArgs); - // return this.commandManager.dispatch(sender, command, commandLabel, args); } /** diff --git a/src/com/onarandombox/MultiverseCore/command/BaseCommand.java b/src/com/onarandombox/MultiverseCore/command/BaseCommand.java index 06a2151f..0bb0bcbc 100644 --- a/src/com/onarandombox/MultiverseCore/command/BaseCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/BaseCommand.java @@ -1,7 +1,6 @@ package com.onarandombox.MultiverseCore.command; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.bukkit.command.CommandSender; @@ -29,22 +28,6 @@ public abstract class BaseCommand { public abstract void execute(CommandSender sender, String[] args); - @Deprecated - public boolean validate(String name, String[] parsedArgs, StringBuilder identifier) { - String match = this.matchIdentifier(name, parsedArgs); - if (match != null) { - identifier = identifier.append(match); - if (parsedArgs == null) { - parsedArgs = new String[0]; - } - int l = parsedArgs.length; - if (l >= this.minArgs && (this.maxArgs == -1 || l <= this.maxArgs)) { - return true; - } - } - return false; - } - public boolean validate(ArrayList args) { int argsLength = args.size(); if ((argsLength == -1 || argsLength >= this.minArgs) && (this.maxArgs == -1 || argsLength <= this.maxArgs)) { @@ -53,29 +36,8 @@ public abstract class BaseCommand { return false; } - @Deprecated - public String matchIdentifier(String input, String[] args) { - - String argsString = this.getArgsString(args); - String lower = input.toLowerCase() + argsString; - int index = -1; - int n = this.identifiers.size(); - for (int i = 0; i < n; i++) { - String identifier = this.identifiers.get(i).toLowerCase(); - if (index == -1 && lower.matches(identifier + "(\\s+.*|\\s*)")) { - index = i; - } - } - - if (index != -1) { - return this.identifiers.get(index); - } else { - return null; - } - } - public String getIdentifier(ArrayList allArgs) { - // Combines our args to a space seperated string + // Combines our args to a space separated string String argsString = this.getArgsString(allArgs); for (String s : this.identifiers) { @@ -96,36 +58,6 @@ public abstract class BaseCommand { return allArgs; } - protected String[] removeRedundantArgs(String[] args, String command) { - System.out.print("Attempting to remove redundant args:"); - System.out.print(Arrays.toString(args)); - System.out.print(command); - String[] cmdSplit = command.split(" "); - // Start at cmdSplit[1], because 0 is the command name - int match = 0; - int i = 0; - while (i + 1 < cmdSplit.length && i < args.length && cmdSplit[i + 1].equalsIgnoreCase(args[i])) { - System.out.print("Found a match!"); - match = i + 1; - i++; - } - ArrayList newArgs = new ArrayList(); - for (int j = match; j < args.length; j++) { - newArgs.add(args[j]); - } - String[] mynewArr = {}; - return newArgs.toArray(mynewArr); - } - - @Deprecated - private String getArgsString(String[] args) { - String returnString = ""; - for (String s : args) { - returnString += " " + s; - } - return returnString; - } - private String getArgsString(ArrayList args) { String returnString = ""; for (String s : args) { diff --git a/src/com/onarandombox/MultiverseCore/command/CommandManager.java b/src/com/onarandombox/MultiverseCore/command/CommandManager.java index f495802c..675cf39f 100644 --- a/src/com/onarandombox/MultiverseCore/command/CommandManager.java +++ b/src/com/onarandombox/MultiverseCore/command/CommandManager.java @@ -9,14 +9,11 @@ package com.onarandombox.MultiverseCore.command; import java.util.ArrayList; -import java.util.Arrays; import java.util.Calendar; import java.util.Iterator; import java.util.List; -import java.util.ListIterator; import org.bukkit.ChatColor; -import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import com.onarandombox.MultiverseCore.MultiverseCore; @@ -68,53 +65,6 @@ public class CommandManager { sender.sendMessage(ChatColor.AQUA + "Usage: " + ChatColor.WHITE + foundCommand.getUsage()); } } - @Deprecated - public boolean dispatch(CommandSender sender, Command command, String label, String[] args) { - - BaseCommand match = null; - String[] trimmedArgs = null; - StringBuilder identifier = new StringBuilder(); - String[] finalArgs = null; - - for (BaseCommand cmd : this.commands) { - StringBuilder tmpIdentifier = new StringBuilder(); - String[] tmpArgs = parseAllQuotedStrings(args); - System.out.print("Before Args"); - System.out.print(Arrays.toString(tmpArgs)); - if (match == null) { - match = cmd.matchIdentifier(label, tmpArgs) == null ? null : cmd; - // If we have a valid match, then we want to remove any extraneous words. - // For example: /mvmodiy add is the name of a command, we want the command - // to never see the "add" - if (match != null) { - finalArgs = cmd.removeRedundantArgs(tmpArgs, cmd.matchIdentifier(label, tmpArgs)); - } - } - - System.out.print("After Args"); - System.out.print(Arrays.toString(tmpArgs)); - - if (match != null && cmd.validate(label, tmpArgs, tmpIdentifier) && tmpIdentifier.length() > identifier.length()) { - identifier = tmpIdentifier; - trimmedArgs = tmpArgs; - } - } - - if (match != null) { - if (this.plugin.ph.hasPermission(sender, match.getPermission(), match.isOpRequired())) { - if (finalArgs != null) { - match.execute(sender, finalArgs); - } else { - sender.sendMessage(ChatColor.AQUA + "Command: " + ChatColor.WHITE + match.getName()); - sender.sendMessage(ChatColor.AQUA + "Description: " + ChatColor.WHITE + match.getDescription()); - sender.sendMessage(ChatColor.AQUA + "Usage: " + ChatColor.WHITE + match.getUsage()); - } - } else { - sender.sendMessage("You do not have permission to use this command. (" + match.getPermission() + ")"); - } - } - return true; - } public void addCommand(BaseCommand command) { this.commands.add(command); @@ -139,63 +89,6 @@ public class CommandManager { return playerCommands; } - /** - * Combines all quoted strings - * - * @param args - * @return - */ - @Deprecated - private String[] parseAllQuotedStrings(String[] args) { - // TODO: Allow ' - ArrayList newArgs = new ArrayList(); - // Iterate through all command params: - // we could have: "Fish dog" the man bear pig "lives today" and maybe "even tomorrow" or "the" next day - int start = -1; - for (int i = 0; i < args.length; i++) { - - // If we aren't looking for an end quote, and the first part of a string is a quote - if (start == -1 && args[i].substring(0, 1).equals("\"")) { - start = i; - } - // Have to keep this seperate for one word quoted strings like: "fish" - if (start != -1 && args[i].substring(args[i].length() - 1, args[i].length()).equals("\"")) { - // Now we've found the second part of a string, let's parse the quoted one out - // Make sure it's i+1, we still want I included - newArgs.add(parseQuotedString(args, start, i + 1)); - // Reset the start to look for more! - start = -1; - } else if (start == -1) { - // This is a word that is NOT enclosed in any quotes, so just add it - newArgs.add(args[i]); - } - } - // If the string was ended but had an open quote... - if (start != -1) { - // ... then we want to close that quote and make that one arg. - newArgs.add(parseQuotedString(args, start, args.length)); - } - - return newArgs.toArray(new String[newArgs.size()]); - } - - /** - * Takes a string array and returns a combined string, excluding the stop position, including the start - * - * @param args - * @param start - * @param stop - * @return - */ - @Deprecated - private String parseQuotedString(String[] args, int start, int stop) { - String returnVal = args[start]; - for (int i = start + 1; i < stop; i++) { - returnVal += " " + args[i]; - } - return returnVal.replace("\"", ""); - } - /** * Combines all quoted strings * diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ConfirmCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ConfirmCommand.java index fb0ffb3f..06a4ef36 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ConfirmCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ConfirmCommand.java @@ -6,7 +6,7 @@ import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.command.BaseCommand; public class ConfirmCommand extends BaseCommand { - + public ConfirmCommand(MultiverseCore plugin) { super(plugin); this.name = "Confirms a command that could destroy life, the universe and everything."; @@ -19,10 +19,10 @@ public class ConfirmCommand extends BaseCommand { // Any command that is dangerous should require op this.requiresOp = true; } - + @Override public void execute(CommandSender sender, String[] args) { this.plugin.getCommandManager().confirmQueuedCommand(sender); } - + } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/CoordCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/CoordCommand.java index 129fb18b..d8335b92 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/CoordCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/CoordCommand.java @@ -27,7 +27,7 @@ public class CoordCommand extends BaseCommand { public void execute(CommandSender sender, String[] args) { // Check if the command was sent from a Player. if (sender instanceof Player) { - Player p = (Player) sender; + Player p = (Player) sender; p.sendMessage(ChatColor.RED + "World: " + ChatColor.WHITE + p.getWorld().getName()); p.sendMessage(ChatColor.RED + "World Scale: " + ChatColor.WHITE + this.plugin.getMVWorld(p.getWorld().getName()).getScaling()); p.sendMessage(ChatColor.RED + "Coordinates: " + ChatColor.WHITE + this.locMan.strCoords(p.getLocation())); diff --git a/src/com/onarandombox/MultiverseCore/command/commands/CreateCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/CreateCommand.java index 809d48f4..0dc7bd52 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/CreateCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/CreateCommand.java @@ -11,7 +11,7 @@ import com.onarandombox.MultiverseCore.command.BaseCommand; import com.onarandombox.MultiverseCore.command.CommandManager; public class CreateCommand extends BaseCommand { - + public CreateCommand(MultiverseCore plugin) { super(plugin); this.name = "Create World"; @@ -22,9 +22,8 @@ public class CreateCommand extends BaseCommand { this.identifiers.add("mvcreate"); this.permission = "multiverse.world.create"; this.requiresOp = true; - } - + @Override public void execute(CommandSender sender, String[] args) { if (args.length % 2 != 0) { @@ -35,13 +34,13 @@ public class CreateCommand extends BaseCommand { String env = args[1]; String seed = CommandManager.getFlag("-s", args); String generator = CommandManager.getFlag("-g", args); - + if (new File(worldName).exists() || this.plugin.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"); return; } - + Environment environment = this.plugin.getEnvFromString(env); if (environment == null) { sender.sendMessage(ChatColor.RED + "That is not a valid environment."); @@ -56,5 +55,4 @@ public class CreateCommand extends BaseCommand { } return; } - } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/DeleteCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/DeleteCommand.java index 65087e58..07683bcc 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/DeleteCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/DeleteCommand.java @@ -7,7 +7,7 @@ import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.command.BaseCommand; public class DeleteCommand extends BaseCommand { - + public DeleteCommand(MultiverseCore plugin) { super(plugin); this.name = "Delete World"; @@ -19,11 +19,10 @@ public class DeleteCommand extends BaseCommand { this.permission = "multiverse.world.delete"; this.requiresOp = true; } - + @Override public void execute(CommandSender sender, String[] args) { - Class paramTypes[] = {String.class}; + Class paramTypes[] = { String.class }; this.plugin.getCommandManager().queueCommand(sender, "mvdelete", "deleteWorld", args, paramTypes, "World Deleted!", "World was not deleted!"); } - } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/EnvironmentCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/EnvironmentCommand.java index d93d61b2..1a33f9ea 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/EnvironmentCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/EnvironmentCommand.java @@ -6,8 +6,8 @@ import org.bukkit.command.CommandSender; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.command.BaseCommand; -public class EnvironmentCommand extends BaseCommand{ - +public class EnvironmentCommand extends BaseCommand { + public EnvironmentCommand(MultiverseCore plugin) { super(plugin); this.name = "List Environments"; @@ -24,12 +24,11 @@ public class EnvironmentCommand extends BaseCommand{ public void execute(CommandSender sender, String[] args) { EnvironmentCommand.showEnvironments(sender); } - + public static void showEnvironments(CommandSender sender) { sender.sendMessage(ChatColor.YELLOW + "Valid Environments are:"); sender.sendMessage(ChatColor.GREEN + "NORMAL"); sender.sendMessage(ChatColor.RED + "NETHER"); sender.sendMessage(ChatColor.AQUA + "SKYLANDS"); } - } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/HelpCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/HelpCommand.java index e502a624..048baf4a 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/HelpCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/HelpCommand.java @@ -5,7 +5,8 @@ * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/3.0/ or send a letter to * Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. **/ - +// Technically this is already a derivative work even by changing the package name. DThielke voiced it OK to modify, but we really should +// get this license changed... package com.onarandombox.MultiverseCore.command.commands; import java.util.List; @@ -61,7 +62,7 @@ public class HelpCommand extends BaseCommand { } for (int c = start; c < end; c++) { BaseCommand cmd = commands.get(c); - + sender.sendMessage(ChatColor.AQUA + " " + cmd.getUsage()); } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ImportCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ImportCommand.java index 3b1d3e1e..cb6516a3 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ImportCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ImportCommand.java @@ -30,26 +30,26 @@ public class ImportCommand extends BaseCommand { sender.sendMessage(ChatColor.RED + "Multiverse already knows about this world!"); return; } - + String generator = null; - if(args.length == 3) { + if (args.length == 3) { generator = args[2]; } - + String env = args[1]; Environment environment = this.plugin.getEnvFromString(env); - if(environment == null) { + if (environment == null) { sender.sendMessage(ChatColor.RED + "That is not a valid environment."); EnvironmentCommand.showEnvironments(sender); return; } - + if (new File(worldName).exists() && env != null) { sender.sendMessage(ChatColor.AQUA + "Starting world import..."); this.plugin.addWorld(worldName, environment, null, generator); sender.sendMessage(ChatColor.GREEN + "Complete!"); return; - } else if(env == null) { + } else if (env == null) { sender.sendMessage(ChatColor.RED + "FAILED."); sender.sendMessage("That world type did not exist."); sender.sendMessage("For a list of available world types, type: /mvenv"); @@ -58,5 +58,4 @@ public class ImportCommand extends BaseCommand { sender.sendMessage("That world folder does not exist..."); } } - } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/InfoCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/InfoCommand.java index 542dacd1..396b6fb6 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/InfoCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/InfoCommand.java @@ -11,7 +11,7 @@ import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.command.BaseCommand; public class InfoCommand extends BaseCommand { - + public InfoCommand(MultiverseCore plugin) { super(plugin); this.name = "World Information"; @@ -23,7 +23,7 @@ public class InfoCommand extends BaseCommand { this.permission = "multiverse.world.info"; this.requiresOp = false; } - + @Override public void execute(CommandSender sender, String[] args) { // Check if the command was sent from a Player. @@ -42,22 +42,22 @@ public class InfoCommand extends BaseCommand { } } } - + private String[] buildEntireCommand(MVWorld world) { StringBuilder sb = new StringBuilder(); ArrayList pagedInfo = new ArrayList(); String[] aPage = new String[5]; // World Name: 1 aPage[0] = "World: " + world.getName(); - + // World Scale: 1 aPage[1] = "World Scale: " + world.getScaling(); - + // PVP: 1 aPage[2] = "PVP: " + world.getPvp(); aPage[3] = "Animals: " + world.allowAnimalSpawning(); aPage[4] = "Monsters: " + world.allowMonsterSpawning(); - + // This feature is not mission critical and I am spending too much time on it... // Stopping work on it for now --FF 20110623 // // Animal Spawning: X @@ -99,7 +99,7 @@ public class InfoCommand extends BaseCommand { // } return aPage; } - + private ChatColor getChatColor(boolean positive) { return positive ? ChatColor.GREEN : ChatColor.RED; } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ListCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ListCommand.java index 518c0c5f..96e9abc2 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ListCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ListCommand.java @@ -10,7 +10,7 @@ import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.command.BaseCommand; public class ListCommand extends BaseCommand { - + public ListCommand(MultiverseCore plugin) { super(plugin); this.name = "World Listing"; @@ -22,21 +22,21 @@ public class ListCommand extends BaseCommand { this.permission = "multiverse.world.list"; this.requiresOp = false; } - + @Override public void execute(CommandSender sender, String[] args) { Player p = null; if (sender instanceof Player) { p = (Player) sender; } - + String output = ChatColor.LIGHT_PURPLE + "Worlds which you can view:\n"; for (MVWorld world : this.plugin.getMVWorlds()) { - + if (p != null && (!this.plugin.ph.canEnterWorld(p, world.getCBWorld()))) { continue; } - + ChatColor color = ChatColor.GOLD; Environment env = world.getEnvironment(); if (env == Environment.NETHER) { @@ -47,11 +47,11 @@ public class ListCommand extends BaseCommand { color = ChatColor.AQUA; } String worldName = world.getName(); - if(world.getAlias() != null && world.getAlias().length() > 0) { + if (world.getAlias() != null && world.getAlias().length() > 0) { worldName = world.getAliasColor() + world.getAlias() + ChatColor.WHITE; } output += ChatColor.WHITE + worldName + " - " + color + world.getEnvironment() + " \n"; - + } String[] response = output.split("\n"); for (String msg : response) { diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ModifyAddCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ModifyAddCommand.java index 60eb6bcf..44eaa255 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ModifyAddCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ModifyAddCommand.java @@ -34,7 +34,7 @@ public class ModifyAddCommand extends BaseCommand { } if (args.length == 2 && p == null) { - sender.sendMessage(ChatColor.RED + "From the command line, WORLD is required."); + sender.sendMessage(ChatColor.RED + "From the console, WORLD is required."); sender.sendMessage(this.description); sender.sendMessage(this.usage); sender.sendMessage("Nothing changed."); diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ModifyClearCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ModifyClearCommand.java index 7bb69b5c..983a110e 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ModifyClearCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ModifyClearCommand.java @@ -9,48 +9,50 @@ import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.command.BaseCommand; public class ModifyClearCommand extends BaseCommand { - + public ModifyClearCommand(MultiverseCore plugin) { super(plugin); this.name = "Modify a World (Clear a property)"; this.description = "Removes all values from a property. This will work on properties that contain lists"; this.usage = "/mvmodify" + ChatColor.GREEN + " CLEAR {PROPERTY}" + ChatColor.GOLD + " [WORLD] "; - this.minArgs = 2; - this.maxArgs = 3; + this.minArgs = 1; + this.maxArgs = 2; this.identifiers.add("mvmodify clear"); + this.identifiers.add("mvmclear"); + this.identifiers.add("mvmc"); this.permission = "multiverse.world.modify"; this.requiresOp = true; } - + @Override public void execute(CommandSender sender, String[] args) { // We NEED a world from the command line Player p = null; - if (!(sender instanceof Player)) { + if (sender instanceof Player) { p = (Player) sender; } - if (args.length == 2 && p == null) { - sender.sendMessage("From the command line, WORLD is required."); + if (args.length == 1 && p == null) { + sender.sendMessage(ChatColor.RED + "From the console, WORLD is required."); sender.sendMessage(this.description); sender.sendMessage(this.usage); sender.sendMessage("Nothing changed."); return; } - + MVWorld world; - String property = args[1]; - - if (args.length == 2) { + String property = args[0]; + + if (args.length == 1) { world = this.plugin.getMVWorld(p.getWorld().getName()); } else { - world = this.plugin.getMVWorld(args[2]); + world = this.plugin.getMVWorld(args[1]); } - + if (world == null) { sender.sendMessage("That world does not exist!"); return; } - + if (!ModifyCommand.validateAction(Action.Clear, property)) { sender.sendMessage("Sorry, you can't use CLEAR with " + property); sender.sendMessage("Please visit our wiki for more information: URLGOESHERE FERNFERRET DON'T FORGET IT!"); @@ -62,5 +64,5 @@ public class ModifyClearCommand extends BaseCommand { sender.sendMessage(property + " was NOT cleared."); } } - + } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ModifyCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ModifyCommand.java index 8b43d8bb..6c6ff649 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ModifyCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ModifyCommand.java @@ -19,31 +19,29 @@ enum SetProperties { } public class ModifyCommand extends BaseCommand { - + public ModifyCommand(MultiverseCore plugin) { super(plugin); this.name = "Modify a World"; this.description = "MVModify requires an extra parameter: SET,ADD,REMOVE or CLEAR. See below for usage."; this.usage = "/mvmodify" + ChatColor.GREEN + " {SET|ADD|REMOVE|CLEAR} ..."; - this.minArgs = 0; + // Make it so they can NEVER execute this one + this.minArgs = 1; this.maxArgs = 0; this.identifiers.add("mvmodify"); this.permission = "multiverse.world.modify"; this.requiresOp = true; } - + @Override public void execute(CommandSender sender, String[] args) { - sender.sendMessage(this.name); - sender.sendMessage(this.description); - sender.sendMessage(this.usage); // This is just a place holder. The real commands are in: // ModifyAddCommand // ModifyRemoveCommand // ModifySetCommand // ModifyClearCommand } - + protected static boolean validateAction(Action action, String property) { if (action == Action.Set) { try { @@ -60,6 +58,6 @@ public class ModifyCommand extends BaseCommand { return false; } } - + } } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ModifyRemoveCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ModifyRemoveCommand.java index 18421cb9..beb5fd41 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ModifyRemoveCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ModifyRemoveCommand.java @@ -9,51 +9,53 @@ import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.command.BaseCommand; public class ModifyRemoveCommand extends BaseCommand { - + public ModifyRemoveCommand(MultiverseCore plugin) { super(plugin); this.name = "Modify a World"; this.description = "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used"; - this.usage = "/mvmodify" + ChatColor.GREEN + "REMOVE {PROPERTY} {VALUE}" + ChatColor.GOLD + " [WORLD] "; - this.minArgs = 3; - this.maxArgs = 4; + this.usage = "/mvmodify" + ChatColor.GREEN + "REMOVE {PROPERTY} {VALUE}" + ChatColor.GOLD + " [WORLD]"; + this.minArgs = 2; + this.maxArgs = 3; this.identifiers.add("mvmodify remove"); this.identifiers.add("mvmodify r"); + this.identifiers.add("mvmremove"); + this.identifiers.add("mvmr"); this.permission = "multiverse.world.modify"; this.requiresOp = true; } - + @Override public void execute(CommandSender sender, String[] args) { // We NEED a world from the command line Player p = null; - if (!(sender instanceof Player)) { + if (sender instanceof Player) { p = (Player) sender; } - - if (args.length == 3 && p == null) { - sender.sendMessage("From the command line, WORLD is required."); + + if (args.length == 2 && p == null) { + sender.sendMessage(ChatColor.RED + "From the console, WORLD is required."); sender.sendMessage(this.description); sender.sendMessage(this.usage); sender.sendMessage("Nothing changed."); return; } - + MVWorld world; - String value = args[1]; - String property = args[2]; - - if (args.length == 3) { + String value = args[0]; + String property = args[1]; + + if (args.length == 2) { world = this.plugin.getMVWorld(p.getWorld().getName()); } else { - world = this.plugin.getMVWorld(args[3]); + world = this.plugin.getMVWorld(args[2]); } - + if (world == null) { sender.sendMessage("That world does not exist!"); return; } - + if (!ModifyCommand.validateAction(Action.Remove, property)) { sender.sendMessage("Sorry, you can't REMOVE anything from" + property); sender.sendMessage("Please visit our wiki for more information: URLGOESHERE FERNFERRET DON'T FORGET IT!"); @@ -65,5 +67,5 @@ public class ModifyRemoveCommand extends BaseCommand { sender.sendMessage(value + " could not be removed from " + property); } } - + } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ModifySetCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ModifySetCommand.java index 0e42f949..eb365010 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ModifySetCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ModifySetCommand.java @@ -9,50 +9,50 @@ import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.command.BaseCommand; public class ModifySetCommand extends BaseCommand { - + public ModifySetCommand(MultiverseCore plugin) { super(plugin); this.name = "Modify a World (Set a value)"; this.description = "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used"; - this.usage = "/mvmodify" + ChatColor.GREEN + " SET {PROPERTY} {VALUE}" + ChatColor.GOLD + " [WORLD] "; - this.minArgs = 3; - this.maxArgs = 4; + this.usage = "/mvmodify" + ChatColor.GREEN + " SET {PROPERTY} {VALUE}" + ChatColor.GOLD + " [WORLD]"; + this.minArgs = 2; + this.maxArgs = 3; this.identifiers.add("mvmodify set"); this.permission = "multiverse.world.modify"; this.requiresOp = true; } - + @Override public void execute(CommandSender sender, String[] args) { // We NEED a world from the command line Player p = null; - if (!(sender instanceof Player)) { + if (sender instanceof Player) { p = (Player) sender; } - - if (args.length == 3 && p == null) { + + if (args.length == 2 && p == null) { sender.sendMessage("From the command line, WORLD is required."); sender.sendMessage(this.description); sender.sendMessage(this.usage); sender.sendMessage("Nothing changed."); return; } - + MVWorld world; String value = args[1]; - String property = args[2]; - - if (args.length == 3) { + String property = args[0]; + + if (args.length == 2) { world = this.plugin.getMVWorld(p.getWorld().getName()); } else { - world = this.plugin.getMVWorld(args[3]); + world = this.plugin.getMVWorld(args[2]); } - + if (world == null) { sender.sendMessage("That world does not exist!"); return; } - + if (!ModifyCommand.validateAction(Action.Set, property)) { sender.sendMessage("Sorry, you can't SET " + property); sender.sendMessage("Please visit our wiki for more information: URLGOESHERE FERNFERRET DON'T FORGET IT!"); @@ -64,5 +64,5 @@ public class ModifySetCommand extends BaseCommand { sender.sendMessage("There was an error setting " + property); } } - + } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/PurgeCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/PurgeCommand.java index aa002471..5e43a250 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/PurgeCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/PurgeCommand.java @@ -29,7 +29,7 @@ public class PurgeCommand extends BaseCommand { @Override public void execute(CommandSender sender, String[] args) { Player p = null; - if(sender instanceof Player) { + if (sender instanceof Player) { p = (Player) sender; } if (args.length == 1 && p == null) { @@ -39,24 +39,24 @@ public class PurgeCommand extends BaseCommand { } String worldName = null; String deathName = null; - if(args.length == 1) { + if (args.length == 1) { worldName = p.getWorld().getName(); deathName = args[0]; } else { worldName = args[0]; deathName = args[1]; } - - if(!this.plugin.isMVWorld(worldName)) { + + if (!this.plugin.isMVWorld(worldName)) { sender.sendMessage("Multiverse doesn't know about " + worldName); sender.sendMessage("... so It cannot be purged"); return; } MVWorld world = this.plugin.getMVWorld(worldName); - + PurgeWorlds purger = this.plugin.getWorldPurger(); ArrayList thingsToKill = new ArrayList(); - if(deathName.equalsIgnoreCase("all") || deathName.equalsIgnoreCase("animals") || deathName.equalsIgnoreCase("monsters")) { + if (deathName.equalsIgnoreCase("all") || deathName.equalsIgnoreCase("animals") || deathName.equalsIgnoreCase("monsters")) { thingsToKill.add(deathName.toUpperCase()); } else { Collections.addAll(thingsToKill, deathName.toUpperCase().split(",")); diff --git a/src/com/onarandombox/MultiverseCore/command/commands/RemoveCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/RemoveCommand.java index 523e89d0..78c31de1 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/RemoveCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/RemoveCommand.java @@ -7,7 +7,7 @@ import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.command.BaseCommand; public class RemoveCommand extends BaseCommand { - + public RemoveCommand(MultiverseCore plugin) { super(plugin); this.name = "Remove World"; @@ -19,7 +19,7 @@ public class RemoveCommand extends BaseCommand { this.permission = "multiverse.world.remove"; this.requiresOp = true; } - + @Override public void execute(CommandSender sender, String[] args) { if (this.plugin.removeWorld(args[0])) { diff --git a/src/com/onarandombox/MultiverseCore/command/commands/SetSpawnCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/SetSpawnCommand.java index bba510fc..34294c76 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/SetSpawnCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/SetSpawnCommand.java @@ -9,7 +9,7 @@ import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.command.BaseCommand; public class SetSpawnCommand extends BaseCommand { - + public SetSpawnCommand(MultiverseCore plugin) { super(plugin); this.name = "Set World Spawn"; @@ -21,7 +21,7 @@ public class SetSpawnCommand extends BaseCommand { this.permission = "multiverse.world.spawn.set"; this.requiresOp = true; } - + @Override public void execute(CommandSender sender, String[] args) { if (sender instanceof Player) { @@ -35,5 +35,4 @@ public class SetSpawnCommand extends BaseCommand { } return; } - } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/SpawnCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/SpawnCommand.java index e196c10f..57bdf798 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/SpawnCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/SpawnCommand.java @@ -8,7 +8,7 @@ import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.command.BaseCommand; public class SpawnCommand extends BaseCommand { - + public SpawnCommand(MultiverseCore plugin) { super(plugin); this.name = "Spawn"; @@ -20,7 +20,7 @@ public class SpawnCommand extends BaseCommand { this.permission = "multiverse.world.spawn.self"; this.requiresOp = false; } - + @Override public void execute(CommandSender sender, String[] args) { Player commandSender = null; @@ -29,7 +29,7 @@ public class SpawnCommand extends BaseCommand { } // If a persons name was passed in, you must be A. the console, or B have permissions if (args.length == 1) { - if(commandSender != null && !this.plugin.ph.hasPermission(commandSender, "multiverse.world.spawn.other", true)) { + if (commandSender != null && !this.plugin.ph.hasPermission(commandSender, "multiverse.world.spawn.other", true)) { sender.sendMessage("You don't have permission to teleport another player to spawn."); return; } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/TeleportCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/TeleportCommand.java index ba66ca36..08beb526 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/TeleportCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/TeleportCommand.java @@ -13,7 +13,7 @@ import com.onarandombox.utils.DestinationType; public class TeleportCommand extends BaseCommand { private MVTeleport playerTeleporter; - + public TeleportCommand(MultiverseCore plugin) { super(plugin); this.name = "Teleport"; @@ -26,7 +26,7 @@ public class TeleportCommand extends BaseCommand { this.permission = "multiverse.world.tp.self"; this.requiresOp = true; } - + @Override public void execute(CommandSender sender, String[] args) { // Check if the command was sent from a Player. @@ -35,9 +35,9 @@ public class TeleportCommand extends BaseCommand { if (sender instanceof Player) { teleporter = (Player) sender; } - + String worldName; - + if (args.length == 2) { if (teleporter != null && !this.plugin.ph.hasPermission(sender, "multiverse.world.tp.other", true)) { sender.sendMessage("You don't have permission to teleport another player."); @@ -49,10 +49,10 @@ public class TeleportCommand extends BaseCommand { return; } worldName = args[1]; - + } else { worldName = args[0]; - + if (!(sender instanceof Player)) { sender.sendMessage("You can only teleport other players from the command line."); return; @@ -60,13 +60,13 @@ public class TeleportCommand extends BaseCommand { teleporter = (Player) sender; teleportee = (Player) sender; } - + Destination d = Destination.parseDestination(worldName, this.plugin); if (!(d.getType() == DestinationType.World)) { sender.sendMessage("Multiverse does not know about this world: " + worldName); return; } - + if (teleporter != null && !this.plugin.ph.canEnterWorld(teleporter, this.plugin.getServer().getWorld(d.getName()))) { if (teleportee.equals(teleporter)) { teleporter.sendMessage("Doesn't look like you're allowed to go " + ChatColor.RED + "there..."); @@ -85,5 +85,4 @@ public class TeleportCommand extends BaseCommand { Location l = this.playerTeleporter.getSafeDestination(this.plugin.getServer().getWorld(d.getName()).getSpawnLocation()); teleportee.teleport(l); } - } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/UnloadCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/UnloadCommand.java index d2407e1d..0a26995c 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/UnloadCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/UnloadCommand.java @@ -7,7 +7,7 @@ import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.command.BaseCommand; public class UnloadCommand extends BaseCommand { - + public UnloadCommand(MultiverseCore plugin) { super(plugin); this.name = "Unload World"; @@ -19,7 +19,7 @@ public class UnloadCommand extends BaseCommand { this.permission = "multiverse.world.unload"; this.requiresOp = true; } - + @Override public void execute(CommandSender sender, String[] args) { if (this.plugin.unloadWorld(args[0])) { @@ -28,5 +28,4 @@ public class UnloadCommand extends BaseCommand { sender.sendMessage("Error trying to unload world!"); } } - } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/WhoCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/WhoCommand.java index c8ee1238..644ab74b 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/WhoCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/WhoCommand.java @@ -14,7 +14,7 @@ import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.command.BaseCommand; public class WhoCommand extends BaseCommand { - + public WhoCommand(MultiverseCore plugin) { super(plugin); this.name = "Who"; @@ -26,7 +26,7 @@ public class WhoCommand extends BaseCommand { this.permission = "multiverse.world.list.who"; this.requiresOp = false; } - + @Override public void execute(CommandSender sender, String[] args) { // If this command was sent from a Player then we need to check Permissions @@ -34,9 +34,9 @@ public class WhoCommand extends BaseCommand { if (sender instanceof Player) { p = (Player) sender; } - + List worlds = new ArrayList(); - + if (args.length > 0) { if (this.plugin.isMVWorld(args[0])) { worlds.add(this.plugin.getMVWorld(args[0])); @@ -47,17 +47,17 @@ public class WhoCommand extends BaseCommand { } else { worlds = new ArrayList(this.plugin.getMVWorlds()); } - + for (MVWorld world : worlds) { if (!(this.plugin.isMVWorld(world.getName()))) { continue; } - + World w = this.plugin.getServer().getWorld(world.getName()); if (p != null && (!this.plugin.ph.canEnterWorld(p, w))) { continue; } - + ChatColor color = ChatColor.GOLD; Environment env = world.getEnvironment(); if (env == Environment.NETHER) { @@ -68,7 +68,7 @@ public class WhoCommand extends BaseCommand { color = ChatColor.AQUA; } List players = w.getPlayers(); - + String result = ""; if (players.size() <= 0) { result = "Empty"; @@ -78,14 +78,13 @@ public class WhoCommand extends BaseCommand { } } String worldName = world.getName(); - if(world.getAlias() != null && world.getAlias().length() > 0) { + if (world.getAlias() != null && world.getAlias().length() > 0) { worldName = world.getAlias(); color = world.getAliasColor(); } - + sender.sendMessage(color + worldName + ChatColor.WHITE + " - " + result); } return; } - } From 6ccb52bc3ea5255ed28ca9081c624fd5c16558e8 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 9 Jul 2011 08:34:18 -0600 Subject: [PATCH 03/55] Change to BSD from CC --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 43af7992..74f37f16 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ -This will do as a README for now - +Copyright (c) 2011, The Multiverse Team All rights reserved. -This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. \ No newline at end of file +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the FernFerret Studios nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file From 949e70b81c8580e1a2f8b64cbc471d5ab1c13292 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 9 Jul 2011 16:57:04 -0600 Subject: [PATCH 04/55] Remove code I don't want anymore. --- .../MultiverseCore/MultiverseCore.java | 26 +++---------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/src/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/com/onarandombox/MultiverseCore/MultiverseCore.java index 32594cc3..7041d8bb 100644 --- a/src/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -238,29 +238,6 @@ public class MultiverseCore extends JavaPlugin { log(Level.INFO, count + " - World(s) loaded."); } - /** - * - * @return - */ - private int loadDefaultWorlds() { - int additonalWorldsLoaded = 0; - // Load the default world: - World world = this.getServer().getWorlds().get(0); - if (!this.worlds.containsKey(world.getName())) { - addWorld(world.getName(), Environment.NORMAL, null, null); - additonalWorldsLoaded++; - } - - // This next one could be null if they have it disabled in server.props - World world_nether = this.getServer().getWorld(world.getName() + "_nether"); - if (world_nether != null && !this.worlds.containsKey(world_nether.getName())) { - addWorld(world_nether.getName(), Environment.NETHER, null, null); - additonalWorldsLoaded++; - } - - return additonalWorldsLoaded; - } - /** * Add a new World to the Multiverse Setup. * @@ -416,6 +393,9 @@ public class MultiverseCore extends JavaPlugin { */ public void onDisable() { debugLog.close(); + this.ph.setPermissions(null); + this.banker = null; + this.bank = null; log(Level.INFO, "- Disabled"); } From 4d39f2ec56f41169fe84adcfe3c104d6772da0a8 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 9 Jul 2011 17:42:32 -0600 Subject: [PATCH 05/55] Removed Licensed CommandManager Code We want no part in CC NoDeriv Code. --- .../MultiverseCore/command/BaseCommand.java | 96 -------- .../command/CommandManager.java | 218 ------------------ 2 files changed, 314 deletions(-) delete mode 100644 src/com/onarandombox/MultiverseCore/command/BaseCommand.java delete mode 100644 src/com/onarandombox/MultiverseCore/command/CommandManager.java diff --git a/src/com/onarandombox/MultiverseCore/command/BaseCommand.java b/src/com/onarandombox/MultiverseCore/command/BaseCommand.java deleted file mode 100644 index 0bb0bcbc..00000000 --- a/src/com/onarandombox/MultiverseCore/command/BaseCommand.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.onarandombox.MultiverseCore.command; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.command.CommandSender; - -import com.onarandombox.MultiverseCore.MultiverseCore; - -public abstract class BaseCommand { - - protected MultiverseCore plugin; - protected String name; - protected String description; - protected String usage; - protected String permission = ""; - protected boolean requiresOp; - protected int minArgs; - protected int maxArgs; - protected List identifiers; - - public final String IN_GAME_COMMAND_MSG = "This command needs to be used as a Player in game."; - - public BaseCommand(MultiverseCore plugin) { - this.identifiers = new ArrayList(); - this.plugin = plugin; - } - - public abstract void execute(CommandSender sender, String[] args); - - public boolean validate(ArrayList args) { - int argsLength = args.size(); - if ((argsLength == -1 || argsLength >= this.minArgs) && (this.maxArgs == -1 || argsLength <= this.maxArgs)) { - return true; - } - return false; - } - - public String getIdentifier(ArrayList allArgs) { - // Combines our args to a space separated string - String argsString = this.getArgsString(allArgs); - - for (String s : this.identifiers) { - String identifier = s.toLowerCase(); - if (argsString.matches(identifier + "(\\s+.*|\\s*)")) { - return identifier; - } - } - return null; - } - - public ArrayList removeIdentifierArgs(ArrayList allArgs, String identifier) { - int identifierLength = identifier.split(" ").length; - for (int i = 0; i < identifierLength; i++) { - // Since we're pulling from the front, always remove the first element - allArgs.remove(0); - } - return allArgs; - } - - private String getArgsString(ArrayList args) { - String returnString = ""; - for (String s : args) { - returnString += s + " "; - } - return returnString.substring(0, returnString.length() - 1); - } - - public List getIdentifiers() { - return this.identifiers; - } - - public void setIdentifiers(List identifiers) { - this.identifiers = identifiers; - } - - public String getName() { - return this.name; - } - - public String getDescription() { - return this.description; - } - - public String getUsage() { - return this.usage; - } - - public boolean isOpRequired() { - return this.requiresOp; - } - - public String getPermission() { - return this.permission; - } -} diff --git a/src/com/onarandombox/MultiverseCore/command/CommandManager.java b/src/com/onarandombox/MultiverseCore/command/CommandManager.java deleted file mode 100644 index 675cf39f..00000000 --- a/src/com/onarandombox/MultiverseCore/command/CommandManager.java +++ /dev/null @@ -1,218 +0,0 @@ -/** - * Copyright (C) 2011 DThielke - * - * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License. - * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/3.0/ or send a letter to - * Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. - **/ - -package com.onarandombox.MultiverseCore.command; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Iterator; -import java.util.List; - -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; - -import com.onarandombox.MultiverseCore.MultiverseCore; - -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; - } - - public boolean dispatch(CommandSender sender, ArrayList allArgs) { - ArrayList parsedArgs = parseAllQuotedStrings(allArgs); - String identifier = null; - - Iterator iterator = this.commands.iterator(); - BaseCommand foundCommand = null; - // This loop is pretty neat. It goes until either the iterator has no more - // Or until we find an identifier. When we do, we no longer iterate, and the - // value left in "foundCommand" is the command we found! - while (iterator.hasNext() && identifier == null) { - foundCommand = iterator.next(); - identifier = foundCommand.getIdentifier(parsedArgs); - if (identifier != null) { - // This method, removeIdentifierArgs mutates parsedArgs - foundCommand.removeIdentifierArgs(parsedArgs, identifier); - validateAndRunCommand(sender, parsedArgs, foundCommand); - } - } - return true; - } - - private void validateAndRunCommand(CommandSender sender, ArrayList parsedArgs, BaseCommand foundCommand) { - if (foundCommand.validate(parsedArgs)) { - if (this.plugin.ph.hasPermission(sender, foundCommand.getPermission(), foundCommand.isOpRequired())) { - foundCommand.execute(sender, parsedArgs.toArray(new String[parsedArgs.size()])); - } else { - sender.sendMessage("You do not have permission to use this command. (" + foundCommand.getPermission() + ")"); - } - } else { - sender.sendMessage(ChatColor.AQUA + "Command: " + ChatColor.WHITE + foundCommand.getName()); - sender.sendMessage(ChatColor.AQUA + "Description: " + ChatColor.WHITE + foundCommand.getDescription()); - sender.sendMessage(ChatColor.AQUA + "Usage: " + ChatColor.WHITE + foundCommand.getUsage()); - } - } - - public void addCommand(BaseCommand command) { - this.commands.add(command); - } - - public void removeCommand(BaseCommand command) { - this.commands.remove(command); - } - - @Deprecated - public List getCommands() { - return this.commands; - } - - public List getCommands(CommandSender sender) { - ArrayList playerCommands = new ArrayList(); - for (BaseCommand c : this.commands) { - if (this.plugin.ph.hasPermission(sender, c.permission, c.isOpRequired())) { - playerCommands.add(c); - } - } - return playerCommands; - } - - /** - * Combines all quoted strings - * - * @param args - * @return - */ - private ArrayList parseAllQuotedStrings(ArrayList args) { - // TODO: Allow ' - ArrayList newArgs = new ArrayList(); - // Iterate through all command params: - // we could have: "Fish dog" the man bear pig "lives today" and maybe "even tomorrow" or "the" next day - int start = -1; - for (int i = 0; i < args.size(); i++) { - - // If we aren't looking for an end quote, and the first part of a string is a quote - if (start == -1 && args.get(i).substring(0, 1).equals("\"")) { - start = i; - } - // Have to keep this seperate for one word quoted strings like: "fish" - if (start != -1 && args.get(i).substring(args.get(i).length() - 1, args.get(i).length()).equals("\"")) { - // Now we've found the second part of a string, let's parse the quoted one out - // Make sure it's i+1, we still want I included - newArgs.add(parseQuotedString(args, start, i + 1)); - // Reset the start to look for more! - start = -1; - } else if (start == -1) { - // This is a word that is NOT enclosed in any quotes, so just add it - newArgs.add(args.get(i)); - } - } - // If the string was ended but had an open quote... - if (start != -1) { - // ... then we want to close that quote and make that one arg. - newArgs.add(parseQuotedString(args, start, args.size())); - } - - return newArgs; - } - - /** - * Takes a string array and returns a combined string, excluding the stop position, including the start - * - * @param args - * @param start - * @param stop - * @return - */ - private String parseQuotedString(ArrayList args, int start, int stop) { - String returnVal = args.get(start); - for (int i = start + 1; i < stop; i++) { - returnVal += " " + args.get(i); - } - return returnVal.replace("\"", ""); - } - - /** - * Returns the given flag value - * - * @param flag A param flag, like -s or -g - * @param args All arguments to search through - * @return A string or null - */ - public static String getFlag(String flag, String[] args) { - int i = 0; - try { - for (String s : args) { - if (s.equalsIgnoreCase(flag)) { - return args[i + 1]; - } - i++; - } - } catch (IndexOutOfBoundsException e) { - } - return null; - } - - /** - * - */ - 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); - } - } -} From f1c94bf851062314de907f11c21055b9f2c11572 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 9 Jul 2011 18:00:30 -0600 Subject: [PATCH 06/55] Started implementing the new CommandHandler --- .gitmodules | 3 + lib/commandhandler | 1 + .../MultiverseCore/MultiverseCore.java | 49 ++++++----- .../MultiverseCore/command/QueuedCommand.java | 88 ------------------- .../command/commands/ConfirmCommand.java | 22 +++-- 5 files changed, 42 insertions(+), 121 deletions(-) create mode 160000 lib/commandhandler delete mode 100644 src/com/onarandombox/MultiverseCore/command/QueuedCommand.java diff --git a/.gitmodules b/.gitmodules index 90325b68..d034c779 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "lib/allpay"] path = lib/allpay url = git://github.com/FernFerret/AllPay.git +[submodule "lib/commandhandler"] + path = lib/commandhandler + url = git://github.com/PneumatiCraft/CommandHandler.git diff --git a/lib/commandhandler b/lib/commandhandler new file mode 160000 index 00000000..5d1210ed --- /dev/null +++ b/lib/commandhandler @@ -0,0 +1 @@ +Subproject commit 5d1210ed57b1d3552821a5d45798101d27b8e244 diff --git a/src/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/com/onarandombox/MultiverseCore/MultiverseCore.java index 7041d8bb..4bf8f28d 100644 --- a/src/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -30,6 +30,7 @@ import com.onarandombox.MultiverseCore.configuration.DefaultConfiguration; import com.onarandombox.utils.DebugLog; import com.onarandombox.utils.PurgeWorlds; import com.onarandombox.utils.UpdateChecker; +import com.pneumaticraft.commandhandler.CommandHandler; public class MultiverseCore extends JavaPlugin { @@ -41,7 +42,7 @@ public class MultiverseCore extends JavaPlugin { private boolean debug; // Setup our Map for our Commands using the CommandHandler. - private CommandManager commandManager; + private CommandHandler commandManager; private final String tag = "[Multiverse-Core]"; @@ -92,7 +93,7 @@ public class MultiverseCore extends JavaPlugin { this.bank = this.banker.loadEconPlugin(); // Setup the command manager - this.commandManager = new CommandManager(this); + this.commandManager = new CommandHandler(this); // Setup the world purger this.worldPurger = new PurgeWorlds(this); // Call the Function to assign all the Commands to their Class. @@ -169,30 +170,30 @@ public class MultiverseCore extends JavaPlugin { */ private void registerCommands() { // Page 1 - this.commandManager.addCommand(new HelpCommand(this)); - this.commandManager.addCommand(new CoordCommand(this)); - this.commandManager.addCommand(new TeleportCommand(this)); - this.commandManager.addCommand(new ListCommand(this)); - this.commandManager.addCommand(new WhoCommand(this)); - this.commandManager.addCommand(new SetSpawnCommand(this)); - this.commandManager.addCommand(new CreateCommand(this)); - this.commandManager.addCommand(new ImportCommand(this)); - this.commandManager.addCommand(new SpawnCommand(this)); - this.commandManager.addCommand(new RemoveCommand(this)); - this.commandManager.addCommand(new DeleteCommand(this)); - this.commandManager.addCommand(new UnloadCommand(this)); - this.commandManager.addCommand(new ConfirmCommand(this)); - this.commandManager.addCommand(new InfoCommand(this)); - this.commandManager.addCommand(new ReloadCommand(this)); + this.commandManager.registerCommand(new HelpCommand(this)); + this.commandManager.registerCommand(new CoordCommand(this)); + this.commandManager.registerCommand(new TeleportCommand(this)); + this.commandManager.registerCommand(new ListCommand(this)); + this.commandManager.registerCommand(new WhoCommand(this)); + this.commandManager.registerCommand(new SetSpawnCommand(this)); + this.commandManager.registerCommand(new CreateCommand(this)); + this.commandManager.registerCommand(new ImportCommand(this)); + this.commandManager.registerCommand(new SpawnCommand(this)); + this.commandManager.registerCommand(new RemoveCommand(this)); + this.commandManager.registerCommand(new DeleteCommand(this)); + this.commandManager.registerCommand(new UnloadCommand(this)); + this.commandManager.registerCommand(new ConfirmCommand(this)); + this.commandManager.registerCommand(new InfoCommand(this)); + this.commandManager.registerCommand(new ReloadCommand(this)); - this.commandManager.addCommand(new ModifyAddCommand(this)); - this.commandManager.addCommand(new ModifySetCommand(this)); - this.commandManager.addCommand(new ModifyRemoveCommand(this)); - this.commandManager.addCommand(new ModifyClearCommand(this)); + this.commandManager.registerCommand(new ModifyAddCommand(this)); + this.commandManager.registerCommand(new ModifySetCommand(this)); + this.commandManager.registerCommand(new ModifyRemoveCommand(this)); + this.commandManager.registerCommand(new ModifyClearCommand(this)); // This modify MUST go last. - this.commandManager.addCommand(new ModifyCommand(this)); - this.commandManager.addCommand(new EnvironmentCommand(this)); - this.commandManager.addCommand(new PurgeCommand(this)); + this.commandManager.registerCommand(new ModifyCommand(this)); + this.commandManager.registerCommand(new EnvironmentCommand(this)); + this.commandManager.registerCommand(new PurgeCommand(this)); } /** diff --git a/src/com/onarandombox/MultiverseCore/command/QueuedCommand.java b/src/com/onarandombox/MultiverseCore/command/QueuedCommand.java deleted file mode 100644 index 66e114e0..00000000 --- a/src/com/onarandombox/MultiverseCore/command/QueuedCommand.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.onarandombox.MultiverseCore.command; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Calendar; - -import org.bukkit.command.CommandSender; - -import com.onarandombox.MultiverseCore.MultiverseCore; - -public class QueuedCommand { - - private String name; - private Object[] args; - private Class paramTypes[]; - private CommandSender sender; - private MultiverseCore plugin; - private Calendar timeRequested; - private String success; - private String fail; - - public QueuedCommand(String commandName, Object[] args, Class partypes[], CommandSender sender, Calendar instance, MultiverseCore plugin, String success, String fail) { - this.plugin = plugin; - this.name = commandName; - this.args = args; - this.sender = sender; - this.timeRequested = instance; - this.paramTypes = partypes; - this.setSuccess(success); - this.setFail(fail); - } - - public CommandSender getSender() { - return this.sender; - } - - public boolean execute() { - this.timeRequested.add(Calendar.SECOND, 10); - if (this.timeRequested.after(Calendar.getInstance())) { - try { - Method method = this.plugin.getClass().getMethod(this.name, this.paramTypes); - try { - method.invoke(this.plugin, this.args); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - return false; - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - return false; - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - return false; - } - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - return false; - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - return false; - } - return true; - } else { - this.sender.sendMessage("This command has expried. Please type the original command again."); - } - return false; - } - - private void setSuccess(String success) { - this.success = success; - } - - public String getSuccess() { - return this.success; - } - - private void setFail(String fail) { - this.fail = fail; - } - - public String getFail() { - return this.fail; - } -} diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ConfirmCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ConfirmCommand.java index 06a4ef36..36bdd586 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ConfirmCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ConfirmCommand.java @@ -1,28 +1,32 @@ package com.onarandombox.MultiverseCore.command.commands; +import java.util.List; + import org.bukkit.command.CommandSender; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.command.BaseCommand; +import com.pneumaticraft.commandhandler.Command; -public class ConfirmCommand extends BaseCommand { +public class ConfirmCommand extends Command { public ConfirmCommand(MultiverseCore plugin) { super(plugin); - this.name = "Confirms a command that could destroy life, the universe and everything."; - this.description = "If you have not been prompted to use this, it will not do anything."; - this.usage = "/mvconfirm"; - this.minArgs = 0; - this.maxArgs = 0; - this.identifiers.add("mvconfirm"); + this.commandName = "Confirms a command that could destroy life, the universe and everything."; + this.commandDesc = "If you have not been prompted to use this, it will not do anything."; + this.commandUsage = "/mvconfirm"; + this.minimumArgLength = 0; + this.maximumArgLength = 0; + this.commandKeys.add("mvconfirm"); this.permission = "multiverse.world.confirm"; // Any command that is dangerous should require op - this.requiresOp = true; + this.opRequired = true; } @Override - public void execute(CommandSender sender, String[] args) { + public void runCommand(CommandSender sender, List args) { this.plugin.getCommandManager().confirmQueuedCommand(sender); + } } From 9c924b04a0af90d183c011df78f8954660b23fca Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 9 Jul 2011 18:06:42 -0600 Subject: [PATCH 07/55] ConfirmCommand has been refitted with the new hooks. --- .../MultiverseCore/MultiverseCore.java | 54 +++++++++---------- .../command/commands/ConfirmCommand.java | 4 +- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/com/onarandombox/MultiverseCore/MultiverseCore.java index 4bf8f28d..81a4d334 100644 --- a/src/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -42,7 +42,7 @@ public class MultiverseCore extends JavaPlugin { private boolean debug; // Setup our Map for our Commands using the CommandHandler. - private CommandHandler commandManager; + private CommandHandler commandHandler; private final String tag = "[Multiverse-Core]"; @@ -93,7 +93,7 @@ public class MultiverseCore extends JavaPlugin { this.bank = this.banker.loadEconPlugin(); // Setup the command manager - this.commandManager = new CommandHandler(this); + this.commandHandler = new CommandHandler(this); // Setup the world purger this.worldPurger = new PurgeWorlds(this); // Call the Function to assign all the Commands to their Class. @@ -170,30 +170,30 @@ public class MultiverseCore extends JavaPlugin { */ private void registerCommands() { // Page 1 - this.commandManager.registerCommand(new HelpCommand(this)); - this.commandManager.registerCommand(new CoordCommand(this)); - this.commandManager.registerCommand(new TeleportCommand(this)); - this.commandManager.registerCommand(new ListCommand(this)); - this.commandManager.registerCommand(new WhoCommand(this)); - this.commandManager.registerCommand(new SetSpawnCommand(this)); - this.commandManager.registerCommand(new CreateCommand(this)); - this.commandManager.registerCommand(new ImportCommand(this)); - this.commandManager.registerCommand(new SpawnCommand(this)); - this.commandManager.registerCommand(new RemoveCommand(this)); - this.commandManager.registerCommand(new DeleteCommand(this)); - this.commandManager.registerCommand(new UnloadCommand(this)); - this.commandManager.registerCommand(new ConfirmCommand(this)); - this.commandManager.registerCommand(new InfoCommand(this)); - this.commandManager.registerCommand(new ReloadCommand(this)); + this.commandHandler.registerCommand(new HelpCommand(this)); + this.commandHandler.registerCommand(new CoordCommand(this)); + this.commandHandler.registerCommand(new TeleportCommand(this)); + this.commandHandler.registerCommand(new ListCommand(this)); + this.commandHandler.registerCommand(new WhoCommand(this)); + this.commandHandler.registerCommand(new SetSpawnCommand(this)); + this.commandHandler.registerCommand(new CreateCommand(this)); + this.commandHandler.registerCommand(new ImportCommand(this)); + this.commandHandler.registerCommand(new SpawnCommand(this)); + this.commandHandler.registerCommand(new RemoveCommand(this)); + this.commandHandler.registerCommand(new DeleteCommand(this)); + this.commandHandler.registerCommand(new UnloadCommand(this)); + this.commandHandler.registerCommand(new ConfirmCommand(this)); + this.commandHandler.registerCommand(new InfoCommand(this)); + this.commandHandler.registerCommand(new ReloadCommand(this)); - this.commandManager.registerCommand(new ModifyAddCommand(this)); - this.commandManager.registerCommand(new ModifySetCommand(this)); - this.commandManager.registerCommand(new ModifyRemoveCommand(this)); - this.commandManager.registerCommand(new ModifyClearCommand(this)); + this.commandHandler.registerCommand(new ModifyAddCommand(this)); + this.commandHandler.registerCommand(new ModifySetCommand(this)); + this.commandHandler.registerCommand(new ModifyRemoveCommand(this)); + this.commandHandler.registerCommand(new ModifyClearCommand(this)); // This modify MUST go last. - this.commandManager.registerCommand(new ModifyCommand(this)); - this.commandManager.registerCommand(new EnvironmentCommand(this)); - this.commandManager.registerCommand(new PurgeCommand(this)); + this.commandHandler.registerCommand(new ModifyCommand(this)); + this.commandHandler.registerCommand(new EnvironmentCommand(this)); + this.commandHandler.registerCommand(new PurgeCommand(this)); } /** @@ -446,7 +446,7 @@ public class MultiverseCore extends JavaPlugin { } ArrayList allArgs = new ArrayList(Arrays.asList(args)); allArgs.add(0, command.getName()); - return this.commandManager.dispatch(sender, allArgs); + return this.commandHandler.dispatch(sender, allArgs); } /** @@ -496,8 +496,8 @@ public class MultiverseCore extends JavaPlugin { return authors.substring(2); } - public CommandManager getCommandManager() { - return this.commandManager; + public CommandHandler getCommandHandler() { + return this.commandHandler; } public String getTag() { diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ConfirmCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ConfirmCommand.java index 36bdd586..56c13dd7 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ConfirmCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ConfirmCommand.java @@ -5,7 +5,6 @@ import java.util.List; import org.bukkit.command.CommandSender; import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.command.BaseCommand; import com.pneumaticraft.commandhandler.Command; public class ConfirmCommand extends Command { @@ -25,8 +24,7 @@ public class ConfirmCommand extends Command { @Override public void runCommand(CommandSender sender, List args) { - this.plugin.getCommandManager().confirmQueuedCommand(sender); - + ((MultiverseCore) this.plugin).getCommandHandler().confirmQueuedCommand(sender); } } From a4b74d172b6b96c1554beffe121edb1f11bf028b Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 9 Jul 2011 18:13:56 -0600 Subject: [PATCH 08/55] More progress --- .../MultiverseCore/command/commands/CoordCommand.java | 10 ++++++---- .../MultiverseCore/command/commands/CreateCommand.java | 8 ++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/com/onarandombox/MultiverseCore/command/commands/CoordCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/CoordCommand.java index d8335b92..d06e594a 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/CoordCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/CoordCommand.java @@ -1,15 +1,17 @@ package com.onarandombox.MultiverseCore.command.commands; +import java.util.List; + import org.bukkit.ChatColor; import org.bukkit.Material; 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.LocationManipulation; +import com.pneumaticraft.commandhandler.Command; -public class CoordCommand extends BaseCommand { +public class CoordCommand extends Command { private LocationManipulation locMan = new LocationManipulation(); @@ -24,12 +26,12 @@ public class CoordCommand extends BaseCommand { } @Override - public void execute(CommandSender sender, String[] args) { + public void runCommand(CommandSender sender, List args) { // Check if the command was sent from a Player. if (sender instanceof Player) { Player p = (Player) sender; p.sendMessage(ChatColor.RED + "World: " + ChatColor.WHITE + p.getWorld().getName()); - p.sendMessage(ChatColor.RED + "World Scale: " + ChatColor.WHITE + this.plugin.getMVWorld(p.getWorld().getName()).getScaling()); + p.sendMessage(ChatColor.RED + "World Scale: " + ChatColor.WHITE + ((MultiverseCore) this.plugin).getMVWorld(p.getWorld().getName()).getScaling()); p.sendMessage(ChatColor.RED + "Coordinates: " + ChatColor.WHITE + this.locMan.strCoords(p.getLocation())); p.sendMessage(ChatColor.RED + "Direction: " + ChatColor.WHITE + this.locMan.getDirection(p.getLocation())); p.sendMessage(ChatColor.RED + "Block: " + ChatColor.WHITE + Material.getMaterial(p.getWorld().getBlockTypeIdAt(p.getLocation()))); diff --git a/src/com/onarandombox/MultiverseCore/command/commands/CreateCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/CreateCommand.java index 0dc7bd52..c0595bcb 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/CreateCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/CreateCommand.java @@ -1,16 +1,16 @@ package com.onarandombox.MultiverseCore.command.commands; import java.io.File; +import java.util.List; import org.bukkit.ChatColor; import org.bukkit.World.Environment; import org.bukkit.command.CommandSender; import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.command.BaseCommand; -import com.onarandombox.MultiverseCore.command.CommandManager; +import com.pneumaticraft.commandhandler.Command; -public class CreateCommand extends BaseCommand { +public class CreateCommand extends Command { public CreateCommand(MultiverseCore plugin) { super(plugin); @@ -25,7 +25,7 @@ public class CreateCommand extends BaseCommand { } @Override - public void execute(CommandSender sender, String[] args) { + public void runCommand(CommandSender sender, List args) { if (args.length % 2 != 0) { sender.sendMessage("You must preface your SEED with -s OR your GENERATOR with -g. Type /mv for help"); return; From 20eb65fd59a2bc11b6b50eb393e85e6dc13269cd Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 9 Jul 2011 18:19:46 -0600 Subject: [PATCH 09/55] Upade CommandHandler --- lib/commandhandler | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commandhandler b/lib/commandhandler index 5d1210ed..1d611c87 160000 --- a/lib/commandhandler +++ b/lib/commandhandler @@ -1 +1 @@ -Subproject commit 5d1210ed57b1d3552821a5d45798101d27b8e244 +Subproject commit 1d611c871c148384eee8515c1c47413b77132f5e From aa96821df1416973c6e6395c4188faa4eb9b7c92 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 9 Jul 2011 18:28:35 -0600 Subject: [PATCH 10/55] working on delete --- .../MultiverseCore/command/commands/DeleteCommand.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/com/onarandombox/MultiverseCore/command/commands/DeleteCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/DeleteCommand.java index 07683bcc..db0cfdfa 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/DeleteCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/DeleteCommand.java @@ -1,12 +1,14 @@ package com.onarandombox.MultiverseCore.command.commands; +import java.util.List; + import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.command.BaseCommand; +import com.pneumaticraft.commandhandler.Command; -public class DeleteCommand extends BaseCommand { +public class DeleteCommand extends Command { public DeleteCommand(MultiverseCore plugin) { super(plugin); @@ -21,8 +23,8 @@ public class DeleteCommand extends BaseCommand { } @Override - public void execute(CommandSender sender, String[] args) { + public void runCommand(CommandSender sender, List args) { Class paramTypes[] = { String.class }; - this.plugin.getCommandManager().queueCommand(sender, "mvdelete", "deleteWorld", args, paramTypes, "World Deleted!", "World was not deleted!"); + ((MultiverseCore) this.plugin).getCommandHandler().queueCommand(sender, "mvdelete", "deleteWorld", args, paramTypes, "World Deleted!", "World was not deleted!"); } } From 71a63d10d6293406a399bbca6608bea76fa8ce1d Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 9 Jul 2011 18:32:33 -0600 Subject: [PATCH 11/55] Update commandhandler version --- lib/commandhandler | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commandhandler b/lib/commandhandler index 1d611c87..39d63dee 160000 --- a/lib/commandhandler +++ b/lib/commandhandler @@ -1 +1 @@ -Subproject commit 1d611c871c148384eee8515c1c47413b77132f5e +Subproject commit 39d63dee25de382c14545df4a17b7850e537fdad From 83bb61a5eeedc7bd024c8a22cbf8e6944aea53fe Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 9 Jul 2011 18:35:01 -0600 Subject: [PATCH 12/55] update CommandHandler Again --- lib/commandhandler | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commandhandler b/lib/commandhandler index 39d63dee..030380b2 160000 --- a/lib/commandhandler +++ b/lib/commandhandler @@ -1 +1 @@ -Subproject commit 39d63dee25de382c14545df4a17b7850e537fdad +Subproject commit 030380b2b201bd2dfe825d9a07fe9ac40cb8dece From 5b30e7214e230d7cddbadd4d7d4305a64cc7dc62 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 9 Jul 2011 19:59:06 -0600 Subject: [PATCH 13/55] Implement new CommandHandler --- .../MultiverseCore/MultiverseCore.java | 3 +- .../command/commands/CoordCommand.java | 12 ++-- .../command/commands/CreateCommand.java | 31 ++++----- .../command/commands/DeleteCommand.java | 14 ++-- .../command/commands/EnvironmentCommand.java | 29 ++++---- .../command/commands/HelpCommand.java | 66 +++---------------- .../command/commands/ImportCommand.java | 35 +++++----- .../command/commands/InfoCommand.java | 32 ++++----- .../command/commands/ListCommand.java | 26 ++++---- .../command/commands/ModifyAddCommand.java | 39 +++++------ .../command/commands/ModifyClearCommand.java | 40 +++++------ .../command/commands/ModifyCommand.java | 38 ++++++----- .../command/commands/ModifyRemoveCommand.java | 44 +++++++------ .../command/commands/ModifySetCommand.java | 38 ++++++----- .../command/commands/PurgeCommand.java | 39 +++++------ .../command/commands/ReloadCommand.java | 29 ++++---- .../command/commands/RemoveCommand.java | 24 +++---- .../command/commands/SetSpawnCommand.java | 25 +++---- .../command/commands/SpawnCommand.java | 30 +++++---- .../command/commands/TeleportCommand.java | 40 +++++------ .../command/commands/UnloadCommand.java | 24 +++---- .../command/commands/WhoCommand.java | 33 +++++----- 22 files changed, 335 insertions(+), 356 deletions(-) diff --git a/src/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/com/onarandombox/MultiverseCore/MultiverseCore.java index 81a4d334..ead54dd8 100644 --- a/src/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -24,7 +24,6 @@ import org.bukkit.util.config.Configuration; import com.fernferret.allpay.AllPay; import com.fernferret.allpay.GenericBank; -import com.onarandombox.MultiverseCore.command.CommandManager; import com.onarandombox.MultiverseCore.command.commands.*; import com.onarandombox.MultiverseCore.configuration.DefaultConfiguration; import com.onarandombox.utils.DebugLog; @@ -446,7 +445,7 @@ public class MultiverseCore extends JavaPlugin { } ArrayList allArgs = new ArrayList(Arrays.asList(args)); allArgs.add(0, command.getName()); - return this.commandHandler.dispatch(sender, allArgs); + return this.commandHandler.locateAndRunCommand(sender, allArgs); } /** diff --git a/src/com/onarandombox/MultiverseCore/command/commands/CoordCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/CoordCommand.java index d06e594a..cb85947a 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/CoordCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/CoordCommand.java @@ -17,12 +17,12 @@ public class CoordCommand extends Command { public CoordCommand(MultiverseCore plugin) { super(plugin); - this.name = "Coordinates"; - this.description = "Returns detailed information on the Players where abouts."; - this.usage = "/mvcoord"; - this.minArgs = 0; - this.maxArgs = 0; - this.identifiers.add("mvcoord"); + this.commandName = "Coordinates"; + this.commandDesc = "Returns detailed information on the Players where abouts."; + this.commandUsage = "/mvcoord"; + this.minimumArgLength = 0; + this.maximumArgLength = 0; + this.commandKeys.add("mvcoord"); } @Override diff --git a/src/com/onarandombox/MultiverseCore/command/commands/CreateCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/CreateCommand.java index c0595bcb..40fef070 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/CreateCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/CreateCommand.java @@ -9,46 +9,47 @@ import org.bukkit.command.CommandSender; import com.onarandombox.MultiverseCore.MultiverseCore; import com.pneumaticraft.commandhandler.Command; +import com.pneumaticraft.commandhandler.CommandHandler; public class CreateCommand extends Command { public CreateCommand(MultiverseCore plugin) { super(plugin); - this.name = "Create World"; - this.description = "Creates a new world of the specified type"; - this.usage = "/mvcreate" + ChatColor.GREEN + " {NAME} {ENV}" + ChatColor.GOLD + " -s [SEED] -g [GENERATOR[:ID]]"; - this.minArgs = 2; - this.maxArgs = 6; - this.identifiers.add("mvcreate"); + this.commandName = "Create World"; + this.commandDesc = "Creates a new world of the specified type"; + this.commandUsage = "/mvcreate" + ChatColor.GREEN + " {NAME} {ENV}" + ChatColor.GOLD + " -s [SEED] -g [GENERATOR[:ID]]"; + this.minimumArgLength = 2; + this.maximumArgLength = 6; + this.commandKeys.add("mvcreate"); this.permission = "multiverse.world.create"; - this.requiresOp = true; + this.opRequired = true; } @Override public void runCommand(CommandSender sender, List args) { - if (args.length % 2 != 0) { + if (args.size() % 2 != 0) { sender.sendMessage("You must preface your SEED with -s OR your GENERATOR with -g. Type /mv for help"); return; } - String worldName = args[0]; - String env = args[1]; - String seed = CommandManager.getFlag("-s", args); - String generator = CommandManager.getFlag("-g", args); + String worldName = args.get(0); + String env = args.get(1); + String seed = CommandHandler.getFlag("-s", args); + String generator = CommandHandler.getFlag("-g", args); - if (new File(worldName).exists() || this.plugin.isMVWorld(worldName)) { + if (new File(worldName).exists() || ((MultiverseCore) this.plugin).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"); return; } - Environment environment = this.plugin.getEnvFromString(env); + Environment environment = ((MultiverseCore) this.plugin).getEnvFromString(env); if (environment == null) { sender.sendMessage(ChatColor.RED + "That is not a valid environment."); EnvironmentCommand.showEnvironments(sender); return; } sender.sendMessage(ChatColor.AQUA + "Starting world creation..."); - if (this.plugin.addWorld(worldName, environment, seed, generator)) { + if (((MultiverseCore) this.plugin).addWorld(worldName, environment, seed, generator)) { sender.sendMessage(ChatColor.GREEN + "Complete!"); } else { sender.sendMessage(ChatColor.RED + "FAILED."); diff --git a/src/com/onarandombox/MultiverseCore/command/commands/DeleteCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/DeleteCommand.java index db0cfdfa..fbd81373 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/DeleteCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/DeleteCommand.java @@ -12,14 +12,14 @@ public class DeleteCommand extends Command { public DeleteCommand(MultiverseCore plugin) { super(plugin); - this.name = "Delete World"; - this.description = "Deletes a world on your server. " + ChatColor.RED + "PERMANENTLY."; - this.usage = "/mvdelete" + ChatColor.GREEN + " {WORLD} "; - this.minArgs = 1; - this.maxArgs = 1; - this.identifiers.add("mvdelete"); + this.commandName = "Delete World"; + this.commandDesc = "Deletes a world on your server. " + ChatColor.RED + "PERMANENTLY."; + this.commandUsage = "/mvdelete" + ChatColor.GREEN + " {WORLD} "; + this.minimumArgLength = 1; + this.maximumArgLength = 1; + this.commandKeys.add("mvdelete"); this.permission = "multiverse.world.delete"; - this.requiresOp = true; + this.opRequired = true; } @Override diff --git a/src/com/onarandombox/MultiverseCore/command/commands/EnvironmentCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/EnvironmentCommand.java index 1a33f9ea..c15110f0 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/EnvironmentCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/EnvironmentCommand.java @@ -1,29 +1,27 @@ package com.onarandombox.MultiverseCore.command.commands; +import java.util.List; + import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.command.BaseCommand; +import com.pneumaticraft.commandhandler.Command; -public class EnvironmentCommand extends BaseCommand { +public class EnvironmentCommand extends Command { public EnvironmentCommand(MultiverseCore plugin) { super(plugin); - this.name = "List Environments"; - this.description = "Lists valid known environments"; - this.usage = "/mvenv"; - this.minArgs = 0; - this.maxArgs = 0; - this.identifiers.add("mvenv"); + this.commandName = "List Environments"; + this.commandDesc = "Lists valid known environments"; + this.commandUsage = "/mvenv"; + this.minimumArgLength = 0; + this.maximumArgLength = 0; + this.commandKeys.add("mvenv"); this.permission = "multiverse.world.list.environments"; - this.requiresOp = false; + this.opRequired = false; } - @Override - public void execute(CommandSender sender, String[] args) { - EnvironmentCommand.showEnvironments(sender); - } public static void showEnvironments(CommandSender sender) { sender.sendMessage(ChatColor.YELLOW + "Valid Environments are:"); @@ -31,4 +29,9 @@ public class EnvironmentCommand extends BaseCommand { sender.sendMessage(ChatColor.RED + "NETHER"); sender.sendMessage(ChatColor.AQUA + "SKYLANDS"); } + + @Override + public void runCommand(CommandSender sender, List args) { + EnvironmentCommand.showEnvironments(sender); + } } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/HelpCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/HelpCommand.java index 048baf4a..0ddf507b 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/HelpCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/HelpCommand.java @@ -1,72 +1,24 @@ -/** - * Copyright (C) 2011 DThielke - * - * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License. - * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/3.0/ or send a letter to - * Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. - **/ -// Technically this is already a derivative work even by changing the package name. DThielke voiced it OK to modify, but we really should -// get this license changed... +// This file is no longer licensed under that silly CC license. I have blanked it out and will start implementaiton of my own in a few days. For now there is no help. package com.onarandombox.MultiverseCore.command.commands; import java.util.List; -import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; +import org.bukkit.plugin.java.JavaPlugin; -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.command.BaseCommand; +import com.pneumaticraft.commandhandler.Command; -public class HelpCommand extends BaseCommand { - private static final int CMDS_PER_PAGE = 8; +public class HelpCommand extends Command { - public HelpCommand(MultiverseCore plugin) { + public HelpCommand(JavaPlugin plugin) { super(plugin); - this.name = "Help"; - this.description = "Displays the help menu"; - this.usage = ChatColor.AQUA + "/mv help " + ChatColor.GOLD + "[page#]"; - this.minArgs = 0; - this.maxArgs = 1; - this.identifiers.add("mv"); - this.identifiers.add("mv help"); - this.permission = "multiverse.help"; - this.requiresOp = false; + // TODO Auto-generated constructor stub } @Override - public void execute(CommandSender sender, String[] args) { - int page = 0; - if (args.length != 0) { - try { - page = Integer.parseInt(args[0]) - 1; - } catch (NumberFormatException e) { - } - } - - // Get only the commands this player has access to - List commands = this.plugin.getCommandManager().getCommands(sender); - - int numPages = commands.size() / CMDS_PER_PAGE; - if (commands.size() % CMDS_PER_PAGE != 0) { - numPages++; - } - - if (page >= numPages || page < 0) { - page = 0; - } - sender.sendMessage(ChatColor.GREEN + "-----[ " + ChatColor.WHITE + this.plugin.getTag().replace("[", "").replace("]", "") + " Help <" + (page + 1) + "/" + numPages + ">" + ChatColor.GREEN + " ]-----"); - int start = page * CMDS_PER_PAGE; - int end = start + CMDS_PER_PAGE; - if (end > commands.size()) { - end = commands.size(); - } - for (int c = start; c < end; c++) { - BaseCommand cmd = commands.get(c); - - sender.sendMessage(ChatColor.AQUA + " " + cmd.getUsage()); - } - - sender.sendMessage(ChatColor.GREEN + "For more info on a particular command, type '/ ?'"); + public void runCommand(CommandSender sender, List args) { + // TODO Auto-generated method stub + } } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ImportCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ImportCommand.java index cb6516a3..c8b5000e 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ImportCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ImportCommand.java @@ -1,43 +1,44 @@ package com.onarandombox.MultiverseCore.command.commands; import java.io.File; +import java.util.List; import org.bukkit.ChatColor; import org.bukkit.World.Environment; import org.bukkit.command.CommandSender; import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.command.BaseCommand; +import com.pneumaticraft.commandhandler.Command; -public class ImportCommand extends BaseCommand { +public class ImportCommand extends Command { public ImportCommand(MultiverseCore plugin) { super(plugin); - this.name = "Import World"; - this.description = "Imports a new world of the specified type"; - this.usage = "/mvimport" + ChatColor.GREEN + " {NAME} {ENV} " + ChatColor.GOLD + "[GENERATOR[:ID]]"; - this.minArgs = 2; - this.maxArgs = 3; - this.identifiers.add("mvimport"); + this.commandName = "Import World"; + this.commandDesc = "Imports a new world of the specified type"; + this.commandUsage = "/mvimport" + ChatColor.GREEN + " {NAME} {ENV} " + ChatColor.GOLD + "[GENERATOR[:ID]]"; + this.minimumArgLength = 2; + this.maximumArgLength = 3; + this.commandKeys.add("mvimport"); this.permission = "multiverse.world.import"; - this.requiresOp = true; + this.opRequired = true; } @Override - public void execute(CommandSender sender, String[] args) { - String worldName = args[0]; - if (this.plugin.isMVWorld(worldName) && new File(worldName).exists()) { + public void runCommand(CommandSender sender, List args) { + String worldName = args.get(0); + if (((MultiverseCore) this.plugin).isMVWorld(worldName) && new File(worldName).exists()) { sender.sendMessage(ChatColor.RED + "Multiverse already knows about this world!"); return; } String generator = null; - if (args.length == 3) { - generator = args[2]; + if (args.size() == 3) { + generator = args.get(2); } - String env = args[1]; - Environment environment = this.plugin.getEnvFromString(env); + String env = args.get(1); + Environment environment = ((MultiverseCore) this.plugin).getEnvFromString(env); if (environment == null) { sender.sendMessage(ChatColor.RED + "That is not a valid environment."); EnvironmentCommand.showEnvironments(sender); @@ -46,7 +47,7 @@ public class ImportCommand extends BaseCommand { if (new File(worldName).exists() && env != null) { sender.sendMessage(ChatColor.AQUA + "Starting world import..."); - this.plugin.addWorld(worldName, environment, null, generator); + ((MultiverseCore) this.plugin).addWorld(worldName, environment, null, generator); sender.sendMessage(ChatColor.GREEN + "Complete!"); return; } else if (env == null) { diff --git a/src/com/onarandombox/MultiverseCore/command/commands/InfoCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/InfoCommand.java index 396b6fb6..336593b8 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/InfoCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/InfoCommand.java @@ -1,6 +1,7 @@ package com.onarandombox.MultiverseCore.command.commands; import java.util.ArrayList; +import java.util.List; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -8,36 +9,36 @@ import org.bukkit.entity.Player; import com.onarandombox.MultiverseCore.MVWorld; import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.command.BaseCommand; +import com.pneumaticraft.commandhandler.Command; -public class InfoCommand extends BaseCommand { +public class InfoCommand extends Command { public InfoCommand(MultiverseCore plugin) { super(plugin); - this.name = "World Information"; - this.description = "Returns detailed information on the world."; - this.usage = "/mvinfo" + ChatColor.GOLD + "[WORLD]" + ChatColor.DARK_PURPLE + ""; - this.minArgs = 0; - this.maxArgs = 2; - this.identifiers.add("mvinfo"); + this.commandName = "World Information"; + this.commandDesc = "Returns detailed information on the world."; + this.commandUsage = "/mvinfo" + ChatColor.GOLD + "[WORLD]" + ChatColor.DARK_PURPLE + ""; + this.minimumArgLength = 0; + this.maximumArgLength = 2; + this.commandKeys.add("mvinfo"); this.permission = "multiverse.world.info"; - this.requiresOp = false; + this.opRequired = false; } @Override - public void execute(CommandSender sender, String[] args) { + public void runCommand(CommandSender sender, List args) { // Check if the command was sent from a Player. String worldName = ""; - if (sender instanceof Player && args.length == 0) { + if (sender instanceof Player && args.size() == 0) { worldName = ((Player) sender).getWorld().getName(); - } else if (args.length == 0) { + } else if (args.size() == 0) { sender.sendMessage("You must enter a" + ChatColor.GOLD + " world" + ChatColor.WHITE + " from the console!"); return; } else { - worldName = args[0]; + worldName = args.get(0); } - if (this.plugin.isMVWorld(worldName)) { - for (String s : buildEntireCommand(this.plugin.getMVWorld(worldName))) { + if (((MultiverseCore) this.plugin).isMVWorld(worldName)) { + for (String s : buildEntireCommand(((MultiverseCore) this.plugin).getMVWorld(worldName))) { sender.sendMessage(s); } } @@ -103,4 +104,5 @@ public class InfoCommand extends BaseCommand { private ChatColor getChatColor(boolean positive) { return positive ? ChatColor.GREEN : ChatColor.RED; } + } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ListCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ListCommand.java index 96e9abc2..fce5b2ca 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ListCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ListCommand.java @@ -1,5 +1,7 @@ package com.onarandombox.MultiverseCore.command.commands; +import java.util.List; + import org.bukkit.ChatColor; import org.bukkit.World.Environment; import org.bukkit.command.CommandSender; @@ -7,33 +9,33 @@ import org.bukkit.entity.Player; import com.onarandombox.MultiverseCore.MVWorld; import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.command.BaseCommand; +import com.pneumaticraft.commandhandler.Command; -public class ListCommand extends BaseCommand { +public class ListCommand extends Command { public ListCommand(MultiverseCore plugin) { super(plugin); - this.name = "World Listing"; - this.description = "Displays a listing of all worlds that you can enter"; - this.usage = "/mvlist"; - this.minArgs = 0; - this.maxArgs = 0; - this.identifiers.add("mvlist"); + this.commandName = "World Listing"; + this.commandDesc = "Displays a listing of all worlds that you can enter"; + this.commandUsage = "/mvlist"; + this.minimumArgLength = 0; + this.maximumArgLength = 0; + this.commandKeys.add("mvlist"); this.permission = "multiverse.world.list"; - this.requiresOp = false; + this.opRequired = false; } @Override - public void execute(CommandSender sender, String[] args) { + public void runCommand(CommandSender sender, List args) { Player p = null; if (sender instanceof Player) { p = (Player) sender; } String output = ChatColor.LIGHT_PURPLE + "Worlds which you can view:\n"; - for (MVWorld world : this.plugin.getMVWorlds()) { + for (MVWorld world : ((MultiverseCore) this.plugin).getMVWorlds()) { - if (p != null && (!this.plugin.ph.canEnterWorld(p, world.getCBWorld()))) { + if (p != null && (!((MultiverseCore) this.plugin).ph.canEnterWorld(p, world.getCBWorld()))) { continue; } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ModifyAddCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ModifyAddCommand.java index 44eaa255..e3411973 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ModifyAddCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ModifyAddCommand.java @@ -1,54 +1,56 @@ package com.onarandombox.MultiverseCore.command.commands; +import java.util.List; + import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.onarandombox.MultiverseCore.MVWorld; import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.command.BaseCommand; +import com.pneumaticraft.commandhandler.Command; // This will contain all the properties that support the ADD/REMOVE // Anything not in here will only support the SET action -public class ModifyAddCommand extends BaseCommand { +public class ModifyAddCommand extends Command { public ModifyAddCommand(MultiverseCore plugin) { super(plugin); - this.name = "Modify a World (Add a value)"; - this.description = "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used"; - this.usage = "/mvmodify " + ChatColor.GREEN + "ADD {VALUE} {PROPERTY}" + ChatColor.GOLD + " [WORLD] "; - this.minArgs = 2; - this.maxArgs = 3; - this.identifiers.add("mvmodify add"); + this.commandName = "Modify a World (Add a value)"; + this.commandDesc = "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used"; + this.commandUsage = "/mvmodify " + ChatColor.GREEN + "ADD {VALUE} {PROPERTY}" + ChatColor.GOLD + " [WORLD] "; + this.minimumArgLength = 2; + this.maximumArgLength = 3; + this.commandKeys.add("mvmodify add"); this.permission = "multiverse.world.modify"; - this.requiresOp = true; + this.opRequired = true; } @Override - public void execute(CommandSender sender, String[] args) { + public void runCommand(CommandSender sender, List args) { // We NEED a world from the command line Player p = null; if (sender instanceof Player) { p = (Player) sender; } - if (args.length == 2 && p == null) { + if (args.size() == 2 && p == null) { sender.sendMessage(ChatColor.RED + "From the console, WORLD is required."); - sender.sendMessage(this.description); - sender.sendMessage(this.usage); + sender.sendMessage(this.commandDesc); + sender.sendMessage(this.commandUsage); sender.sendMessage("Nothing changed."); return; } MVWorld world; - String value = args[0]; - String property = args[1]; + String value = args.get(0); + String property = args.get(1); - if (args.length == 2) { - world = this.plugin.getMVWorld(p.getWorld().getName()); + if (args.size() == 2) { + world = ((MultiverseCore) this.plugin).getMVWorld(p.getWorld().getName()); } else { - world = this.plugin.getMVWorld(args[2]); + world = ((MultiverseCore) this.plugin).getMVWorld(args.get(2)); } if (world == null) { @@ -67,6 +69,5 @@ public class ModifyAddCommand extends BaseCommand { } else { sender.sendMessage(value + " could not be added to " + property); } - } } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ModifyClearCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ModifyClearCommand.java index 983a110e..57987a20 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ModifyClearCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ModifyClearCommand.java @@ -1,51 +1,53 @@ package com.onarandombox.MultiverseCore.command.commands; +import java.util.List; + import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.onarandombox.MultiverseCore.MVWorld; import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.command.BaseCommand; +import com.pneumaticraft.commandhandler.Command; -public class ModifyClearCommand extends BaseCommand { +public class ModifyClearCommand extends Command { public ModifyClearCommand(MultiverseCore plugin) { super(plugin); - this.name = "Modify a World (Clear a property)"; - this.description = "Removes all values from a property. This will work on properties that contain lists"; - this.usage = "/mvmodify" + ChatColor.GREEN + " CLEAR {PROPERTY}" + ChatColor.GOLD + " [WORLD] "; - this.minArgs = 1; - this.maxArgs = 2; - this.identifiers.add("mvmodify clear"); - this.identifiers.add("mvmclear"); - this.identifiers.add("mvmc"); + this.commandName = "Modify a World (Clear a property)"; + this.commandDesc = "Removes all values from a property. This will work on properties that contain lists"; + this.commandUsage = "/mvmodify" + ChatColor.GREEN + " CLEAR {PROPERTY}" + ChatColor.GOLD + " [WORLD] "; + this.minimumArgLength = 1; + this.maximumArgLength = 2; + this.commandKeys.add("mvmodify clear"); + this.commandKeys.add("mvmclear"); + this.commandKeys.add("mvmc"); this.permission = "multiverse.world.modify"; - this.requiresOp = true; + this.opRequired = true; } @Override - public void execute(CommandSender sender, String[] args) { + public void runCommand(CommandSender sender, List args) { // We NEED a world from the command line Player p = null; if (sender instanceof Player) { p = (Player) sender; } - if (args.length == 1 && p == null) { + if (args.size() == 1 && p == null) { sender.sendMessage(ChatColor.RED + "From the console, WORLD is required."); - sender.sendMessage(this.description); - sender.sendMessage(this.usage); + sender.sendMessage(this.commandDesc); + sender.sendMessage(this.commandUsage); sender.sendMessage("Nothing changed."); return; } MVWorld world; - String property = args[0]; + String property = args.get(0); - if (args.length == 1) { - world = this.plugin.getMVWorld(p.getWorld().getName()); + if (args.size() == 1) { + world = ((MultiverseCore) this.plugin).getMVWorld(p.getWorld().getName()); } else { - world = this.plugin.getMVWorld(args[1]); + world = ((MultiverseCore) this.plugin).getMVWorld(args.get(1)); } if (world == null) { diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ModifyCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ModifyCommand.java index 6c6ff649..78ebba22 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ModifyCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ModifyCommand.java @@ -1,10 +1,12 @@ package com.onarandombox.MultiverseCore.command.commands; +import java.util.List; + import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.command.BaseCommand; +import com.pneumaticraft.commandhandler.Command; enum AddProperties { animallist, monsterlist, blockblacklist, playerwhitelist, playerblacklist, editwhitelist, editblacklist, worldblacklist, animals, monsters @@ -18,28 +20,19 @@ enum SetProperties { alias, animals, monsters, pvp, scaling } -public class ModifyCommand extends BaseCommand { +public class ModifyCommand extends Command { public ModifyCommand(MultiverseCore plugin) { super(plugin); - this.name = "Modify a World"; - this.description = "MVModify requires an extra parameter: SET,ADD,REMOVE or CLEAR. See below for usage."; - this.usage = "/mvmodify" + ChatColor.GREEN + " {SET|ADD|REMOVE|CLEAR} ..."; + this.commandName = "Modify a World"; + this.commandDesc = "MVModify requires an extra parameter: SET,ADD,REMOVE or CLEAR. See below for usage."; + this.commandUsage = "/mvmodify" + ChatColor.GREEN + " {SET|ADD|REMOVE|CLEAR} ..."; // Make it so they can NEVER execute this one - this.minArgs = 1; - this.maxArgs = 0; - this.identifiers.add("mvmodify"); + this.minimumArgLength = 1; + this.maximumArgLength = 0; + this.commandKeys.add("mvmodify"); this.permission = "multiverse.world.modify"; - this.requiresOp = true; - } - - @Override - public void execute(CommandSender sender, String[] args) { - // This is just a place holder. The real commands are in: - // ModifyAddCommand - // ModifyRemoveCommand - // ModifySetCommand - // ModifyClearCommand + this.opRequired = true; } protected static boolean validateAction(Action action, String property) { @@ -60,4 +53,13 @@ public class ModifyCommand extends BaseCommand { } } + + @Override + public void runCommand(CommandSender sender, List args) { + // This is just a place holder. The real commands are in: + // ModifyAddCommand + // ModifyRemoveCommand + // ModifySetCommand + // ModifyClearCommand + } } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ModifyRemoveCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ModifyRemoveCommand.java index beb5fd41..3abe64fc 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ModifyRemoveCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ModifyRemoveCommand.java @@ -1,54 +1,56 @@ package com.onarandombox.MultiverseCore.command.commands; +import java.util.List; + import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.onarandombox.MultiverseCore.MVWorld; import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.command.BaseCommand; +import com.pneumaticraft.commandhandler.Command; -public class ModifyRemoveCommand extends BaseCommand { +public class ModifyRemoveCommand extends Command { public ModifyRemoveCommand(MultiverseCore plugin) { super(plugin); - this.name = "Modify a World"; - this.description = "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used"; - this.usage = "/mvmodify" + ChatColor.GREEN + "REMOVE {PROPERTY} {VALUE}" + ChatColor.GOLD + " [WORLD]"; - this.minArgs = 2; - this.maxArgs = 3; - this.identifiers.add("mvmodify remove"); - this.identifiers.add("mvmodify r"); - this.identifiers.add("mvmremove"); - this.identifiers.add("mvmr"); + this.commandName = "Modify a World"; + this.commandDesc = "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used"; + this.commandUsage = "/mvmodify" + ChatColor.GREEN + "REMOVE {PROPERTY} {VALUE}" + ChatColor.GOLD + " [WORLD]"; + this.minimumArgLength = 2; + this.maximumArgLength = 3; + this.commandKeys.add("mvmodify remove"); + this.commandKeys.add("mvmodify r"); + this.commandKeys.add("mvmremove"); + this.commandKeys.add("mvmr"); this.permission = "multiverse.world.modify"; - this.requiresOp = true; + this.opRequired = true; } @Override - public void execute(CommandSender sender, String[] args) { + public void runCommand(CommandSender sender, List args) { // We NEED a world from the command line Player p = null; if (sender instanceof Player) { p = (Player) sender; } - if (args.length == 2 && p == null) { + if (args.size() == 2 && p == null) { sender.sendMessage(ChatColor.RED + "From the console, WORLD is required."); - sender.sendMessage(this.description); - sender.sendMessage(this.usage); + sender.sendMessage(this.commandDesc); + sender.sendMessage(this.commandUsage); sender.sendMessage("Nothing changed."); return; } MVWorld world; - String value = args[0]; - String property = args[1]; + String value = args.get(0); + String property = args.get(1); - if (args.length == 2) { - world = this.plugin.getMVWorld(p.getWorld().getName()); + if (args.size() == 2) { + world = ((MultiverseCore) this.plugin).getMVWorld(p.getWorld().getName()); } else { - world = this.plugin.getMVWorld(args[2]); + world = ((MultiverseCore) this.plugin).getMVWorld(args.get(2)); } if (world == null) { diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ModifySetCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ModifySetCommand.java index eb365010..15688890 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ModifySetCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ModifySetCommand.java @@ -1,51 +1,53 @@ package com.onarandombox.MultiverseCore.command.commands; +import java.util.List; + import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.onarandombox.MultiverseCore.MVWorld; import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.command.BaseCommand; +import com.pneumaticraft.commandhandler.Command; -public class ModifySetCommand extends BaseCommand { +public class ModifySetCommand extends Command { public ModifySetCommand(MultiverseCore plugin) { super(plugin); - this.name = "Modify a World (Set a value)"; - this.description = "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used"; - this.usage = "/mvmodify" + ChatColor.GREEN + " SET {PROPERTY} {VALUE}" + ChatColor.GOLD + " [WORLD]"; - this.minArgs = 2; - this.maxArgs = 3; - this.identifiers.add("mvmodify set"); + this.commandName = "Modify a World (Set a value)"; + this.commandDesc = "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used"; + this.commandUsage = "/mvmodify" + ChatColor.GREEN + " SET {PROPERTY} {VALUE}" + ChatColor.GOLD + " [WORLD]"; + this.minimumArgLength = 2; + this.maximumArgLength = 3; + this.commandKeys.add("mvmodify set"); this.permission = "multiverse.world.modify"; - this.requiresOp = true; + this.opRequired = true; } @Override - public void execute(CommandSender sender, String[] args) { + public void runCommand(CommandSender sender, List args) { // We NEED a world from the command line Player p = null; if (sender instanceof Player) { p = (Player) sender; } - if (args.length == 2 && p == null) { + if (args.size() == 2 && p == null) { sender.sendMessage("From the command line, WORLD is required."); - sender.sendMessage(this.description); - sender.sendMessage(this.usage); + sender.sendMessage(this.commandDesc); + sender.sendMessage(this.commandUsage); sender.sendMessage("Nothing changed."); return; } MVWorld world; - String value = args[1]; - String property = args[0]; + String value = args.get(1); + String property = args.get(0); - if (args.length == 2) { - world = this.plugin.getMVWorld(p.getWorld().getName()); + if (args.size() == 2) { + world = ((MultiverseCore) this.plugin).getMVWorld(p.getWorld().getName()); } else { - world = this.plugin.getMVWorld(args[2]); + world = ((MultiverseCore) this.plugin).getMVWorld(args.get(2)); } if (world == null) { diff --git a/src/com/onarandombox/MultiverseCore/command/commands/PurgeCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/PurgeCommand.java index 5e43a250..e2e9e6e6 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/PurgeCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/PurgeCommand.java @@ -2,6 +2,7 @@ package com.onarandombox.MultiverseCore.command.commands; import java.util.ArrayList; import java.util.Collections; +import java.util.List; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -9,52 +10,52 @@ import org.bukkit.entity.Player; import com.onarandombox.MultiverseCore.MVWorld; import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.command.BaseCommand; import com.onarandombox.utils.PurgeWorlds; +import com.pneumaticraft.commandhandler.Command; -public class PurgeCommand extends BaseCommand { +public class PurgeCommand extends Command { 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.commandName = "Purge the world "; + this.commandDesc = "Removed the specified type of mob from the specified world."; + this.commandUsage = "/mvpurge" + ChatColor.GOLD + " [WORLD|all] " + ChatColor.GREEN + "{all|animals|monsters|MOBNAME}"; + this.minimumArgLength = 1; + this.maximumArgLength = 2; + this.commandKeys.add("mvpurge"); this.permission = "multiverse.world.purge"; - this.requiresOp = true; + this.opRequired = true; } @Override - public void execute(CommandSender sender, String[] args) { + public void runCommand(CommandSender sender, List args) { Player p = null; if (sender instanceof Player) { p = (Player) sender; } - if (args.length == 1 && p == null) { + if (args.size() == 1 && p == null) { sender.sendMessage("This command requires a WORLD when being run from the console!"); - sender.sendMessage(this.usage); + sender.sendMessage(this.commandUsage); return; } String worldName = null; String deathName = null; - if (args.length == 1) { + if (args.size() == 1) { worldName = p.getWorld().getName(); - deathName = args[0]; + deathName = args.get(0); } else { - worldName = args[0]; - deathName = args[1]; + worldName = args.get(0); + deathName = args.get(1); } - if (!this.plugin.isMVWorld(worldName)) { + if (!((MultiverseCore) this.plugin).isMVWorld(worldName)) { sender.sendMessage("Multiverse doesn't know about " + worldName); sender.sendMessage("... so It cannot be purged"); return; } - MVWorld world = this.plugin.getMVWorld(worldName); + MVWorld world = ((MultiverseCore) this.plugin).getMVWorld(worldName); - PurgeWorlds purger = this.plugin.getWorldPurger(); + PurgeWorlds purger = ((MultiverseCore) this.plugin).getWorldPurger(); ArrayList thingsToKill = new ArrayList(); if (deathName.equalsIgnoreCase("all") || deathName.equalsIgnoreCase("animals") || deathName.equalsIgnoreCase("monsters")) { thingsToKill.add(deathName.toUpperCase()); diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ReloadCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ReloadCommand.java index f913f831..6751bf5b 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ReloadCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ReloadCommand.java @@ -1,32 +1,33 @@ package com.onarandombox.MultiverseCore.command.commands; +import java.util.List; import java.util.logging.Level; import org.bukkit.command.CommandSender; import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.command.BaseCommand; +import com.pneumaticraft.commandhandler.Command; -public class ReloadCommand extends BaseCommand { +public class ReloadCommand extends Command { public ReloadCommand(MultiverseCore plugin) { super(plugin); - this.name = "Reload worlds.yml"; - this.description = "Reloads all worlds that are in worlds.yml. Use this if you've modified worlds.yml."; - this.usage = "/mvreload"; - this.minArgs = 0; - this.maxArgs = 0; - this.identifiers.add("mvreload"); + this.commandName = "Reload worlds.yml"; + this.commandDesc = "Reloads all worlds that are in worlds.yml. Use this if you've modified worlds.yml."; + this.commandUsage = "/mvreload"; + this.minimumArgLength = 0; + this.maximumArgLength = 0; + this.commandKeys.add("mvreload"); this.permission = "multiverse.world.reload"; - this.requiresOp = true; + this.opRequired = true; } @Override - public void execute(CommandSender sender, String[] args) { - this.plugin.log(Level.INFO, "Reloading Multiverse-Core config"); - this.plugin.loadConfigs(); - this.plugin.loadWorlds(true); - this.plugin.log(Level.INFO, "Reload Complete!"); + public void runCommand(CommandSender sender, List args) { + ((MultiverseCore) this.plugin).log(Level.INFO, "Reloading Multiverse-Core config"); + ((MultiverseCore) this.plugin).loadConfigs(); + ((MultiverseCore) this.plugin).loadWorlds(true); + ((MultiverseCore) this.plugin).log(Level.INFO, "Reload Complete!"); } } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/RemoveCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/RemoveCommand.java index 78c31de1..ed01924d 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/RemoveCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/RemoveCommand.java @@ -1,28 +1,30 @@ package com.onarandombox.MultiverseCore.command.commands; +import java.util.List; + import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.command.BaseCommand; +import com.pneumaticraft.commandhandler.Command; -public class RemoveCommand extends BaseCommand { +public class RemoveCommand extends Command { public RemoveCommand(MultiverseCore plugin) { super(plugin); - this.name = "Remove World"; - this.description = "Unloads a world from Multiverse and removes it from worlds.yml, this does NOT remove the world folder."; - this.usage = "/mvremove" + ChatColor.GREEN + " {WORLD} "; - this.minArgs = 1; - this.maxArgs = 1; - this.identifiers.add("mvremove"); + this.commandName = "Remove World"; + this.commandDesc = "Unloads a world from Multiverse and removes it from worlds.yml, this does NOT remove the world folder."; + this.commandUsage = "/mvremove" + ChatColor.GREEN + " {WORLD} "; + this.minimumArgLength = 1; + this.maximumArgLength = 1; + this.commandKeys.add("mvremove"); this.permission = "multiverse.world.remove"; - this.requiresOp = true; + this.opRequired = true; } @Override - public void execute(CommandSender sender, String[] args) { - if (this.plugin.removeWorld(args[0])) { + public void runCommand(CommandSender sender, List args) { + if (((MultiverseCore) this.plugin).removeWorld(args.get(0))) { sender.sendMessage("World removed from config!"); } else { sender.sendMessage("Error trying to remove world from config!"); diff --git a/src/com/onarandombox/MultiverseCore/command/commands/SetSpawnCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/SetSpawnCommand.java index 34294c76..c276581b 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/SetSpawnCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/SetSpawnCommand.java @@ -1,29 +1,31 @@ package com.onarandombox.MultiverseCore.command.commands; +import java.util.List; + import org.bukkit.Location; import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.command.BaseCommand; +import com.pneumaticraft.commandhandler.Command; -public class SetSpawnCommand extends BaseCommand { +public class SetSpawnCommand extends Command { public SetSpawnCommand(MultiverseCore plugin) { super(plugin); - this.name = "Set World Spawn"; - this.description = "Sets the spawn for the current world."; - this.usage = "/mvsetspawn"; - this.minArgs = 0; - this.maxArgs = 0; - this.identifiers.add("mvsetspawn"); + this.commandName = "Set World Spawn"; + this.commandDesc = "Sets the spawn for the current world."; + this.commandUsage = "/mvsetspawn"; + this.minimumArgLength = 0; + this.maximumArgLength = 0; + this.commandKeys.add("mvsetspawn"); this.permission = "multiverse.world.spawn.set"; - this.requiresOp = true; + this.opRequired = true; } @Override - public void execute(CommandSender sender, String[] args) { + public void runCommand(CommandSender sender, List args) { if (sender instanceof Player) { Player p = (Player) sender; Location l = p.getLocation(); @@ -31,8 +33,7 @@ public class SetSpawnCommand extends BaseCommand { w.setSpawnLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ()); p.sendMessage(w.getName() + " - Spawn set to X: " + l.getBlockX() + " Y: " + l.getBlockY() + " Z: " + l.getBlockZ()); } else { - sender.sendMessage(this.IN_GAME_COMMAND_MSG); + sender.sendMessage("You cannot use this command from the console."); } - return; } } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/SpawnCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/SpawnCommand.java index 57bdf798..4f60ebb4 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/SpawnCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/SpawnCommand.java @@ -1,39 +1,41 @@ package com.onarandombox.MultiverseCore.command.commands; +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.pneumaticraft.commandhandler.Command; -public class SpawnCommand extends BaseCommand { +public class SpawnCommand extends Command { public SpawnCommand(MultiverseCore plugin) { super(plugin); - this.name = "Spawn"; - this.description = "Transports the player to the that player's current world Spawn Point."; - this.usage = "/mvspawn" + ChatColor.GOLD + " [PLAYER]"; - this.minArgs = 0; - this.maxArgs = 1; - this.identifiers.add("mvspawn"); + this.commandName = "Spawn"; + this.commandDesc = "Transports the player to the that player's current world Spawn Point."; + this.commandUsage = "/mvspawn" + ChatColor.GOLD + " [PLAYER]"; + this.minimumArgLength = 0; + this.maximumArgLength = 1; + this.commandKeys.add("mvspawn"); this.permission = "multiverse.world.spawn.self"; - this.requiresOp = false; + this.opRequired = false; } @Override - public void execute(CommandSender sender, String[] args) { + public void runCommand(CommandSender sender, List args) { Player commandSender = null; if (sender instanceof Player) { commandSender = (Player) sender; } // If a persons name was passed in, you must be A. the console, or B have permissions - if (args.length == 1) { - if (commandSender != null && !this.plugin.ph.hasPermission(commandSender, "multiverse.world.spawn.other", true)) { + if (args.size() == 1) { + if (commandSender != null && !((MultiverseCore) this.plugin).getPermissions().hasPermission(commandSender, "multiverse.world.spawn.other", true)) { sender.sendMessage("You don't have permission to teleport another player to spawn."); return; } - Player target = this.plugin.getServer().getPlayer(args[0]); + Player target = this.plugin.getServer().getPlayer(args.get(0)); if (target != null) { target.sendMessage("Teleporting to this world's spawn..."); target.teleport(target.getWorld().getSpawnLocation()); @@ -43,7 +45,7 @@ public class SpawnCommand extends BaseCommand { target.sendMessage("You were teleported by: " + ChatColor.LIGHT_PURPLE + "the console"); } } else { - sender.sendMessage(args[0] + " is not logged on right now!"); + sender.sendMessage(args.get(0) + " is not logged on right now!"); } } else { if (commandSender != null) { diff --git a/src/com/onarandombox/MultiverseCore/command/commands/TeleportCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/TeleportCommand.java index 08beb526..004c5048 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/TeleportCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/TeleportCommand.java @@ -1,5 +1,7 @@ package com.onarandombox.MultiverseCore.command.commands; +import java.util.List; + import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.command.CommandSender; @@ -7,28 +9,28 @@ import org.bukkit.entity.Player; import com.onarandombox.MultiverseCore.MVTeleport; import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.command.BaseCommand; import com.onarandombox.utils.Destination; import com.onarandombox.utils.DestinationType; +import com.pneumaticraft.commandhandler.Command; -public class TeleportCommand extends BaseCommand { +public class TeleportCommand extends Command { private MVTeleport playerTeleporter; public TeleportCommand(MultiverseCore plugin) { super(plugin); - this.name = "Teleport"; - this.description = "Teleports you to a different world."; - this.usage = "/mvtp" + ChatColor.GOLD + "[PLAYER]" + ChatColor.GREEN + " {WORLD}"; - this.minArgs = 1; - this.maxArgs = 2; - this.identifiers.add("mvtp"); + this.commandName = "Teleport"; + this.commandDesc = "Teleports you to a different world."; + this.commandUsage = "/mvtp" + ChatColor.GOLD + "[PLAYER]" + ChatColor.GREEN + " {WORLD}"; + this.minimumArgLength = 1; + this.maximumArgLength = 2; + this.commandKeys.add("mvtp"); this.playerTeleporter = new MVTeleport(plugin); this.permission = "multiverse.world.tp.self"; - this.requiresOp = true; + this.opRequired = true; } @Override - public void execute(CommandSender sender, String[] args) { + public void runCommand(CommandSender sender, List args) { // Check if the command was sent from a Player. Player teleporter = null; Player teleportee = null; @@ -38,20 +40,20 @@ public class TeleportCommand extends BaseCommand { String worldName; - if (args.length == 2) { - if (teleporter != null && !this.plugin.ph.hasPermission(sender, "multiverse.world.tp.other", true)) { + if (args.size() == 2) { + if (teleporter != null && !((MultiverseCore) this.plugin).getPermissions().hasPermission(sender, "multiverse.world.tp.other", true)) { sender.sendMessage("You don't have permission to teleport another player."); return; } - teleportee = this.plugin.getServer().getPlayer(args[0]); + teleportee = this.plugin.getServer().getPlayer(args.get(0)); if (teleportee == null) { - sender.sendMessage("Sorry, I couldn't find player: " + args[0]); + sender.sendMessage("Sorry, I couldn't find player: " + args.get(0)); return; } - worldName = args[1]; + worldName = args.get(1); } else { - worldName = args[0]; + worldName = args.get(0); if (!(sender instanceof Player)) { sender.sendMessage("You can only teleport other players from the command line."); @@ -61,20 +63,20 @@ public class TeleportCommand extends BaseCommand { teleportee = (Player) sender; } - Destination d = Destination.parseDestination(worldName, this.plugin); + Destination d = Destination.parseDestination(worldName, (MultiverseCore) this.plugin); if (!(d.getType() == DestinationType.World)) { sender.sendMessage("Multiverse does not know about this world: " + worldName); return; } - if (teleporter != null && !this.plugin.ph.canEnterWorld(teleporter, this.plugin.getServer().getWorld(d.getName()))) { + if (teleporter != null && !((MultiverseCore) this.plugin).getPermissions().canEnterWorld(teleporter, this.plugin.getServer().getWorld(d.getName()))) { if (teleportee.equals(teleporter)) { teleporter.sendMessage("Doesn't look like you're allowed to go " + ChatColor.RED + "there..."); } else { teleporter.sendMessage("Doesn't look like you're allowed to send " + ChatColor.GOLD + teleportee.getName() + ChatColor.WHITE + " to " + ChatColor.RED + "there..."); } return; - } else if (teleporter != null && !this.plugin.ph.canTravelFromWorld(teleporter, this.plugin.getServer().getWorld(d.getName()))) { + } else if (teleporter != null && !((MultiverseCore) this.plugin).getPermissions().canTravelFromWorld(teleporter, this.plugin.getServer().getWorld(d.getName()))) { if (teleportee.equals(teleporter)) { teleporter.sendMessage("DOH! Doesn't look like you can get to " + ChatColor.RED + d.getName() + " from " + ChatColor.GREEN + teleporter.getWorld().getName()); } else { diff --git a/src/com/onarandombox/MultiverseCore/command/commands/UnloadCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/UnloadCommand.java index 0a26995c..7f84d274 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/UnloadCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/UnloadCommand.java @@ -1,28 +1,30 @@ package com.onarandombox.MultiverseCore.command.commands; +import java.util.List; + import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.command.BaseCommand; +import com.pneumaticraft.commandhandler.Command; -public class UnloadCommand extends BaseCommand { +public class UnloadCommand extends Command { public UnloadCommand(MultiverseCore plugin) { super(plugin); - this.name = "Unload World"; - this.description = "Unloads a world from Multiverse. This does NOT remove the world folder. This does NOT remove it from the config file."; - this.usage = "/mvunload" + ChatColor.GREEN + " {WORLD} "; - this.minArgs = 1; - this.maxArgs = 1; - this.identifiers.add("mvunload"); + this.commandName = "Unload World"; + this.commandDesc = "Unloads a world from Multiverse. This does NOT remove the world folder. This does NOT remove it from the config file."; + this.commandUsage = "/mvunload" + ChatColor.GREEN + " {WORLD} "; + this.minimumArgLength = 1; + this.maximumArgLength = 1; + this.commandKeys.add("mvunload"); this.permission = "multiverse.world.unload"; - this.requiresOp = true; + this.opRequired = true; } @Override - public void execute(CommandSender sender, String[] args) { - if (this.plugin.unloadWorld(args[0])) { + public void runCommand(CommandSender sender, List args) { + if (((MultiverseCore) this.plugin).unloadWorld(args.get(0))) { sender.sendMessage("World Unloaded!"); } else { sender.sendMessage("Error trying to unload world!"); diff --git a/src/com/onarandombox/MultiverseCore/command/commands/WhoCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/WhoCommand.java index 644ab74b..d7e65f74 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/WhoCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/WhoCommand.java @@ -11,24 +11,24 @@ import org.bukkit.entity.Player; import com.onarandombox.MultiverseCore.MVWorld; import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.command.BaseCommand; +import com.pneumaticraft.commandhandler.Command; -public class WhoCommand extends BaseCommand { +public class WhoCommand extends Command { public WhoCommand(MultiverseCore plugin) { super(plugin); - this.name = "Who"; - this.description = "States who is in what world"; - this.usage = "/mvwho" + ChatColor.GOLD + " [WORLD]"; - this.minArgs = 0; - this.maxArgs = 1; - this.identifiers.add("mvwho"); + this.commandName = "Who"; + this.commandDesc = "States who is in what world"; + this.commandUsage = "/mvwho" + ChatColor.GOLD + " [WORLD]"; + this.minimumArgLength = 0; + this.maximumArgLength = 1; + this.commandKeys.add("mvwho"); this.permission = "multiverse.world.list.who"; - this.requiresOp = false; + this.opRequired = false; } @Override - public void execute(CommandSender sender, String[] args) { + public void runCommand(CommandSender sender, List args) { // If this command was sent from a Player then we need to check Permissions Player p = null; if (sender instanceof Player) { @@ -37,24 +37,24 @@ public class WhoCommand extends BaseCommand { List worlds = new ArrayList(); - if (args.length > 0) { - if (this.plugin.isMVWorld(args[0])) { - worlds.add(this.plugin.getMVWorld(args[0])); + if (args.size() > 0) { + if (((MultiverseCore) this.plugin).isMVWorld(args.get(0))) { + worlds.add(((MultiverseCore) this.plugin).getMVWorld(args.get(0))); } else { sender.sendMessage(ChatColor.RED + "World does not exist"); return; } } else { - worlds = new ArrayList(this.plugin.getMVWorlds()); + worlds = new ArrayList(((MultiverseCore) this.plugin).getMVWorlds()); } for (MVWorld world : worlds) { - if (!(this.plugin.isMVWorld(world.getName()))) { + if (!(((MultiverseCore) this.plugin).isMVWorld(world.getName()))) { continue; } World w = this.plugin.getServer().getWorld(world.getName()); - if (p != null && (!this.plugin.ph.canEnterWorld(p, w))) { + if (p != null && (!((MultiverseCore) this.plugin).getPermissions().canEnterWorld(p, w))) { continue; } @@ -85,6 +85,5 @@ public class WhoCommand extends BaseCommand { sender.sendMessage(color + worldName + ChatColor.WHITE + " - " + result); } - return; } } From 5da92705bbdee36f737c42be9985ead42287daf0 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 9 Jul 2011 20:05:14 -0600 Subject: [PATCH 14/55] Increment commandhandler --- lib/commandhandler | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commandhandler b/lib/commandhandler index 030380b2..02e3771b 160000 --- a/lib/commandhandler +++ b/lib/commandhandler @@ -1 +1 @@ -Subproject commit 030380b2b201bd2dfe825d9a07fe9ac40cb8dece +Subproject commit 02e3771bbcbadb2d194b611a4685bb37e940378a From a8999ee5a1442277df9f225c7ac0d71d8c26b6cb Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 9 Jul 2011 20:10:43 -0600 Subject: [PATCH 15/55] Made MVPermissions implement PermissionsInterface, Increment CommandHandler --- lib/commandhandler | 2 +- src/com/onarandombox/MultiverseCore/MVPermissions.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/commandhandler b/lib/commandhandler index 02e3771b..90dc8bdc 160000 --- a/lib/commandhandler +++ b/lib/commandhandler @@ -1 +1 @@ -Subproject commit 02e3771bbcbadb2d194b611a4685bb37e940378a +Subproject commit 90dc8bdc92feefb63b41204c41b904c0aeea6bf9 diff --git a/src/com/onarandombox/MultiverseCore/MVPermissions.java b/src/com/onarandombox/MultiverseCore/MVPermissions.java index e1b2faf9..03401787 100644 --- a/src/com/onarandombox/MultiverseCore/MVPermissions.java +++ b/src/com/onarandombox/MultiverseCore/MVPermissions.java @@ -8,8 +8,9 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.nijiko.permissions.PermissionHandler; +import com.pneumaticraft.commandhandler.PermissionsInterface; -public class MVPermissions { +public class MVPermissions implements PermissionsInterface{ private MultiverseCore plugin; public PermissionHandler permissions = null; From 8adf06f247ddfc7c33eac340bc1692a0ac0a8f51 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 9 Jul 2011 20:21:22 -0600 Subject: [PATCH 16/55] Implement permissions --- .../MultiverseCore/MVPermissions.java | 79 ++++++++++--------- .../MultiverseCore/MultiverseCore.java | 2 +- 2 files changed, 41 insertions(+), 40 deletions(-) diff --git a/src/com/onarandombox/MultiverseCore/MVPermissions.java b/src/com/onarandombox/MultiverseCore/MVPermissions.java index 03401787..6749e5b0 100644 --- a/src/com/onarandombox/MultiverseCore/MVPermissions.java +++ b/src/com/onarandombox/MultiverseCore/MVPermissions.java @@ -10,11 +10,11 @@ import org.bukkit.entity.Player; import com.nijiko.permissions.PermissionHandler; import com.pneumaticraft.commandhandler.PermissionsInterface; -public class MVPermissions implements PermissionsInterface{ - +public class MVPermissions implements PermissionsInterface { + private MultiverseCore plugin; public PermissionHandler permissions = null; - + /** * Constructor FTW * @@ -23,12 +23,12 @@ public class MVPermissions implements PermissionsInterface{ public MVPermissions(MultiverseCore plugin) { this.plugin = plugin; // We have to see if permissions was loaded before MV was - if(this.plugin.getServer().getPluginManager().getPlugin("Permissions") != null) { - this.setPermissions(((com.nijikokun.bukkit.Permissions.Permissions)this.plugin.getServer().getPluginManager().getPlugin("Permissions")).getHandler()); + if (this.plugin.getServer().getPluginManager().getPlugin("Permissions") != null) { + this.setPermissions(((com.nijikokun.bukkit.Permissions.Permissions) this.plugin.getServer().getPluginManager().getPlugin("Permissions")).getHandler()); this.plugin.log(Level.INFO, "- Attached to Permissions"); } } - + /** * Use hasPermission() Now * @@ -39,38 +39,16 @@ public class MVPermissions implements PermissionsInterface{ @Deprecated public boolean has(Player p, String node) { boolean result = false; - + if (this.permissions != null) { result = this.permissions.has(p, node); } else if (p.isOp()) { result = true; } - + return result; } - - public boolean hasPermission(CommandSender sender, String node, boolean isOpRequired) { - - if (!(sender instanceof Player)) { - return true; - } - Player player = (Player) sender; - boolean opFallback = this.plugin.configMV.getBoolean("opfallback", true); - if (player.isOp() && opFallback) { - // If Player is Op we always let them use it if they have the fallback enabled! - return true; - } else if (this.permissions != null && this.permissions.has(player, node)) { - // If Permissions is enabled we check against them. - return true; - } - // If the Player doesn't have Permissions and isn't an Op then - // we return true if OP is not required, otherwise we return false - // This allows us to act as a default permission guidance - - // If they have the op fallback disabled, NO commands will work without a permissions plugin. - return !isOpRequired && opFallback; - } - + /** * Check if a Player can teleport to the Destination world from there current world. This checks against the Worlds Blacklist * @@ -80,23 +58,23 @@ public class MVPermissions implements PermissionsInterface{ */ public Boolean canTravelFromWorld(Player p, World w) { List blackList = this.plugin.getMVWorld(w.getName()).getWorldBlacklist(); - + boolean returnValue = true; - + if (blackList.size() == 0) { returnValue = true; } - + for (String s : blackList) { if (s.equalsIgnoreCase(p.getWorld().getName())) { returnValue = false; break; } } - + return returnValue; } - + /** * Check if the Player has the permissions to enter this world. * @@ -105,14 +83,14 @@ public class MVPermissions implements PermissionsInterface{ * @return */ public Boolean canEnterWorld(Player p, World w) { - + if (!this.plugin.isMVWorld(w.getName())) { return false; } List whiteList = this.plugin.getMVWorld(w.getName()).getPlayerWhitelist(); List blackList = this.plugin.getMVWorld(w.getName()).getPlayerBlacklist(); boolean returnValue = true; - + // I lied. You definitely want this. Sorry Rigby :( You were right. --FF // If there's anyone in the whitelist, then the whitelist is ACTIVE, anyone not in it is blacklisted. if (whiteList.size() > 0) { @@ -140,7 +118,7 @@ public class MVPermissions implements PermissionsInterface{ } return returnValue; } - + /** * Returns true if a player is in a group. * @@ -160,4 +138,27 @@ public class MVPermissions implements PermissionsInterface{ public void setPermissions(PermissionHandler handler) { this.permissions = handler; } + + public boolean hasPermission(CommandSender sender, String node, boolean isOpRequired) { + + if (!(sender instanceof Player)) { + return true; + } + Player player = (Player) sender; + boolean opFallback = this.plugin.configMV.getBoolean("opfallback", true); + if (player.isOp() && opFallback) { + // If Player is Op we always let them use it if they have the fallback enabled! + return true; + } else if (this.permissions != null && this.permissions.has(player, node)) { + // If Permissions is enabled we check against them. + return true; + } + // If the Player doesn't have Permissions and isn't an Op then + // we return true if OP is not required, otherwise we return false + // This allows us to act as a default permission guidance + + // If they have the op fallback disabled, NO commands will work without a permissions plugin. + return !isOpRequired && opFallback; + + } } diff --git a/src/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/com/onarandombox/MultiverseCore/MultiverseCore.java index ead54dd8..740adf02 100644 --- a/src/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -92,7 +92,7 @@ public class MultiverseCore extends JavaPlugin { this.bank = this.banker.loadEconPlugin(); // Setup the command manager - this.commandHandler = new CommandHandler(this); + this.commandHandler = new CommandHandler(this,this.ph); // Setup the world purger this.worldPurger = new PurgeWorlds(this); // Call the Function to assign all the Commands to their Class. From f9114996e2c3ad8a9dd4ab19ba7b892058036b42 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 9 Jul 2011 20:21:50 -0600 Subject: [PATCH 17/55] increment CH version --- lib/commandhandler | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commandhandler b/lib/commandhandler index 90dc8bdc..e9151828 160000 --- a/lib/commandhandler +++ b/lib/commandhandler @@ -1 +1 @@ -Subproject commit 90dc8bdc92feefb63b41204c41b904c0aeea6bf9 +Subproject commit e9151828c2720d800c6604b204b55a2bd1c6aae1 From 6be11c01ee1a339e9424a4806d359cad15b6ff04 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 9 Jul 2011 21:00:01 -0600 Subject: [PATCH 18/55] Remove deprecated method --- .../MultiverseCore/MVPermissions.java | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/src/com/onarandombox/MultiverseCore/MVPermissions.java b/src/com/onarandombox/MultiverseCore/MVPermissions.java index 6749e5b0..ef6e87eb 100644 --- a/src/com/onarandombox/MultiverseCore/MVPermissions.java +++ b/src/com/onarandombox/MultiverseCore/MVPermissions.java @@ -29,26 +29,6 @@ public class MVPermissions implements PermissionsInterface { } } - /** - * Use hasPermission() Now - * - * @param p The player instance. - * @param node The permission node we are checking against. - * @return - */ - @Deprecated - public boolean has(Player p, String node) { - boolean result = false; - - if (this.permissions != null) { - result = this.permissions.has(p, node); - } else if (p.isOp()) { - result = true; - } - - return result; - } - /** * Check if a Player can teleport to the Destination world from there current world. This checks against the Worlds Blacklist * From 1c3d3b08078962d120c75040341d7d9b33abe552 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 9 Jul 2011 21:50:25 -0600 Subject: [PATCH 19/55] Add a freshly baked BSD help command --- lib/commandhandler | 2 +- .../command/commands/HelpCommand.java | 43 +++++++++++++++++-- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/lib/commandhandler b/lib/commandhandler index e9151828..a7cbc0f0 160000 --- a/lib/commandhandler +++ b/lib/commandhandler @@ -1 +1 @@ -Subproject commit e9151828c2720d800c6604b204b55a2bd1c6aae1 +Subproject commit a7cbc0f047c8ef06216ea45e1966e0c0914f2658 diff --git a/src/com/onarandombox/MultiverseCore/command/commands/HelpCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/HelpCommand.java index 0ddf507b..0a0261d0 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/HelpCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/HelpCommand.java @@ -3,22 +3,59 @@ package com.onarandombox.MultiverseCore.command.commands; import java.util.List; +import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.plugin.java.JavaPlugin; +import com.onarandombox.MultiverseCore.MultiverseCore; import com.pneumaticraft.commandhandler.Command; public class HelpCommand extends Command { + private static final int CMDS_PER_PAGE = 10; public HelpCommand(JavaPlugin plugin) { super(plugin); - // TODO Auto-generated constructor stub + this.commandName = "Get Help with Multiverse"; + this.commandDesc = "Displays a nice help menu"; + this.commandUsage = "/mv " + ChatColor.GOLD + "[PAGE #]"; + this.minimumArgLength = 0; + this.maximumArgLength = 1; + this.commandKeys.add("mv"); + this.commandKeys.add("mvhelp"); + this.commandKeys.add("mv help"); + this.permission = "multiverse.help"; + this.opRequired = false; } @Override public void runCommand(CommandSender sender, List args) { - // TODO Auto-generated method stub - + int page = 1; + if (args.size() == 1) { + try { + page = Integer.parseInt(args.get(0)); + } catch (NumberFormatException e) { + } + } + + List availableCommands = ((MultiverseCore) this.plugin).getCommandHandler().getCommands(sender); + int totalPages = (int) Math.ceil(availableCommands.size() / ( CMDS_PER_PAGE + 0.0)); + + if (page > totalPages) { + page = totalPages; + } + + sender.sendMessage(ChatColor.AQUA + "====[ Multiverse Help ]===="); + sender.sendMessage(ChatColor.AQUA + " Page " + page + " of " + totalPages); + this.showPage(page, sender, availableCommands); + + } + + private void showPage(int page, CommandSender sender, List cmds) { + int start = (page - 1) * CMDS_PER_PAGE; + int end = start + CMDS_PER_PAGE; + for (int i = start; i < cmds.size() && i < end; i++) { + sender.sendMessage(ChatColor.AQUA + cmds.get(i).getCommandUsage()); + } } } From 54573889af050a1d01758d9049eccd3206a4e3eb Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 9 Jul 2011 22:00:07 -0600 Subject: [PATCH 20/55] Add 'fakepvp' config, currently untested... --- .../MultiverseCore/MVEntityListener.java | 57 +++++++++++++++++++ .../MultiverseCore/MultiverseCore.java | 2 +- src/defaults/config.yml | 6 +- 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/src/com/onarandombox/MultiverseCore/MVEntityListener.java b/src/com/onarandombox/MultiverseCore/MVEntityListener.java index 3ced3019..916040d2 100644 --- a/src/com/onarandombox/MultiverseCore/MVEntityListener.java +++ b/src/com/onarandombox/MultiverseCore/MVEntityListener.java @@ -2,14 +2,20 @@ package com.onarandombox.MultiverseCore; import java.util.List; +import org.bukkit.ChatColor; import org.bukkit.World; import org.bukkit.entity.Animals; import org.bukkit.entity.CreatureType; +import org.bukkit.entity.Entity; import org.bukkit.entity.Ghast; import org.bukkit.entity.Monster; +import org.bukkit.entity.Player; import org.bukkit.entity.Slime; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageByProjectileEvent; +import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityListener; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; @@ -23,6 +29,57 @@ public class MVEntityListener extends EntityListener { public MVEntityListener(MultiverseCore plugin) { this.plugin = plugin; } + + /** + * Event - When a Entity is Damaged, we first sort out whether it is of + * importance to us, such as EntityVSEntity or EntityVSProjectile. Then we + * grab the attacked and defender and check if its a player. Then deal with + * the PVP Aspect. + */ + @Override + public void onEntityDamage(EntityDamageEvent event) { + if (event.isCancelled()) { + return; + } + Entity attacker = null; + Entity defender = null; + if (event instanceof EntityDamageByEntityEvent) { + EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent) event; + attacker = sub.getDamager(); + defender = sub.getEntity(); + } else if (event instanceof EntityDamageByProjectileEvent) { + EntityDamageByProjectileEvent sub = (EntityDamageByProjectileEvent) event; + attacker = sub.getDamager(); + defender = sub.getEntity(); + } else { + return; + } + if (attacker == null || defender == null) { + return; + } + if (defender instanceof Player) { + Player player = (Player) defender; + World w = player.getWorld(); + + if(!this.plugin.isMVWorld(w.getName())) { + //if the world is not handled, we don't care + return; + } + MVWorld world = this.plugin.getMVWorld(w.getName()); + + if (attacker != null && attacker instanceof Player) { + Player pattacker = (Player) attacker; + + + + if (!world.getPvp() && this.plugin.configMV.getBoolean("fakepvp", false)) { + pattacker.sendMessage(ChatColor.RED + "PVP is disabled in this World."); + event.setCancelled(true); + return; + } + } + } + } @Override public void onEntityRegainHealth(EntityRegainHealthEvent event) { diff --git a/src/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/com/onarandombox/MultiverseCore/MultiverseCore.java index 740adf02..9424dd24 100644 --- a/src/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -121,7 +121,7 @@ public class MultiverseCore extends JavaPlugin { pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_REGAIN_HEALTH, this.entityListener, Priority.Normal, this); - pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Priority.Normal, this); // To Allow/Disallow PVP as well as EnableHealth. + pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Priority.Normal, this); // To Allow/Disallow fake PVP pm.registerEvent(Event.Type.CREATURE_SPAWN, this.entityListener, Priority.Normal, this); // To prevent all or certain animals/monsters from spawning. pm.registerEvent(Event.Type.PLUGIN_ENABLE, this.pluginListener, Priority.Monitor, this); diff --git a/src/defaults/config.yml b/src/defaults/config.yml index 9fde569a..13fee412 100644 --- a/src/defaults/config.yml +++ b/src/defaults/config.yml @@ -37,4 +37,8 @@ opfallback: true # If you have a world(s) that has monsters = false, and you want to disable the built # in autohealing, set this to true. This will have NO EFFECT if monsters = true for a given world. -disableautoheal: false \ No newline at end of file +disableautoheal: false + +# This will use the old style of PVP prevention so you can have zones of PVP +# Players will be notified when they punch/shoot and it's not allowed. +fakepvp: false \ No newline at end of file From b6d718a0bac45ec427445c3f2c75f13c3885c136 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 9 Jul 2011 22:15:36 -0600 Subject: [PATCH 21/55] Fix fakePVP --- src/com/onarandombox/MultiverseCore/MVWorld.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/com/onarandombox/MultiverseCore/MVWorld.java b/src/com/onarandombox/MultiverseCore/MVWorld.java index 1638135f..93a82cd1 100644 --- a/src/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/com/onarandombox/MultiverseCore/MVWorld.java @@ -78,13 +78,6 @@ public class MVWorld { private List blockBlacklist; // Contain a list of Blocks which we won't allow on this World. - // These have been moved to a hash, for easy editing with strings. - // private List playerWhitelist; // Contain a list of Players/Groups which can join this World. - // private List playerBlacklist; // Contain a list of Players/Groups which cannot join this World. - // private List editWhitelist; // Contain a list of Players/Groups which can edit this World. (Place/Destroy Blocks) - // private List editBlacklist; // Contain a list of Players/Groups which cannot edit this World. (Place/Destroy Blocks) - // private List worldBlacklist; // Contain a list of Worlds which Players cannot use to Portal to this World. - private HashMap> masterList; private Double scaling; // How stretched/compressed distances are @@ -274,6 +267,7 @@ public class MVWorld { } private void syncMobs() { + if (this.getAnimalList().isEmpty()) { this.world.setSpawnFlags(this.world.getAllowMonsters(), this.allowAnimals); } else { @@ -427,7 +421,12 @@ public class MVWorld { } public void setPvp(Boolean pvp) { - this.world.setPVP(pvp); + boolean fakepvp = this.plugin.configMV.getBoolean("fakepvp", false); + if(fakepvp) { + this.world.setPVP(false); + } else { + this.world.setPVP(pvp); + } this.pvp = pvp; this.config.setProperty("worlds." + this.name + ".pvp", pvp); this.config.save(); From c54a746c2f2ddeecdfeb95c1e578807d80145890 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sun, 10 Jul 2011 08:40:06 -0600 Subject: [PATCH 22/55] Minor Fixes to some commands --- src/com/onarandombox/MultiverseCore/MVPermissions.java | 4 ++-- .../MultiverseCore/command/commands/HelpCommand.java | 10 ++++++++-- .../MultiverseCore/command/commands/InfoCommand.java | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/com/onarandombox/MultiverseCore/MVPermissions.java b/src/com/onarandombox/MultiverseCore/MVPermissions.java index ef6e87eb..af080dba 100644 --- a/src/com/onarandombox/MultiverseCore/MVPermissions.java +++ b/src/com/onarandombox/MultiverseCore/MVPermissions.java @@ -8,6 +8,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.nijiko.permissions.PermissionHandler; +import com.nijikokun.bukkit.Permissions.Permissions; import com.pneumaticraft.commandhandler.PermissionsInterface; public class MVPermissions implements PermissionsInterface { @@ -24,7 +25,7 @@ public class MVPermissions implements PermissionsInterface { this.plugin = plugin; // We have to see if permissions was loaded before MV was if (this.plugin.getServer().getPluginManager().getPlugin("Permissions") != null) { - this.setPermissions(((com.nijikokun.bukkit.Permissions.Permissions) this.plugin.getServer().getPluginManager().getPlugin("Permissions")).getHandler()); + this.setPermissions(((Permissions) this.plugin.getServer().getPluginManager().getPlugin("Permissions")).getHandler()); this.plugin.log(Level.INFO, "- Attached to Permissions"); } } @@ -71,7 +72,6 @@ public class MVPermissions implements PermissionsInterface { List blackList = this.plugin.getMVWorld(w.getName()).getPlayerBlacklist(); boolean returnValue = true; - // I lied. You definitely want this. Sorry Rigby :( You were right. --FF // If there's anyone in the whitelist, then the whitelist is ACTIVE, anyone not in it is blacklisted. if (whiteList.size() > 0) { returnValue = false; diff --git a/src/com/onarandombox/MultiverseCore/command/commands/HelpCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/HelpCommand.java index 0a0261d0..8f29d197 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/HelpCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/HelpCommand.java @@ -5,13 +5,14 @@ import java.util.List; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import com.onarandombox.MultiverseCore.MultiverseCore; import com.pneumaticraft.commandhandler.Command; public class HelpCommand extends Command { - private static final int CMDS_PER_PAGE = 10; + private static final int CMDS_PER_PAGE = 8; public HelpCommand(JavaPlugin plugin) { super(plugin); @@ -53,8 +54,13 @@ public class HelpCommand extends Command { private void showPage(int page, CommandSender sender, List cmds) { int start = (page - 1) * CMDS_PER_PAGE; int end = start + CMDS_PER_PAGE; - for (int i = start; i < cmds.size() && i < end; i++) { + for (int i = start; i < end; i++) { + // For consistancy, print some extra lines if it's a player: + if (i < cmds.size()) { sender.sendMessage(ChatColor.AQUA + cmds.get(i).getCommandUsage()); + } else if(sender instanceof Player) { + sender.sendMessage(" "); + } } } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/InfoCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/InfoCommand.java index 336593b8..ae513e49 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/InfoCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/InfoCommand.java @@ -17,7 +17,7 @@ public class InfoCommand extends Command { super(plugin); this.commandName = "World Information"; this.commandDesc = "Returns detailed information on the world."; - this.commandUsage = "/mvinfo" + ChatColor.GOLD + "[WORLD]" + ChatColor.DARK_PURPLE + ""; + this.commandUsage = "/mvinfo" + ChatColor.GOLD + " [WORLD] " + ChatColor.DARK_PURPLE + " "; this.minimumArgLength = 0; this.maximumArgLength = 2; this.commandKeys.add("mvinfo"); From 8a0301f162b79663a274403264bfcf78837f0ca3 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sun, 10 Jul 2011 12:06:14 -0600 Subject: [PATCH 23/55] What's this? MV2 Supports multi-world bed respawns now? It sure does! --- .../MultiverseCore/MVPlayerListener.java | 65 ++++++++------- .../MultiverseCore/MVPlayerSession.java | 65 ++++++++++++--- .../MultiverseCore/MVTeleport.java | 55 ++++++++----- .../MultiverseCore/MultiverseCore.java | 9 ++- .../command/commands/SleepCommand.java | 48 +++++++++++ src/com/onarandombox/utils/BlockSafety.java | 80 ++++++++++++++----- src/defaults/config.yml | 6 +- 7 files changed, 243 insertions(+), 85 deletions(-) create mode 100644 src/com/onarandombox/MultiverseCore/command/commands/SleepCommand.java diff --git a/src/com/onarandombox/MultiverseCore/MVPlayerListener.java b/src/com/onarandombox/MultiverseCore/MVPlayerListener.java index d786ab46..2707609d 100644 --- a/src/com/onarandombox/MultiverseCore/MVPlayerListener.java +++ b/src/com/onarandombox/MultiverseCore/MVPlayerListener.java @@ -3,6 +3,8 @@ package com.onarandombox.MultiverseCore; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerBedEnterEvent; +import org.bukkit.event.player.PlayerBedLeaveEvent; import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerKickEvent; @@ -16,23 +18,12 @@ import com.onarandombox.MultiverseCore.event.MVRespawnEvent; public class MVPlayerListener extends PlayerListener { MultiverseCore plugin; - + MVTeleport mvteleporter; + public MVPlayerListener(MultiverseCore plugin) { this.plugin = plugin; } - - @Override - public void onPlayerTeleport(PlayerTeleportEvent event) { - MVPlayerSession ps = this.plugin.getPlayerSession(event.getPlayer()); - ps.setRespawnWorld(event.getTo().getWorld()); - } - - @Override - public void onPlayerKick(PlayerKickEvent event) { - // TODO Auto-generated method stub - super.onPlayerKick(event); - } - + @Override public void onPlayerMove(PlayerMoveEvent event) { Player p = event.getPlayer(); // Grab Player @@ -47,12 +38,20 @@ public class MVPlayerListener extends PlayerListener { ps.loc = loc; // Update the Players Session to the new Location. } } - + + @Override + public void onPlayerBedLeave(PlayerBedLeaveEvent event) { + Location bedLoc = event.getBed().getLocation(); + bedLoc = this.plugin.getTeleporter().getSafeBedDestination(bedLoc); + this.plugin.getPlayerSession(event.getPlayer()).setRespawnLocation(bedLoc); + event.getPlayer().sendMessage("You should come back here when you type '/mv sleep'!"); + } + @Override public void onPlayerChat(PlayerChatEvent event) { - // Not sure if this should be a seperat plugin... in here for now!!! + // Not sure if this should be a separate plugin... in here for now!!! // FernFerret - + if (event.isCancelled()) { return; } @@ -60,40 +59,46 @@ public class MVPlayerListener extends PlayerListener { * Check whether the Server is set to prefix the chat with the World name. If not we do nothing, if so we need to check if the World has an Alias. */ if (this.plugin.configMV.getBoolean("worldnameprefix", true)) { - + String world = event.getPlayer().getWorld().getName(); - + String prefix = ""; - + // If we're not a MV world, don't do anything if (!this.plugin.isMVWorld(world)) { return; } MVWorld mvworld = this.plugin.getMVWorld(world); prefix = mvworld.getColoredWorldString(); - + String format = event.getFormat(); - + event.setFormat("[" + prefix + "]" + format); } } - + @Override public void onPlayerRespawn(PlayerRespawnEvent event) { // TODO: Handle Global Respawn from config - + // TODO: Handle Alternate Respawn from config - + MVPlayerSession ps = this.plugin.getPlayerSession(event.getPlayer()); // Location newrespawn = ps.getRespawnWorld().getSpawnLocation(); Location newrespawn = event.getPlayer().getWorld().getSpawnLocation(); String respawnStyle = this.plugin.configMV.getString("notchrespawnstyle", "none"); String defaultWorld = this.plugin.configMV.getString("defaultspawnworld", "world"); + boolean bedRespawn = this.plugin.configMV.getBoolean("bedrespawn", true); + Location bedRespawnLoc = this.plugin.getPlayerSession(event.getPlayer()).getBedRespawnLocation(); - if (respawnStyle.equalsIgnoreCase("none")) { + + if (bedRespawn && bedRespawnLoc != null) { + Location correctedBedRespawn = new Location(bedRespawnLoc.getWorld(), bedRespawnLoc.getX(), bedRespawnLoc.getY() + 1, bedRespawnLoc.getZ()); + event.setRespawnLocation(correctedBedRespawn); + } else if (respawnStyle.equalsIgnoreCase("none")) { event.setRespawnLocation(newrespawn); } else if (respawnStyle.equalsIgnoreCase("default")) { - + if (this.plugin.isMVWorld(defaultWorld)) { event.setRespawnLocation(this.plugin.getServer().getWorld(defaultWorld).getSpawnLocation()); } else { @@ -105,7 +110,7 @@ public class MVPlayerListener extends PlayerListener { event.setRespawnLocation(mvevent.getPlayersRespawnLocation()); } } - + @Override public void onPlayerJoin(PlayerJoinEvent event) { if (this.plugin.getMVWorlds().size() == 0 && this.plugin.ph.hasPermission(event.getPlayer(), "multiverse.world.import", true)) { @@ -115,9 +120,9 @@ public class MVPlayerListener extends PlayerListener { event.getPlayer().sendMessage("If you just wanna see all of the Multiverse Help, type: " + ChatColor.GREEN + "/mv"); } } - + @Override public void onPlayerQuit(PlayerQuitEvent event) { - + } } diff --git a/src/com/onarandombox/MultiverseCore/MVPlayerSession.java b/src/com/onarandombox/MultiverseCore/MVPlayerSession.java index e33e7ec5..c27a257c 100644 --- a/src/com/onarandombox/MultiverseCore/MVPlayerSession.java +++ b/src/com/onarandombox/MultiverseCore/MVPlayerSession.java @@ -3,24 +3,32 @@ package com.onarandombox.MultiverseCore; import java.util.Date; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.util.config.Configuration; +import com.onarandombox.utils.BlockSafety; + public class MVPlayerSession { private Player player; // Player holder, may be unnecessary. - public Location loc = new Location(null, 0, 0, 0); // Contain the Players Location so on player move we can compare this and check if they've moved a block. - - public String portal = null; // Allow a player to target a portal to prevent them typing its name every command. - + protected Location loc = new Location(null, 0, 0, 0); // Contain the Players Location so on player move we can compare this and check if they've moved a block. + private BlockSafety bs = new BlockSafety(); + // Move to portals plugin + protected String portal = null; // Allow a player to target a portal to prevent them typing its name every command. + // Move to portals plugin public Location coord1 = null; // Coordinate 1 (Left Click) public Location coord2 = null; // Coordinate 2 (Right Click) private Long teleportLast = 0L; // Timestamp for the Players last Portal Teleportation. private Long messageLast = 0L; // Timestamp for the Players last Alert Message. - - private World currentSpawn; + + private Location bedSpawn; + + // Beds are 2 blocks, thus we need to store both places + private Location bedA; + private Location bedB; private Configuration config; // Configuration file to find out Cooldown Timers. @@ -28,7 +36,7 @@ public class MVPlayerSession { this.player = player; this.loc = player.getLocation(); this.config = config; - this.currentSpawn = player.getWorld(); + this.bedSpawn = null; } /** @@ -40,6 +48,7 @@ public class MVPlayerSession { /** * Grab whether the cooldown on Portal use has expired or not. + * * @return */ public boolean getTeleportable() { @@ -53,6 +62,7 @@ public class MVPlayerSession { /** * Send a Message to the Player as long as enough time has passed since the last message. + * * @param msg */ public void message(String msg) { @@ -63,11 +73,42 @@ public class MVPlayerSession { } } - public void setRespawnWorld(World world) { - this.currentSpawn = world; + public void setRespawnLocation(Location location) { + this.bedSpawn = location; } - - public World getRespawnWorld() { - return this.currentSpawn; + + // + // public Location getRespawnLocation() { + // if (this.bedSpawn != null && !this.bs.playerCanSpawnHereSafely(this.bedSpawn)) { + // this.bedSpawn = null; + // } + // return this.bedSpawn; + // } + + // This one simply spawns the player closer to the bed. + public Location getBedRespawnLocation() { + // There is a bedrespawn set + if (this.bedSpawn != null) { + if (!this.bs.playerCanSpawnHereSafely(this.bedSpawn) || !bedStillExists(this.bedSpawn)) { + this.bedSpawn = null; + return this.bedSpawn; + } + Location actualRespawn = this.bedSpawn; + Location bedRespawn = new Location(actualRespawn.getWorld(), actualRespawn.getX(), actualRespawn.getY(), actualRespawn.getZ()); + bedRespawn.setY(bedRespawn.getY() - .25); + return bedRespawn; + } + return null; + } + + private boolean bedStillExists(Location bedSpawn) { + System.out.print("Dangers:"); + this.bs.showDangers(bedSpawn); + Location locationDown = new Location(bedSpawn.getWorld(), bedSpawn.getX(), bedSpawn.getY(), bedSpawn.getZ()); + locationDown.setY(locationDown.getY() - 1); + if (locationDown.getBlock().getType() != Material.BED_BLOCK) { + return false; + } + return true; } } diff --git a/src/com/onarandombox/MultiverseCore/MVTeleport.java b/src/com/onarandombox/MultiverseCore/MVTeleport.java index 9b011661..e1f4857d 100644 --- a/src/com/onarandombox/MultiverseCore/MVTeleport.java +++ b/src/com/onarandombox/MultiverseCore/MVTeleport.java @@ -12,16 +12,16 @@ import org.bukkit.entity.Player; import com.onarandombox.utils.BlockSafety; public class MVTeleport { - + MultiverseCore plugin; - + BlockSafety bs = new BlockSafety(); private static final Logger log = Logger.getLogger("Minecraft"); - + public MVTeleport(MultiverseCore plugin) { this.plugin = plugin; } - + /** * TODO: Sort out JavaDoc * @@ -35,15 +35,15 @@ public class MVTeleport { if (l.getWorld().getName().equalsIgnoreCase(w.getName())) { return l; } - + double x, y, z; - + // Grab the Scaling value for each world. double srcComp = this.plugin.getMVWorld(l.getWorld().getName()).getScaling(); double trgComp = this.plugin.getMVWorld(w.getName()).getScaling(); - + // MultiverseCore.debugMsg(p.getName() + " -> " + p.getWorld().getName() + "(" + srcComp + ") -> " + w.getName() + "(" + trgComp + ")"); - + // If the Targets Compression is 0 then we teleport them to the Spawn of the World. if (trgComp == 0.0) { x = w.getSpawnLocation().getX(); @@ -56,7 +56,26 @@ public class MVTeleport { } return new Location(w, x, y, z); } - + + /** + * This method will be specific to beds, and check on top of the bed then around it. + * + * @return + */ + public Location getSafeBedDestination(Location bedLocation) { + System.out.print(bedLocation); + Location idealLocation = bedLocation; + idealLocation.setY(idealLocation.getY() + 1); + idealLocation.setX(idealLocation.getX() + .5); + idealLocation.setZ(idealLocation.getZ() + .5); + System.out.print(idealLocation); + if (this.bs.playerCanSpawnHereSafely(idealLocation)) { + System.out.print(idealLocation); + return bedLocation; + } + return null; + } + /** * This function gets a safe place to teleport to. * @@ -69,12 +88,12 @@ public class MVTeleport { double y = l.getY(); double z = l.getZ(); World w = l.getWorld(); - + // To make things easier we'll start with the Y Coordinate on top of a Solid Block. // while (bs.blockIsAboveAir(w, x, y, z)) { // y--; // } - + double i = 0, r = 0, aux = -1; for (r = 0; r < 32; r++) { for (i = x - r; i <= x + r; i++) { @@ -106,17 +125,17 @@ public class MVTeleport { break; } } - + if (aux == -1) { log.warning("Uh oh, no safe location."); return null; } - - //log.info("Target location (safe): " + x + ", " + aux + ", " + z); - + + // log.info("Target location (safe): " + x + ", " + aux + ", " + z); + return new Location(w, x, aux, z); } - + /** * Check the Column given to see if there is an available safe spot. * @@ -137,7 +156,7 @@ public class MVTeleport { } return -1; } - + /** * Find a portal around the given location and return a new location. * @@ -156,7 +175,7 @@ public class MVTeleport { } } } - + // For each column try to find a portal block for (Block col : columns) { for (int y = 0; y <= 127; y++) { diff --git a/src/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/com/onarandombox/MultiverseCore/MultiverseCore.java index 9424dd24..2443a9c1 100644 --- a/src/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -65,7 +65,7 @@ public class MultiverseCore extends JavaPlugin { private HashMap worlds = new HashMap(); // HashMap to contain information relating to the Players. - public HashMap playerSessions = new HashMap(); + private HashMap playerSessions; private PurgeWorlds worldPurger; public GenericBank bank = null; public AllPay banker = new AllPay(this, "[Multiverse-Core] ");; @@ -97,6 +97,8 @@ public class MultiverseCore extends JavaPlugin { this.worldPurger = new PurgeWorlds(this); // Call the Function to assign all the Commands to their Class. this.registerCommands(); + + this.playerSessions = new HashMap(); // Start the Update Checker // updateCheck = new UpdateChecker(this.getDescription().getName(), this.getDescription().getVersion()); @@ -119,6 +121,7 @@ public class MultiverseCore extends JavaPlugin { pm.registerEvent(Event.Type.PLAYER_KICK, this.playerListener, Priority.Highest, this); pm.registerEvent(Event.Type.PLAYER_RESPAWN, this.playerListener, Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Priority.Normal, this); + pm.registerEvent(Event.Type.PLAYER_BED_LEAVE, this.playerListener, Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_REGAIN_HEALTH, this.entityListener, Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Priority.Normal, this); // To Allow/Disallow fake PVP @@ -169,7 +172,7 @@ public class MultiverseCore extends JavaPlugin { */ private void registerCommands() { // Page 1 - this.commandHandler.registerCommand(new HelpCommand(this)); + this.commandHandler.registerCommand(new CoordCommand(this)); this.commandHandler.registerCommand(new TeleportCommand(this)); this.commandHandler.registerCommand(new ListCommand(this)); @@ -193,6 +196,8 @@ public class MultiverseCore extends JavaPlugin { this.commandHandler.registerCommand(new ModifyCommand(this)); this.commandHandler.registerCommand(new EnvironmentCommand(this)); this.commandHandler.registerCommand(new PurgeCommand(this)); + this.commandHandler.registerCommand(new SleepCommand(this)); + this.commandHandler.registerCommand(new HelpCommand(this)); } /** diff --git a/src/com/onarandombox/MultiverseCore/command/commands/SleepCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/SleepCommand.java new file mode 100644 index 00000000..d8f5f5b1 --- /dev/null +++ b/src/com/onarandombox/MultiverseCore/command/commands/SleepCommand.java @@ -0,0 +1,48 @@ +package com.onarandombox.MultiverseCore.command.commands; + +import java.util.List; + +import org.bukkit.ChatColor; +import org.bukkit.World.Environment; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.onarandombox.MultiverseCore.MVPlayerSession; +import com.onarandombox.MultiverseCore.MVWorld; +import com.onarandombox.MultiverseCore.MultiverseCore; +import com.pneumaticraft.commandhandler.Command; + +public class SleepCommand extends Command { + + public SleepCommand(MultiverseCore plugin) { + super(plugin); + this.commandName = "Go To Sleep"; + this.commandDesc = "Takes you the latest bed you've slept in."; + this.commandUsage = "/mv sleep"; + this.minimumArgLength = 0; + this.maximumArgLength = 0; + this.commandKeys.add("mv sleep"); + this.permission = "multiverse.sleep"; + this.opRequired = false; + } + + @Override + public void runCommand(CommandSender sender, List args) { + Player p = null; + if (sender instanceof Player) { + p = (Player) sender; + } + + if(p == null) { + return; + } + MVPlayerSession session = ((MultiverseCore) this.plugin).getPlayerSession(p); + if(session.getBedRespawnLocation() != null) { + p.teleport(session.getBedRespawnLocation()); + } else { + sender.sendMessage("Hmm this is awkward..."); + sender.sendMessage("Something is wrong with your bed."); + sender.sendMessage("It has either been destroyed or obstructed."); + } + } +} diff --git a/src/com/onarandombox/utils/BlockSafety.java b/src/com/onarandombox/utils/BlockSafety.java index 26c2e0a6..31f5730b 100644 --- a/src/com/onarandombox/utils/BlockSafety.java +++ b/src/com/onarandombox/utils/BlockSafety.java @@ -1,5 +1,6 @@ package com.onarandombox.utils; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -13,12 +14,19 @@ public class BlockSafety { * @param z * @return */ - public boolean blockIsAboveAir(World world, double x, double y, double z) { - return (world.getBlockAt((int) Math.floor(x), (int) Math.floor(y - 1), (int) Math.floor(z)).getType() == Material.AIR); + private boolean blockIsAboveAir(Location l) { + Location downOne = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()); + downOne.setY(downOne.getY() - 1); + return (downOne.getBlock().getType() == Material.AIR); } - + + public boolean blockIsNotSafe(World world, double x, double y, double z) { + Location l = new Location(world, x, y, z); + return !playerCanSpawnHereSafely(l); + } + /** - * This function checks whether the block at the coordinates given is safe or not by checking for Laval/Fire/Air etc. + * This function checks whether the block at the coordinates given is safe or not by checking for Laval/Fire/Air etc. This also ensures there is enough space for a player to spawn! * * @param world * @param x @@ -26,26 +34,54 @@ public class BlockSafety { * @param z * @return */ - public boolean blockIsNotSafe(World world, double x, double y, double z) { - if (world.getBlockAt((int) Math.floor(x), (int) Math.floor(y), (int) Math.floor(z)).getType() != Material.AIR || world.getBlockAt((int) Math.floor(x), (int) Math.floor(y + 1), (int) Math.floor(z)).getType() != Material.AIR) - return true; + public boolean playerCanSpawnHereSafely(Location l) { + Location actual = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()); + Location upOne = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()); + Location downOne = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()); + upOne.setY(upOne.getY() + 1); + downOne.setY(downOne.getY() - 1); - if ((world.getBlockAt((int) Math.floor(x), (int) Math.floor(y - 1), (int) Math.floor(z)).getType() == Material.LAVA)) - return true; + System.out.print("Location Up: " + upOne.getBlock().getType()); + System.out.print(" " + upOne); + System.out.print("Location: " + actual.getBlock().getType()); + System.out.print(" " + actual); + System.out.print("Location Down: " + downOne.getBlock().getType()); + System.out.print(" " + downOne); - if ((world.getBlockAt((int) Math.floor(x), (int) Math.floor(y - 1), (int) Math.floor(z)).getType() == Material.STATIONARY_LAVA)) - return true; - - if ((world.getBlockAt((int) Math.floor(x), (int) Math.floor(y - 1), (int) Math.floor(z)).getType() == Material.FIRE)) - return true; - - if ((world.getBlockAt((int) Math.floor(x), (int) Math.floor(y), (int) Math.floor(z)).getType() == Material.FIRE)) - return true; - - if (blockIsAboveAir(world, x, y, z)) - return true; - - return false; + if (actual.getBlock().getType() != Material.AIR || upOne.getBlock().getType() != Material.AIR) + return false; + + if (downOne.getBlock().getType() == Material.LAVA) + return false; + + if (downOne.getBlock().getType() == Material.STATIONARY_LAVA) + return false; + + if (downOne.getBlock().getType() == Material.FIRE) + return false; + + if (actual.getBlock().getType() == Material.FIRE) + return false; + + if (blockIsAboveAir(actual)) + return false; + + return true; } + public void showDangers(Location l) { + Location actual = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()); + Location upOne = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()); + Location downOne = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()); + upOne.setY(upOne.getY() + 1); + downOne.setY(downOne.getY() - 1); + + System.out.print("Location Up: " + upOne.getBlock().getType()); + System.out.print(" " + upOne); + System.out.print("Location: " + actual.getBlock().getType()); + System.out.print(" " + actual); + System.out.print("Location Down: " + downOne.getBlock().getType()); + System.out.print(" " + downOne); + } + } diff --git a/src/defaults/config.yml b/src/defaults/config.yml index 13fee412..f287465d 100644 --- a/src/defaults/config.yml +++ b/src/defaults/config.yml @@ -41,4 +41,8 @@ disableautoheal: false # This will use the old style of PVP prevention so you can have zones of PVP # Players will be notified when they punch/shoot and it's not allowed. -fakepvp: false \ No newline at end of file +fakepvp: false + +# When this is enabled, users will spawn at their last bed slept at. If the bed is destroyed or obstructed, +# they will spawn according to how you have 'notchrespawnstyle' set. +bedrespawn: true \ No newline at end of file From 0edd3f80e04d43dd204b7e175b27b20fd9131046 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sun, 10 Jul 2011 13:19:38 -0600 Subject: [PATCH 24/55] Oh silly booleans... --- .../onarandombox/MultiverseCore/MVWorld.java | 11 +++++++--- .../command/commands/InfoCommand.java | 22 ++++++++++--------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/com/onarandombox/MultiverseCore/MVWorld.java b/src/com/onarandombox/MultiverseCore/MVWorld.java index 93a82cd1..69899aee 100644 --- a/src/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/com/onarandombox/MultiverseCore/MVWorld.java @@ -75,6 +75,7 @@ public class MVWorld { // public List monsters = new ArrayList(); // Contain a list of Monsters which we want to ignore the Spawn Setting. private Boolean pvp; // Does this World allow PVP? + private Boolean fakepvp; private List blockBlacklist; // Contain a list of Blocks which we won't allow on this World. @@ -421,9 +422,9 @@ public class MVWorld { } public void setPvp(Boolean pvp) { - boolean fakepvp = this.plugin.configMV.getBoolean("fakepvp", false); - if(fakepvp) { - this.world.setPVP(false); + this.fakepvp = this.plugin.configMV.getBoolean("fakepvp", false); + if(this.fakepvp) { + this.world.setPVP(true); } else { this.world.setPVP(pvp); } @@ -497,4 +498,8 @@ public class MVWorld { } return false; } + + public boolean getFakePVP() { + return this.fakepvp; + } } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/InfoCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/InfoCommand.java index ae513e49..37123bdb 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/InfoCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/InfoCommand.java @@ -44,20 +44,22 @@ public class InfoCommand extends Command { } } - private String[] buildEntireCommand(MVWorld world) { - StringBuilder sb = new StringBuilder(); - ArrayList pagedInfo = new ArrayList(); - String[] aPage = new String[5]; + private List buildEntireCommand(MVWorld world) { + List page = new ArrayList(); // World Name: 1 - aPage[0] = "World: " + world.getName(); + page.add("World: " + world.getName()); // World Scale: 1 - aPage[1] = "World Scale: " + world.getScaling(); + page.add("World Scale: " + world.getScaling()); // PVP: 1 - aPage[2] = "PVP: " + world.getPvp(); - aPage[3] = "Animals: " + world.allowAnimalSpawning(); - aPage[4] = "Monsters: " + world.allowMonsterSpawning(); + page.add("PVP (MV): " + world.getPvp()); + page.add("PVP: " + world.getCBWorld().getPVP()); + page.add("Fake PVP: " + world.getFakePVP()); + page.add("Animals (MV): " + world.allowAnimalSpawning()); + page.add("Animals: " + world.getCBWorld().getAllowAnimals()); + page.add("Monsters (MV): " + world.allowMonsterSpawning()); + page.add("Monsters: " + world.getCBWorld().getAllowMonsters()); // This feature is not mission critical and I am spending too much time on it... // Stopping work on it for now --FF 20110623 @@ -98,7 +100,7 @@ public class InfoCommand extends Command { // } // } // } - return aPage; + return page; } private ChatColor getChatColor(boolean positive) { From d9cca0f822ab942493a0fd45401c726c71503bf8 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sun, 10 Jul 2011 13:42:13 -0600 Subject: [PATCH 25/55] Permissions is Silly Where Silly = Stupid --- .../MultiverseCore/MVPermissions.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/com/onarandombox/MultiverseCore/MVPermissions.java b/src/com/onarandombox/MultiverseCore/MVPermissions.java index af080dba..d3d94c5c 100644 --- a/src/com/onarandombox/MultiverseCore/MVPermissions.java +++ b/src/com/onarandombox/MultiverseCore/MVPermissions.java @@ -129,10 +129,19 @@ public class MVPermissions implements PermissionsInterface { if (player.isOp() && opFallback) { // If Player is Op we always let them use it if they have the fallback enabled! return true; - } else if (this.permissions != null && this.permissions.has(player, node)) { - // If Permissions is enabled we check against them. - return true; - } + //} else if (this.permissions != null && this.permissions.has(player, node)) { + } else + try { + if (this.permissions != null && this.permissions.safeGetUser(player.getWorld().getName(), player.getName()).hasPermission(node)) { + // If Permissions 3 is enabled we check against them. + return true; + } + } catch (Exception e) { + if (this.permissions != null && this.permissions.has(player, node)) { + // If Permissions 2 is enabled we check against them. + return true; + } + } // If the Player doesn't have Permissions and isn't an Op then // we return true if OP is not required, otherwise we return false // This allows us to act as a default permission guidance From 8e92496fb9178a189f8d53695d952a864978aa00 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sun, 10 Jul 2011 14:02:39 -0600 Subject: [PATCH 26/55] Revert "Permissions is Silly" This reverts commit d9cca0f822ab942493a0fd45401c726c71503bf8. --- .../MultiverseCore/MVPermissions.java | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/com/onarandombox/MultiverseCore/MVPermissions.java b/src/com/onarandombox/MultiverseCore/MVPermissions.java index d3d94c5c..af080dba 100644 --- a/src/com/onarandombox/MultiverseCore/MVPermissions.java +++ b/src/com/onarandombox/MultiverseCore/MVPermissions.java @@ -129,19 +129,10 @@ public class MVPermissions implements PermissionsInterface { if (player.isOp() && opFallback) { // If Player is Op we always let them use it if they have the fallback enabled! return true; - //} else if (this.permissions != null && this.permissions.has(player, node)) { - } else - try { - if (this.permissions != null && this.permissions.safeGetUser(player.getWorld().getName(), player.getName()).hasPermission(node)) { - // If Permissions 3 is enabled we check against them. - return true; - } - } catch (Exception e) { - if (this.permissions != null && this.permissions.has(player, node)) { - // If Permissions 2 is enabled we check against them. - return true; - } - } + } else if (this.permissions != null && this.permissions.has(player, node)) { + // If Permissions is enabled we check against them. + return true; + } // If the Player doesn't have Permissions and isn't an Op then // we return true if OP is not required, otherwise we return false // This allows us to act as a default permission guidance From 91802f0e551b7287303f60eb052b635f404cf758 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sun, 10 Jul 2011 14:23:44 -0600 Subject: [PATCH 27/55] Move the filtering of commands out of the Handler --- lib/commandhandler | 2 +- .../MultiverseCore/command/commands/HelpCommand.java | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/commandhandler b/lib/commandhandler index a7cbc0f0..b555fd75 160000 --- a/lib/commandhandler +++ b/lib/commandhandler @@ -1 +1 @@ -Subproject commit a7cbc0f047c8ef06216ea45e1966e0c0914f2658 +Subproject commit b555fd75d72ded08ae4f78e014ff3ed73759ac06 diff --git a/src/com/onarandombox/MultiverseCore/command/commands/HelpCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/HelpCommand.java index 8f29d197..fbd1e5e7 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/HelpCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/HelpCommand.java @@ -1,6 +1,7 @@ // This file is no longer licensed under that silly CC license. I have blanked it out and will start implementaiton of my own in a few days. For now there is no help. package com.onarandombox.MultiverseCore.command.commands; +import java.util.ArrayList; import java.util.List; import org.bukkit.ChatColor; @@ -38,7 +39,12 @@ public class HelpCommand extends Command { } } - List availableCommands = ((MultiverseCore) this.plugin).getCommandHandler().getCommands(sender); + List availableCommands = new ArrayList (((MultiverseCore) this.plugin).getCommandHandler().getAllCommands()); + for(Command c : availableCommands) { + if(!((MultiverseCore) this.plugin).getPermissions().hasPermission(sender, c.getPermission(), c.isOpRequired())) { + availableCommands.remove(c); + } + } int totalPages = (int) Math.ceil(availableCommands.size() / ( CMDS_PER_PAGE + 0.0)); if (page > totalPages) { From e059a565c7ed14913a70743190614884ccc3c5c4 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sun, 10 Jul 2011 15:32:35 -0600 Subject: [PATCH 28/55] Add more finely grained permissions for MVTP --- .../MultiverseCore/command/commands/TeleportCommand.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/com/onarandombox/MultiverseCore/command/commands/TeleportCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/TeleportCommand.java index 004c5048..afa7d979 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/TeleportCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/TeleportCommand.java @@ -25,7 +25,7 @@ public class TeleportCommand extends Command { this.maximumArgLength = 2; this.commandKeys.add("mvtp"); this.playerTeleporter = new MVTeleport(plugin); - this.permission = "multiverse.world.tp.self"; + this.permission = "multiverse.world.tp"; this.opRequired = true; } @@ -42,7 +42,7 @@ public class TeleportCommand extends Command { if (args.size() == 2) { if (teleporter != null && !((MultiverseCore) this.plugin).getPermissions().hasPermission(sender, "multiverse.world.tp.other", true)) { - sender.sendMessage("You don't have permission to teleport another player."); + sender.sendMessage("You don't have permission to teleport another player. (multiverse.world.tp.other)"); return; } teleportee = this.plugin.getServer().getPlayer(args.get(0)); @@ -54,6 +54,10 @@ public class TeleportCommand extends Command { } else { worldName = args.get(0); + if (teleporter != null && !((MultiverseCore) this.plugin).getPermissions().hasPermission(sender, "multiverse.world.tp.self", true)) { + sender.sendMessage("You don't have permission to teleport yourself between worlds. (multiverse.world.tp.self)"); + return; + } if (!(sender instanceof Player)) { sender.sendMessage("You can only teleport other players from the command line."); From 77a25ad8e682ea4788237f2e2692eb71ce86cd2e Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sun, 10 Jul 2011 16:08:24 -0600 Subject: [PATCH 29/55] Added a bunch more short commands --- .../MultiverseCore/MultiverseCore.java | 21 ++++----- .../command/commands/InfoCommand.java | 4 +- src/plugin.yml | 45 +++++++++++++++++++ 3 files changed, 59 insertions(+), 11 deletions(-) diff --git a/src/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/com/onarandombox/MultiverseCore/MultiverseCore.java index 2443a9c1..fd6ac9e6 100644 --- a/src/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -171,31 +171,32 @@ public class MultiverseCore extends JavaPlugin { * Register Multiverse-Core commands to Command Manager. */ private void registerCommands() { - // Page 1 - - this.commandHandler.registerCommand(new CoordCommand(this)); - this.commandHandler.registerCommand(new TeleportCommand(this)); + // Intro Commands this.commandHandler.registerCommand(new ListCommand(this)); - this.commandHandler.registerCommand(new WhoCommand(this)); - this.commandHandler.registerCommand(new SetSpawnCommand(this)); + this.commandHandler.registerCommand(new InfoCommand(this)); this.commandHandler.registerCommand(new CreateCommand(this)); this.commandHandler.registerCommand(new ImportCommand(this)); + this.commandHandler.registerCommand(new ReloadCommand(this)); + this.commandHandler.registerCommand(new SetSpawnCommand(this)); + this.commandHandler.registerCommand(new CoordCommand(this)); + this.commandHandler.registerCommand(new TeleportCommand(this)); + this.commandHandler.registerCommand(new WhoCommand(this)); this.commandHandler.registerCommand(new SpawnCommand(this)); + // Dangerous Commands this.commandHandler.registerCommand(new RemoveCommand(this)); this.commandHandler.registerCommand(new DeleteCommand(this)); this.commandHandler.registerCommand(new UnloadCommand(this)); this.commandHandler.registerCommand(new ConfirmCommand(this)); - this.commandHandler.registerCommand(new InfoCommand(this)); - this.commandHandler.registerCommand(new ReloadCommand(this)); - + // Modification commands + this.commandHandler.registerCommand(new PurgeCommand(this)); this.commandHandler.registerCommand(new ModifyAddCommand(this)); this.commandHandler.registerCommand(new ModifySetCommand(this)); this.commandHandler.registerCommand(new ModifyRemoveCommand(this)); this.commandHandler.registerCommand(new ModifyClearCommand(this)); // This modify MUST go last. this.commandHandler.registerCommand(new ModifyCommand(this)); + // Misc Commands this.commandHandler.registerCommand(new EnvironmentCommand(this)); - this.commandHandler.registerCommand(new PurgeCommand(this)); this.commandHandler.registerCommand(new SleepCommand(this)); this.commandHandler.registerCommand(new HelpCommand(this)); } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/InfoCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/InfoCommand.java index 37123bdb..0ee7a442 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/InfoCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/InfoCommand.java @@ -17,10 +17,12 @@ public class InfoCommand extends Command { super(plugin); this.commandName = "World Information"; this.commandDesc = "Returns detailed information on the world."; - this.commandUsage = "/mvinfo" + ChatColor.GOLD + " [WORLD] " + ChatColor.DARK_PURPLE + " "; + this.commandUsage = "/mvinfo" + ChatColor.GOLD + " [WORLD] "; this.minimumArgLength = 0; this.maximumArgLength = 2; this.commandKeys.add("mvinfo"); + this.commandKeys.add("mv info"); + this.commandKeys.add("mvi"); this.permission = "multiverse.world.info"; this.opRequired = false; } diff --git a/src/plugin.yml b/src/plugin.yml index 002957fc..c9a4562a 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -12,12 +12,24 @@ commands: / / creative normal -- Creates a world called 'creative' with a NORMAL environment. / hellworld nether -- Creates a world called 'hellworld' with a NETHER environment. + mvc: + description: World create command + usage: | + / + / creative normal -- Creates a world called 'creative' with a NORMAL environment. + / hellworld nether -- Creates a world called 'hellworld' with a NETHER environment. mvimport: description: World import command usage: | / / creative normal -- Imports an existing world called 'creative' with a NORMAL environment. / hellworld nether -- Imports an existing world called 'hellworld' with a NETHER environment. + mvim: + description: World import command + usage: | + / + / creative normal -- Imports an existing world called 'creative' with a NORMAL environment. + / hellworld nether -- Imports an existing world called 'hellworld' with a NETHER environment. mvremove: description: World remove command usage: | @@ -35,6 +47,11 @@ commands: usage: | /