use of com.sk89q.minecraft.util.commands.CommandException in project WorldGuard by EngineHub.
the class StringMatcher method matchSinglePlayer.
/**
* Match only a single player.
*
* @param sender The {@link Actor} who is requesting a player match
* @param filter The filter string.
* @see #matchPlayers(LocalPlayer) for filter string syntax
* @return The single player
* @throws CommandException If more than one player match was found
*/
default LocalPlayer matchSinglePlayer(Actor sender, String filter) throws CommandException {
// This will throw an exception if there are no matches
Iterator<? extends LocalPlayer> players = matchPlayers(sender, filter).iterator();
LocalPlayer match = players.next();
// as that may be the wrong player)
if (players.hasNext()) {
throw new CommandException("More than one player found! " + "Use @<name> for exact matching.");
}
return match;
}
Aggregations