diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java index 0acb90b7..b64b9252 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java @@ -12,6 +12,9 @@ import ru.gravit.launchserver.command.modules.ModulesCommand; import ru.gravit.launchserver.command.service.*; import ru.gravit.utils.command.BaseCommandCategory; +import ru.gravit.utils.command.basic.ClearCommand; +import ru.gravit.utils.command.basic.DebugCommand; +import ru.gravit.utils.command.basic.GCCommand; import ru.gravit.utils.command.basic.HelpCommand; public abstract class CommandHandler extends ru.gravit.utils.command.CommandHandler { @@ -25,9 +28,9 @@ public static void registerCommands(ru.gravit.utils.command.CommandHandler handl basic.registerCommand("stop", new StopCommand(server)); basic.registerCommand("restart", new RestartCommand(server)); basic.registerCommand("rebind", new RebindCommand(server)); - basic.registerCommand("debug", new DebugCommand(server)); - basic.registerCommand("clear", new ClearCommand(server)); - basic.registerCommand("gc", new GCCommand(server)); + basic.registerCommand("debug", new DebugCommand()); + basic.registerCommand("clear", new ClearCommand(handler)); + basic.registerCommand("gc", new GCCommand()); basic.registerCommand("proguardClean", new ProguardCleanCommand(server)); basic.registerCommand("proguardDictRegen", new RegenProguardDictCommand(server)); basic.registerCommand("proguardMappingsRemove", new RemoveMappingsProguardCommand(server)); diff --git a/Launcher/src/main/java/ru/gravit/launcher/console/UnlockCommand.java b/Launcher/src/main/java/ru/gravit/launcher/console/UnlockCommand.java index e2cc5134..e3943dc9 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/console/UnlockCommand.java +++ b/Launcher/src/main/java/ru/gravit/launcher/console/UnlockCommand.java @@ -12,7 +12,7 @@ public String getArgsDescription() { @Override public String getUsageDescription() { - return "Unlock other commands"; + return "Unlock console commands"; } @Override @@ -22,6 +22,7 @@ public void invoke(String... args) throws Exception { { LogHelper.info("Unlock successful"); ConsoleManager.unlock(); + ConsoleManager.handler.unregisterCommand("unlock"); } else { diff --git a/Launcher/src/main/java/ru/gravit/launcher/managers/ConsoleManager.java b/Launcher/src/main/java/ru/gravit/launcher/managers/ConsoleManager.java index 916e595b..a7ab05c9 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/managers/ConsoleManager.java +++ b/Launcher/src/main/java/ru/gravit/launcher/managers/ConsoleManager.java @@ -1,5 +1,8 @@ package ru.gravit.launcher.managers; +import ru.gravit.utils.command.basic.ClearCommand; +import ru.gravit.utils.command.basic.DebugCommand; +import ru.gravit.utils.command.basic.GCCommand; import ru.gravit.launcher.console.UnlockCommand; import ru.gravit.utils.command.CommandHandler; import ru.gravit.utils.command.JLineCommandHandler; @@ -34,6 +37,8 @@ public static void initConsole() throws IOException public static void registerCommands() { handler.registerCommand("help", new HelpCommand(handler)); + handler.registerCommand("gc", new GCCommand()); + handler.registerCommand("clear", new ClearCommand(handler)); handler.registerCommand("unlock", new UnlockCommand()); } public static boolean checkUnlockKey(String key) @@ -42,6 +47,6 @@ public static boolean checkUnlockKey(String key) } public static void unlock() { - + handler.registerCommand("debug", new DebugCommand()); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/ClearCommand.java b/libLauncher/src/main/java/ru/gravit/utils/command/basic/ClearCommand.java similarity index 60% rename from LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/ClearCommand.java rename to libLauncher/src/main/java/ru/gravit/utils/command/basic/ClearCommand.java index f6e62e8c..014238de 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/ClearCommand.java +++ b/libLauncher/src/main/java/ru/gravit/utils/command/basic/ClearCommand.java @@ -1,12 +1,13 @@ -package ru.gravit.launchserver.command.basic; +package ru.gravit.utils.command.basic; -import ru.gravit.launchserver.LaunchServer; -import ru.gravit.launchserver.command.Command; +import ru.gravit.utils.command.Command; +import ru.gravit.utils.command.CommandHandler; import ru.gravit.utils.helper.LogHelper; public final class ClearCommand extends Command { - public ClearCommand(LaunchServer server) { - super(server); + private CommandHandler handler; + public ClearCommand(CommandHandler handler) { + this.handler = handler; } @Override @@ -21,7 +22,7 @@ public String getUsageDescription() { @Override public void invoke(String... args) throws Exception { - server.commandHandler.clear(); + handler.clear(); LogHelper.subInfo("Terminal cleared"); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/DebugCommand.java b/libLauncher/src/main/java/ru/gravit/utils/command/basic/DebugCommand.java similarity index 65% rename from LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/DebugCommand.java rename to libLauncher/src/main/java/ru/gravit/utils/command/basic/DebugCommand.java index 44ff49e3..306c171d 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/DebugCommand.java +++ b/libLauncher/src/main/java/ru/gravit/utils/command/basic/DebugCommand.java @@ -1,26 +1,21 @@ -package ru.gravit.launchserver.command.basic; +package ru.gravit.utils.command.basic; -import ru.gravit.launchserver.LaunchServer; -import ru.gravit.launchserver.command.Command; +import ru.gravit.utils.command.Command; import ru.gravit.utils.helper.LogHelper; -public final class DebugCommand extends Command { - public DebugCommand(LaunchServer server) { - super(server); - } - +public class DebugCommand extends Command { @Override public String getArgsDescription() { - return "[true/false] (true/false)"; + return "[true/false] [true/false]"; } @Override public String getUsageDescription() { - return "Enable or disable debug and stacktrace logging at runtime"; + return null; } @Override - public void invoke(String... args) { + public void invoke(String... args) throws Exception { boolean newValue, newTraceValue; if (args.length >= 1) { newValue = Boolean.parseBoolean(args[0]); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/GCCommand.java b/libLauncher/src/main/java/ru/gravit/utils/command/basic/GCCommand.java similarity index 66% rename from LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/GCCommand.java rename to libLauncher/src/main/java/ru/gravit/utils/command/basic/GCCommand.java index f81b36e5..ed04861e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/GCCommand.java +++ b/libLauncher/src/main/java/ru/gravit/utils/command/basic/GCCommand.java @@ -1,16 +1,11 @@ -package ru.gravit.launchserver.command.basic; +package ru.gravit.utils.command.basic; import ru.gravit.launcher.managers.GarbageManager; -import ru.gravit.launchserver.LaunchServer; -import ru.gravit.launchserver.command.Command; +import ru.gravit.utils.command.Command; import ru.gravit.utils.helper.JVMHelper; import ru.gravit.utils.helper.LogHelper; -public final class GCCommand extends Command { - public GCCommand(LaunchServer server) { - super(server); - } - +public class GCCommand extends Command { @Override public String getArgsDescription() { return null; @@ -18,11 +13,11 @@ public String getArgsDescription() { @Override public String getUsageDescription() { - return "Perform Garbage Collection and print memory usage"; + return null; } @Override - public void invoke(String... args) { + public void invoke(String... args) throws Exception { LogHelper.subInfo("Performing full GC"); JVMHelper.fullGC(); GarbageManager.gc();