Make getPlayers a little safer. Should probably use a CopyOnWrite collection though.

This commit is contained in:
md_5 2013-12-23 17:41:17 +11:00
parent 608eaace1c
commit d0d0f4ec9f
2 changed files with 3 additions and 2 deletions

View File

@ -399,7 +399,7 @@ public class BungeeCord extends ProxyServer
connectionLock.readLock().lock(); connectionLock.readLock().lock();
try try
{ {
return (Collection) new HashSet<>( connections.values() ); return Collections.unmodifiableCollection( new HashSet( connections.values() ) );
} finally } finally
{ {
connectionLock.readLock().unlock(); connectionLock.readLock().unlock();

View File

@ -10,6 +10,7 @@ import java.net.InetSocketAddress;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Objects; import java.util.Objects;
import java.util.Queue; import java.util.Queue;
@ -60,7 +61,7 @@ public class BungeeServerInfo implements ServerInfo
@Override @Override
public Collection<ProxiedPlayer> getPlayers() public Collection<ProxiedPlayer> getPlayers()
{ {
return Collections.unmodifiableCollection( players ); return Collections.unmodifiableCollection( new HashSet( players ) );
} }
@Override @Override