mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-16 20:41:59 +01:00
Fixed Spacing, fixed Modify commands
This commit is contained in:
parent
fc9aa456da
commit
2985167936
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,5 +25,4 @@ public class DeleteCommand extends BaseCommand {
|
||||
Class<?> paramTypes[] = { String.class };
|
||||
this.plugin.getCommandManager().queueCommand(sender, "mvdelete", "deleteWorld", args, paramTypes, "World Deleted!", "World was not deleted!");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,5 +31,4 @@ public class EnvironmentCommand extends BaseCommand{
|
||||
sender.sendMessage(ChatColor.RED + "NETHER");
|
||||
sender.sendMessage(ChatColor.AQUA + "SKYLANDS");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -58,5 +58,4 @@ public class ImportCommand extends BaseCommand {
|
||||
sender.sendMessage("That world folder does not exist...");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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.");
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -15,10 +15,12 @@ public class ModifyRemoveCommand extends BaseCommand {
|
||||
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.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) {
|
||||
|
@ -15,8 +15,8 @@ public class ModifySetCommand extends BaseCommand {
|
||||
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.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) {
|
||||
|
@ -35,5 +35,4 @@ public class SetSpawnCommand extends BaseCommand {
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -85,5 +85,4 @@ public class TeleportCommand extends BaseCommand {
|
||||
Location l = this.playerTeleporter.getSafeDestination(this.plugin.getServer().getWorld(d.getName()).getSpawnLocation());
|
||||
teleportee.teleport(l);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,5 +28,4 @@ public class UnloadCommand extends BaseCommand {
|
||||
sender.sendMessage("Error trying to unload world!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -87,5 +87,4 @@ public class WhoCommand extends BaseCommand {
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user