From aad11eb5feb715718f2496213f0d7f81feb9f05e Mon Sep 17 00:00:00 2001 From: Jab125 <67534807+Jab125@users.noreply.github.com> Date: Fri, 18 Oct 2024 22:31:18 +1100 Subject: [PATCH] use uuid of player for the folder --- src/main/java/dev/jab125/hotjoin/HotJoin.java | 13 ++++++++----- .../dev/jab125/hotjoin/api/HotJoinAccess.java | 6 +++++- .../hotjoin/compat/authme/AuthMeCompat.java | 4 ++-- .../compat/legacy4j/Legacy4JModCompat.java | 11 ++++++----- .../mixin/authme/MicrosoftAuthScreenMixin.java | 11 ++++++----- .../mixin/legacy4j/ChooseUserScreenMixin.java | 18 ++++-------------- .../hotjoin/mixin/legacy4j/MCAccountMixin.java | 3 ++- .../dev/jab125/hotjoin/util/AuthCallback.java | 6 +++--- 8 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/main/java/dev/jab125/hotjoin/HotJoin.java b/src/main/java/dev/jab125/hotjoin/HotJoin.java index 49bb7ae..bfd4aa0 100644 --- a/src/main/java/dev/jab125/hotjoin/HotJoin.java +++ b/src/main/java/dev/jab125/hotjoin/HotJoin.java @@ -23,6 +23,7 @@ import net.minecraft.client.server.IntegratedServer; import org.apache.commons.io.file.PathUtils; import org.apache.commons.lang3.ArrayUtils; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import wily.legacy.client.screen.Assort; @@ -337,7 +338,7 @@ public static T crashgoByeBye(SupplierButBetter static int hotJoin(CommandContext a) { HotJoin.canLaunchOtherwiseThrow(); try { - launchMinecraftClient(null, null, null); + launchMinecraftClient(null, null, null, null); } catch (IOException e) { throw new RuntimeException(e); } @@ -345,8 +346,9 @@ static int hotJoin(CommandContext a) { } // The goal is to launch Minecraft a second time, under a different directory. - public static UUID launchMinecraftClient(String compat, String magic, String legacy4jData) throws IOException { + public static UUID launchMinecraftClient(String compat, String magic, String legacy4jData, @Nullable String folderName) throws IOException { HotJoin.canLaunchOtherwiseThrow(); + if (folderName == null || folderName.isBlank()) folderName = "second"; if (magic != null) magic = magic.replace("=", "$"); if (legacy4jData != null) legacy4jData = legacy4jData.replace("=", "$"); UUID uuid = UUID.randomUUID(); @@ -362,9 +364,10 @@ public static UUID launchMinecraftClient(String compat, String magic, String leg } i++; } - Path path = Path.of("second"); - path.toFile().mkdirs(); - transfer(path); + Path path = Path.of(".hotjoin-instances/" + folderName); + boolean directory = path.toFile().isDirectory(); + if (!directory) path.toFile().mkdirs(); + if (!directory) transfer(path); launchArguments[i + 1] = path.toAbsolutePath().toString(); String cp = System.getProperty("java.class.path"); List splitClassPath = Arrays.stream(cp.split(File.pathSeparator)).toList(); diff --git a/src/main/java/dev/jab125/hotjoin/api/HotJoinAccess.java b/src/main/java/dev/jab125/hotjoin/api/HotJoinAccess.java index 32e40fe..5212e23 100644 --- a/src/main/java/dev/jab125/hotjoin/api/HotJoinAccess.java +++ b/src/main/java/dev/jab125/hotjoin/api/HotJoinAccess.java @@ -10,8 +10,12 @@ public static UUID launchMinecraftClient(String compat, String magic) { return launchMinecraftClient(compat, magic, null); } public static UUID launchMinecraftClient(String compat, String magic, @Nullable String legacy4jData) throws T { + return launchMinecraftClient(compat, magic, legacy4jData, null); + } + + public static UUID launchMinecraftClient(String compat, String magic, @Nullable String legacy4jData, @Nullable String folderName) throws T { try { - return HotJoin.launchMinecraftClient(compat, magic, legacy4jData); + return HotJoin.launchMinecraftClient(compat, magic, legacy4jData, folderName); } catch (Throwable t) { throw (T) t; } diff --git a/src/main/java/dev/jab125/hotjoin/compat/authme/AuthMeCompat.java b/src/main/java/dev/jab125/hotjoin/compat/authme/AuthMeCompat.java index ea30768..f6948fd 100644 --- a/src/main/java/dev/jab125/hotjoin/compat/authme/AuthMeCompat.java +++ b/src/main/java/dev/jab125/hotjoin/compat/authme/AuthMeCompat.java @@ -22,8 +22,8 @@ public int hotJoinAuthMeMicrosoft(CommandContext a) { return 0; } - private static void launchAuthMeClient(String magic) { - HotJoinAccess.launchMinecraftClient("authme", magic); + private static void launchAuthMeClient(String uuid, String magic) { + HotJoinAccess.launchMinecraftClient("authme", magic, null, uuid); } @Override diff --git a/src/main/java/dev/jab125/hotjoin/compat/legacy4j/Legacy4JModCompat.java b/src/main/java/dev/jab125/hotjoin/compat/legacy4j/Legacy4JModCompat.java index 2c07b00..bb7432c 100644 --- a/src/main/java/dev/jab125/hotjoin/compat/legacy4j/Legacy4JModCompat.java +++ b/src/main/java/dev/jab125/hotjoin/compat/legacy4j/Legacy4JModCompat.java @@ -36,13 +36,14 @@ import java.util.Base64; import java.util.HashMap; import java.util.UUID; +import java.util.function.BiConsumer; import java.util.function.Consumer; import static dev.jab125.hotjoin.HotJoin.crashgoByeBye; public class Legacy4JModCompat implements ILegacy4JModCompat { // used by MCAccountMixin due to the lack of mutable static fields in interfaces - public static Consumer authConsumer; + public static BiConsumer authConsumer; public static final HashMap uuidLegacy4JMap = new HashMap<>(); public Legacy4JModCompat() { ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> { @@ -69,16 +70,16 @@ public static void openLegacy4JUserPicker() { public static void openLegacy4JUserPicker(Legacy4JData data) { if (data != null) ScreenUtil.getLegacyOptions().selectedController().set(data.controllerIndex()); ChooseUserScreen chooseUserScreen = new ChooseUserScreen(null); - ((AuthCallback)chooseUserScreen).hotjoin$authResponse(s -> { + ((AuthCallback)chooseUserScreen).hotjoin$authResponse((uuid, s) -> { Minecraft.getInstance().getToasts().addToast(new LegacyTip(Component.literal("Success, joining world..."))); - launchLegacy4jClient(s, data); + launchLegacy4jClient(s, data, uuid); }); ((AuthCallback) chooseUserScreen).hotjoin$legacy4jData(data); Minecraft.getInstance().setScreen(chooseUserScreen); } @SuppressWarnings("unchecked") - private static void launchLegacy4jClient(String magic, Legacy4JData legacy4JData) throws T { + private static void launchLegacy4jClient(String magic, Legacy4JData legacy4JData, String _uuid) throws T { String data; if (legacy4JData != null) { Tag tag = Legacy4JData.CODEC.encodeStart(NbtOps.INSTANCE, legacy4JData).resultOrPartial(HotJoin.LOGGER::error).orElseThrow(); @@ -92,7 +93,7 @@ private static void launchLegacy4jClient(String magic, Leg } else { data = null; } - UUID uuid = HotJoinAccess.launchMinecraftClient("legacy4j", magic, data); + UUID uuid = HotJoinAccess.launchMinecraftClient("legacy4j", magic, data, _uuid); if (legacy4JData != null) uuidLegacy4JMap.put(uuid, legacy4JData); } diff --git a/src/main/java/dev/jab125/hotjoin/mixin/authme/MicrosoftAuthScreenMixin.java b/src/main/java/dev/jab125/hotjoin/mixin/authme/MicrosoftAuthScreenMixin.java index 92bcf95..9974835 100644 --- a/src/main/java/dev/jab125/hotjoin/mixin/authme/MicrosoftAuthScreenMixin.java +++ b/src/main/java/dev/jab125/hotjoin/mixin/authme/MicrosoftAuthScreenMixin.java @@ -3,6 +3,7 @@ import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import dev.jab125.hotjoin.HotJoin; +import dev.jab125.hotjoin.mixin.UserAccessor; import dev.jab125.hotjoin.util.AuthCallback; import dev.jab125.hotjoin.util.HotJoinCodecs; import me.axieum.mcmod.authme.api.gui.AuthScreen; @@ -21,14 +22,14 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.Base64; -import java.util.function.Consumer; +import java.util.function.BiConsumer; @Mixin(MicrosoftAuthScreen.class) public abstract class MicrosoftAuthScreenMixin extends AuthScreen implements AuthCallback { public MicrosoftAuthScreenMixin() { super(null, null, null); } - private @Unique @Nullable Consumer authResponse; + private @Unique @Nullable BiConsumer authResponse; @Inject(method = "lambda$init$7", at = @At("HEAD"), cancellable = true) void d(User session, CallbackInfo ci) { @@ -37,7 +38,7 @@ void d(User session, CallbackInfo ci) { Tag tag = HotJoinCodecs.USER_CODEC.encodeStart(NbtOps.INSTANCE, session).resultOrPartial(HotJoin.LOGGER::error).orElseThrow(); ByteArrayDataOutput byteArrayDataOutput = ByteStreams.newDataOutput(); NbtIo.write((CompoundTag) tag, byteArrayDataOutput); - authResponse.accept(Base64.getEncoder().encodeToString(byteArrayDataOutput.toByteArray())); + authResponse.accept(((UserAccessor)session).getUUID().toString(), Base64.getEncoder().encodeToString(byteArrayDataOutput.toByteArray())); this.success = true; ci.cancel(); return; @@ -48,12 +49,12 @@ void d(User session, CallbackInfo ci) { } @Override - public void hotjoin$authResponse(Consumer authConsumer) { + public void hotjoin$authResponse(BiConsumer authConsumer) { authResponse = authConsumer; } @Override - public Consumer hotjoin$authResponse() { + public BiConsumer hotjoin$authResponse() { return authResponse; } } diff --git a/src/main/java/dev/jab125/hotjoin/mixin/legacy4j/ChooseUserScreenMixin.java b/src/main/java/dev/jab125/hotjoin/mixin/legacy4j/ChooseUserScreenMixin.java index 3c97d46..34d604c 100644 --- a/src/main/java/dev/jab125/hotjoin/mixin/legacy4j/ChooseUserScreenMixin.java +++ b/src/main/java/dev/jab125/hotjoin/mixin/legacy4j/ChooseUserScreenMixin.java @@ -2,27 +2,17 @@ import dev.jab125.hotjoin.compat.legacy4j.Legacy4JData; import dev.jab125.hotjoin.util.AuthCallback; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.components.Renderable; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.network.chat.Component; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import wily.legacy.client.screen.ChooseUserScreen; -import wily.legacy.client.screen.Panel; import wily.legacy.client.screen.PanelVListScreen; -import wily.legacy.client.screen.RenderableVListScreen; -import java.util.function.Consumer; -import java.util.function.Function; +import java.util.function.BiConsumer; @Mixin(ChooseUserScreen.class) public abstract class ChooseUserScreenMixin extends PanelVListScreen implements AuthCallback { - private @Unique @Nullable Consumer authResponse; + private @Unique @Nullable BiConsumer authResponse; @SuppressWarnings("DataFlowIssue") public ChooseUserScreenMixin() { @@ -30,12 +20,12 @@ public ChooseUserScreenMixin() { } @Override - public void hotjoin$authResponse(Consumer authConsumer) { + public void hotjoin$authResponse(BiConsumer authConsumer) { this.authResponse = authConsumer; } @Override - public Consumer hotjoin$authResponse() { + public BiConsumer hotjoin$authResponse() { return this.authResponse; } diff --git a/src/main/java/dev/jab125/hotjoin/mixin/legacy4j/MCAccountMixin.java b/src/main/java/dev/jab125/hotjoin/mixin/legacy4j/MCAccountMixin.java index 8116c86..9393a2c 100644 --- a/src/main/java/dev/jab125/hotjoin/mixin/legacy4j/MCAccountMixin.java +++ b/src/main/java/dev/jab125/hotjoin/mixin/legacy4j/MCAccountMixin.java @@ -4,6 +4,7 @@ import com.google.common.io.ByteStreams; import dev.jab125.hotjoin.HotJoin; import dev.jab125.hotjoin.compat.legacy4j.Legacy4JModCompat; +import dev.jab125.hotjoin.mixin.UserAccessor; import dev.jab125.hotjoin.util.AuthCallback; import dev.jab125.hotjoin.util.HotJoinCodecs; import net.minecraft.client.Minecraft; @@ -43,7 +44,7 @@ private static void interceptSetUser(User user, CallbackInfo ci) throws IOExcept Tag tag = HotJoinCodecs.USER_CODEC.encodeStart(NbtOps.INSTANCE, user).resultOrPartial(HotJoin.LOGGER::error).orElseThrow(); ByteArrayDataOutput byteArrayDataOutput = ByteStreams.newDataOutput(); NbtIo.write((CompoundTag) tag, byteArrayDataOutput); - Legacy4JModCompat.authConsumer.accept(Base64.getEncoder().encodeToString(byteArrayDataOutput.toByteArray())); + Legacy4JModCompat.authConsumer.accept(((UserAccessor)user).getUUID().toString(), Base64.getEncoder().encodeToString(byteArrayDataOutput.toByteArray())); Legacy4JModCompat.authConsumer = null; ci.cancel(); } diff --git a/src/main/java/dev/jab125/hotjoin/util/AuthCallback.java b/src/main/java/dev/jab125/hotjoin/util/AuthCallback.java index 7784444..23ac517 100644 --- a/src/main/java/dev/jab125/hotjoin/util/AuthCallback.java +++ b/src/main/java/dev/jab125/hotjoin/util/AuthCallback.java @@ -1,11 +1,11 @@ package dev.jab125.hotjoin.util; -import java.util.function.Consumer; +import java.util.function.BiConsumer; public interface AuthCallback { - void hotjoin$authResponse(Consumer authConsumer); + void hotjoin$authResponse(BiConsumer authConsumer); - Consumer hotjoin$authResponse(); + BiConsumer hotjoin$authResponse(); @SuppressWarnings("UnnecessaryReturnStatement") default void hotjoin$legacy4jData(Object object) {