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