Skip to content

Commit

Permalink
[1.11] Revert setting config properties
Browse files Browse the repository at this point in the history
  • Loading branch information
3arthqu4ke committed Jul 27, 2024
1 parent 4d0e39a commit c5118c7
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,4 @@ default <T> T get(Property<T> property, T defaultValue) {
return getValue(property, () -> defaultValue);
}

// Implement a setter function for config properties, this allows for overwriting
// the values of them from the cli which enables per invocation configuration.
<T> T setValue(Property<T> property, Supplier<T> value);

default <T> T set(Property<T> property, T value) { return setValue(property, () -> value); }
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,4 @@ public <T> T getValue(Property<T> property, Supplier<T> defaultValue) {
return result == null ? defaultValue.get() : result;
}

@Override
public <T> T setValue(Property<T> property, Supplier<T> value) {
return (T)properties.setProperty(property.getName(), value.get().toString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ public interface LauncherProperties extends HmcProperties {
Property<String> PROFILE_PROPERTIES = string("hmc.profileproperties");

Property<String> FABRIC_URL = string("hmc.fabric.url");
Property<Boolean> RE_THROW_LAUNCH_EXCEPTIONS = bool("hmc.rethrow.launch.exceptions");

Property<Boolean> OFFLINE = bool("hmc.offline");
Property<String> OFFLINE_USERNAME = string("hmc.offline.username");
Property<String> OFFLINE_UUID = string("hmc.offline.uuid");
Property<Boolean> RE_THROW_LAUNCH_EXCEPTIONS = bool("hmc.rethrow.launch.exceptions");
Property<String> OFFLINE_TOKEN = string("hmc.offline.token");
Property<String> OFFLINE_REFRESH_TOKEN = string("hmc.offline.refresh.token");
Property<String> OFFLINE_XUID = string("hmc.offline.xuid");
Property<String> OFFLINE_CLIENT_ID = string("hmc.offline.client.id");

// TODO: also check hashes for the libraries?
Property<Long> ASSETS_DELAY = number("hmc.assets.delay");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ public Account login(Config config) throws AuthException {
}

if (offlineChecker.isOffline()) {
val username = config.get(LauncherProperties.OFFLINE_USERNAME, "Offline");
val uuid = config.get(LauncherProperties.OFFLINE_UUID, OFFLINE_UUID);
return new Account(username, uuid, "", "", "", "");
return new Account(
config.get(LauncherProperties.OFFLINE_USERNAME, "Offline"),
config.get(LauncherProperties.OFFLINE_UUID, OFFLINE_UUID),
config.get(LauncherProperties.OFFLINE_TOKEN, ""),
config.get(LauncherProperties.OFFLINE_REFRESH_TOKEN, ""),
config.get(LauncherProperties.OFFLINE_XUID, ""),
config.get(LauncherProperties.OFFLINE_CLIENT_ID, ""));
}

log.warning("No valid account found!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public LaunchCommand(Launcher launcher) {
// TODO: is this really necessary?
args.put("-noout", "Doesn't print Minecrafts output to the console.");
args.put("-quit", "Quit HeadlessMc after launching the game.");
args.put("-username", "Set the username in offline mode");
args.put("--jvm", "Jvm args to use.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import lombok.RequiredArgsConstructor;
import lombok.val;
import lombok.var;
import me.earth.headlessmc.api.command.CommandException;
import me.earth.headlessmc.launcher.Launcher;
import me.earth.headlessmc.launcher.files.FileManager;
import me.earth.headlessmc.launcher.instrumentation.ResourceExtractor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,4 @@ public <T> T getValue(Property<T> property, Supplier<T> defaultValue) {
return result == null ? defaultValue.get() : result;
}

@Override
public <T> T setValue(Property<T> property, Supplier<T> value) {
return property.parse(System.setProperty(property.getName(), value.get().toString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import lombok.CustomLog;
import lombok.RequiredArgsConstructor;
import me.earth.headlessmc.api.config.HasConfig;
import me.earth.headlessmc.launcher.Main;
import me.earth.headlessmc.launcher.auth.AuthException;
import me.earth.headlessmc.launcher.files.FileManager;
import me.earth.headlessmc.launcher.os.OS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ public class LaunchOptions {
private final boolean noOut;
private final boolean noIn;
private final boolean inMemory;
private final String username;

public static class LaunchOptionsBuilder {
private LaunchOptionsBuilder() {
this.additionalJvmArgs = Collections.emptyList();
}

public LaunchOptionsBuilder parseFlags(
Launcher ctx, boolean quit, String... args) {
Launcher ctx, boolean quit, String... args) {
boolean lwjgl = flag(ctx, "-lwjgl", INVERT_LWJGL_FLAG, args);
// if offline only allow launching with the lwjgl flag!
if (!lwjgl && launcher.getAccountManager().getOfflineChecker().isOffline()) {
Expand All @@ -58,24 +57,23 @@ public LaunchOptionsBuilder parseFlags(
.paulscode(flag(ctx, "-paulscode", INVERT_PAULS_FLAG, args))
.noOut(quit || CommandUtil.hasFlag("-noout", args))
.parseJvmArgs(args)
.noIn(quit)
.username(CommandUtil.getOption("-username", args));
.noIn(quit);
}

public LaunchOptionsBuilder parseJvmArgs(String... args) {
String jvmArgs = CommandUtil.getOption("--jvm", args);
if (jvmArgs != null) {
this.additionalJvmArgs = new ArrayList<>(
Arrays.asList(CommandUtil.split(jvmArgs)));
Arrays.asList(CommandUtil.split(jvmArgs)));
}

return this;
}

private boolean flag(
HasConfig ctx, String flg, Property<Boolean> inv, String... args) {
HasConfig ctx, String flg, Property<Boolean> inv, String... args) {
return CommandUtil.hasFlag(flg, args)
^ ctx.getConfig().get(inv, false);
^ ctx.getConfig().get(inv, false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.zip.ZipFile;

@CustomLog
Expand All @@ -37,14 +40,7 @@ public Process run(LaunchOptions options)

public Process run(LaunchOptions options, Instrumentation instrumentation)
throws IOException, LaunchException, AuthException {

val launcher = options.getLauncher();

if (options.getUsername() != null) {
launcher.getConfig().set(LauncherProperties.OFFLINE_USERNAME, options.getUsername());
launcher.getConfig().set(LauncherProperties.OFFLINE_UUID, UUID.randomUUID().toString());
}

if (launcher.getAccountManager().getLastAccount() == null) {
launcher.getAccountManager().login(launcher.getConfig());
}
Expand Down

0 comments on commit c5118c7

Please sign in to comment.