Skip to content

[networking] Improve connection events - #75

Merged
SpaceWalkerRS merged 5 commits into
gen2from
improve-connection-events
Aug 16, 2026
Merged

[networking] Improve connection events#75
SpaceWalkerRS merged 5 commits into
gen2from
improve-connection-events

Conversation

@SpaceWalkerRS

Copy link
Copy Markdown
Member

The LOGIN, PLAY_READY, and DISCONNECT events currently provide very little context. The client-side events give a Minecraft instance, and the server-side events give a MinecraftServer instance and a ServerPlayerEntity instance.

This PR replaces those with a single context object through which these instances and other relevant data can be accessed.

The PR also fixes the DISCONNECT event not firing if initiated by the remote side. For example, the client-side DISCONNECT event would not fire if the player was kicked from the server or had a connection issue. And the server-side DISCONNECT event would not fire if the player left the game through the game menu or by closing the game. These issues have been fixed.

Here are some example usages of the new API:

ClientConnectionEvents.LOGIN.register(context -> {
	Minecraft minecraft = context.minecraft();

	if (context.isServerLocal()) {
		String worldName = context.worldName();
	} else {
		String serverAddress = context.serverAddress();
		int serverPort = context.serverPort();
	}
});
ClientConnectionEvents.DISCONNECT.register(context -> {
	TextComponent disconnectReason = context.disconnectReason();
});
ServerConnectionEvents.LOGIN.register(context -> {
	MinecraftServer server = context.server();
	ServerPlayerEntity player = context.player();
});
ServerConnectionEvents.DISCONNECT.register(context -> {
	TextComponent disconnectReason = context.disconnectReason();
});

@SpaceWalkerRS SpaceWalkerRS added the enhancement New feature or request label Jul 10, 2026
@SpaceWalkerRS SpaceWalkerRS changed the title Improve connection events [networking] Improve connection events Jul 10, 2026
@SpaceWalkerRS
SpaceWalkerRS force-pushed the improve-connection-events branch from a5386bf to 72e96b8 Compare August 16, 2026 15:17
@SpaceWalkerRS
SpaceWalkerRS force-pushed the improve-connection-events branch from 72e96b8 to 007a34c Compare August 16, 2026 17:53
@SpaceWalkerRS
SpaceWalkerRS merged commit 1f28aba into gen2 Aug 16, 2026
2 checks passed
@SpaceWalkerRS
SpaceWalkerRS deleted the improve-connection-events branch August 16, 2026 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant