Unknit refactor: Extract arg replacement methods

main
Charlotte Som 2022-02-13 06:08:30 +00:00
parent 8f578dcd4a
commit 501c20ffdb
1 changed files with 17 additions and 9 deletions

View File

@ -31,11 +31,25 @@ public abstract class MixinMinecraftMain {
} }
} }
private static void replaceVersion(List<String> arguments) {
replace(arguments, "--version", "1.18.1");
replace(arguments, "--versionType", "release");
}
private static void replaceSession(List<String> arguments, Session session) {
replace(arguments, "--accessToken", session.getAccessToken());
arguments.add("--username");
arguments.add(session.getUsername());
arguments.add("--uuid");
arguments.add(session.getUuid());
}
@ModifyVariable(method = "main", at = @At("HEAD"), argsOnly = true, remap = false) @ModifyVariable(method = "main", at = @At("HEAD"), argsOnly = true, remap = false)
private static String[] setArgs(String[] args) { private static String[] setArgs(String[] args) {
List<String> arguments = new ArrayList<>(Arrays.asList(args)); List<String> arguments = new ArrayList<>(Arrays.asList(args));
replace(arguments, "--version", "1.18.1"); replaceVersion(arguments);
replace(arguments, "--versionType", "release");
try { try {
String authFile = System.getenv("LOGIN_FILE"); String authFile = System.getenv("LOGIN_FILE");
@ -44,13 +58,7 @@ public abstract class MixinMinecraftMain {
List<String> loginDetails = Files.readAllLines(Paths.get(authFile)); List<String> loginDetails = Files.readAllLines(Paths.get(authFile));
if (loginDetails.size() >= 2) { if (loginDetails.size() >= 2) {
Session session = getAuthenticatedSession(loginDetails.get(0), loginDetails.get(1)); Session session = getAuthenticatedSession(loginDetails.get(0), loginDetails.get(1));
replace(arguments, "--accessToken", session.getAccessToken()); replaceSession(arguments, session);
arguments.add("--username");
arguments.add(session.getUsername());
arguments.add("--uuid");
arguments.add(session.getUuid());
} }
} catch (AuthenticationException | IOException ignored) { } catch (AuthenticationException | IOException ignored) {
} }