From 045ed67f126ee67037e167dc9c87e230eedd4c0f Mon Sep 17 00:00:00 2001 From: dima_dencep Date: Sat, 24 Sep 2022 00:27:54 +0700 Subject: [PATCH] idea cleanup lancher --- .../pro/gravit/launcher/BasicLauncherEventHandler.java | 1 - .../java/pro/gravit/launcher/ClientLauncherWrapper.java | 2 +- .../src/main/java/pro/gravit/launcher/LauncherEngine.java | 4 ++-- .../main/java/pro/gravit/launcher/api/SystemService.java | 2 -- .../gravit/launcher/client/ClientLauncherEntryPoint.java | 6 +++--- .../pro/gravit/launcher/client/ClientLauncherProcess.java | 8 +++----- .../java/pro/gravit/launcher/client/ServerPinger.java | 2 +- .../java/pro/gravit/launcher/console/ModulesCommand.java | 4 ++-- .../main/java/pro/gravit/launcher/debug/DebugMain.java | 2 +- .../java/pro/gravit/launcher/utils/ApiBridgeService.java | 2 +- .../java/pro/gravit/launcher/utils/LauncherUpdater.java | 8 +++----- .../java/pro/gravit/launcher/utils/NativeJVMHalt.java | 5 +---- 12 files changed, 18 insertions(+), 28 deletions(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/BasicLauncherEventHandler.java b/Launcher/src/main/java/pro/gravit/launcher/BasicLauncherEventHandler.java index a1246bb0..c02deec7 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/BasicLauncherEventHandler.java +++ b/Launcher/src/main/java/pro/gravit/launcher/BasicLauncherEventHandler.java @@ -7,7 +7,6 @@ import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.RequestService; import pro.gravit.launcher.request.WebSocketEvent; -import pro.gravit.launcher.request.websockets.ClientWebSocketService; import pro.gravit.utils.helper.LogHelper; public class BasicLauncherEventHandler implements RequestService.EventHandler { diff --git a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java index 6d0ca26b..5b487024 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java +++ b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java @@ -140,7 +140,7 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep if (context.memoryLimit != 0) { args.add(String.format("-Xmx%dM", context.memoryLimit)); } - if(customJvmOptions != null) { + if (customJvmOptions != null) { args.addAll(customJvmOptions); } args.add("-cp"); diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index 1921c8a2..0294860b 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -246,14 +246,14 @@ public void start(String... args) throws Throwable { try { service = StdWebSocketService.initWebSockets(address).get(); } catch (Throwable e) { - if(LogHelper.isDebugEnabled()) { + if (LogHelper.isDebugEnabled()) { LogHelper.error(e); } LogHelper.warning("Launcher in offline mode"); service = initOffline(); } Request.setRequestService(service); - if(service instanceof StdWebSocketService) { + if (service instanceof StdWebSocketService) { ((StdWebSocketService) service).reconnectCallback = () -> { LogHelper.debug("WebSocket connect closed. Try reconnect"); diff --git a/Launcher/src/main/java/pro/gravit/launcher/api/SystemService.java b/Launcher/src/main/java/pro/gravit/launcher/api/SystemService.java index 57c60481..dfdd74b3 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/api/SystemService.java +++ b/Launcher/src/main/java/pro/gravit/launcher/api/SystemService.java @@ -1,8 +1,6 @@ package pro.gravit.launcher.api; import pro.gravit.launcher.LauncherEngine; -import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.utils.helper.LogHelper; public class SystemService { private SystemService() { diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java index ad94d22f..8e88a405 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java @@ -121,7 +121,7 @@ public static void main(String[] args) throws Throwable { List classpathURLs = classpath.stream().map(IOHelper::toURL).collect(Collectors.toList()); // Start client with WatchService monitoring RequestService service; - if(params.offlineMode) { + if (params.offlineMode) { service = initOffline(LauncherEngine.modulesManager, params); Request.setRequestService(service); } else { @@ -231,13 +231,13 @@ public static RequestService initOffline(LauncherModulesManager modulesManager, public static void applyClientOfflineProcessors(OfflineRequestService service, ClientLauncherProcess.ClientParams params) { service.registerRequestProcessor(ProfileByUsernameRequest.class, (r) -> { - if(params.playerProfile.username.equals(r.username)) { + if (params.playerProfile.username.equals(r.username)) { return new ProfileByUsernameRequestEvent(params.playerProfile); } throw new RequestException("User not found"); }); service.registerRequestProcessor(ProfileByUUIDRequest.class, (r) -> { - if(params.playerProfile.uuid.equals(r.uuid)) { + if (params.playerProfile.uuid.equals(r.uuid)) { return new ProfileByUUIDRequestEvent(params.playerProfile); } throw new RequestException("User not found"); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java index 93e41298..98e2ba96 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java @@ -3,7 +3,6 @@ import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherConfig; import pro.gravit.launcher.LauncherEngine; -import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.client.events.client.ClientProcessBuilderCreateEvent; import pro.gravit.launcher.client.events.client.ClientProcessBuilderLaunchedEvent; import pro.gravit.launcher.client.events.client.ClientProcessBuilderParamsWrittedEvent; @@ -28,7 +27,6 @@ import java.net.SocketAddress; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.*; import java.util.stream.Collectors; @@ -79,7 +77,7 @@ public ClientLauncherProcess(Path clientDir, Path assetDir, JavaHelper.JavaVersi this.params.resourcePackDir = resourcePackDir.toAbsolutePath().toString(); this.params.assetDir = assetDir.toAbsolutePath().toString(); Path nativesPath = workDir.resolve("natives").resolve(JVMHelper.OS_TYPE.name).resolve(javaVersion.arch.name); - if(!Files.isDirectory(nativesPath)) { + if (!Files.isDirectory(nativesPath)) { nativesPath = workDir.resolve("natives"); } this.params.nativesDir = nativesPath.toString(); @@ -158,7 +156,7 @@ public void start(boolean pipeOutput) throws IOException, InterruptedException { .map(Path::toString) .collect(Collectors.toList())); } - if(Launcher.getConfig().environment != LauncherConfig.LauncherEnvironment.PROD) { + if (Launcher.getConfig().environment != LauncherConfig.LauncherEnvironment.PROD) { processArgs.add(JVMHelper.jvmProperty(LogHelper.DEV_PROPERTY, String.valueOf(LogHelper.isDevEnabled()))); processArgs.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, String.valueOf(LogHelper.isDebugEnabled()))); processArgs.add(JVMHelper.jvmProperty(LogHelper.STACKTRACE_PROPERTY, String.valueOf(LogHelper.isStacktraceEnabled()))); @@ -211,7 +209,7 @@ private void applyJava9Params(List processArgs) { if (modulesAdd.length() > 0) modulesAdd.append(","); modulesAdd.append(moduleName); } - for(String modulePath : jvmModulesPaths) { + for (String modulePath : jvmModulesPaths) { if (modulesPath.length() > 0) modulesPath.append(File.pathSeparator); modulesPath.append(modulePath); } diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java b/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java index 09ef1511..5cea3f32 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java @@ -163,7 +163,7 @@ private Result modernPing(HInput input, HOutput output) throws IOException { // Parse JSON response JsonObject object = JsonParser.parseString(response).getAsJsonObject(); - if(object.has("error")) { + if (object.has("error")) { throw new IOException(object.get("error").getAsString()); } JsonObject playersObject = object.get("players").getAsJsonObject(); diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/ModulesCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/ModulesCommand.java index dc722cd1..69206700 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/console/ModulesCommand.java +++ b/Launcher/src/main/java/pro/gravit/launcher/console/ModulesCommand.java @@ -24,10 +24,10 @@ public String getUsageDescription() { @Override public void invoke(String... args) throws Exception { - for(LauncherModule module : LauncherEngine.modulesManager.getModules()) { + for (LauncherModule module : LauncherEngine.modulesManager.getModules()) { LauncherModuleInfo info = module.getModuleInfo(); LauncherTrustManager.CheckClassResult checkStatus = module.getCheckResult(); - if(!ConsoleManager.isConsoleUnlock) { + if (!ConsoleManager.isConsoleUnlock) { LogHelper.info("[MODULE] %s v: %s", info.name, info.version.getVersionString()); } else { LogHelper.info("[MODULE] %s v: %s p: %d deps: %s sig: %s", info.name, info.version.getVersionString(), info.priority, Arrays.toString(info.dependencies), checkStatus == null ? "null" : checkStatus.type); diff --git a/Launcher/src/main/java/pro/gravit/launcher/debug/DebugMain.java b/Launcher/src/main/java/pro/gravit/launcher/debug/DebugMain.java index 6c03bd9e..c5559229 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/debug/DebugMain.java +++ b/Launcher/src/main/java/pro/gravit/launcher/debug/DebugMain.java @@ -57,7 +57,7 @@ public static void main(String[] args) throws Throwable { ConsoleManager.initConsole(); LauncherEngine.modulesManager.invokeEvent(new PreConfigPhase()); RequestService service; - if(offlineMode) { + if (offlineMode) { OfflineRequestService offlineRequestService = new OfflineRequestService(); LauncherEngine.applyBasicOfflineProcessors(offlineRequestService); OfflineModeEvent event = new OfflineModeEvent(offlineRequestService); diff --git a/Launcher/src/main/java/pro/gravit/launcher/utils/ApiBridgeService.java b/Launcher/src/main/java/pro/gravit/launcher/utils/ApiBridgeService.java index 99c81596..76cb77d9 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/utils/ApiBridgeService.java +++ b/Launcher/src/main/java/pro/gravit/launcher/utils/ApiBridgeService.java @@ -18,7 +18,7 @@ public static void checkCertificatesSuccess(X509Certificate[] certs) throws Exce } public static String findLibrary(ClassLoader classLoader, String library) { - if(classLoader instanceof ClientClassLoader) { + if (classLoader instanceof ClientClassLoader) { ClientClassLoader clientClassLoader = (ClientClassLoader) classLoader; return clientClassLoader.findLibrary(library); } diff --git a/Launcher/src/main/java/pro/gravit/launcher/utils/LauncherUpdater.java b/Launcher/src/main/java/pro/gravit/launcher/utils/LauncherUpdater.java index 0d4f7c50..b4194ab5 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/utils/LauncherUpdater.java +++ b/Launcher/src/main/java/pro/gravit/launcher/utils/LauncherUpdater.java @@ -1,10 +1,8 @@ package pro.gravit.launcher.utils; import pro.gravit.launcher.AsyncDownloader; -import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherEngine; import pro.gravit.launcher.LauncherInject; -import pro.gravit.launcher.events.request.LauncherRequestEvent; import pro.gravit.launcher.request.update.LauncherRequest; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; @@ -13,12 +11,10 @@ import javax.net.ssl.HttpsURLConnection; import java.io.IOException; import java.io.InputStream; -import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.StandardOpenOption; import java.security.KeyManagementException; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; @@ -30,14 +26,16 @@ public class LauncherUpdater { @LauncherInject("launcher.certificatePinning") private static boolean isCertificatePinning; + public static void nothing() { } + private static Path getLauncherPath() { Path pathToCore = IOHelper.getCodeSource(IOHelper.class); Path pathToApi = IOHelper.getCodeSource(LauncherRequest.class); Path pathToSelf = IOHelper.getCodeSource(LauncherUpdater.class); - if(pathToCore.equals(pathToApi) && pathToCore.equals(pathToSelf)) { + if (pathToCore.equals(pathToApi) && pathToCore.equals(pathToSelf)) { return pathToCore; } else { throw new SecurityException("Found split-jar launcher"); diff --git a/Launcher/src/main/java/pro/gravit/launcher/utils/NativeJVMHalt.java b/Launcher/src/main/java/pro/gravit/launcher/utils/NativeJVMHalt.java index df22b64b..3d79d20c 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/utils/NativeJVMHalt.java +++ b/Launcher/src/main/java/pro/gravit/launcher/utils/NativeJVMHalt.java @@ -1,11 +1,8 @@ package pro.gravit.launcher.utils; -import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; import java.lang.reflect.Method; -import java.security.AccessController; -import java.security.PrivilegedAction; public final class NativeJVMHalt { public final int haltCode; @@ -30,7 +27,7 @@ public static void haltA(int code) { exitMethod.invoke(null, code); } catch (Throwable e) { th[1] = e; - if(LogHelper.isDevEnabled()) { + if (LogHelper.isDevEnabled()) { LogHelper.error(e); } }