[REFACTOR] IDEA mini refactor

This commit is contained in:
Gravita 2023-12-23 12:25:11 +07:00
parent dfbb6e507a
commit e6516a8991
33 changed files with 75 additions and 148 deletions

View file

@ -28,15 +28,12 @@
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.JVMHelper;
import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.LogHelper;
import pro.gravit.utils.launch.LaunchOptions;
import pro.gravit.utils.launch.ModuleLaunch;
import java.io.*; import java.io.*;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.security.Security; import java.security.Security;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public class LaunchServerStarter { public class LaunchServerStarter {

View file

@ -1,13 +1,7 @@
package pro.gravit.launchserver; package pro.gravit.launchserver;
import java.io.IOException;
import java.lang.instrument.Instrumentation; import java.lang.instrument.Instrumentation;
import java.nio.file.*; 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 { public final class StarterAgent {

View file

@ -57,7 +57,7 @@ public static void getFeatures(Class<?> clazz, Set<String> list) {
} }
} }
public final <T> T isSupport(Class<T> clazz) { public <T> T isSupport(Class<T> clazz) {
if (core == null) return null; if (core == null) return null;
T result = core.isSupport(clazz); T result = core.isSupport(clazz);
if (result == null && mixes != null) { if (result == null && mixes != null) {
@ -71,7 +71,7 @@ public final <T> T isSupport(Class<T> clazz) {
return result; return result;
} }
public final void init(LaunchServer srv, String name) { public void init(LaunchServer srv, String name) {
this.name = name; this.name = name;
if (links != null) link(srv); if (links != null) link(srv);
core.init(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) -> { links.forEach((k, v) -> {
AuthProviderPair pair = srv.config.getAuthProviderPair(v); AuthProviderPair pair = srv.config.getAuthProviderPair(v);
if (pair == null) { 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(); core.close();
if (textureProvider != null) { if (textureProvider != null) {
textureProvider.close(); textureProvider.close();

View file

@ -332,7 +332,7 @@ public String toString() {
} }
} }
public class MySQLUser extends SQLUser { public static class MySQLUser extends SQLUser {
protected long hwidId; protected long hwidId;
public MySQLUser(UUID uuid, String username, String accessToken, String serverId, String password, ClientPermissions permissions, long hwidId) { public MySQLUser(UUID uuid, String username, String accessToken, String serverId, String password, ClientPermissions permissions, long hwidId) {

View file

@ -1,6 +1,5 @@
package pro.gravit.launchserver.auth.core.interfaces.provider; 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.auth.core.UserSession;
import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.Client;

View file

@ -22,7 +22,7 @@ public boolean allowGetAccessToken(AuthResponse.AuthContext context) {
@Override @Override
public void init(LaunchServer server) { 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'"); logger.warn("profileWhitelist deprecated. Please use permission 'launchserver.profile.PROFILE_UUID.show' and 'launchserver.profile.PROFILE_UUID.enter'");
} }
} }

View file

@ -7,12 +7,10 @@
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Collectors; import java.util.stream.Collectors;

View file

@ -5,7 +5,6 @@
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.binary.tasks.LauncherBuildTask; import pro.gravit.launchserver.binary.tasks.LauncherBuildTask;
import pro.gravit.utils.Version; import pro.gravit.utils.Version;
import pro.gravit.utils.helper.IOHelper;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;

View file

@ -24,7 +24,7 @@ public SaveProfilesCommand(LaunchServer server) {
public static void saveProfile(ClientProfile profile, Path path) throws IOException { public static void saveProfile(ClientProfile profile, Path path) throws IOException {
if (profile.getUUID() == null) profile.setUUID(UUID.randomUUID()); if (profile.getUUID() == null) profile.setUUID(UUID.randomUUID());
if (profile.getServers().size() == 0) { if (profile.getServers().isEmpty()) {
ClientProfile.ServerProfile serverProfile = new ClientProfile.ServerProfile(); ClientProfile.ServerProfile serverProfile = new ClientProfile.ServerProfile();
serverProfile.isDefault = true; serverProfile.isDefault = true;
serverProfile.name = profile.getTitle(); serverProfile.name = profile.getTitle();

View file

@ -142,7 +142,7 @@ public void setEnv(LauncherConfig.LauncherEnvironment env) {
} }
public void verify() { 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"); throw new NullPointerException("AuthProviderPair`s count should be at least one");
} }

View file

@ -2,7 +2,6 @@
import pro.gravit.launcher.ClientPermissions; import pro.gravit.launcher.ClientPermissions;
import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.profiles.ClientProfile;
import pro.gravit.launcher.request.secure.HardwareReportRequest;
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.AuthProviderPair;
import pro.gravit.launchserver.auth.core.interfaces.UserHardware; import pro.gravit.launchserver.auth.core.interfaces.UserHardware;

View file

@ -5,8 +5,6 @@
import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.AuthProviderPair;
import pro.gravit.launchserver.auth.Feature; import pro.gravit.launchserver.auth.Feature;
import java.util.List;
public class FeatureCollectionTest { public class FeatureCollectionTest {
public static class TestClass1 implements TextInterface1 { public static class TestClass1 implements TextInterface1 {

View file

@ -197,18 +197,18 @@ private void applyJava9Params(List<String> processArgs) {
StringBuilder modulesPath = new StringBuilder(); StringBuilder modulesPath = new StringBuilder();
StringBuilder modulesAdd = new StringBuilder(); StringBuilder modulesAdd = new StringBuilder();
for (String moduleName : jvmModules) { for (String moduleName : jvmModules) {
if (modulesAdd.length() > 0) modulesAdd.append(","); if (!modulesAdd.isEmpty()) modulesAdd.append(",");
modulesAdd.append(moduleName); modulesAdd.append(moduleName);
} }
for (String modulePath : jvmModulesPaths) { for (String modulePath : jvmModulesPaths) {
if (modulesPath.length() > 0) modulesPath.append(File.pathSeparator); if (!modulesPath.isEmpty()) modulesPath.append(File.pathSeparator);
modulesPath.append(modulePath); modulesPath.append(modulePath);
} }
if (modulesAdd.length() > 0) { if (!modulesAdd.isEmpty()) {
processArgs.add("--add-modules"); processArgs.add("--add-modules");
processArgs.add(modulesAdd.toString()); processArgs.add(modulesAdd.toString());
} }
if (modulesPath.length() > 0) { if (!modulesPath.isEmpty()) {
processArgs.add("--module-path"); processArgs.add("--module-path");
processArgs.add(modulesPath.toString()); processArgs.add(modulesPath.toString());
} }

View file

@ -41,7 +41,7 @@ public int getProcessorLogicalCount() {
public boolean isBattery() { public boolean isBattery() {
List<PowerSource> powerSources = hardware.getPowerSources(); List<PowerSource> powerSources = hardware.getPowerSources();
return powerSources != null && powerSources.size() != 0; return powerSources != null && !powerSources.isEmpty();
} }
//Hardware Information //Hardware Information
@ -93,7 +93,7 @@ public long getGraphicCardMemory() {
public byte[] getDisplayID() { public byte[] getDisplayID() {
List<Display> displays = hardware.getDisplays(); List<Display> displays = hardware.getDisplays();
if (displays == null || displays.size() == 0) return null; if (displays == null || displays.isEmpty()) return null;
for (Display display : displays) { for (Display display : displays) {
return display.getEdid(); return display.getEdid();
} }

View file

@ -96,7 +96,7 @@ public LauncherConfig(String address, ECPublicKey ecdsaPublicKey, RSAPublicKey r
this.address = address; this.address = address;
this.ecdsaPublicKey = ecdsaPublicKey; this.ecdsaPublicKey = ecdsaPublicKey;
this.rsaPublicKey = rsaPublicKey; this.rsaPublicKey = rsaPublicKey;
this.runtime = Collections.unmodifiableMap(new HashMap<>(runtime)); this.runtime = Map.copyOf(runtime);
this.projectName = projectName; this.projectName = projectName;
this.clientPort = 32148; this.clientPort = 32148;
environment = LauncherEnvironment.STD; environment = LauncherEnvironment.STD;
@ -109,7 +109,7 @@ public LauncherConfig(String address, ECPublicKey ecdsaPublicKey, RSAPublicKey r
public LauncherConfig(String address, Map<String, byte[]> runtime, String projectName, LauncherEnvironment env, LauncherTrustManager trustManager) { public LauncherConfig(String address, Map<String, byte[]> runtime, String projectName, LauncherEnvironment env, LauncherTrustManager trustManager) {
this.address = address; this.address = address;
this.runtime = Collections.unmodifiableMap(new HashMap<>(runtime)); this.runtime = Map.copyOf(runtime);
this.projectName = projectName; this.projectName = projectName;
this.clientPort = 32148; this.clientPort = 32148;
this.trustManager = trustManager; this.trustManager = trustManager;

View file

@ -203,12 +203,12 @@ public static synchronized RequestRestoreReport restore(boolean needUserInfo, bo
} }
RestoreRequestEvent event = request.request(); RestoreRequestEvent event = request.request();
List<String> invalidTokens = null; List<String> invalidTokens = null;
if (event.invalidTokens != null && event.invalidTokens.size() > 0) { if (event.invalidTokens != null && !event.invalidTokens.isEmpty()) {
Map<String, String> tokens = makeNewTokens(event.invalidTokens); Map<String, String> tokens = makeNewTokens(event.invalidTokens);
if (!tokens.isEmpty()) { if (!tokens.isEmpty()) {
request = new RestoreRequest(authId, null, tokens, false); request = new RestoreRequest(authId, null, tokens, false);
event = request.request(); 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)); LogHelper.warning("Tokens %s not restored", String.join(",", event.invalidTokens));
} }
} }

View file

@ -72,8 +72,7 @@ public <T extends WebSocketEvent> void processEventHandlers(T event) {
@SuppressWarnings({"unchecked"}) @SuppressWarnings({"unchecked"})
public <T extends WebSocketEvent> void eventHandle(T webSocketEvent) { public <T extends WebSocketEvent> void eventHandle(T webSocketEvent) {
if (webSocketEvent instanceof RequestEvent) { if (webSocketEvent instanceof RequestEvent event) {
RequestEvent event = (RequestEvent) webSocketEvent;
if (event.requestUUID == null) { if (event.requestUUID == null) {
LogHelper.warning("Request event type %s.requestUUID is null", event.getType() == null ? "null" : event.getType()); LogHelper.warning("Request event type %s.requestUUID is null", event.getType() == null ? "null" : event.getType());
return; return;

View file

@ -51,15 +51,13 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Except
return; return;
} }
if (msg instanceof FullHttpResponse) { if (msg instanceof FullHttpResponse response) {
final FullHttpResponse response = (FullHttpResponse) msg;
throw new Exception("Unexpected FullHttpResponse (getStatus=" + response.status() + ", content=" throw new Exception("Unexpected FullHttpResponse (getStatus=" + response.status() + ", content="
+ response.content().toString(CharsetUtil.UTF_8) + ')'); + response.content().toString(CharsetUtil.UTF_8) + ')');
} }
final WebSocketFrame frame = (WebSocketFrame) msg; final WebSocketFrame frame = (WebSocketFrame) msg;
if (frame instanceof TextWebSocketFrame) { if (frame instanceof TextWebSocketFrame textFrame) {
final TextWebSocketFrame textFrame = (TextWebSocketFrame) frame;
if (LogHelper.isDevEnabled()) { if (LogHelper.isDevEnabled()) {
LogHelper.dev("Message: %s", textFrame.text()); LogHelper.dev("Message: %s", textFrame.text());
} }

View file

@ -28,8 +28,7 @@ public <T extends WebSocketEvent> boolean eventHandle(T event) {
if (token != null) { if (token != null) {
Request.addExtendedToken(event1.getExtendedTokenName(), new Request.ExtendedToken(event1.getExtendedToken(), event1.getExtendedTokenExpire())); Request.addExtendedToken(event1.getExtendedTokenName(), new Request.ExtendedToken(event1.getExtendedToken(), event1.getExtendedTokenExpire()));
} }
} else if (event instanceof NotificationEvent) { } else if (event instanceof NotificationEvent n) {
NotificationEvent n = (NotificationEvent) event;
if (DialogService.isNotificationsAvailable()) { if (DialogService.isNotificationsAvailable()) {
DialogService.createNotification(n.icon, n.head, n.message); DialogService.createNotification(n.icon, n.head, n.message);
} }

View file

@ -78,20 +78,14 @@ private static CheckClassResultApi fromCheckClassResult(LauncherTrustManager.Che
private static CheckClassResultTypeApi fromType(LauncherTrustManager.CheckClassResultType type) { private static CheckClassResultTypeApi fromType(LauncherTrustManager.CheckClassResultType type) {
if (type == null) return null; if (type == null) return null;
switch (type) { return switch (type) {
case NOT_SIGNED: case NOT_SIGNED -> CheckClassResultTypeApi.NOT_SIGNED;
return CheckClassResultTypeApi.NOT_SIGNED; case SUCCESS -> CheckClassResultTypeApi.SUCCESS;
case SUCCESS: case UNTRUSTED -> CheckClassResultTypeApi.UNTRUSTED;
return CheckClassResultTypeApi.SUCCESS; case UNVERIFED -> CheckClassResultTypeApi.UNVERIFED;
case UNTRUSTED: case UNCOMPAT -> CheckClassResultTypeApi.UNCOMPAT;
return CheckClassResultTypeApi.UNTRUSTED; default -> CheckClassResultTypeApi.UNKNOWN;
case UNVERIFED: };
return CheckClassResultTypeApi.UNVERIFED;
case UNCOMPAT:
return CheckClassResultTypeApi.UNCOMPAT;
default:
return CheckClassResultTypeApi.UNKNOWN;
}
} }
} }
} }

View file

@ -34,7 +34,7 @@ public List<LauncherModule> getModules() {
} }
@Override @Override
public final boolean verifyClassCheckResult(LauncherTrustManager.CheckClassResult result) { public boolean verifyClassCheckResult(LauncherTrustManager.CheckClassResult result) {
return result.type == LauncherTrustManager.CheckClassResultType.SUCCESS; return result.type == LauncherTrustManager.CheckClassResultType.SUCCESS;
} }
} }

View file

@ -30,16 +30,11 @@ public HashedDir(HInput input) throws IOException {
// Read entry // Read entry
HashedEntry entry; HashedEntry entry;
Type type = Type.read(input); Type type = Type.read(input);
switch (type) { entry = switch (type) {
case FILE: case FILE -> new HashedFile(input);
entry = new HashedFile(input); case DIR -> new HashedDir(input);
break; default -> throw new AssertionError("Unsupported hashed entry type: " + type.name());
case DIR: };
entry = new HashedDir(input);
break;
default:
throw new AssertionError("Unsupported hashed entry type: " + type.name());
}
// Try add entry to map // Try add entry to map
VerifyHelper.putIfAbsent(map, name, entry, String.format("Duplicate dir entry: '%s'", name)); VerifyHelper.putIfAbsent(map, name, entry, String.format("Duplicate dir entry: '%s'", name));

View file

@ -42,14 +42,11 @@ public BigInteger readBigInteger(int maxBytes) throws IOException {
public boolean readBoolean() throws IOException { public boolean readBoolean() throws IOException {
int b = readUnsignedByte(); int b = readUnsignedByte();
switch (b) { return switch (b) {
case 0b0: case 0b0 -> false;
return false; case 0b1 -> true;
case 0b1: default -> throw new IOException("Invalid boolean state: " + b);
return true; };
default:
throw new IOException("Invalid boolean state: " + b);
}
} }

View file

@ -73,7 +73,7 @@ public static String[] parseCommand(CharSequence line) throws CommandException {
throw new CommandException("Quotes wasn't closed"); throw new CommandException("Quotes wasn't closed");
// Empty args are ignored (except if was quoted) // Empty args are ignored (except if was quoted)
if (wasQuoted || builder.length() > 0) if (wasQuoted || !builder.isEmpty())
result.add(builder.toString()); result.add(builder.toString());
// Reset file builder // Reset file builder

View file

@ -14,17 +14,12 @@ public class FormatHelper {
public static Ansi rawAnsiFormat(LogHelper.Level level, String dateTime, boolean sub) { public static Ansi rawAnsiFormat(LogHelper.Level level, String dateTime, boolean sub) {
Ansi.Color levelColor; Ansi.Color levelColor;
boolean bright = level != LogHelper.Level.DEBUG; boolean bright = level != LogHelper.Level.DEBUG;
switch (level) { levelColor = switch (level) {
case WARNING: case WARNING -> Ansi.Color.YELLOW;
levelColor = Ansi.Color.YELLOW; case ERROR -> Ansi.Color.RED;
break; default -> // INFO, DEBUG, Unknown
case ERROR: Ansi.Color.WHITE;
levelColor = Ansi.Color.RED; };
break;
default: // INFO, DEBUG, Unknown
levelColor = Ansi.Color.WHITE;
break;
}
// Date-time // Date-time
Ansi ansi = new Ansi(); Ansi ansi = new Ansi();

View file

@ -3,8 +3,6 @@
import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.function.Consumer;
public class HackHelper { public class HackHelper {
private static native MethodHandles.Lookup createHackLookupNative(Class<?> lookupClass); private static native MethodHandles.Lookup createHackLookupNative(Class<?> lookupClass);

View file

@ -138,17 +138,13 @@ public static String getIP(SocketAddress address) {
} }
public static Path getRoot() { public static Path getRoot() {
switch (JVMHelper.OS_TYPE) { return switch (JVMHelper.OS_TYPE) {
case MUSTDIE: { case MUSTDIE -> {
String drive = System.getenv("SystemDrive").concat("\\"); String drive = System.getenv("SystemDrive").concat("\\");
return Paths.get(drive); yield Paths.get(drive);
} }
case LINUX: case LINUX, MACOSX -> Paths.get("/");
case MACOSX: { };
return Paths.get("/");
}
}
throw new UnsupportedOperationException();
} }
public static byte[] getResourceBytes(String name) throws IOException { 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) { public static String urlDecode(String s) {
try { return URLDecoder.decode(s, UNICODE_CHARSET);
return URLDecoder.decode(s, UNICODE_CHARSET.name());
} catch (UnsupportedEncodingException e) {
throw new InternalError(e);
}
} }
public static String urlEncode(String s) { public static String urlEncode(String s) {
try { return URLEncoder.encode(s, UNICODE_CHARSET);
return URLEncoder.encode(s, UNICODE_CHARSET.name());
} catch (UnsupportedEncodingException e) {
throw new InternalError(e);
}
} }
public static String verifyFileName(String fileName) { public static String verifyFileName(String fileName) {

View file

@ -62,26 +62,19 @@ public static int getBuild() {
} }
public static String getNativeExtension(JVMHelper.OS OS_TYPE) { public static String getNativeExtension(JVMHelper.OS OS_TYPE) {
switch (OS_TYPE) { return switch (OS_TYPE) {
case MUSTDIE: case MUSTDIE -> ".dll";
return ".dll"; case LINUX -> ".so";
case LINUX: case MACOSX -> ".dylib";
return ".so"; default -> throw new InternalError(String.format("Unsupported OS TYPE '%s'", OS_TYPE));
case MACOSX: };
return ".dylib";
default:
throw new InternalError(String.format("Unsupported OS TYPE '%s'", OS_TYPE));
}
} }
public static String getNativePrefix(JVMHelper.OS OS_TYPE) { public static String getNativePrefix(JVMHelper.OS OS_TYPE) {
switch (OS_TYPE) { return switch (OS_TYPE) {
case LINUX: case LINUX, MACOSX -> "lib";
case MACOSX: default -> "";
return "lib"; };
default:
return "";
}
} }
public static void appendVars(ProcessBuilder builder, Map<String, String> vars) { public static void appendVars(ProcessBuilder builder, Map<String, String> vars) {

View file

@ -13,15 +13,7 @@ public class JavaHelper {
public static final List<String> javaFxModules; public static final List<String> javaFxModules;
static { static {
List<String> modules = new ArrayList<>(); javaFxModules = List.of("javafx.base", "javafx.graphics", "javafx.fxml", "javafx.controls", "javafx.swing", "javafx.media", "javafx.web");
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);
} }
public static Path tryGetOpenJFXPath(Path jvmDir) { public static Path tryGetOpenJFXPath(Path jvmDir) {
@ -60,7 +52,7 @@ public static boolean tryAddModule(List<Path> paths, String moduleName, StringBu
if (path == null) continue; if (path == null) continue;
Path result = tryFindModule(path, moduleName); Path result = tryFindModule(path, moduleName);
if (result != null) { if (result != null) {
if (args.length() != 0) args.append(File.pathSeparatorChar); if (!args.isEmpty()) args.append(File.pathSeparatorChar);
args.append(result.toAbsolutePath()); args.append(result.toAbsolutePath());
return true; return true;
} }

View file

@ -78,9 +78,7 @@ public static Downloader downloadFile(URI uri, Path path, ExecutorService execut
downloader.future = downloader.downloadFile(uri, path); downloader.future = downloader.downloadFile(uri, path);
if (closeExecutor) { if (closeExecutor) {
ExecutorService finalExecutor = executor; ExecutorService finalExecutor = executor;
downloader.future = downloader.future.thenAccept((e) -> { downloader.future = downloader.future.thenAccept((e) -> finalExecutor.shutdownNow()).exceptionallyCompose((ex) -> {
finalExecutor.shutdownNow();
}).exceptionallyCompose((ex) -> {
finalExecutor.shutdownNow(); finalExecutor.shutdownNow();
return CompletableFuture.failedFuture(ex); return CompletableFuture.failedFuture(ex);
}); });
@ -99,9 +97,7 @@ public static Downloader downloadList(List<SizedFile> files, String baseURL, Pat
downloader.future = downloader.downloadFiles(files, baseURL, targetDir, callback, executor, threads); downloader.future = downloader.downloadFiles(files, baseURL, targetDir, callback, executor, threads);
if (closeExecutor) { if (closeExecutor) {
ExecutorService finalExecutor = executor; ExecutorService finalExecutor = executor;
downloader.future = downloader.future.thenAccept((e) -> { downloader.future = downloader.future.thenAccept((e) -> finalExecutor.shutdownNow()).exceptionallyCompose((ex) -> {
finalExecutor.shutdownNow();
}).exceptionallyCompose((ex) -> {
finalExecutor.shutdownNow(); finalExecutor.shutdownNow();
return CompletableFuture.failedFuture(ex); return CompletableFuture.failedFuture(ex);
}); });

View file

@ -34,7 +34,7 @@ public List<LauncherModule> getModules() {
} }
@Override @Override
public final boolean verifyClassCheckResult(LauncherTrustManager.CheckClassResult result) { public boolean verifyClassCheckResult(LauncherTrustManager.CheckClassResult result) {
return result.type == LauncherTrustManager.CheckClassResultType.SUCCESS; return result.type == LauncherTrustManager.CheckClassResultType.SUCCESS;
} }

View file

@ -122,8 +122,7 @@ public void run(String... args) throws Throwable {
LogHelper.debug("Read ServerWrapperConfig.json"); LogHelper.debug("Read ServerWrapperConfig.json");
loadConfig(); loadConfig();
updateLauncherConfig(); updateLauncherConfig();
if (config.env != null) Launcher.applyLauncherEnv(config.env); Launcher.applyLauncherEnv(Objects.requireNonNullElse(config.env, LauncherConfig.LauncherEnvironment.STD));
else Launcher.applyLauncherEnv(LauncherConfig.LauncherEnvironment.STD);
StdWebSocketService service = StdWebSocketService.initWebSockets(config.address).get(); StdWebSocketService service = StdWebSocketService.initWebSockets(config.address).get();
service.reconnectCallback = () -> service.reconnectCallback = () ->
{ {
@ -153,7 +152,7 @@ public void run(String... args) throws Throwable {
KeyService.serverEcPublicKey = SecurityHelper.toPublicECDSAKey(config.encodedServerEcPublicKey); KeyService.serverEcPublicKey = SecurityHelper.toPublicECDSAKey(config.encodedServerEcPublicKey);
} }
String classname = (config.mainclass == null || config.mainclass.isEmpty()) ? args[0] : config.mainclass; 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"); LogHelper.error("MainClass not found. Please set MainClass for ServerWrapper.json or first commandline argument");
System.exit(-1); 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("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()); LogHelper.info("Minecraft Version (for profile): %s", wrapper.profile == null ? "unknown" : wrapper.profile.getVersion().toString());
String[] real_args; 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]); real_args = config.args.toArray(new String[0]);
} else if (args.length > 0) { } else if (args.length > 0) {
real_args = new String[args.length - 1]; real_args = new String[args.length - 1];

View file

@ -41,7 +41,7 @@ public void run(String... args) throws Exception {
} }
context.workdir = IOHelper.WORKING_DIR; context.workdir = IOHelper.WORKING_DIR;
LogHelper.info("Search .jar files in %s", context.workdir.toAbsolutePath()); LogHelper.info("Search .jar files in %s", context.workdir.toAbsolutePath());
IOHelper.walk(context.workdir, new SimpleFileVisitor<Path>() { IOHelper.walk(context.workdir, new SimpleFileVisitor<>() {
@Override @Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
if (file.getFileName().toString().endsWith(".jar")) { if (file.getFileName().toString().endsWith(".jar")) {