Add permissions for individual flag values.

Closes WORLDGUARD-3103.
This commit is contained in:
sk89q 2015-01-08 01:04:36 -08:00
parent d8dd86dfe8
commit 0900289437
2 changed files with 14 additions and 2 deletions

View File

@ -519,7 +519,7 @@ public void flag(CommandContext args, CommandSender sender) throws CommandExcept
// Also make sure that we can use this flag
// This permission is confusing and probably should be replaced, but
// but not here -- in the model
if (!permModel.maySetFlag(existing, foundFlag)) {
if (!permModel.maySetFlag(existing, foundFlag, value)) {
throw new CommandPermissionsException();
}

View File

@ -117,13 +117,25 @@ public boolean mayList(String targetPlayer) {
public boolean maySetFlag(ProtectedRegion region) {
return hasPatternPermission("flag.regions", region);
}
public boolean maySetFlag(ProtectedRegion region, Flag<?> flag) {
// This is a WTF permission
return hasPatternPermission(
"flag.flags." + flag.getName().toLowerCase(), region);
}
public boolean maySetFlag(ProtectedRegion region, Flag<?> flag, String value) {
String sanitizedValue = value.trim().toLowerCase().replaceAll("[^a-z0-9]", "");
if (sanitizedValue.length() > 20) {
sanitizedValue = sanitizedValue.substring(0, 20);
}
// This is a WTF permission
return hasPatternPermission(
"flag.flags." + flag.getName().toLowerCase() + "." + sanitizedValue, region);
}
public boolean mayAddMembers(ProtectedRegion region) {
return hasPatternPermission("addmember", region);
}