mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-12-25 18:47:44 +01:00
Remove both UUID and names from domains for removal commands.
This commit is contained in:
parent
9b69c07663
commit
387431c9c7
@ -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<DefaultDomain> 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<DefaultDomain> 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(
|
||||
|
@ -39,17 +39,23 @@
|
||||
|
||||
/**
|
||||
* Resolves input for a domain (i.e. "player1 player2 <uuid> g:group").
|
||||
*
|
||||
* <p>Unless {@link #getUseNames()} is true, names will be resolved into
|
||||
* UUIDs.</p>
|
||||
*/
|
||||
public class DomainInputResolver implements Callable<DefaultDomain> {
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user