From 495dba899d39a5f4a0f1354eabc89c3ddbab7535 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 18 Jan 2020 17:25:49 +0700 Subject: [PATCH] [FEATURE] ClientUnlockConsoleEvent --- .../client/events/ClientUnlockConsoleEvent.java | 12 ++++++++++++ .../pro/gravit/launcher/console/UnlockCommand.java | 7 +++++-- .../pro/gravit/launcher/managers/ConsoleManager.java | 10 +++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 Launcher/src/main/java/pro/gravit/launcher/client/events/ClientUnlockConsoleEvent.java diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientUnlockConsoleEvent.java b/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientUnlockConsoleEvent.java new file mode 100644 index 00000000..2bf5ba5b --- /dev/null +++ b/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientUnlockConsoleEvent.java @@ -0,0 +1,12 @@ +package pro.gravit.launcher.client.events; + +import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.utils.command.CommandHandler; + +public class ClientUnlockConsoleEvent extends LauncherModule.Event { + public final CommandHandler handler; + + public ClientUnlockConsoleEvent(CommandHandler handler) { + this.handler = handler; + } +} diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/UnlockCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/UnlockCommand.java index 73bc54a6..c6419756 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/console/UnlockCommand.java +++ b/Launcher/src/main/java/pro/gravit/launcher/console/UnlockCommand.java @@ -21,8 +21,11 @@ public void invoke(String... args) throws Exception { verifyArgs(args, 1); if (ConsoleManager.checkUnlockKey(args[0])) { LogHelper.info("Unlock successful"); - ConsoleManager.unlock(); - ConsoleManager.handler.unregisterCommand("unlock"); + if(!ConsoleManager.unlock()) + { + LogHelper.error("Console unlock canceled"); + return; + } LogHelper.info("Write unlock key"); SettingsManager.settings.consoleUnlockKey = args[0]; } else { diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java b/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java index 6b87f2ec..24f2acdc 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java @@ -1,6 +1,8 @@ package pro.gravit.launcher.managers; import pro.gravit.launcher.Launcher; +import pro.gravit.launcher.LauncherEngine; +import pro.gravit.launcher.client.events.ClientUnlockConsoleEvent; import pro.gravit.launcher.console.UnlockCommand; import pro.gravit.utils.command.CommandHandler; import pro.gravit.utils.command.JLineCommandHandler; @@ -48,8 +50,14 @@ public static boolean checkUnlockKey(String key) { return key.equals(Launcher.getConfig().oemUnlockKey); } - public static void unlock() { + public static boolean unlock() { + if(isConsoleUnlock) return true; + ClientUnlockConsoleEvent event = new ClientUnlockConsoleEvent(handler); + LauncherEngine.modulesManager.invokeEvent(event); + if(event.isCancel()) return false; handler.registerCommand("debug", new DebugCommand()); + handler.unregisterCommand("unlock"); isConsoleUnlock = true; + return true; } }