Skip to content

Commit

Permalink
fix null pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
MrNavaStar committed Dec 16, 2024
1 parent 1b85d03 commit 64cbfea
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

Expand Down Expand Up @@ -107,9 +108,14 @@ public static Optional<ProtoServer> getRegisteredServer(SocketAddress address) {
*/
public static List<ProtoServer> getConnectedServers(@NonNull Protocol protocol) {
List<ProtoServer> connected = new ArrayList<>();
servers.forEach((server, clients) -> clients.stream()

servers.forEach(((server, clients) -> {
if (!server.isConnected()) return;

clients.stream()
.filter(c -> protocol.equals(c.getCurrentProtocol()) || c.isConnected())
.findFirst().ifPresent(c -> connected.add(server)));
.findFirst().ifPresent(c -> connected.add(server));
}));
return connected;
}

Expand All @@ -118,7 +124,7 @@ public static List<ProtoServer> getConnectedServers(@NonNull Protocol protocol)
* @param connection the connection to match.
*/
public static Optional<ProtoServer> getConnectedServer(ProtoConnection connection) {
return getConnectedServers(connection.getProtocol()).stream().filter(server -> server.getConnection().equals(connection)).findFirst();
return getConnectedServers(connection.getProtocol()).stream().filter(server -> Objects.equals(server.getConnection(), connection)).findFirst();
}

/**
Expand Down

0 comments on commit 64cbfea

Please sign in to comment.