[FEATURE] ClientUnlockConsoleEvent

This commit is contained in:
Gravit 2020-01-18 17:25:49 +07:00
parent 036b593356
commit 495dba899d
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
3 changed files with 26 additions and 3 deletions

View file

@ -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;
}
}

View file

@ -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 {

View file

@ -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;
}
}