command system
This commit is contained in:
parent
a8f6af2b37
commit
a891ab4d3a
11 changed files with 361 additions and 87 deletions
|
@ -9,6 +9,7 @@ import com.google.common.collect.Maps;
|
|||
|
||||
import game.Server;
|
||||
import game.color.TextColor;
|
||||
import game.command.commands.CommandSpawn;
|
||||
|
||||
public class ScriptEnvironment {
|
||||
private final Server server;
|
||||
|
@ -20,6 +21,7 @@ public class ScriptEnvironment {
|
|||
|
||||
public ScriptEnvironment(Server server) {
|
||||
this.server = server;
|
||||
this.registerDefaults();
|
||||
}
|
||||
|
||||
public void registerExecutable(Executable executable) {
|
||||
|
@ -107,8 +109,35 @@ public class ScriptEnvironment {
|
|||
}
|
||||
}
|
||||
|
||||
public void complete(String cmd, ScriptExecutor exec) {
|
||||
|
||||
public List<String> complete(String cmd, ScriptExecutor exec) {
|
||||
List<String> list = Lists.newArrayList();
|
||||
try {
|
||||
String[][] cmds = ArgumentParser.splitString(cmd.endsWith(" ") ? cmd + "END" : cmd);
|
||||
if(cmds.length == 0)
|
||||
return list;
|
||||
String[] argv = cmds[cmds.length - 1];
|
||||
if(argv.length == 0)
|
||||
return list;
|
||||
String[] comp;
|
||||
if(argv.length > 1) {
|
||||
CachedExecutable cached = this.executables.get(argv[0]);
|
||||
if(cached == null)
|
||||
return list;
|
||||
comp = ScriptArgs.parseComplete(this, argv, cached);
|
||||
}
|
||||
else {
|
||||
comp = this.executables.keySet().toArray(new String[this.executables.keySet().size()]);
|
||||
}
|
||||
String param = cmd.endsWith(" ") ? "" : argv[argv.length - 1];
|
||||
for(String cmp : comp) {
|
||||
if(cmp.regionMatches(true, 0, param, 0, param.length()))
|
||||
list.add(cmp);
|
||||
}
|
||||
}
|
||||
catch(Throwable t) {
|
||||
list.clear();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public void registerDefaults() {
|
||||
|
@ -127,5 +156,7 @@ public class ScriptEnvironment {
|
|||
return ScriptEnvironment.this.previousOutput == null ? null : ScriptEnvironment.this.previousOutput.toString();
|
||||
}
|
||||
});
|
||||
|
||||
this.registerExecutable(new CommandSpawn());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue