From bc8abb670e62bd3ed5f7731acdf4ede90adb373a Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Wed, 1 Jul 2026 00:37:05 -0700 Subject: [PATCH] fix: dispatch ServerJoinEvent once the play connection is established ServerJoinEvent was posted from the RETURN of the login-handshake handler on ClientHandshakePacketListenerImpl, which runs before the play phase begins. At that point Minecraft.getCurrentServer() is still null, so handlers reading mc.currentServer received null. Re-target the mixin to the play-phase listener ClientPacketListener and inject at the RETURN of handleLogin, where the play connection and world are established and currentServer is populated. handleLogin has a stable name across all supported versions (1.21.1-1.21.11), so the previous handleGameProfile/handleLoginFinished version conditional is no longer needed. --- .../internal/mixin/events/Mixin_ServerJoinEvent.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/minecraft/src/main/java/org/polyfrost/oneconfig/internal/mixin/events/Mixin_ServerJoinEvent.java b/minecraft/src/main/java/org/polyfrost/oneconfig/internal/mixin/events/Mixin_ServerJoinEvent.java index 2c74f0e97..dbeefbc00 100644 --- a/minecraft/src/main/java/org/polyfrost/oneconfig/internal/mixin/events/Mixin_ServerJoinEvent.java +++ b/minecraft/src/main/java/org/polyfrost/oneconfig/internal/mixin/events/Mixin_ServerJoinEvent.java @@ -1,6 +1,6 @@ package org.polyfrost.oneconfig.internal.mixin.events; -import net.minecraft.client.multiplayer.ClientHandshakePacketListenerImpl; +import net.minecraft.client.multiplayer.ClientPacketListener; import org.polyfrost.oneconfig.api.event.v1.EventManager; import org.polyfrost.oneconfig.api.event.v1.events.ServerJoinEvent; import org.spongepowered.asm.mixin.Mixin; @@ -8,14 +8,10 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(ClientHandshakePacketListenerImpl.class) +@Mixin(ClientPacketListener.class) public class Mixin_ServerJoinEvent { - //? < 1.21.4 { - /*@Inject(method = "handleGameProfile", at = @At("RETURN")) - *///? } else { - @Inject(method = "handleLoginFinished", at = @At("RETURN")) - //? } + @Inject(method = "handleLogin", at = @At("RETURN")) private void onLoginSuccess(CallbackInfo ci) { EventManager.INSTANCE.post(ServerJoinEvent.INSTANCE); }