Skip to content

fix: dispatch ServerJoinEvent once the play connection is established#694

Merged
Wyvest merged 1 commit into
Polyfrost:v1from
mvanhorn:fix/604-serverjoinevent-timing
Jul 1, 2026
Merged

fix: dispatch ServerJoinEvent once the play connection is established#694
Wyvest merged 1 commit into
Polyfrost:v1from
mvanhorn:fix/604-serverjoinevent-timing

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Description

ServerJoinEvent was posted from the RETURN of the login-handshake handler on ClientHandshakePacketListenerImpl (handleLoginFinished on 1.21.4+, handleGameProfile on 1.21.1). That handler runs during the login handshake, before the play phase begins, so at that point Minecraft.getCurrentServer() is still null. Any handler reading mc.currentServer from a ServerJoinEvent therefore received null, as reported.

This re-targets the mixin to the play-phase listener ClientPacketListener and injects at the RETURN of handleLogin, which is where the play connection and world are established and currentServer is populated. The event still fires exactly once per join, just at a point where the current-server state is actually available.

Because handleLogin has a stable name across every supported version (1.21.1 through 1.21.11), the previous handleGameProfile / handleLoginFinished version conditional is no longer needed and has been removed, leaving a single injection target. The event object and the EventManager.INSTANCE.post(ServerJoinEvent.INSTANCE) wiring are unchanged.

Related Issue(s)

Fixes #604

Checklist

  • I made a clear description of what was changed
  • I stated why these changes were necessary
  • I updated documentation or said what needs to be updated
  • I made sure these changes are backwards compatible
  • This pull request is for one feature/bug fix

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.
@Wyvest Wyvest merged commit 73539c5 into Polyfrost:v1 Jul 1, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this to Done in OneConfig Jul 1, 2026
@Wyvest

Wyvest commented Jul 1, 2026

Copy link
Copy Markdown
Member

thank you mr claude

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

ServerJoinEvent gets dispatched too early

2 participants