Jump to content

Client-side event when player joins a singleplayer/multiplayer server


Recommended Posts

9 hours ago, diesieben07 said:


Thanks, I'm trying to use the event to determine whether a player has joined an integrated/dedicated server, but it seems that `LocalPlayer` has no `getServer()` and thus I can't use `MinecraftServer#isDedicatedServer`


It crashes with `NoSuchMethodError` when i join an inte/dedi server


public static void onJoin(ClientPlayerNetworkEvent.LoggedInEvent event) {
	String serverType = event.getPlayer().getServer().isDedicatedServer() ? "Multiplayer" : "Singleplayer";


Edited by Arkyo
Link to comment
Share on other sites

2 hours ago, diesieben07 said:

The event has getConnection. Connection#isMemoryConnection will tell you if this is a single player connection. Note that when "open the LAN" is selected, other players joining will see it as a normal server, not "single player".

I don't think it has `getConnection()` ... Both IntelliJ and javadoc didn't show a `getConnection()` for LoggedInEvent


EDIT: there is a getNetworkManager() for this event which returns a Connection. However event.getNetworkManager().isMemoryConnection() still throws NoSuchMethodError

Edited by Arkyo
Link to comment
Share on other sites

3 minutes ago, diesieben07 said:

getConnection definitely exists. Show your code and the error.



And this is the error line in crash report when I used event.getNetworkManager().isMemoryConnection():

java.lang.NoSuchMethodError: 'boolean net.minecraft.network.Connection.isMemoryConnection()'


Link to comment
Share on other sites

1 hour ago, diesieben07 said:

1.17.1 is no longer a supported versions. Currently supported versions are 1.18.1 (Latest) and 1.16.5 (LTS).

yeah, but even if I backport it to 1.16.5, updated the build.gradle and reloaded the project, there is still no event.getConnection().

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.