make commands direct
This commit is contained in:
parent
bd516d0d88
commit
4849bc9276
3 changed files with 46 additions and 63 deletions
|
@ -186,7 +186,7 @@ public class Proxy {
|
|||
Proxy.this.schedule(new Runnable() {
|
||||
public void run() {
|
||||
String msg = Formatter.filterSpaces(cmd);
|
||||
Proxy.this.runCommand(null, msg.isEmpty() ? new String[0] : msg.split(" ", -1), msg);
|
||||
Proxy.this.runCommand(null, msg.isEmpty() ? new String[] {"phelp"} : msg.split(" "), msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -464,16 +464,18 @@ public class Proxy {
|
|||
this.running = false;
|
||||
}
|
||||
|
||||
public void runCommand(ProxyHandler player, String[] args, String line) {
|
||||
public boolean runCommand(ProxyHandler player, String[] args, String line) {
|
||||
if(args.length == 0)
|
||||
args = new String[] {"help"};
|
||||
Command cmd = this.commands.get(args[0].toLowerCase());
|
||||
return false;
|
||||
Command cmd = this.commands.get(args[0].toLowerCase(Locale.US));
|
||||
if(cmd == null) {
|
||||
if(player != null)
|
||||
player.sendMessage(Formatter.DARK_RED + "Proxy command '%s' not found", args[0]);
|
||||
else
|
||||
if(player == null)
|
||||
Log.error("Command '%s' not found", args[0]);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if(player != null && !player.isAdmin()) {
|
||||
player.sendMessage(Formatter.DARK_RED + "You are not allowed to execute this command");
|
||||
return true;
|
||||
}
|
||||
String[] argv = new String[args.length - 1];
|
||||
System.arraycopy(args, 1, argv, 0, argv.length);
|
||||
|
@ -494,7 +496,7 @@ public class Proxy {
|
|||
if(player != null) {
|
||||
int redacted = cmd.getRedactedLogArg(argv.length);
|
||||
if(redacted >= 0 && redacted < argv.length) {
|
||||
StringBuilder sb = new StringBuilder("/vproxy " + cmd.getName());
|
||||
StringBuilder sb = new StringBuilder(cmd.getName());
|
||||
for(int z = 0; z < argv.length && z < redacted; z++) {
|
||||
sb.append(' ').append(argv[z]);
|
||||
}
|
||||
|
@ -502,5 +504,6 @@ public class Proxy {
|
|||
}
|
||||
Log.info("%s executed: %s", player.getUsername(), line);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import proxy.util.Formatter;
|
|||
|
||||
public class CommandHelp extends Command {
|
||||
public String getName() {
|
||||
return "help";
|
||||
return "phelp";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
|
@ -21,7 +21,7 @@ public class CommandHelp extends Command {
|
|||
|
||||
private static String formatCommand(Command cmd, boolean prefix) {
|
||||
String args = cmd.getArgs();
|
||||
return (prefix ? Formatter.DARK_GRAY + "/" + Formatter.DARK_GREEN + "vproxy " : "") + Formatter.AQUA + cmd.getName() + (args == null || args.isEmpty() ? "" : Formatter.GREEN + " " + args)
|
||||
return (prefix ? Formatter.DARK_GRAY + "/" : "") + Formatter.AQUA + cmd.getName() + (args == null || args.isEmpty() ? "" : Formatter.GREEN + " " + args)
|
||||
+ Formatter.GRAY + " - " + Formatter.YELLOW + cmd.getHelp();
|
||||
}
|
||||
|
||||
|
|
|
@ -334,31 +334,23 @@ public class ProxyHandler extends User implements Handler {
|
|||
}
|
||||
|
||||
public List<String> getCompletions(String[] args) {
|
||||
if(args.length == 0)
|
||||
args = new String[] {""};
|
||||
String param = args[0];
|
||||
if(args.length <= 1)
|
||||
return null;
|
||||
Command cmd = this.proxy.getCommands().get(args[0].toLowerCase(Locale.US));
|
||||
if(cmd == null)
|
||||
return null;
|
||||
List<String> list = Lists.<String>newArrayList();
|
||||
if(args.length == 1) {
|
||||
for(String cmd : this.proxy.getCommands().keySet()) {
|
||||
if(cmd.regionMatches(true, 0, param, 0, param.length()))
|
||||
list.add(cmd);
|
||||
}
|
||||
if(!this.isAdmin())
|
||||
return list;
|
||||
}
|
||||
else if(args.length > 1) {
|
||||
Command cmd = this.proxy.getCommands().get(param.toLowerCase(Locale.US));
|
||||
if(cmd == null)
|
||||
return list;
|
||||
String[] argv = new String[args.length - 1];
|
||||
System.arraycopy(args, 1, argv, 0, argv.length);
|
||||
Iterable<String> comps = cmd.complete(this.proxy, this, argv);
|
||||
if(comps == null)
|
||||
return list;
|
||||
param = args[args.length - 1];
|
||||
for(String comp : comps) {
|
||||
if(comp.regionMatches(true, 0, param, 0, param.length()))
|
||||
list.add(comp);
|
||||
}
|
||||
String[] argv = new String[args.length - 1];
|
||||
System.arraycopy(args, 1, argv, 0, argv.length);
|
||||
Iterable<String> comps = cmd.complete(this.proxy, this, argv);
|
||||
if(comps == null)
|
||||
return list;
|
||||
String param = args[args.length - 1];
|
||||
for(String comp : comps) {
|
||||
if(comp.regionMatches(true, 0, param, 0, param.length()))
|
||||
list.add(comp);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
@ -373,26 +365,14 @@ public class ProxyHandler extends User implements Handler {
|
|||
if(msg.isEmpty())
|
||||
return;
|
||||
if(msg.startsWith("/")) {
|
||||
if(msg.equals("/vproxy")) {
|
||||
if(!this.admin) {
|
||||
this.sendMessage(Formatter.DARK_RED + "You are not allowed to execute this command");
|
||||
return;
|
||||
}
|
||||
this.proxy.runCommand(this, new String[0], msg);
|
||||
}
|
||||
else if(msg.startsWith("/vproxy ")) {
|
||||
if(!this.admin) {
|
||||
this.sendMessage(Formatter.DARK_RED + "You are not allowed to execute this command");
|
||||
return;
|
||||
}
|
||||
String[] args = msg.split(" ", -1);
|
||||
String[] argv = new String[args.length - 1];
|
||||
System.arraycopy(args, 1, argv, 0, argv.length);
|
||||
this.proxy.runCommand(this, argv, msg);
|
||||
}
|
||||
else {
|
||||
this.sendToServer(msg.split(" ", -1)[0].indexOf(':') != -1 ? new C01PacketChatMessage("/") : packetIn);
|
||||
msg = msg.substring(1);
|
||||
String[] args = msg.split(" ");
|
||||
if(args[0].indexOf(':') != -1) {
|
||||
this.sendToServer(new C01PacketChatMessage("/"));
|
||||
return;
|
||||
}
|
||||
if(!this.proxy.runCommand(this, args, msg))
|
||||
this.sendToServer(packetIn);
|
||||
}
|
||||
else {
|
||||
msg = String.format(Formatter.BLUE + "%s" + Formatter.DARK_GRAY + ": " + Formatter.GRAY + "%s", this.username, packetIn.getMessage());
|
||||
|
@ -426,18 +406,18 @@ public class ProxyHandler extends User implements Handler {
|
|||
if(iter.next().indexOf(':') != -1)
|
||||
iter.remove();
|
||||
}
|
||||
if(this.admin && "/vproxy".regionMatches(true, 0, this.completion, 0, this.completion.length()))
|
||||
list.add("/vproxy");
|
||||
if(this.admin) {
|
||||
for(String cmd : this.proxy.getCommands().keySet()) {
|
||||
String command = "/" + cmd;
|
||||
if(this.admin && command.regionMatches(true, 0, this.completion, 0, this.completion.length()))
|
||||
list.add(command);
|
||||
}
|
||||
}
|
||||
Collections.sort(list);
|
||||
}
|
||||
else if(this.admin && this.completion.startsWith("/vproxy ")) {
|
||||
String[] args = this.completion.split(" ", -1);
|
||||
String[] argv = new String[args.length - 1];
|
||||
System.arraycopy(args, 1, argv, 0, argv.length);
|
||||
list = this.getCompletions(argv);
|
||||
}
|
||||
else if(this.completion.split(" ", -1)[0].indexOf(':') != -1) {
|
||||
list = Lists.newArrayList();
|
||||
else {
|
||||
String[] args = this.completion.substring(1).split(" ", -1);
|
||||
list = args[0].indexOf(':') != -1 ? Lists.newArrayList() : this.getCompletions(args);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue