From a49e523d5dd38d2982e3b8092a61294b21991256 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 24 Apr 2019 16:18:34 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=A1=D1=82=D0=B0=D0=BD=D0=B4?= =?UTF-8?q?=D0=B0=D1=80=D1=82=D0=BD=D1=8B=D0=B5=20=D0=BA=D0=BE=D0=BC=D0=B0?= =?UTF-8?q?=D0=BD=D0=B4=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/handler/CommandHandler.java | 9 ++++++--- .../gravit/launcher/console/UnlockCommand.java | 3 ++- .../launcher/managers/ConsoleManager.java | 7 ++++++- .../utils}/command/basic/ClearCommand.java | 13 +++++++------ .../utils}/command/basic/DebugCommand.java | 17 ++++++----------- .../gravit/utils}/command/basic/GCCommand.java | 15 +++++---------- 6 files changed, 32 insertions(+), 32 deletions(-) rename {LaunchServer/src/main/java/ru/gravit/launchserver => libLauncher/src/main/java/ru/gravit/utils}/command/basic/ClearCommand.java (60%) rename {LaunchServer/src/main/java/ru/gravit/launchserver => libLauncher/src/main/java/ru/gravit/utils}/command/basic/DebugCommand.java (65%) rename {LaunchServer/src/main/java/ru/gravit/launchserver => libLauncher/src/main/java/ru/gravit/utils}/command/basic/GCCommand.java (66%) 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();