Search in sources :

Example 26 with CommandException

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;
}
Also used : LocalPlayer(com.sk89q.worldguard.LocalPlayer) CommandException(com.sk89q.minecraft.util.commands.CommandException)

Aggregations

CommandException (com.sk89q.minecraft.util.commands.CommandException)26 Command (com.sk89q.minecraft.util.commands.Command)18 LocalPlayer (com.sk89q.worldguard.LocalPlayer)16 CommandPermissionsException (com.sk89q.minecraft.util.commands.CommandPermissionsException)15 World (com.sk89q.worldedit.world.World)14 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)12 RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)11 GlobalProtectedRegion (com.sk89q.worldguard.protection.regions.GlobalProtectedRegion)10 LoggerToChatHandler (com.sk89q.worldguard.util.logging.LoggerToChatHandler)5 Logger (java.util.logging.Logger)5 ConfigurationManager (com.sk89q.worldguard.config.ConfigurationManager)4 RegionPermissionModel (com.sk89q.worldguard.internal.permission.RegionPermissionModel)4 CommandPermissions (com.sk89q.minecraft.util.commands.CommandPermissions)3 NestedCommand (com.sk89q.minecraft.util.commands.NestedCommand)3 TextComponent (com.sk89q.worldedit.util.formatting.text.TextComponent)3 ProtectedPolygonalRegion (com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion)3 RegionContainer (com.sk89q.worldguard.protection.regions.RegionContainer)3 WorldEdit (com.sk89q.worldedit.WorldEdit)2 Actor (com.sk89q.worldedit.extension.platform.Actor)2 Capability (com.sk89q.worldedit.extension.platform.Capability)2