Allow Custom input handling in servers (#6452)

* enable input redirection

* oops
This commit is contained in:
Phinner
2021-12-24 05:30:46 +01:00
committed by GitHub
parent 0036efba0c
commit 84d87e7e9f

View File

@ -45,6 +45,14 @@ public class ServerControl implements ApplicationListener{
public final CommandHandler handler = new CommandHandler("");
public final Fi logFolder = Core.settings.getDataDirectory().child("logs/");
public Runnable serverInput = () -> {
Scanner scan = new Scanner(System.in);
while(scan.hasNext()){
String line = scan.nextLine();
Core.app.post(() -> handleCommandString(line));
}
};
private Fi currentLogFile;
private boolean inExtraRound;
private Task lastTask;
@ -147,10 +155,6 @@ public class ServerControl implements ApplicationListener{
customMapDirectory.mkdirs();
Thread thread = new Thread(this::readCommands, "Server Controls");
thread.setDaemon(true);
thread.start();
if(Version.build == -1){
warn("&lyYour server is running a custom build, which means that client checking is disabled.");
warn("&lyIt is highly advised to specify which version you're using by building with gradle args &lb&fb-Pbuildversion=&lr<build>");
@ -258,7 +262,13 @@ public class ServerControl implements ApplicationListener{
toggleSocket(Config.socketInput.bool());
info("Server loaded. Type @ for help.", "'help'");
Events.on(ServerLoadEvent.class, e -> {
Thread thread = new Thread(serverInput, "Server Controls");
thread.setDaemon(true);
thread.start();
info("Server loaded. Type @ for help.", "'help'");
});
}
protected void registerCommands(){
@ -963,15 +973,7 @@ public class ServerControl implements ApplicationListener{
mods.eachClass(p -> p.registerServerCommands(handler));
}
private void readCommands(){
Scanner scan = new Scanner(System.in);
while(scan.hasNext()){
String line = scan.nextLine();
Core.app.post(() -> handleCommandString(line));
}
}
private void handleCommandString(String line){
public void handleCommandString(String line){
CommandResponse response = handler.handleMessage(line);
if(response.type == ResponseType.unknownCommand){