2019-03-08 15:43:26 +03:00
|
|
|
package ru.gravit.launchserver.console;
|
|
|
|
|
|
|
|
import ru.gravit.launcher.server.ServerWrapper;
|
|
|
|
import ru.gravit.utils.command.CommandHandler;
|
2019-04-13 03:09:19 +03:00
|
|
|
import ru.gravit.utils.command.JLineCommandHandler;
|
|
|
|
import ru.gravit.utils.command.StdCommandHandler;
|
|
|
|
import ru.gravit.utils.command.basic.HelpCommand;
|
2019-03-08 15:43:26 +03:00
|
|
|
import ru.gravit.utils.helper.LogHelper;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
public class ConsoleMain {
|
|
|
|
public static CommandHandler commandHandler;
|
2019-04-03 16:27:40 +03:00
|
|
|
|
2019-03-08 15:43:26 +03:00
|
|
|
public static void main(String[] args) throws IOException {
|
2019-04-03 17:14:23 +03:00
|
|
|
if (ServerWrapper.wrapper.config == null) {
|
2019-03-08 15:43:26 +03:00
|
|
|
LogHelper.warning("ServerWrapper not found");
|
|
|
|
}
|
2019-04-03 16:41:56 +03:00
|
|
|
if (!ServerWrapper.wrapper.permissions.canAdmin) {
|
2019-03-08 15:43:26 +03:00
|
|
|
LogHelper.warning("Permission canAdmin not found");
|
|
|
|
}
|
|
|
|
try {
|
2019-05-11 12:35:32 +03:00
|
|
|
Class.forName("org.jline.terminal.Terminal");
|
2019-03-08 15:43:26 +03:00
|
|
|
|
|
|
|
// JLine2 available
|
2019-04-13 03:09:19 +03:00
|
|
|
commandHandler = new JLineCommandHandler();
|
2019-03-08 15:43:26 +03:00
|
|
|
LogHelper.info("JLine2 terminal enabled");
|
|
|
|
} catch (ClassNotFoundException ignored) {
|
2019-04-13 03:09:19 +03:00
|
|
|
commandHandler = new StdCommandHandler(true);
|
2019-03-08 15:43:26 +03:00
|
|
|
LogHelper.warning("JLine2 isn't in classpath, using std");
|
|
|
|
}
|
2019-04-13 03:09:19 +03:00
|
|
|
registerCommands();
|
2019-03-08 15:43:26 +03:00
|
|
|
LogHelper.info("CommandHandler started. Use 'exit' to exit this console");
|
|
|
|
commandHandler.run();
|
|
|
|
}
|
2019-04-13 03:09:19 +03:00
|
|
|
public static void registerCommands()
|
|
|
|
{
|
|
|
|
commandHandler.registerCommand("help", new HelpCommand(commandHandler));
|
|
|
|
commandHandler.registerCommand("exit", new ExitCommand());
|
|
|
|
commandHandler.registerCommand("logListener", new LogListenerCommand());
|
|
|
|
commandHandler.registerCommand("exec", new ExecCommand());
|
|
|
|
}
|
2019-03-08 15:43:26 +03:00
|
|
|
}
|