Fabric API

Fabric API

106M Downloads

Get player's current server

CommandCracker8 opened this issue ยท 3 comments

commented

How can I get the current server IP and/or world name the player is currently on?

commented

I assume you are trying to do this programmatically?

Using logic similar to Vanilla's MinecraftClient.getWindowTitle()

ServerInfo info = MinecraftClient.getCurrentServerEntry();

which has a name and address when not null.

Or you use the network information;

ClientConnection clientConnection = MinecraftClient.getInstance().getNetworkHandler().getConnection();

If this is not null you can getAddress().
If it is a remote server the address should be castable to a java.net.InetSocketAddress

commented

Okay thanks! What about the world name?

commented

Probably a similar way, have a look at MC's source code.