mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-01-23 16:51:28 +01:00
Supports CommandManager level string combining
Now when someone enters a command surrounded in quotes, it gets combined and passed as an arg with spaces! Woot.
This commit is contained in:
parent
a5a3618439
commit
80fd19c0f8
@ -18,12 +18,14 @@ import org.bukkit.command.CommandSender;
|
||||
public class CommandManager {
|
||||
|
||||
protected List<BaseCommand> commands;
|
||||
private CommandSender sender;
|
||||
|
||||
public CommandManager() {
|
||||
commands = new ArrayList<BaseCommand>();
|
||||
}
|
||||
|
||||
public boolean dispatch(CommandSender sender, Command command, String label, String[] args) {
|
||||
this.sender = sender;
|
||||
String input = label + " ";
|
||||
for (String s : args) {
|
||||
input += s + " ";
|
||||
@ -36,6 +38,8 @@ public class CommandManager {
|
||||
for (BaseCommand cmd : commands) {
|
||||
StringBuilder tmpIdentifier = new StringBuilder();
|
||||
String[] tmpArgs = cmd.validate(input, tmpIdentifier);
|
||||
// If temp args is not null, then we'll parse the quoted strings out of it
|
||||
tmpArgs = tmpArgs == null ? null : parseAllQuotedStrings(tmpArgs);
|
||||
if (tmpIdentifier.length() > identifier.length()) {
|
||||
identifier = tmpIdentifier;
|
||||
match = cmd;
|
||||
@ -67,10 +71,49 @@ public class CommandManager {
|
||||
public List<BaseCommand> getCommands() {
|
||||
return commands;
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines all quoted strings
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
private String[] parseAllQuotedStrings(String[] args) {
|
||||
String[] returnVal = {};
|
||||
return returnVal;
|
||||
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) {
|
||||
newArgs.add(parseQuotedString(args, start, args.length));
|
||||
}
|
||||
String[] results = newArgs.toArray(new String[newArgs.size()]);
|
||||
String msg = "Here's what I have boss: [";
|
||||
if (results != null) {
|
||||
for (String s : results) {
|
||||
msg += s + ", ";
|
||||
}
|
||||
msg += "]";
|
||||
this.sender.sendMessage(msg);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user