Skip to content

[networking] Improve connection events#75

Open
SpaceWalkerRS wants to merge 7 commits into
gen2from
improve-connection-events
Open

[networking] Improve connection events#75
SpaceWalkerRS wants to merge 7 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
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