diff --git a/src/main/java/com/sk89q/worldguard/bukkit/commands/RegionMemberCommands.java b/src/main/java/com/sk89q/worldguard/bukkit/commands/RegionMemberCommands.java index c95f597b..e981d2a8 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/commands/RegionMemberCommands.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/commands/RegionMemberCommands.java @@ -28,6 +28,7 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.domains.DefaultDomain; import com.sk89q.worldguard.protection.databases.util.DomainInputResolver; +import com.sk89q.worldguard.protection.databases.util.DomainInputResolver.UserLocatorPolicy; import com.sk89q.worldguard.protection.flags.DefaultFlag; import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.ProtectedRegion; @@ -95,7 +96,7 @@ public void addMember(CommandContext args, CommandSender sender) throws CommandE // Resolve members asynchronously DomainInputResolver resolver = new DomainInputResolver( plugin.getProfileService(), args.getParsedPaddedSlice(1, 0)); - resolver.setUseNames(args.hasFlag('n')); + resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_ONLY); // Then add it to the members ListenableFuture future = Futures.transform( @@ -167,7 +168,7 @@ public void addOwner(CommandContext args, CommandSender sender) throws CommandEx // Resolve owners asynchronously DomainInputResolver resolver = new DomainInputResolver( plugin.getProfileService(), args.getParsedPaddedSlice(1, 0)); - resolver.setUseNames(args.hasFlag('n')); + resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_ONLY); // Then add it to the owners ListenableFuture future = Futures.transform( @@ -237,7 +238,7 @@ public void removeMember(CommandContext args, CommandSender sender) throws Comma // Resolve members asynchronously DomainInputResolver resolver = new DomainInputResolver( plugin.getProfileService(), args.getParsedPaddedSlice(1, 0)); - resolver.setUseNames(args.hasFlag('n')); + resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_AND_NAME); // Then remove it from the members future = Futures.transform( @@ -309,7 +310,7 @@ public void removeOwner(CommandContext args, // Resolve owners asynchronously DomainInputResolver resolver = new DomainInputResolver( plugin.getProfileService(), args.getParsedPaddedSlice(1, 0)); - resolver.setUseNames(args.hasFlag('n')); + resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_AND_NAME); // Then remove it from the owners future = Futures.transform( diff --git a/src/main/java/com/sk89q/worldguard/protection/databases/util/DomainInputResolver.java b/src/main/java/com/sk89q/worldguard/protection/databases/util/DomainInputResolver.java index 55bda8c6..c4ff7a75 100644 --- a/src/main/java/com/sk89q/worldguard/protection/databases/util/DomainInputResolver.java +++ b/src/main/java/com/sk89q/worldguard/protection/databases/util/DomainInputResolver.java @@ -39,17 +39,23 @@ /** * Resolves input for a domain (i.e. "player1 player2 <uuid> g:group"). - * - *

Unless {@link #getUseNames()} is true, names will be resolved into - * UUIDs.

*/ public class DomainInputResolver implements Callable { private static final Pattern GROUP_PATTERN = Pattern.compile("(?i)^[G]:(.+)$"); + /** + * The policy for locating users. + */ + public enum UserLocatorPolicy { + UUID_ONLY, + NAME_ONLY, + UUID_AND_NAME + } + private final ProfileService profileService; private final String[] input; - private boolean useNames = false; + private UserLocatorPolicy locatorPolicy = UserLocatorPolicy.UUID_ONLY; /** * Create a new instance. @@ -65,21 +71,22 @@ public DomainInputResolver(ProfileService profileService, String[] input) { } /** - * Get whether names should be used rather than UUIDs. + * Get the policy used for identifying users. * - * @return true to use names + * @return the policy */ - public boolean getUseNames() { - return useNames; + public UserLocatorPolicy getLocatorPolicy() { + return locatorPolicy; } /** - * Set whether names should be used rather than UUIDs. + * Set the policy used for identifying users. * - * @param useNames true to use names + * @param locatorPolicy the policy */ - public void setUseNames(boolean useNames) { - this.useNames = useNames; + public void setLocatorPolicy(UserLocatorPolicy locatorPolicy) { + checkNotNull(locatorPolicy); + this.locatorPolicy = locatorPolicy; } @Override @@ -93,12 +100,19 @@ public DefaultDomain call() throws UnresolvedNamesException { domain.addGroup(m.group(1)); } else { try { - domain.addPlayer(UUID.fromString(UUIDs.addDashes(s))); + // Try to add any UUIDs given + domain.addPlayer(UUID.fromString(UUIDs.addDashes(s.replaceAll("^uuid:", "")))); } catch (IllegalArgumentException e) { - if (useNames) { - domain.addPlayer(s); - } else { - namesToQuery.add(s.toLowerCase()); + switch (locatorPolicy) { + case NAME_ONLY: + domain.addPlayer(s); + break; + case UUID_ONLY: + namesToQuery.add(s.toLowerCase()); + break; + case UUID_AND_NAME: + domain.addPlayer(s); + namesToQuery.add(s.toLowerCase()); } } }