From e1901f72a3608369eab79cb21f1230b275f0ff22 Mon Sep 17 00:00:00 2001 From: MrNavaStar Date: Tue, 13 Aug 2024 14:56:43 -0600 Subject: [PATCH] fix using proto server as key in map --- .../mrnavastar/protoweaver/proxy/api/ProtoProxy.java | 4 ++++ .../mrnavastar/protoweaver/proxy/api/ProtoServer.java | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/proxy/src/main/java/me/mrnavastar/protoweaver/proxy/api/ProtoProxy.java b/proxy/src/main/java/me/mrnavastar/protoweaver/proxy/api/ProtoProxy.java index 9cd5e09..1e6e304 100644 --- a/proxy/src/main/java/me/mrnavastar/protoweaver/proxy/api/ProtoProxy.java +++ b/proxy/src/main/java/me/mrnavastar/protoweaver/proxy/api/ProtoProxy.java @@ -83,6 +83,10 @@ public void unregister(ProtoServer server) { Optional.ofNullable(servers.remove(server)).ifPresent(clients -> clients.forEach(ProtoClient::disconnect)); } + /** + * Returns a list of servers connected on the supplied {@link Protocol}. + * @param protocol the protocol to check for. + */ public static ArrayList getConnectedServers(@NonNull Protocol protocol) { ArrayList connected = new ArrayList<>(); servers.forEach((server, clients) -> clients.stream() diff --git a/proxy/src/main/java/me/mrnavastar/protoweaver/proxy/api/ProtoServer.java b/proxy/src/main/java/me/mrnavastar/protoweaver/proxy/api/ProtoServer.java index 47ffc14..4dfb9bb 100644 --- a/proxy/src/main/java/me/mrnavastar/protoweaver/proxy/api/ProtoServer.java +++ b/proxy/src/main/java/me/mrnavastar/protoweaver/proxy/api/ProtoServer.java @@ -5,6 +5,7 @@ import me.mrnavastar.protoweaver.api.netty.ProtoConnection; import java.net.SocketAddress; +import java.util.Objects; @Setter @Getter @@ -19,6 +20,16 @@ public ProtoServer(String name, SocketAddress address) { this.address = address; } + @Override + public boolean equals(Object obj) { + return obj instanceof ProtoServer server && Objects.equals(server.name, name); + } + + @Override + public int hashCode() { + return name.hashCode(); + } + @Override public String toString() { return name + " : " + address;