mirror of
https://github.com/System-End/Discord-MC-Chat.git
synced 2026-04-20 00:25:18 +00:00
Add methods to retrieve connected client names and check client connection status
This commit is contained in:
parent
aab632eb34
commit
dc8fc6bf3e
1 changed files with 21 additions and 0 deletions
|
|
@ -8,7 +8,9 @@ import com.xujiayao.discord_mc_chat.utils.EnvironmentUtils;
|
|||
import io.netty.channel.Channel;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
|
@ -112,6 +114,25 @@ public class NetworkManager {
|
|||
clientChannels.remove(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all connected client names.
|
||||
*
|
||||
* @return A list of connected client names.
|
||||
*/
|
||||
public static List<String> getConnectedClientNames() {
|
||||
return new ArrayList<>(clientChannels.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a client is connected by name.
|
||||
*
|
||||
* @param clientName The client name to check.
|
||||
* @return true if connected, false otherwise.
|
||||
*/
|
||||
public static boolean isClientConnected(String clientName) {
|
||||
return clientChannels.values().stream().anyMatch(name -> name.equals(clientName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the remote address of a channel as a string (IP:Port).
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue