From 501c20ffdbdd30d83e5a8c2d7a20fda6850dc157 Mon Sep 17 00:00:00 2001 From: videogame hacker Date: Sun, 13 Feb 2022 06:08:30 +0000 Subject: [PATCH] Unknit refactor: Extract arg replacement methods --- .../hackery/unknit/MixinMinecraftMain.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/java/site/hackery/unknit/MixinMinecraftMain.java b/src/main/java/site/hackery/unknit/MixinMinecraftMain.java index 0f97d73..9240d7a 100644 --- a/src/main/java/site/hackery/unknit/MixinMinecraftMain.java +++ b/src/main/java/site/hackery/unknit/MixinMinecraftMain.java @@ -31,11 +31,25 @@ public abstract class MixinMinecraftMain { } } + private static void replaceVersion(List arguments) { + replace(arguments, "--version", "1.18.1"); + replace(arguments, "--versionType", "release"); + } + + private static void replaceSession(List 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) private static String[] setArgs(String[] args) { List arguments = new ArrayList<>(Arrays.asList(args)); - replace(arguments, "--version", "1.18.1"); - replace(arguments, "--versionType", "release"); + replaceVersion(arguments); try { String authFile = System.getenv("LOGIN_FILE"); @@ -44,13 +58,7 @@ public abstract class MixinMinecraftMain { List loginDetails = Files.readAllLines(Paths.get(authFile)); if (loginDetails.size() >= 2) { Session session = getAuthenticatedSession(loginDetails.get(0), loginDetails.get(1)); - replace(arguments, "--accessToken", session.getAccessToken()); - - arguments.add("--username"); - arguments.add(session.getUsername()); - - arguments.add("--uuid"); - arguments.add(session.getUuid()); + replaceSession(arguments, session); } } catch (AuthenticationException | IOException ignored) { }