Don't use Optional<T> for parameters

This commit is contained in:
Johannes Frohnmeyer 2021-12-16 18:09:15 +01:00
parent c53b60bf18
commit 320ffac699
Signed by: Johannes
GPG Key ID: E76429612C2929F4
4 changed files with 12 additions and 11 deletions

View File

@ -46,7 +46,7 @@ if (flavor == 'custom') {
dependencies {
implementation 'com.google.code.gson:gson:2.8.9'
implementation 'org.slf4j:slf4j-api:1.7.32'
implementation 'ch.qos.logback:logback-classic:1.2.7'
implementation 'ch.qos.logback:logback-classic:1.2.8'
implementation 'org.eclipse.jgit:org.eclipse.jgit:6.0.0.202111291000-r'
implementation project(":wrapper")

View File

@ -85,7 +85,7 @@ public class LaunchCommand extends Command {
}
if (server) {
try {
InstanceLauncher.launch(instanceDir, instance, InstanceLauncher.LaunchType.Server, restart, Optional.empty());
InstanceLauncher.launch(instanceDir, instance, InstanceLauncher.LaunchType.Server, restart, AccountManager.NULL_AUTH);
} catch (InstanceLauncher.LaunchException | IOException e) {
Inceptum.showError("Could not launch instance", e);
}

View File

@ -7,7 +7,6 @@ import io.gitlab.jfronny.inceptum.util.api.account.AuthInfo;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Optional;
public class ClientLauncher {
public static void launch(Path path, InstanceMeta instance) {
@ -36,7 +35,7 @@ public class ClientLauncher {
private static void launchI(Path path, InstanceMeta instance, AuthInfo authInfo) {
try {
InstanceLauncher.launch(path, instance, InstanceLauncher.LaunchType.Client, false, Optional.of(authInfo));
InstanceLauncher.launch(path, instance, InstanceLauncher.LaunchType.Client, false, authInfo);
} catch (InstanceLauncher.LaunchException | IOException e) {
Inceptum.showError("Could not launch client", e);
}

View File

@ -13,7 +13,6 @@ import io.gitlab.jfronny.inceptum.util.Utils;
import io.gitlab.jfronny.inceptum.util.VersionInfoLibraryResolver;
import io.gitlab.jfronny.inceptum.util.api.FabricMetaApi;
import io.gitlab.jfronny.inceptum.util.api.McApi;
import io.gitlab.jfronny.inceptum.util.api.account.AccountManager;
import io.gitlab.jfronny.inceptum.util.api.account.AuthInfo;
import java.io.File;
@ -22,13 +21,16 @@ import java.net.URISyntaxException;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
public class InstanceLauncher {
public static void launch(Path instancePath, InstanceMeta instance, LaunchType launchType, boolean restart, Optional<AuthInfo> authInfo) throws LaunchException, IOException {
if (authInfo.isEmpty()) authInfo = Optional.of(AccountManager.NULL_AUTH);
public static void launch(Path instancePath, InstanceMeta instance, LaunchType launchType, boolean restart, AuthInfo authInfo) throws LaunchException, IOException {
if (authInfo == null) throw new LaunchException("authInfo is null");
VersionsListInfo versionDataSimple = getVersion(instance.getMinecraftVersion());
VersionInfo versionInfo = McApi.getVersionInfo(versionDataSimple);
// Add fabric metadata if using fabric
@ -54,7 +56,7 @@ public class InstanceLauncher {
Path gameJar = Inceptum.LIBRARIES_DIR.resolve("net/minecraft/" + launchType.name).resolve(versionDataSimple.id + ".jar").toAbsolutePath();
classPath.append(gameJar);
// JVM arguments
if (launchType == LaunchType.Client && versionInfo.arguments != null) args.addAll(parse(versionInfo.arguments.jvm, versionInfo, instance, classPath.toString(), instancePath.toAbsolutePath().toString(), authInfo.get()));
if (launchType == LaunchType.Client && versionInfo.arguments != null) args.addAll(parse(versionInfo.arguments.jvm, versionInfo, instance, classPath.toString(), instancePath.toAbsolutePath().toString(), authInfo));
if (instance.minMem != null) args.add("-Xms" + instance.minMem);
if (instance.maxMem != null) args.add("-Xmx" + instance.maxMem);
if (instance.arguments != null && instance.arguments.jvm != null) args.addAll(instance.arguments.jvm);
@ -67,10 +69,10 @@ public class InstanceLauncher {
args.add(resolveMainClass(instance, versionInfo, gameJar, launchType));
// Game arguments
if (launchType == LaunchType.Client) {
if (versionInfo.arguments != null) args.addAll(parse(versionInfo.arguments.game, versionInfo, instance, classPath.toString(), instancePath.toAbsolutePath().toString(), authInfo.get()));
if (versionInfo.arguments != null) args.addAll(parse(versionInfo.arguments.game, versionInfo, instance, classPath.toString(), instancePath.toAbsolutePath().toString(), authInfo));
else if (versionInfo.minecraftArguments != null) {
for (String s : versionInfo.minecraftArguments.split(" ")) {
args.add(expandArg(s, versionInfo, instance, classPath.toString(), instancePath.toAbsolutePath().toString(), authInfo.get()));
args.add(expandArg(s, versionInfo, instance, classPath.toString(), instancePath.toAbsolutePath().toString(), authInfo));
}
}
else throw new LaunchException("Could not launch: No valid source for client arguments found");