Arkyo Posted February 22, 2022 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
Arkyo Posted February 22, 2022 Author Posted February 22, 2022 (edited) On 2/22/2022 at 8:05 AM, diesieben07 said: ClientPlayerNetworkEvent.LoggedInEvent Expand 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
Luis_ST Posted February 22, 2022 Posted February 22, 2022 your are on client so there is no Server Quote
Arkyo Posted February 22, 2022 Author Posted February 22, 2022 On 2/22/2022 at 6:13 PM, Luis_ST said: your are on client so there is no Server Expand 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
Arkyo Posted February 22, 2022 Author Posted February 22, 2022 (edited) On 2/22/2022 at 6:35 PM, 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". Expand 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
Arkyo Posted February 22, 2022 Author Posted February 22, 2022 On 2/22/2022 at 9:38 PM, diesieben07 said: getConnection definitely exists. Show your code and the error. Expand 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
Arkyo Posted February 22, 2022 Author Posted February 22, 2022 (edited) On 2/22/2022 at 10:06 PM, diesieben07 said: What version of Minecraft are you using? Show the full stacktrace. Expand 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
Arkyo Posted February 22, 2022 Author Posted February 22, 2022 On 2/22/2022 at 10:27 PM, diesieben07 said: 1.17.1 is no longer a supported versions. Currently supported versions are 1.18.1 (Latest) and 1.16.5 (LTS). Expand 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
loordgek Posted February 22, 2022 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
Arkyo Posted February 23, 2022 Author Posted February 23, 2022 On 2/22/2022 at 11:51 PM, loordgek said: https://github.com/MinecraftForge/MinecraftForge/blob/1.16.x/src/main/java/net/minecraftforge/client/event/ClientPlayerNetworkEvent.java#L57 Expand Ok, but how can I use NetworkManager to achieve my goal? There is no isMemoryConnection() for 1.16.5 Quote
Arkyo Posted February 23, 2022 Author 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
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.