From fb888c3b8aaa7863625f9bdb950ed86fa9166a58 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Fri, 6 Nov 2020 09:38:26 -0500 Subject: [PATCH] Store players in VelocityRegisteredServer by UUID instead. Fixes an issue where players would be repeated in /glist and the like. --- .../proxy/server/VelocityRegisteredServer.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java b/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java index bec7dab41..5987311e1 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java @@ -32,7 +32,8 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoop; import io.netty.handler.timeout.ReadTimeoutHandler; import java.util.Collection; -import java.util.Set; +import java.util.Map; +import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; @@ -45,7 +46,7 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud private final @Nullable VelocityServer server; private final ServerInfo serverInfo; - private final Set players = ConcurrentHashMap.newKeySet(); + private final Map players = new ConcurrentHashMap<>(); public VelocityRegisteredServer(@Nullable VelocityServer server, ServerInfo serverInfo) { this.server = server; @@ -59,7 +60,7 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud @Override public Collection getPlayersConnected() { - return ImmutableList.copyOf(players); + return ImmutableList.copyOf(players.values()); } @Override @@ -111,11 +112,11 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud } public void addPlayer(ConnectedPlayer player) { - players.add(player); + players.put(player.getUniqueId(), player); } public void removePlayer(ConnectedPlayer player) { - players.remove(player); + players.remove(player.getUniqueId(), player); } @Override @@ -130,7 +131,7 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud * @return whether or not the message was sent */ public boolean sendPluginMessage(ChannelIdentifier identifier, ByteBuf data) { - for (ConnectedPlayer player : players) { + for (ConnectedPlayer player : players.values()) { VelocityServerConnection connection = player.getConnectedServer(); if (connection != null && connection.getServerInfo().equals(serverInfo)) { return connection.sendPluginMessage(identifier, data);