Skip to content

Commit

Permalink
fix using proto server as key in map
Browse files Browse the repository at this point in the history
  • Loading branch information
MrNavaStar committed Aug 13, 2024
1 parent 306288a commit e1901f7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProtoServer> getConnectedServers(@NonNull Protocol protocol) {
ArrayList<ProtoServer> connected = new ArrayList<>();
servers.forEach((server, clients) -> clients.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import me.mrnavastar.protoweaver.api.netty.ProtoConnection;

import java.net.SocketAddress;
import java.util.Objects;

@Setter
@Getter
Expand All @@ -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;
Expand Down

0 comments on commit e1901f7

Please sign in to comment.