Add matchPlayer API
This commit is contained in:
parent
59ba644623
commit
e54388a5e0
@ -282,4 +282,14 @@ public abstract class ProxyServer
|
|||||||
*/
|
*/
|
||||||
public abstract ProxyConfig getConfig();
|
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<ProxiedPlayer> matchPlayer(String name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package net.md_5.bungee;
|
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 com.google.gson.GsonBuilder;
|
||||||
import net.md_5.bungee.api.Favicon;
|
import net.md_5.bungee.api.Favicon;
|
||||||
import net.md_5.bungee.api.ServerPing;
|
import net.md_5.bungee.api.ServerPing;
|
||||||
@ -581,8 +585,31 @@ public class BungeeCord extends ProxyServer
|
|||||||
return new Custom( player );
|
return new Custom( player );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Collection<String> getDisabledCommands()
|
public Collection<String> getDisabledCommands()
|
||||||
{
|
{
|
||||||
return config.getDisabledCommands();
|
return config.getDisabledCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<ProxiedPlayer> 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<ProxiedPlayer>()
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(ProxiedPlayer input)
|
||||||
|
{
|
||||||
|
return input.getName().toLowerCase().contains( partialName.toLowerCase() );
|
||||||
|
}
|
||||||
|
} ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user