Static import

This commit is contained in:
Skat
2020-11-05 21:19:46 +03:00
parent 6bf23a9056
commit 7d0da558ef
2 changed files with 37 additions and 41 deletions

View File

@ -111,7 +111,7 @@ public class ServerControl implements ApplicationListener{
state.set(State.playing); state.set(State.playing);
netServer.openServer(); netServer.openServer();
}catch(Throwable e){ }catch(Throwable e){
Log.err(e); err(e);
} }
} }
} }
@ -237,7 +237,7 @@ public class ServerControl implements ApplicationListener{
JsonValue value = JsonIO.json().fromJson(null, Core.settings.getString("globalrules")); JsonValue value = JsonIO.json().fromJson(null, Core.settings.getString("globalrules"));
JsonIO.json().readFields(state.rules, value); JsonIO.json().readFields(state.rules, value);
}catch(Throwable t){ }catch(Throwable t){
Log.err("Error applying custom rules, proceeding without them.", t); err("Error applying custom rules, proceeding without them.", t);
} }
}); });
@ -326,7 +326,7 @@ public class ServerControl implements ApplicationListener{
netServer.openServer(); netServer.openServer();
}catch(MapException e){ }catch(MapException e){
Log.err(e.map.name() + ": " + e.getMessage()); err(e.map.name() + ": " + e.getMessage());
} }
}); });
@ -431,27 +431,27 @@ public class ServerControl implements ApplicationListener{
JsonValue base = JsonIO.json().fromJson(null, rules); JsonValue base = JsonIO.json().fromJson(null, rules);
if(arg.length == 0){ if(arg.length == 0){
Log.info("Rules:\n@", JsonIO.print(rules)); info("Rules:\n@", JsonIO.print(rules));
}else if(arg.length == 1){ }else if(arg.length == 1){
Log.err("Invalid usage. Specify which rule to remove or add."); err("Invalid usage. Specify which rule to remove or add.");
}else{ }else{
if(!(arg[0].equals("remove") || arg[0].equals("add"))){ if(!(arg[0].equals("remove") || arg[0].equals("add"))){
Log.err("Invalid usage. Either add or remove rules."); err("Invalid usage. Either add or remove rules.");
return; return;
} }
boolean remove = arg[0].equals("remove"); boolean remove = arg[0].equals("remove");
if(remove){ if(remove){
if(base.has(arg[1])){ if(base.has(arg[1])){
Log.info("Rule '@' removed.", arg[1]); info("Rule '@' removed.", arg[1]);
base.remove(arg[1]); base.remove(arg[1]);
}else{ }else{
Log.err("Rule not defined, so not removed."); err("Rule not defined, so not removed.");
return; return;
} }
}else{ }else{
if(arg.length < 3){ if(arg.length < 3){
Log.err("Missing last argument. Specify which value to set the rule to."); err("Missing last argument. Specify which value to set the rule to.");
return; return;
} }
@ -467,9 +467,9 @@ public class ServerControl implements ApplicationListener{
base.remove(value.name); base.remove(value.name);
} }
base.addChild(arg[1], value); base.addChild(arg[1], value);
Log.info("Changed rule: @", value.toString().replace("\n", " ")); info("Changed rule: @", value.toString().replace("\n", " "));
}catch(Throwable e){ }catch(Throwable e){
Log.err("Error parsing rule JSON: @", e.getMessage()); err("Error parsing rule JSON: @", e.getMessage());
} }
} }
@ -501,7 +501,6 @@ public class ServerControl implements ApplicationListener{
} }
info("Core filled."); info("Core filled.");
}); });
handler.register("playerlimit", "[off/somenumber]", "Set the server player limit.", arg -> { handler.register("playerlimit", "[off/somenumber]", "Set the server player limit.", arg -> {
@ -528,9 +527,9 @@ public class ServerControl implements ApplicationListener{
if(arg.length == 0){ if(arg.length == 0){
info("All config values:"); info("All config values:");
for(Config c : Config.all){ for(Config c : Config.all){
Log.info("&lk| @: @", c.name(), "&lc&fi" + c.get()); info("&lk| @: @", c.name(), "&lc&fi" + c.get());
Log.info("&lk| | &lw" + c.description); info("&lk| | &lw" + c.description);
Log.info("&lk|"); info("&lk|");
} }
return; return;
} }
@ -538,7 +537,7 @@ public class ServerControl implements ApplicationListener{
try{ try{
Config c = Config.valueOf(arg[0]); Config c = Config.valueOf(arg[0]);
if(arg.length == 1){ if(arg.length == 1){
Log.info("'@' is currently @.", c.name(), c.get()); info("'@' is currently @.", c.name(), c.get());
}else{ }else{
if(c.isBool()){ if(c.isBool()){
c.set(arg[1].equals("on") || arg[1].equals("true")); c.set(arg[1].equals("on") || arg[1].equals("true"));
@ -546,14 +545,14 @@ public class ServerControl implements ApplicationListener{
try{ try{
c.set(Integer.parseInt(arg[1])); c.set(Integer.parseInt(arg[1]));
}catch(NumberFormatException e){ }catch(NumberFormatException e){
Log.err("Not a valid number: @", arg[1]); err("Not a valid number: @", arg[1]);
return; return;
} }
}else if(c.isString()){ }else if(c.isString()){
c.set(arg[1]); c.set(arg[1]);
} }
Log.info("@ set to @.", c.name(), c.get()); info("@ set to @.", c.name(), c.get());
Core.settings.forceSave(); Core.settings.forceSave();
} }
}catch(IllegalArgumentException e){ }catch(IllegalArgumentException e){
@ -563,9 +562,9 @@ public class ServerControl implements ApplicationListener{
handler.register("subnet-ban", "[add/remove] [address]", "Ban a subnet. This simply rejects all connections with IPs starting with some string.", arg -> { handler.register("subnet-ban", "[add/remove] [address]", "Ban a subnet. This simply rejects all connections with IPs starting with some string.", arg -> {
if(arg.length == 0){ if(arg.length == 0){
Log.info("Subnets banned: @", netServer.admins.getSubnetBans().isEmpty() ? "<none>" : ""); info("Subnets banned: @", netServer.admins.getSubnetBans().isEmpty() ? "<none>" : "");
for(String subnet : netServer.admins.getSubnetBans()){ for(String subnet : netServer.admins.getSubnetBans()){
Log.info("&lw " + subnet + ""); info("&lw " + subnet);
} }
}else if(arg.length == 1){ }else if(arg.length == 1){
err("You must provide a subnet to add or remove."); err("You must provide a subnet to add or remove.");
@ -577,7 +576,7 @@ public class ServerControl implements ApplicationListener{
} }
netServer.admins.addSubnetBan(arg[1]); netServer.admins.addSubnetBan(arg[1]);
Log.info("Banned @**", arg[1]); info("Banned @**", arg[1]);
}else if(arg[0].equals("remove")){ }else if(arg[0].equals("remove")){
if(!netServer.admins.getSubnetBans().contains(arg[1])){ if(!netServer.admins.getSubnetBans().contains(arg[1])){
err("That subnet isn't banned."); err("That subnet isn't banned.");
@ -585,7 +584,7 @@ public class ServerControl implements ApplicationListener{
} }
netServer.admins.removeSubnetBan(arg[1]); netServer.admins.removeSubnetBan(arg[1]);
Log.info("Unbanned @**", arg[1]); info("Unbanned @**", arg[1]);
}else{ }else{
err("Incorrect usage. You must provide add/remove as the second argument."); err("Incorrect usage. You must provide add/remove as the second argument.");
} }
@ -643,9 +642,9 @@ public class ServerControl implements ApplicationListener{
Map res = maps.all().find(map -> map.name().equalsIgnoreCase(arg[0].replace('_', ' ')) || map.name().equalsIgnoreCase(arg[0])); Map res = maps.all().find(map -> map.name().equalsIgnoreCase(arg[0].replace('_', ' ')) || map.name().equalsIgnoreCase(arg[0]));
if(res != null){ if(res != null){
nextMapOverride = res; nextMapOverride = res;
Log.info("Next map set to '@'.", res.name()); info("Next map set to '@'.", res.name());
}else{ }else{
Log.err("No map '@' found.", arg[0]); err("No map '@' found.", arg[0]);
} }
}); });
@ -871,7 +870,6 @@ public class ServerControl implements ApplicationListener{
}); });
handler.register("info", "<IP/UUID/name...>", "Find player info(s). Can optionally check for all names or IPs a player has had.", arg -> { handler.register("info", "<IP/UUID/name...>", "Find player info(s). Can optionally check for all names or IPs a player has had.", arg -> {
ObjectSet<PlayerInfo> infos = netServer.admins.findByName(arg[0]); ObjectSet<PlayerInfo> infos = netServer.admins.findByName(arg[0]);
if(infos.size > 0){ if(infos.size > 0){
@ -892,7 +890,6 @@ public class ServerControl implements ApplicationListener{
}); });
handler.register("search", "<name...>", "Search players who have used part of a name.", arg -> { handler.register("search", "<name...>", "Search players who have used part of a name.", arg -> {
ObjectSet<PlayerInfo> infos = netServer.admins.searchNames(arg[0]); ObjectSet<PlayerInfo> infos = netServer.admins.searchNames(arg[0]);
if(infos.size > 0){ if(infos.size > 0){
@ -926,7 +923,6 @@ public class ServerControl implements ApplicationListener{
} }
private void readCommands(){ private void readCommands(){
Scanner scan = new Scanner(System.in); Scanner scan = new Scanner(System.in);
while(scan.hasNext()){ while(scan.hasNext()){
String line = scan.nextLine(); String line = scan.nextLine();
@ -1002,7 +998,7 @@ public class ServerControl implements ApplicationListener{
try{ try{
r.run(); r.run();
}catch(MapException e){ }catch(MapException e){
Log.err(e.map.name() + ": " + e.getMessage()); err(e.map.name() + ": " + e.getMessage());
net.closeServer(); net.closeServer();
} }
} }
@ -1057,7 +1053,7 @@ public class ServerControl implements ApplicationListener{
}catch(IOException e){ }catch(IOException e){
if(!e.getMessage().equals("Socket closed")){ if(!e.getMessage().equals("Socket closed")){
err("Terminating socket server."); err("Terminating socket server.");
e.printStackTrace(); err(e);
} }
} }
}); });
@ -1068,7 +1064,7 @@ public class ServerControl implements ApplicationListener{
try{ try{
serverSocket.close(); serverSocket.close();
}catch(IOException e){ }catch(IOException e){
e.printStackTrace(); err(e);
} }
socketThread = null; socketThread = null;
socketOutput = null; socketOutput = null;

View File

@ -30,9 +30,9 @@ public class ServerLauncher implements ApplicationListener{
Vars.net = new Net(platform.getNet()); Vars.net = new Net(platform.getNet());
logger = (level1, text) -> { logger = (level1, text) -> {
String result = "[" + dateTime.format(LocalDateTime.now()) + "] " + format(tags[level1.ordinal()] + " " + text + "&fr"); String result = "[" + dateTime.format(LocalDateTime.now()) + "] " + format(tags[level1.ordinal()] + " " + text + "&fr");
System.out.println(result); System.out.println(result);
}; };
new HeadlessApplication(new ServerLauncher(), null, throwable -> CrashSender.send(throwable, f -> {})); new HeadlessApplication(new ServerLauncher(), null, throwable -> CrashSender.send(throwable, f -> {}));
}catch(Throwable t){ }catch(Throwable t){
CrashSender.send(t, f -> {}); CrashSender.send(t, f -> {});
@ -47,7 +47,7 @@ public class ServerLauncher implements ApplicationListener{
Fi plugins = Core.settings.getDataDirectory().child("plugins"); Fi plugins = Core.settings.getDataDirectory().child("plugins");
if(plugins.isDirectory() && plugins.list().length > 0 && !plugins.sibling("mods").exists()){ if(plugins.isDirectory() && plugins.list().length > 0 && !plugins.sibling("mods").exists()){
Log.warn("[IMPORTANT NOTICE] &lrPlugins have been detected.&ly Automatically moving all contents of the plugin folder into the 'mods' folder. The original folder will not be removed; please do so manually."); warn("[IMPORTANT NOTICE] &lrPlugins have been detected.&ly Automatically moving all contents of the plugin folder into the 'mods' folder. The original folder will not be removed; please do so manually.");
plugins.sibling("mods").mkdirs(); plugins.sibling("mods").mkdirs();
for(Fi file : plugins.list()){ for(Fi file : plugins.list()){
file.copyTo(plugins.sibling("mods")); file.copyTo(plugins.sibling("mods"));
@ -61,16 +61,16 @@ public class ServerLauncher implements ApplicationListener{
content.createModContent(); content.createModContent();
content.init(); content.init();
if(mods.hasContentErrors()){ if(mods.hasContentErrors()){
Log.err("Error occurred loading mod content:"); err("Error occurred loading mod content:");
for(LoadedMod mod : mods.list()){ for(LoadedMod mod : mods.list()){
if(mod.hasContentErrors()){ if(mod.hasContentErrors()){
Log.err("| &ly[@]", mod.name); err("| &ly[@]", mod.name);
for(Content cont : mod.erroredContent){ for(Content cont : mod.erroredContent){
Log.err("| | &y@: &c@", cont.minfo.sourceFile.name(), Strings.getSimpleMessage(cont.minfo.baseError).replace("\n", " ")); err("| | &y@: &c@", cont.minfo.sourceFile.name(), Strings.getSimpleMessage(cont.minfo.baseError).replace("\n", " "));
} }
} }
} }
Log.err("The server will now exit."); err("The server will now exit.");
System.exit(1); System.exit(1);
} }