3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-12-24 23:30:26 +01:00

Store players in VelocityRegisteredServer by UUID instead.

Fixes an issue where players would be repeated in /glist and the like.
Dieser Commit ist enthalten in:
Andrew Steinborn 2020-11-06 09:38:26 -05:00
Ursprung cc89a2a1e5
Commit fb888c3b8a

Datei anzeigen

@ -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<ConnectedPlayer> players = ConcurrentHashMap.newKeySet();
private final Map<UUID, ConnectedPlayer> 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<Player> 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);