From a642346a2c76e3a89e872b725219efae98933df7 Mon Sep 17 00:00:00 2001 From: Keir Nellyer Date: Wed, 9 Apr 2014 20:25:15 +0100 Subject: [PATCH] Add method to get a connected player via their UUID --- .../java/net/md_5/bungee/api/ProxyServer.java | 9 +++++++++ .../main/java/net/md_5/bungee/BungeeCord.java | 20 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/api/src/main/java/net/md_5/bungee/api/ProxyServer.java b/api/src/main/java/net/md_5/bungee/api/ProxyServer.java index 5a165b22..2a542415 100644 --- a/api/src/main/java/net/md_5/bungee/api/ProxyServer.java +++ b/api/src/main/java/net/md_5/bungee/api/ProxyServer.java @@ -7,6 +7,7 @@ import java.io.File; import java.net.InetSocketAddress; import java.util.Collection; import java.util.Map; +import java.util.UUID; import java.util.logging.Logger; import lombok.Getter; import net.md_5.bungee.api.config.ConfigurationAdapter; @@ -79,6 +80,14 @@ public abstract class ProxyServer */ public abstract ProxiedPlayer getPlayer(String name); + /** + * Gets a connected player via their UUID + * + * @param uuid of the player + * @return their player instance + */ + public abstract ProxiedPlayer getPlayer(UUID uuid); + /** * Return all servers registered to this proxy, keyed by name. Unlike the * methods in {@link ConfigurationAdapter#getServers()}, this will not 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 7f1775c5..80ab55d2 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -442,6 +442,26 @@ public class BungeeCord extends ProxyServer } } + public ProxiedPlayer getPlayer(UUID uuid) + { + connectionLock.readLock().lock(); + try + { + for ( ProxiedPlayer proxiedPlayer : connections.values() ) + { + if ( proxiedPlayer.getUniqueId().equals( uuid ) ) + { + return proxiedPlayer; + } + } + + return null; + } finally + { + connectionLock.readLock().unlock(); + } + } + @Override public Map getServers() {