From bfab8a1d9c757d8e5f414ead5e0a5cf8d3df5815 Mon Sep 17 00:00:00 2001 From: Molek Date: Wed, 26 Apr 2017 08:39:49 +0200 Subject: [PATCH] Index UUIDs to speed up player queries (#2121) --- proxy/src/main/java/net/md_5/bungee/BungeeCord.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index 9fdb4c76..f31faa99 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -125,6 +125,7 @@ public class BungeeCord extends ProxyServer private final Map connections = new CaseInsensitiveMap<>(); // Used to help with packet rewriting private final Map connectionsByOfflineUUID = new HashMap<>(); + private final Map connectionsByUUID = new HashMap<>(); private final ReadWriteLock connectionLock = new ReentrantReadWriteLock(); /** * Plugin manager. @@ -542,15 +543,7 @@ public class BungeeCord extends ProxyServer connectionLock.readLock().lock(); try { - for ( ProxiedPlayer proxiedPlayer : connections.values() ) - { - if ( proxiedPlayer.getUniqueId().equals( uuid ) ) - { - return proxiedPlayer; - } - } - - return null; + return connectionsByUUID.get( uuid ); } finally { connectionLock.readLock().unlock(); @@ -645,6 +638,7 @@ public class BungeeCord extends ProxyServer try { connections.put( con.getName(), con ); + connectionsByUUID.put( con.getUniqueId(), con ); connectionsByOfflineUUID.put( con.getPendingConnection().getOfflineId(), con ); } finally { @@ -661,6 +655,7 @@ public class BungeeCord extends ProxyServer if ( connections.get( con.getName() ) == con ) { connections.remove( con.getName() ); + connectionsByUUID.remove( con.getUniqueId() ); connectionsByOfflineUUID.remove( con.getPendingConnection().getOfflineId() ); } } finally