diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index 57d87cf3..e7b93168 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -28,15 +28,12 @@ import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; -import pro.gravit.utils.launch.LaunchOptions; -import pro.gravit.utils.launch.ModuleLaunch; import java.io.*; import java.nio.file.Files; import java.nio.file.Path; import java.security.Security; import java.security.cert.CertificateException; -import java.util.ArrayList; import java.util.List; public class LaunchServerStarter { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/StarterAgent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/StarterAgent.java index 2809eac6..484d754e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/StarterAgent.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/StarterAgent.java @@ -1,13 +1,7 @@ package pro.gravit.launchserver; -import java.io.IOException; import java.lang.instrument.Instrumentation; import java.nio.file.*; -import java.nio.file.attribute.BasicFileAttributes; -import java.nio.file.attribute.PosixFileAttributeView; -import java.nio.file.attribute.PosixFilePermission; -import java.util.*; -import java.util.jar.JarFile; public final class StarterAgent { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java index 9645fa01..72c198f2 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java @@ -57,7 +57,7 @@ public static void getFeatures(Class clazz, Set list) { } } - public final T isSupport(Class clazz) { + public T isSupport(Class clazz) { if (core == null) return null; T result = core.isSupport(clazz); if (result == null && mixes != null) { @@ -71,7 +71,7 @@ public final T isSupport(Class clazz) { return result; } - public final void init(LaunchServer srv, String name) { + public void init(LaunchServer srv, String name) { this.name = name; if (links != null) link(srv); core.init(srv); @@ -85,7 +85,7 @@ public final void init(LaunchServer srv, String name) { } } - public final void link(LaunchServer srv) { + public void link(LaunchServer srv) { links.forEach((k, v) -> { AuthProviderPair pair = srv.config.getAuthProviderPair(v); if (pair == null) { @@ -99,7 +99,7 @@ public final void link(LaunchServer srv) { }); } - public final void close() throws IOException { + public void close() throws IOException { core.close(); if (textureProvider != null) { textureProvider.close(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java index ce093a2e..c5ed101a 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java @@ -332,7 +332,7 @@ public String toString() { } } - public class MySQLUser extends SQLUser { + public static class MySQLUser extends SQLUser { protected long hwidId; public MySQLUser(UUID uuid, String username, String accessToken, String serverId, String password, ClientPermissions permissions, long hwidId) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportExtendedCheckServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportExtendedCheckServer.java index fb188782..a0eb8365 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportExtendedCheckServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportExtendedCheckServer.java @@ -1,6 +1,5 @@ package pro.gravit.launchserver.auth.core.interfaces.provider; -import pro.gravit.launchserver.auth.core.User; import pro.gravit.launchserver.auth.core.UserSession; import pro.gravit.launchserver.socket.Client; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/StdProtectHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/StdProtectHandler.java index 1b34b7ac..1188dcab 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/StdProtectHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/StdProtectHandler.java @@ -22,7 +22,7 @@ public boolean allowGetAccessToken(AuthResponse.AuthContext context) { @Override public void init(LaunchServer server) { - if (profileWhitelist != null && profileWhitelist.size() > 0) { + if (profileWhitelist != null && !profileWhitelist.isEmpty()) { logger.warn("profileWhitelist deprecated. Please use permission 'launchserver.profile.PROFILE_UUID.show' and 'launchserver.profile.PROFILE_UUID.enter'"); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BinaryPipeline.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BinaryPipeline.java index dec8e0e2..86fbf9c3 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BinaryPipeline.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BinaryPipeline.java @@ -7,12 +7,10 @@ import pro.gravit.utils.helper.IOHelper; import java.io.IOException; -import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Optional; -import java.util.concurrent.atomic.AtomicLong; import java.util.function.Predicate; import java.util.stream.Collectors; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java index 51197ee1..f9390719 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java @@ -5,7 +5,6 @@ import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.binary.tasks.LauncherBuildTask; import pro.gravit.utils.Version; -import pro.gravit.utils.helper.IOHelper; import java.io.IOException; import java.nio.file.Path; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SaveProfilesCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SaveProfilesCommand.java index 151011ba..c4609883 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SaveProfilesCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SaveProfilesCommand.java @@ -24,7 +24,7 @@ public SaveProfilesCommand(LaunchServer server) { public static void saveProfile(ClientProfile profile, Path path) throws IOException { if (profile.getUUID() == null) profile.setUUID(UUID.randomUUID()); - if (profile.getServers().size() == 0) { + if (profile.getServers().isEmpty()) { ClientProfile.ServerProfile serverProfile = new ClientProfile.ServerProfile(); serverProfile.isDefault = true; serverProfile.name = profile.getTitle(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java index 502889f8..8f01b866 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -142,7 +142,7 @@ public void setEnv(LauncherConfig.LauncherEnvironment env) { } public void verify() { - if (auth == null || auth.size() < 1) { + if (auth == null || auth.isEmpty()) { throw new NullPointerException("AuthProviderPair`s count should be at least one"); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java index 3853bf93..32b4fdf4 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java @@ -2,7 +2,6 @@ import pro.gravit.launcher.ClientPermissions; import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.request.secure.HardwareReportRequest; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.core.interfaces.UserHardware; diff --git a/LaunchServer/src/test/java/pro/gravit/launchserver/FeatureCollectionTest.java b/LaunchServer/src/test/java/pro/gravit/launchserver/FeatureCollectionTest.java index f222f818..670d95a2 100644 --- a/LaunchServer/src/test/java/pro/gravit/launchserver/FeatureCollectionTest.java +++ b/LaunchServer/src/test/java/pro/gravit/launchserver/FeatureCollectionTest.java @@ -5,8 +5,6 @@ import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.Feature; -import java.util.List; - public class FeatureCollectionTest { public static class TestClass1 implements TextInterface1 { diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/runtime/client/ClientLauncherProcess.java b/Launcher/src/main/java/pro/gravit/launcher/client/runtime/client/ClientLauncherProcess.java index 3942d933..29239476 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/runtime/client/ClientLauncherProcess.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/runtime/client/ClientLauncherProcess.java @@ -197,18 +197,18 @@ private void applyJava9Params(List processArgs) { StringBuilder modulesPath = new StringBuilder(); StringBuilder modulesAdd = new StringBuilder(); for (String moduleName : jvmModules) { - if (modulesAdd.length() > 0) modulesAdd.append(","); + if (!modulesAdd.isEmpty()) modulesAdd.append(","); modulesAdd.append(moduleName); } for (String modulePath : jvmModulesPaths) { - if (modulesPath.length() > 0) modulesPath.append(File.pathSeparator); + if (!modulesPath.isEmpty()) modulesPath.append(File.pathSeparator); modulesPath.append(modulePath); } - if (modulesAdd.length() > 0) { + if (!modulesAdd.isEmpty()) { processArgs.add("--add-modules"); processArgs.add(modulesAdd.toString()); } - if (modulesPath.length() > 0) { + if (!modulesPath.isEmpty()) { processArgs.add("--module-path"); processArgs.add(modulesPath.toString()); } diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/runtime/utils/HWIDProvider.java b/Launcher/src/main/java/pro/gravit/launcher/client/runtime/utils/HWIDProvider.java index 31e7b261..4e1c8d4c 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/runtime/utils/HWIDProvider.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/runtime/utils/HWIDProvider.java @@ -41,7 +41,7 @@ public int getProcessorLogicalCount() { public boolean isBattery() { List powerSources = hardware.getPowerSources(); - return powerSources != null && powerSources.size() != 0; + return powerSources != null && !powerSources.isEmpty(); } //Hardware Information @@ -93,7 +93,7 @@ public long getGraphicCardMemory() { public byte[] getDisplayID() { List displays = hardware.getDisplays(); - if (displays == null || displays.size() == 0) return null; + if (displays == null || displays.isEmpty()) return null; for (Display display : displays) { return display.getEdid(); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java index 19e26ccd..4b923236 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java @@ -96,7 +96,7 @@ public LauncherConfig(String address, ECPublicKey ecdsaPublicKey, RSAPublicKey r this.address = address; this.ecdsaPublicKey = ecdsaPublicKey; this.rsaPublicKey = rsaPublicKey; - this.runtime = Collections.unmodifiableMap(new HashMap<>(runtime)); + this.runtime = Map.copyOf(runtime); this.projectName = projectName; this.clientPort = 32148; environment = LauncherEnvironment.STD; @@ -109,7 +109,7 @@ public LauncherConfig(String address, ECPublicKey ecdsaPublicKey, RSAPublicKey r public LauncherConfig(String address, Map runtime, String projectName, LauncherEnvironment env, LauncherTrustManager trustManager) { this.address = address; - this.runtime = Collections.unmodifiableMap(new HashMap<>(runtime)); + this.runtime = Map.copyOf(runtime); this.projectName = projectName; this.clientPort = 32148; this.trustManager = trustManager; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java index 991a638d..593e309b 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java @@ -203,12 +203,12 @@ public static synchronized RequestRestoreReport restore(boolean needUserInfo, bo } RestoreRequestEvent event = request.request(); List invalidTokens = null; - if (event.invalidTokens != null && event.invalidTokens.size() > 0) { + if (event.invalidTokens != null && !event.invalidTokens.isEmpty()) { Map tokens = makeNewTokens(event.invalidTokens); if (!tokens.isEmpty()) { request = new RestoreRequest(authId, null, tokens, false); event = request.request(); - if (event.invalidTokens != null && event.invalidTokens.size() > 0) { + if (event.invalidTokens != null && !event.invalidTokens.isEmpty()) { LogHelper.warning("Tokens %s not restored", String.join(",", event.invalidTokens)); } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StdWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StdWebSocketService.java index 1ee786f8..c4946129 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StdWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StdWebSocketService.java @@ -72,8 +72,7 @@ public void processEventHandlers(T event) { @SuppressWarnings({"unchecked"}) public void eventHandle(T webSocketEvent) { - if (webSocketEvent instanceof RequestEvent) { - RequestEvent event = (RequestEvent) webSocketEvent; + if (webSocketEvent instanceof RequestEvent event) { if (event.requestUUID == null) { LogHelper.warning("Request event type %s.requestUUID is null", event.getType() == null ? "null" : event.getType()); return; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WebSocketClientHandler.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WebSocketClientHandler.java index 1fa99c11..99739729 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WebSocketClientHandler.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WebSocketClientHandler.java @@ -51,15 +51,13 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Except return; } - if (msg instanceof FullHttpResponse) { - final FullHttpResponse response = (FullHttpResponse) msg; + if (msg instanceof FullHttpResponse response) { throw new Exception("Unexpected FullHttpResponse (getStatus=" + response.status() + ", content=" + response.content().toString(CharsetUtil.UTF_8) + ')'); } final WebSocketFrame frame = (WebSocketFrame) msg; - if (frame instanceof TextWebSocketFrame) { - final TextWebSocketFrame textFrame = (TextWebSocketFrame) frame; + if (frame instanceof TextWebSocketFrame textFrame) { if (LogHelper.isDevEnabled()) { LogHelper.dev("Message: %s", textFrame.text()); } diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/client/BasicLauncherEventHandler.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/BasicLauncherEventHandler.java index aea92c9d..8b36651f 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/client/BasicLauncherEventHandler.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/BasicLauncherEventHandler.java @@ -28,8 +28,7 @@ public boolean eventHandle(T event) { if (token != null) { Request.addExtendedToken(event1.getExtendedTokenName(), new Request.ExtendedToken(event1.getExtendedToken(), event1.getExtendedTokenExpire())); } - } else if (event instanceof NotificationEvent) { - NotificationEvent n = (NotificationEvent) event; + } else if (event instanceof NotificationEvent n) { if (DialogService.isNotificationsAvailable()) { DialogService.createNotification(n.icon, n.head, n.message); } diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/client/api/CertificateService.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/api/CertificateService.java index 1bfbe960..222c8de6 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/client/api/CertificateService.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/api/CertificateService.java @@ -78,20 +78,14 @@ private static CheckClassResultApi fromCheckClassResult(LauncherTrustManager.Che private static CheckClassResultTypeApi fromType(LauncherTrustManager.CheckClassResultType type) { if (type == null) return null; - switch (type) { - case NOT_SIGNED: - return CheckClassResultTypeApi.NOT_SIGNED; - case SUCCESS: - return CheckClassResultTypeApi.SUCCESS; - case UNTRUSTED: - return CheckClassResultTypeApi.UNTRUSTED; - case UNVERIFED: - return CheckClassResultTypeApi.UNVERIFED; - case UNCOMPAT: - return CheckClassResultTypeApi.UNCOMPAT; - default: - return CheckClassResultTypeApi.UNKNOWN; - } + return switch (type) { + case NOT_SIGNED -> CheckClassResultTypeApi.NOT_SIGNED; + case SUCCESS -> CheckClassResultTypeApi.SUCCESS; + case UNTRUSTED -> CheckClassResultTypeApi.UNTRUSTED; + case UNVERIFED -> CheckClassResultTypeApi.UNVERIFED; + case UNCOMPAT -> CheckClassResultTypeApi.UNCOMPAT; + default -> CheckClassResultTypeApi.UNKNOWN; + }; } } } diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/client/runtime/client/ClientModuleManager.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/runtime/client/ClientModuleManager.java index 046cbc33..e89b8af5 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/client/runtime/client/ClientModuleManager.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/runtime/client/ClientModuleManager.java @@ -34,7 +34,7 @@ public List getModules() { } @Override - public final boolean verifyClassCheckResult(LauncherTrustManager.CheckClassResult result) { + public boolean verifyClassCheckResult(LauncherTrustManager.CheckClassResult result) { return result.type == LauncherTrustManager.CheckClassResultType.SUCCESS; } } diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/core/hasher/HashedDir.java b/LauncherCore/src/main/java/pro/gravit/launcher/core/hasher/HashedDir.java index 14ed4211..232e98ce 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/core/hasher/HashedDir.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/core/hasher/HashedDir.java @@ -30,16 +30,11 @@ public HashedDir(HInput input) throws IOException { // Read entry HashedEntry entry; Type type = Type.read(input); - switch (type) { - case FILE: - entry = new HashedFile(input); - break; - case DIR: - entry = new HashedDir(input); - break; - default: - throw new AssertionError("Unsupported hashed entry type: " + type.name()); - } + entry = switch (type) { + case FILE -> new HashedFile(input); + case DIR -> new HashedDir(input); + default -> throw new AssertionError("Unsupported hashed entry type: " + type.name()); + }; // Try add entry to map VerifyHelper.putIfAbsent(map, name, entry, String.format("Duplicate dir entry: '%s'", name)); diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/core/serialize/HInput.java b/LauncherCore/src/main/java/pro/gravit/launcher/core/serialize/HInput.java index 9ee4e103..5b8161a7 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/core/serialize/HInput.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/core/serialize/HInput.java @@ -42,14 +42,11 @@ public BigInteger readBigInteger(int maxBytes) throws IOException { public boolean readBoolean() throws IOException { int b = readUnsignedByte(); - switch (b) { - case 0b0: - return false; - case 0b1: - return true; - default: - throw new IOException("Invalid boolean state: " + b); - } + return switch (b) { + case 0b0 -> false; + case 0b1 -> true; + default -> throw new IOException("Invalid boolean state: " + b); + }; } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/CommonHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/CommonHelper.java index ccaeb8ea..1d5d7ac9 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/CommonHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/CommonHelper.java @@ -73,7 +73,7 @@ public static String[] parseCommand(CharSequence line) throws CommandException { throw new CommandException("Quotes wasn't closed"); // Empty args are ignored (except if was quoted) - if (wasQuoted || builder.length() > 0) + if (wasQuoted || !builder.isEmpty()) result.add(builder.toString()); // Reset file builder diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/FormatHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/FormatHelper.java index 9043f27d..a69e0f73 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/FormatHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/FormatHelper.java @@ -14,17 +14,12 @@ public class FormatHelper { public static Ansi rawAnsiFormat(LogHelper.Level level, String dateTime, boolean sub) { Ansi.Color levelColor; boolean bright = level != LogHelper.Level.DEBUG; - switch (level) { - case WARNING: - levelColor = Ansi.Color.YELLOW; - break; - case ERROR: - levelColor = Ansi.Color.RED; - break; - default: // INFO, DEBUG, Unknown - levelColor = Ansi.Color.WHITE; - break; - } + levelColor = switch (level) { + case WARNING -> Ansi.Color.YELLOW; + case ERROR -> Ansi.Color.RED; + default -> // INFO, DEBUG, Unknown + Ansi.Color.WHITE; + }; // Date-time Ansi ansi = new Ansi(); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/HackHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/HackHelper.java index 8be8d890..21acd3d4 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/HackHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/HackHelper.java @@ -3,8 +3,6 @@ import java.lang.invoke.MethodHandles; import java.lang.reflect.Constructor; import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.function.Consumer; public class HackHelper { private static native MethodHandles.Lookup createHackLookupNative(Class lookupClass); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java index 4151dc98..0c8425de 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java @@ -138,17 +138,13 @@ public static String getIP(SocketAddress address) { } public static Path getRoot() { - switch (JVMHelper.OS_TYPE) { - case MUSTDIE: { + return switch (JVMHelper.OS_TYPE) { + case MUSTDIE -> { String drive = System.getenv("SystemDrive").concat("\\"); - return Paths.get(drive); + yield Paths.get(drive); } - case LINUX: - case MACOSX: { - return Paths.get("/"); - } - } - throw new UnsupportedOperationException(); + case LINUX, MACOSX -> Paths.get("/"); + }; } public static byte[] getResourceBytes(String name) throws IOException { @@ -545,19 +541,11 @@ public static void transfer(Path file, OutputStream output) throws IOException { } public static String urlDecode(String s) { - try { - return URLDecoder.decode(s, UNICODE_CHARSET.name()); - } catch (UnsupportedEncodingException e) { - throw new InternalError(e); - } + return URLDecoder.decode(s, UNICODE_CHARSET); } public static String urlEncode(String s) { - try { - return URLEncoder.encode(s, UNICODE_CHARSET.name()); - } catch (UnsupportedEncodingException e) { - throw new InternalError(e); - } + return URLEncoder.encode(s, UNICODE_CHARSET); } public static String verifyFileName(String fileName) { diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java index d2779207..a7cdb354 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java @@ -62,26 +62,19 @@ public static int getBuild() { } public static String getNativeExtension(JVMHelper.OS OS_TYPE) { - switch (OS_TYPE) { - case MUSTDIE: - return ".dll"; - case LINUX: - return ".so"; - case MACOSX: - return ".dylib"; - default: - throw new InternalError(String.format("Unsupported OS TYPE '%s'", OS_TYPE)); - } + return switch (OS_TYPE) { + case MUSTDIE -> ".dll"; + case LINUX -> ".so"; + case MACOSX -> ".dylib"; + default -> throw new InternalError(String.format("Unsupported OS TYPE '%s'", OS_TYPE)); + }; } public static String getNativePrefix(JVMHelper.OS OS_TYPE) { - switch (OS_TYPE) { - case LINUX: - case MACOSX: - return "lib"; - default: - return ""; - } + return switch (OS_TYPE) { + case LINUX, MACOSX -> "lib"; + default -> ""; + }; } public static void appendVars(ProcessBuilder builder, Map vars) { diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/JavaHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/JavaHelper.java index a4d1f58f..2bfb54cf 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/JavaHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/JavaHelper.java @@ -13,15 +13,7 @@ public class JavaHelper { public static final List javaFxModules; static { - List modules = new ArrayList<>(); - modules.add("javafx.base"); - modules.add("javafx.graphics"); - modules.add("javafx.fxml"); - modules.add("javafx.controls"); - modules.add("javafx.swing"); - modules.add("javafx.media"); - modules.add("javafx.web"); - javaFxModules = Collections.unmodifiableList(modules); + javaFxModules = List.of("javafx.base", "javafx.graphics", "javafx.fxml", "javafx.controls", "javafx.swing", "javafx.media", "javafx.web"); } public static Path tryGetOpenJFXPath(Path jvmDir) { @@ -60,7 +52,7 @@ public static boolean tryAddModule(List paths, String moduleName, StringBu if (path == null) continue; Path result = tryFindModule(path, moduleName); if (result != null) { - if (args.length() != 0) args.append(File.pathSeparatorChar); + if (!args.isEmpty()) args.append(File.pathSeparatorChar); args.append(result.toAbsolutePath()); return true; } diff --git a/LauncherModernCore/src/main/java/pro/gravit/launcher/modern/Downloader.java b/LauncherModernCore/src/main/java/pro/gravit/launcher/modern/Downloader.java index 9ab8fae7..1d7e052d 100644 --- a/LauncherModernCore/src/main/java/pro/gravit/launcher/modern/Downloader.java +++ b/LauncherModernCore/src/main/java/pro/gravit/launcher/modern/Downloader.java @@ -78,9 +78,7 @@ public static Downloader downloadFile(URI uri, Path path, ExecutorService execut downloader.future = downloader.downloadFile(uri, path); if (closeExecutor) { ExecutorService finalExecutor = executor; - downloader.future = downloader.future.thenAccept((e) -> { - finalExecutor.shutdownNow(); - }).exceptionallyCompose((ex) -> { + downloader.future = downloader.future.thenAccept((e) -> finalExecutor.shutdownNow()).exceptionallyCompose((ex) -> { finalExecutor.shutdownNow(); return CompletableFuture.failedFuture(ex); }); @@ -99,9 +97,7 @@ public static Downloader downloadList(List files, String baseURL, Pat downloader.future = downloader.downloadFiles(files, baseURL, targetDir, callback, executor, threads); if (closeExecutor) { ExecutorService finalExecutor = executor; - downloader.future = downloader.future.thenAccept((e) -> { - finalExecutor.shutdownNow(); - }).exceptionallyCompose((ex) -> { + downloader.future = downloader.future.thenAccept((e) -> finalExecutor.shutdownNow()).exceptionallyCompose((ex) -> { finalExecutor.shutdownNow(); return CompletableFuture.failedFuture(ex); }); diff --git a/LauncherStart/src/main/java/pro/gravit/launcher/start/RuntimeModuleManager.java b/LauncherStart/src/main/java/pro/gravit/launcher/start/RuntimeModuleManager.java index 597d086b..8f5a350c 100644 --- a/LauncherStart/src/main/java/pro/gravit/launcher/start/RuntimeModuleManager.java +++ b/LauncherStart/src/main/java/pro/gravit/launcher/start/RuntimeModuleManager.java @@ -34,7 +34,7 @@ public List getModules() { } @Override - public final boolean verifyClassCheckResult(LauncherTrustManager.CheckClassResult result) { + public boolean verifyClassCheckResult(LauncherTrustManager.CheckClassResult result) { return result.type == LauncherTrustManager.CheckClassResultType.SUCCESS; } diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java index 596dfdf2..77faaa45 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java @@ -122,8 +122,7 @@ public void run(String... args) throws Throwable { LogHelper.debug("Read ServerWrapperConfig.json"); loadConfig(); updateLauncherConfig(); - if (config.env != null) Launcher.applyLauncherEnv(config.env); - else Launcher.applyLauncherEnv(LauncherConfig.LauncherEnvironment.STD); + Launcher.applyLauncherEnv(Objects.requireNonNullElse(config.env, LauncherConfig.LauncherEnvironment.STD)); StdWebSocketService service = StdWebSocketService.initWebSockets(config.address).get(); service.reconnectCallback = () -> { @@ -153,7 +152,7 @@ public void run(String... args) throws Throwable { KeyService.serverEcPublicKey = SecurityHelper.toPublicECDSAKey(config.encodedServerEcPublicKey); } String classname = (config.mainclass == null || config.mainclass.isEmpty()) ? args[0] : config.mainclass; - if (classname.length() == 0) { + if (classname.isEmpty()) { LogHelper.error("MainClass not found. Please set MainClass for ServerWrapper.json or first commandline argument"); System.exit(-1); } @@ -174,7 +173,7 @@ public void run(String... args) throws Throwable { LogHelper.info("ServerWrapper: LaunchServer address: %s. Title: %s", config.address, Launcher.profile != null ? Launcher.profile.getTitle() : "unknown"); LogHelper.info("Minecraft Version (for profile): %s", wrapper.profile == null ? "unknown" : wrapper.profile.getVersion().toString()); String[] real_args; - if(config.args != null && config.args.size() > 0) { + if(config.args != null && !config.args.isEmpty()) { real_args = config.args.toArray(new String[0]); } else if (args.length > 0) { real_args = new String[args.length - 1]; diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/authlib/InstallAuthlib.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/authlib/InstallAuthlib.java index aa6fdbef..3cdf6d22 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/authlib/InstallAuthlib.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/authlib/InstallAuthlib.java @@ -41,10 +41,10 @@ public void run(String... args) throws Exception { } context.workdir = IOHelper.WORKING_DIR; LogHelper.info("Search .jar files in %s", context.workdir.toAbsolutePath()); - IOHelper.walk(context.workdir, new SimpleFileVisitor() { + IOHelper.walk(context.workdir, new SimpleFileVisitor<>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { - if(file.getFileName().toString().endsWith(".jar")) { + if (file.getFileName().toString().endsWith(".jar")) { context.files.add(file); } return FileVisitResult.CONTINUE;