Arkyo Posted February 22, 2022 Share Posted February 22, 2022 Hi, is there an event for client-side when a player joins an integrated or dedicated server for 1.17+? 1 Quote Link to comment Share on other sites More sharing options...
Arkyo Posted February 22, 2022 Author Share Posted February 22, 2022 (edited) 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 February 22, 2022 by Arkyo Quote Link to comment Share on other sites More sharing options...
Luis_ST Posted February 22, 2022 Share Posted February 22, 2022 your are on client so there is no Server Quote Link to comment Share on other sites More sharing options...
Arkyo Posted February 22, 2022 Author Share Posted February 22, 2022 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 Quote Link to comment Share on other sites More sharing options...
Arkyo Posted February 22, 2022 Author Share Posted February 22, 2022 (edited) 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 February 22, 2022 by Arkyo Quote Link to comment Share on other sites More sharing options...
Arkyo Posted February 22, 2022 Author Share Posted February 22, 2022 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()' Quote Link to comment Share on other sites More sharing options...
Arkyo Posted February 22, 2022 Author Share Posted February 22, 2022 (edited) 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 February 22, 2022 by Arkyo Quote Link to comment Share on other sites More sharing options...
Arkyo Posted February 22, 2022 Author Share Posted February 22, 2022 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(). Quote Link to comment Share on other sites More sharing options...
loordgek Posted February 22, 2022 Share Posted February 22, 2022 https://github.com/MinecraftForge/MinecraftForge/blob/1.16.x/src/main/java/net/minecraftforge/client/event/ClientPlayerNetworkEvent.java#L57 1 Quote Link to comment Share on other sites More sharing options...
Arkyo Posted February 23, 2022 Author Share Posted February 23, 2022 19 minutes ago, loordgek said: https://github.com/MinecraftForge/MinecraftForge/blob/1.16.x/src/main/java/net/minecraftforge/client/event/ClientPlayerNetworkEvent.java#L57 Ok, but how can I use NetworkManager to achieve my goal? There is no isMemoryConnection() for 1.16.5 Quote Link to comment Share on other sites More sharing options...
Arkyo Posted February 23, 2022 Author Share Posted February 23, 2022 (edited) 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 February 23, 2022 by Arkyo Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.