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 2a542415..b6b656e0 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 @@ -282,4 +282,14 @@ public abstract class ProxyServer */ public abstract ProxyConfig getConfig(); + /** + * Attempts to match any players with the given name, and returns a list of + * all possible matches. + * + * @param name the (partial) name to match + * @return list of all possible players, singleton if there is an exact + * match + */ + public abstract Collection matchPlayer(String name); + } 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 4459d0f5..435f00ff 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -1,5 +1,9 @@ package net.md_5.bungee; +import com.google.common.base.Preconditions; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; import com.google.gson.GsonBuilder; import net.md_5.bungee.api.Favicon; import net.md_5.bungee.api.ServerPing; @@ -581,8 +585,31 @@ public class BungeeCord extends ProxyServer return new Custom( player ); } + @Override public Collection getDisabledCommands() { return config.getDisabledCommands(); } + + @Override + public Collection matchPlayer(final String partialName) + { + Preconditions.checkNotNull( partialName, "partialName" ); + + ProxiedPlayer exactMatch = getPlayer( partialName ); + if ( exactMatch != null ) + { + return Collections.singleton( exactMatch ); + } + + return Sets.newHashSet( Iterables.find( getPlayers(), new Predicate() + { + + @Override + public boolean apply(ProxiedPlayer input) + { + return input.getName().toLowerCase().contains( partialName.toLowerCase() ); + } + } ) ); + } }