Index UUIDs to speed up player queries (#2121)

This commit is contained in:
Molek 2017-04-26 08:39:49 +02:00 committed by md-5
parent 53cc3242e1
commit bfab8a1d9c

View File

@ -125,6 +125,7 @@ public class BungeeCord extends ProxyServer
private final Map<String, UserConnection> connections = new CaseInsensitiveMap<>(); private final Map<String, UserConnection> connections = new CaseInsensitiveMap<>();
// Used to help with packet rewriting // Used to help with packet rewriting
private final Map<UUID, UserConnection> connectionsByOfflineUUID = new HashMap<>(); private final Map<UUID, UserConnection> connectionsByOfflineUUID = new HashMap<>();
private final Map<UUID, UserConnection> connectionsByUUID = new HashMap<>();
private final ReadWriteLock connectionLock = new ReentrantReadWriteLock(); private final ReadWriteLock connectionLock = new ReentrantReadWriteLock();
/** /**
* Plugin manager. * Plugin manager.
@ -542,15 +543,7 @@ public class BungeeCord extends ProxyServer
connectionLock.readLock().lock(); connectionLock.readLock().lock();
try try
{ {
for ( ProxiedPlayer proxiedPlayer : connections.values() ) return connectionsByUUID.get( uuid );
{
if ( proxiedPlayer.getUniqueId().equals( uuid ) )
{
return proxiedPlayer;
}
}
return null;
} finally } finally
{ {
connectionLock.readLock().unlock(); connectionLock.readLock().unlock();
@ -645,6 +638,7 @@ public class BungeeCord extends ProxyServer
try try
{ {
connections.put( con.getName(), con ); connections.put( con.getName(), con );
connectionsByUUID.put( con.getUniqueId(), con );
connectionsByOfflineUUID.put( con.getPendingConnection().getOfflineId(), con ); connectionsByOfflineUUID.put( con.getPendingConnection().getOfflineId(), con );
} finally } finally
{ {
@ -661,6 +655,7 @@ public class BungeeCord extends ProxyServer
if ( connections.get( con.getName() ) == con ) if ( connections.get( con.getName() ) == con )
{ {
connections.remove( con.getName() ); connections.remove( con.getName() );
connectionsByUUID.remove( con.getUniqueId() );
connectionsByOfflineUUID.remove( con.getPendingConnection().getOfflineId() ); connectionsByOfflineUUID.remove( con.getPendingConnection().getOfflineId() );
} }
} finally } finally