command system
This commit is contained in:
parent
a8f6af2b37
commit
a891ab4d3a
11 changed files with 361 additions and 87 deletions
|
@ -23,6 +23,7 @@ import game.clipboard.Rotation;
|
|||
import game.clipboard.RotationValue;
|
||||
import game.clipboard.Vector;
|
||||
import game.color.TextColor;
|
||||
import game.command.ScriptExecutor;
|
||||
import game.dimension.Dimension;
|
||||
import game.entity.Entity;
|
||||
import game.entity.animal.EntityHorse;
|
||||
|
@ -125,7 +126,7 @@ import game.world.WorldServer;
|
|||
import io.netty.util.concurrent.Future;
|
||||
import io.netty.util.concurrent.GenericFutureListener;
|
||||
|
||||
public class NetHandlerPlayServer extends NetHandler implements ICrafting
|
||||
public class NetHandlerPlayServer extends NetHandler implements ICrafting, ScriptExecutor
|
||||
{
|
||||
private static enum EditAction {
|
||||
SELECT("Auswahlmodus"), COPYPASTE("Kopiermodus"), TRANSFORM("Drehmodus");
|
||||
|
@ -1630,7 +1631,7 @@ public class NetHandlerPlayServer extends NetHandler implements ICrafting
|
|||
private boolean setVar(String line) {
|
||||
if(!this.isAdmin())
|
||||
return false;
|
||||
if(line.length() < 2) {
|
||||
if(line.length() < 1) {
|
||||
for(Entry<String, Config.Value> entry : Config.VARS.entrySet()) {
|
||||
Config.Value cvar = entry.getValue();
|
||||
String v = cvar.getValue();
|
||||
|
@ -1953,6 +1954,31 @@ public class NetHandlerPlayServer extends NetHandler implements ICrafting
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void runCommand(String command) {
|
||||
this.server.getScriptEnvironment().execute(command, this);
|
||||
}
|
||||
|
||||
private List<String> completeCommand(String command) {
|
||||
return this.server.getScriptEnvironment().complete(command, this);
|
||||
// return Lists.newArrayList();
|
||||
}
|
||||
|
||||
public void logConsole(String msg) {
|
||||
this.addFeed(msg);
|
||||
}
|
||||
|
||||
public String getExecId() {
|
||||
return this.user;
|
||||
}
|
||||
|
||||
public String getExecName() {
|
||||
return this.entity != null ? this.entity.getCommandName() : this.user;
|
||||
}
|
||||
|
||||
public Position getExecPos() {
|
||||
return this.entity != null ? this.entity.getPos() : null;
|
||||
}
|
||||
|
||||
public void processMessage(CPacketMessage packetIn)
|
||||
{
|
||||
|
@ -1967,7 +1993,7 @@ public class NetHandlerPlayServer extends NetHandler implements ICrafting
|
|||
switch(packetIn.getType()) {
|
||||
case COMMAND:
|
||||
if(!this.teleport(msg) && !this.setVar(msg) && !this.setAdmin(msg))
|
||||
this.addFeed(TextColor.RED + "Befehl wurde nicht gefunden");
|
||||
this.runCommand(msg); // this.addFeed(TextColor.RED + "Befehl wurde nicht gefunden");
|
||||
break;
|
||||
|
||||
case CHAT:
|
||||
|
@ -1990,6 +2016,73 @@ public class NetHandlerPlayServer extends NetHandler implements ICrafting
|
|||
throw new IllegalArgumentException("Ungültiger Nachrichten-Typ!");
|
||||
}
|
||||
}
|
||||
|
||||
private Iterable<String> getWarpList(char pre) {
|
||||
switch(pre) {
|
||||
case '+':
|
||||
return Lists.newArrayList(this.server.getUsers());
|
||||
case '@':
|
||||
List<String> warps = Lists.newArrayList("spawn");
|
||||
for(String warp : this.server.getWarps().keySet()) {
|
||||
warps.add(warp);
|
||||
}
|
||||
return warps;
|
||||
case '*':
|
||||
return UniverseRegistry.getWorldNames();
|
||||
}
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
|
||||
private static List<String> getVarList() {
|
||||
List<String> list = Lists.newArrayList(Config.VARS.keySet());
|
||||
list.add("time");
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<String> getVarCompletion(String var) {
|
||||
Config.Value v = Config.VARS.get(var);
|
||||
if(v == null)
|
||||
return Lists.newArrayList();
|
||||
if(v.type == ValueType.BOOLEAN)
|
||||
return Boolean.parseBoolean(v.getValue()) ? Lists.newArrayList("false", "true") : Lists.newArrayList("true", "false");
|
||||
else if(v.type == ValueType.INTEGER || v.type == ValueType.FLOAT)
|
||||
return Lists.newArrayList(v.def);
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
|
||||
public void processComplete(CPacketComplete packetIn)
|
||||
{
|
||||
NetHandler.checkThread(packetIn, this, this.server);
|
||||
if(packetIn.getMessage().startsWith(" ")) {
|
||||
this.entity.connection.sendPacket(new S3APacketTabComplete(new String[0]));
|
||||
return;
|
||||
}
|
||||
List<String> list = Lists.<String>newArrayList(); // Command.getCompletions(this.playerEntity, packetIn.getMessage());
|
||||
|
||||
// for (String s : )
|
||||
// {
|
||||
// list.add(s);
|
||||
// }
|
||||
|
||||
// if(list == null) {
|
||||
// list = Lists.<String>newArrayList();
|
||||
String s = packetIn.getMessage();
|
||||
char pre = s.startsWith("#") || s.startsWith("!") || s.startsWith("+") || s.startsWith("*") || s.startsWith("@") ? s.charAt(0) : 0;
|
||||
s = pre == 0 ? s : s.substring(1);
|
||||
String[] argv = s.split(" ", -1);
|
||||
s = argv[argv.length - 1];
|
||||
Iterable<String> res = pre == '#' && (Config.teleportAllowed || this.isAdmin()) ? (argv.length == 5 ? UniverseRegistry.getWorldNames() : Lists.newArrayList()) : ((pre == '+' || pre == '*' || pre == '@') && (Config.teleportAllowed || this.isAdmin()) ? (argv.length == 1 ? this.getWarpList(pre) : Lists.newArrayList()) : (pre == '!' && this.isAdmin() ? this.server.getAllUsernames() : ((this.isAdmin() ? (argv.length == 1 ? getVarList() : (argv.length == 2 ? (argv[0].equals("time") ? Lists.newArrayList("day", "night", "noon", "midnight", "sunrise", "sunset") : getVarCompletion(argv[0])) : Lists.newArrayList())) : Lists.newArrayList()))));
|
||||
for(String s1 : res) {
|
||||
if(s1.regionMatches(true, 0, s, 0, s.length()))
|
||||
list.add((argv.length == 1 && pre != 0 ? pre : "") + s1);
|
||||
}
|
||||
// if(list.isEmpty()) {
|
||||
list.addAll(this.completeCommand(packetIn.getMessage()));
|
||||
// }
|
||||
// }
|
||||
|
||||
this.entity.connection.sendPacket(new S3APacketTabComplete((String[])list.toArray(new String[list.size()])));
|
||||
}
|
||||
|
||||
private static boolean isFinite(double value) {
|
||||
return Double.NEGATIVE_INFINITY < value & value < Double.POSITIVE_INFINITY;
|
||||
|
@ -2902,66 +2995,6 @@ public class NetHandlerPlayServer extends NetHandler implements ICrafting
|
|||
}
|
||||
}
|
||||
|
||||
private Iterable<String> getWarpList(char pre) {
|
||||
switch(pre) {
|
||||
case '+':
|
||||
return Lists.newArrayList(this.server.getUsers());
|
||||
case '@':
|
||||
List<String> warps = Lists.newArrayList("spawn");
|
||||
for(String warp : this.server.getWarps().keySet()) {
|
||||
warps.add(warp);
|
||||
}
|
||||
return warps;
|
||||
case '*':
|
||||
return UniverseRegistry.getWorldNames();
|
||||
}
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
|
||||
private static List<String> getVarList() {
|
||||
List<String> list = Lists.newArrayList(Config.VARS.keySet());
|
||||
list.add("time");
|
||||
return list;
|
||||
}
|
||||
|
||||
private static List<String> getVarCompletion(String var) {
|
||||
Config.Value v = Config.VARS.get(var);
|
||||
if(v == null)
|
||||
return Lists.newArrayList();
|
||||
if(v.type == ValueType.BOOLEAN)
|
||||
return Boolean.parseBoolean(v.getValue()) ? Lists.newArrayList("false", "true") : Lists.newArrayList("true", "false");
|
||||
else if(v.type == ValueType.INTEGER || v.type == ValueType.FLOAT)
|
||||
return Lists.newArrayList(v.def);
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
|
||||
public void processComplete(CPacketComplete packetIn)
|
||||
{
|
||||
NetHandler.checkThread(packetIn, this, this.server);
|
||||
List<String> list = Lists.<String>newArrayList(); // Command.getCompletions(this.playerEntity, packetIn.getMessage());
|
||||
|
||||
// for (String s : )
|
||||
// {
|
||||
// list.add(s);
|
||||
// }
|
||||
|
||||
// if(list == null) {
|
||||
// list = Lists.<String>newArrayList();
|
||||
String s = packetIn.getMessage();
|
||||
char pre = s.startsWith("#") || s.startsWith("!") || s.startsWith("+") || s.startsWith("*") || s.startsWith("@") ? s.charAt(0) : 0;
|
||||
s = pre == 0 ? s : s.substring(1);
|
||||
String[] argv = s.split(" ", -1);
|
||||
s = argv[argv.length - 1];
|
||||
Iterable<String> res = pre == '#' && (Config.teleportAllowed || this.isAdmin()) ? (argv.length == 5 ? UniverseRegistry.getWorldNames() : Lists.newArrayList()) : ((pre == '+' || pre == '*' || pre == '@') && (Config.teleportAllowed || this.isAdmin()) ? (argv.length == 1 ? this.getWarpList(pre) : Lists.newArrayList()) : (pre == '!' && this.isAdmin() ? this.server.getAllUsernames() : ((this.isAdmin() ? (argv.length == 1 ? getVarList() : (argv.length == 2 ? (argv[0].equals("time") ? Lists.newArrayList("day", "night", "noon", "midnight", "sunrise", "sunset") : getVarCompletion(argv[0])) : Lists.newArrayList())) : Lists.newArrayList()))));
|
||||
for(String s1 : res) {
|
||||
if(s1.regionMatches(true, 0, s, 0, s.length()))
|
||||
list.add((argv.length == 1 && pre != 0 ? pre : "") + s1);
|
||||
}
|
||||
// }
|
||||
|
||||
this.entity.connection.sendPacket(new S3APacketTabComplete((String[])list.toArray(new String[list.size()])));
|
||||
}
|
||||
|
||||
public boolean respawnPlayer() {
|
||||
if(this.entity.getHealth() > 0)
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue