fix command system a bit

This commit is contained in:
Sen 2025-05-31 14:02:55 +02:00
parent 35277daca8
commit f4c024cde7
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
29 changed files with 318 additions and 269 deletions

View file

@ -19,7 +19,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Map.Entry;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
@ -42,7 +41,6 @@ import common.init.Config;
import common.init.EntityRegistry;
import common.init.Registry;
import common.init.UniverseRegistry;
import common.init.Config.ValueType;
import common.log.Log;
import common.net.bootstrap.ServerBootstrap;
import common.net.channel.Channel;
@ -95,7 +93,6 @@ import server.biome.GenBiome;
import server.clipboard.ReorderRegistry;
import server.clipboard.RotationRegistry;
import server.command.CommandEnvironment;
import server.command.Executor;
import server.command.FixedExecutor;
import server.network.HandshakeHandler;
import server.network.Player;
@ -374,94 +371,6 @@ public final class Server implements IThreadListener {
}
}
public boolean setVar(Executor exec, String line) {
if(line.length() < 1) {
for(Entry<String, Config.Value> entry : Config.VARS.entrySet()) {
Config.Value cvar = entry.getValue();
String v = cvar.getValue();
String comp = TextColor.YELLOW + entry.getKey() + TextColor.GRAY + " = ";
if(cvar.noDef && cvar.def.equals(v))
comp += TextColor.DGRAY + "[ - ]";
else if(entry.getKey().equals("password") && !v.isEmpty())
comp += TextColor.NEON + "'****'";
else if(cvar.type == ValueType.STRING)
comp += TextColor.NEON + "'" + v + "'";
else
comp += ((cvar.type == ValueType.BOOLEAN ? (v.equals("true") ? TextColor.GREEN : TextColor.RED) : TextColor.BLUE)) + v;
if(!cvar.def.equals(v)) {
comp += TextColor.GRAY + " (" + (cvar.noDef ? TextColor.DGRAY + "[ - ]" : TextColor.BROWN + cvar.def) + TextColor.GRAY + ")";
}
exec.logConsole(comp);
}
exec.logConsole(TextColor.GREEN + "SVARs insgesamt registriert: %d", Config.VARS.size());
return true;
}
line = line.trim();
String[] args = /* line.isEmpty() ? new String[0] : */ line.split(" ", -1);
if(args.length == 1) {
// case 0:
// break;
// case 1:
Config.Value cfg = Config.VARS.get(args[0]);
if(cfg == null)
return false;
String v = cfg.getValue();
String comp = TextColor.YELLOW + args[0] + TextColor.GRAY + " = ";
if(cfg.noDef && cfg.def.equals(v))
comp += TextColor.DGRAY + "[ - ]";
else if(cfg.type == ValueType.STRING)
comp += TextColor.NEON + "'" + v + "'";
else
comp += ((cfg.type == ValueType.BOOLEAN ? (v.equals("true") ? TextColor.GREEN : TextColor.RED) : TextColor.BLUE)) + v;
if(!cfg.def.equals(v))
comp += TextColor.GRAY + " (" + (cfg.noDef ? TextColor.DGRAY + "[ - ]" : TextColor.BROWN + cfg.def) + TextColor.GRAY + ")";
exec.logConsole(comp);
// break;
// default:
}
else {
Config.Value cv = Config.VARS.get(args[0]);
if(cv == null)
return false;
String value = args[1];
if(cv.type == ValueType.STRING && "\"\"".equals(value)) {
value = "";
}
// else if(cv.type == ValueType.BOOLEAN && "toggle".equalsIgnoreCase(value)) {
// value = "" + !Boolean.parseBoolean(cv.getValue());
// }
// else
if(cv.type == ValueType.BOOLEAN && !"true".equals(value) && !"false".equals(value)) {
if(!value.equalsIgnoreCase("true") && !value.equalsIgnoreCase("false")) {
exec.logConsole(TextColor.DRED + "'%s' ist nicht 'true' oder 'false'", value);
return true;
}
value = value.toLowerCase();
}
if(cv.type == ValueType.INTEGER) {
try {
Integer.parseInt(value);
}
catch(NumberFormatException e) {
exec.logConsole(TextColor.DRED + "'%s' ist keine gültige Zahl", value);
return true;
}
}
else if(cv.type == ValueType.FLOAT) {
try {
Float.parseFloat(value);
}
catch(NumberFormatException e) {
exec.logConsole(TextColor.DRED + "'%s' ist keine gültige Zahl", value);
return true;
}
}
Config.set(args[0], value, true);
exec.logConsole(TextColor.YELLOW + "%s" + TextColor.GRAY + " -> " + (cv.noDef && cv.def.equals(cv.getValue()) ? TextColor.DGRAY + "[ - ]" : ((cv.type == ValueType.BOOLEAN ? (cv.getValue().equals("true") ? TextColor.GREEN : TextColor.RED) : (cv.type == ValueType.STRING ? TextColor.NEON : TextColor.BLUE))) + "%s"), args[0], cv.type == ValueType.STRING ? ("'" + cv.getValue() + "'") : cv.getValue());
}
return true;
}
public void run(long time) {
if(!this.debug) {
Converter.convert();
@ -527,9 +436,9 @@ public final class Server implements IThreadListener {
if(Config.port >= 0)
this.bind(Config.port);
else
Log.SYSTEM.warn("Kein Port definiert, verwende 'port <1024-32767>' um einen Hosting-Port festzulegen");
Log.SYSTEM.warn("Kein Port definiert, verwende 'sv port <1024-32767>' um einen Hosting-Port festzulegen");
if(Config.accessRequired && Config.password.length() < 8)
Log.SYSTEM.warn("Kein Passwort definiert, verwende 'password <8-" + IPlayer.MAX_PASS_LENGTH + " Zeichen>' um ein Zugangspasswort festzulegen");
Log.SYSTEM.warn("Kein Passwort definiert, verwende 'sv password <8-" + IPlayer.MAX_PASS_LENGTH + " Zeichen>' um ein Zugangspasswort festzulegen");
Thread con = new Thread(new Runnable() {
private final BufferedReader reader = new BufferedReader(new InputStreamReader(new BufferedInputStream(System.in)));
@ -547,9 +456,7 @@ public final class Server implements IThreadListener {
final String cmd = line;
Server.this.schedule(new Runnable() {
public void run() {
FixedExecutor exec = new FixedExecutor(Server.this, "#con", "KONSOLE", null);
if(!Server.this.setVar(exec, cmd))
Server.this.scriptEnv.execute(cmd, exec);
Server.this.scriptEnv.execute(cmd, new FixedExecutor(Server.this, "#con", "KONSOLE", null));
}
});
}