Fixed Spacing, fixed Modify commands

This commit is contained in:
Eric Stokes 2011-07-09 08:33:18 -06:00
parent fc9aa456da
commit 2985167936
24 changed files with 147 additions and 332 deletions

View File

@ -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<String> allArgs = new ArrayList<String>(Arrays.asList(args));
allArgs.add(0, command.getName());
return this.commandManager.dispatch(sender, allArgs);
// return this.commandManager.dispatch(sender, command, commandLabel, args);
}
/**

View File

@ -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<String> 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<String> 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<String> newArgs = new ArrayList<String>();
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<String> args) {
String returnString = "";
for (String s : args) {

View File

@ -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<String> newArgs = new ArrayList<String>();
// 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
*

View File

@ -22,7 +22,6 @@ public class CreateCommand extends BaseCommand {
this.identifiers.add("mvcreate");
this.permission = "multiverse.world.create";
this.requiresOp = true;
}
@Override
@ -56,5 +55,4 @@ public class CreateCommand extends BaseCommand {
}
return;
}
}

View File

@ -22,8 +22,7 @@ public class DeleteCommand extends BaseCommand {
@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!");
}
}

View File

@ -6,7 +6,7 @@ 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);
@ -31,5 +31,4 @@ public class EnvironmentCommand extends BaseCommand{
sender.sendMessage(ChatColor.RED + "NETHER");
sender.sendMessage(ChatColor.AQUA + "SKYLANDS");
}
}

View File

@ -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;

View File

@ -32,13 +32,13 @@ public class ImportCommand extends BaseCommand {
}
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;
@ -49,7 +49,7 @@ public class ImportCommand extends BaseCommand {
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...");
}
}
}

View File

@ -47,7 +47,7 @@ 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";

View File

@ -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.");

View File

@ -15,9 +15,11 @@ public class ModifyClearCommand extends BaseCommand {
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;
}
@ -26,11 +28,11 @@ public class ModifyClearCommand extends BaseCommand {
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.");
@ -38,12 +40,12 @@ public class ModifyClearCommand extends BaseCommand {
}
MVWorld world;
String property = args[1];
String property = args[0];
if (args.length == 2) {
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) {

View File

@ -25,7 +25,8 @@ public class ModifyCommand extends BaseCommand {
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";
@ -34,9 +35,6 @@ public class ModifyCommand extends BaseCommand {
@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

View File

@ -14,11 +14,13 @@ public class ModifyRemoveCommand extends BaseCommand {
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;
}
@ -27,12 +29,12 @@ public class ModifyRemoveCommand extends BaseCommand {
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.");
@ -40,13 +42,13 @@ public class ModifyRemoveCommand extends BaseCommand {
}
MVWorld world;
String value = args[1];
String property = args[2];
String value = args[0];
String property = args[1];
if (args.length == 3) {
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) {

View File

@ -14,9 +14,9 @@ public class ModifySetCommand extends BaseCommand {
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;
@ -26,11 +26,11 @@ public class ModifySetCommand extends BaseCommand {
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);
@ -40,12 +40,12 @@ public class ModifySetCommand extends BaseCommand {
MVWorld world;
String value = args[1];
String property = args[2];
String property = args[0];
if (args.length == 3) {
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) {

View File

@ -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,7 +39,7 @@ 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 {
@ -47,7 +47,7 @@ public class PurgeCommand extends BaseCommand {
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;
@ -56,7 +56,7 @@ public class PurgeCommand extends BaseCommand {
PurgeWorlds purger = this.plugin.getWorldPurger();
ArrayList<String> thingsToKill = new ArrayList<String>();
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(","));

View File

@ -35,5 +35,4 @@ public class SetSpawnCommand extends BaseCommand {
}
return;
}
}

View File

@ -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;
}

View File

@ -85,5 +85,4 @@ public class TeleportCommand extends BaseCommand {
Location l = this.playerTeleporter.getSafeDestination(this.plugin.getServer().getWorld(d.getName()).getSpawnLocation());
teleportee.teleport(l);
}
}

View File

@ -28,5 +28,4 @@ public class UnloadCommand extends BaseCommand {
sender.sendMessage("Error trying to unload world!");
}
}
}

View File

@ -78,7 +78,7 @@ 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();
}
@ -87,5 +87,4 @@ public class WhoCommand extends BaseCommand {
}
return;
}
}