Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hi, is there an event for client-side when a player joins an integrated or dedicated server for 1.17+?

  • Author
9 hours ago, diesieben07 said:

ClientPlayerNetworkEvent.LoggedInEvent

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

 

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

 

Edited by Arkyo

  • Author
2 minutes ago, Luis_ST said:

your are on client so there is no Server

If so, is there an client-side event for this? I just want to determine on the client-side whether a player has joined an integrated/dedicated server

  • Author
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

  • Author
3 minutes ago, diesieben07 said:

getConnection definitely exists. Show your code and the error.

Imgur

 

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

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

 

  • Author
19 minutes ago, diesieben07 said:

What version of Minecraft are you using?

Show the full stacktrace.

1.17.1, Forge 37.1.1

https://pastebin.com/a0MzG42J

 

Should I try it on Forge 1.16.5 / 1.18.1?

Edited by Arkyo

  • Author
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().

  • Author

Ok I've found a hacky way for 1.16.5:

EDIT: Also works for 1.17.1

event.getNetworkManager().channel().remoteAddress().toString().startsWith("local:E") ? "Singleplayer" : "Multiplayer"

 

Edited by Arkyo

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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.