Question Getting list of players on a server not connected through the proxy

MrJoshuaT

New member
Jan 22, 2023
1
0
1
Doing the normal proxyServer.getAllPlayers() will get a list of players connected to all servers via the proxy, in the event a player is summoned via the fabric carpet mod /player name spawn that player isn't connected via the proxy so getAllPlayers() wont return them, is there a way to query the server directly?
 
Last edited:

Voigon

New member
Feb 5, 2023
2
0
1
I am not familiar with the mod but I can help you figure this out with some questions.
For starters, does the mod in that case run on client, server, or both?
 

Josh

New member
Feb 21, 2023
4
0
1
You can use the ServerInfo object to get a list of players connected to a specific server, even if that server is not connected to the proxy.
Java:
ServerInfo serverInfo = ProxyServer.getInstance().getServerInfo("server_name"); // replace "server_name" with the name of the server you want to query
if (serverInfo != null) {
    serverInfo.getPlayers().forEach(player -> {
        // Do something with the player
    });
} else {
    // Handle the case where the server doesn't exist
}

This retrieves the ServerInfo object for the server with the specified name (in this case, "server_name"), and then gets a list of players connected to that server using the getPlayers method. If the server doesn't exist or is not currently running, serverInfo will be null.

By using this method, you can retrieve a list of players connected to a specific server, regardless of whether they were connected through the proxy or directly to the server.