Re-add regex permissions & actually take note of the config options

This commit is contained in:
Luck 2016-09-19 21:00:23 +01:00
parent cff1b8a411
commit b1e34b55f8
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
8 changed files with 63 additions and 25 deletions

View File

@ -59,10 +59,15 @@ public class LPPermissible extends PermissibleBase {
super(sender);
this.parent = sender;
List<PermissionProcessor> processors = new ArrayList<>(4);
List<PermissionProcessor> processors = new ArrayList<>(5);
processors.add(new PermissionCalculator.MapProcessor(luckPermsPermissions));
processors.add(new AttachmentProcessor(attachmentPermissions));
processors.add(new PermissionCalculator.WildcardProcessor(luckPermsPermissions));
if (plugin.getConfiguration().getApplyWildcards()) {
processors.add(new PermissionCalculator.WildcardProcessor(luckPermsPermissions));
}
if (plugin.getConfiguration().getApplyRegex()) {
processors.add(new PermissionCalculator.RegexProcessor(luckPermsPermissions));
}
processors.add(new BukkitDefaultsProcessor(parent::isOp));
calculator = new PermissionCalculator(plugin, parent.getName(), plugin.getConfiguration().getDebugPermissionChecks(), processors);

View File

@ -46,8 +46,7 @@ apply-wildcards: true
# If the plugin should parse regex permissions.
# If set to true, LuckPerms will detect regex permissions, marked with "r=" at the start of the node, and resolve &
# apply all registered permissions matching the regex. This will only work for plugins that define all of their
# permissions to the server.
# apply all registered permissions matching the regex.
apply-regex: true
# If the plugin should complete and apply shorthand permissions.

View File

@ -39,9 +39,14 @@ public class BungeePlayerCache {
private final Map<String, Boolean> permissions = new ConcurrentHashMap<>();
public BungeePlayerCache(LuckPermsPlugin plugin, String name) {
List<PermissionProcessor> processors = new ArrayList<>(2);
List<PermissionProcessor> processors = new ArrayList<>(3);
processors.add(new PermissionCalculator.MapProcessor(permissions));
processors.add(new PermissionCalculator.WildcardProcessor(permissions));
if (plugin.getConfiguration().getApplyWildcards()) {
processors.add(new PermissionCalculator.WildcardProcessor(permissions));
}
if (plugin.getConfiguration().getApplyRegex()) {
processors.add(new PermissionCalculator.RegexProcessor(permissions));
}
calculator = new PermissionCalculator(plugin, name, plugin.getConfiguration().getDebugPermissionChecks(), processors);
}

View File

@ -46,8 +46,7 @@ apply-wildcards: true
# If the plugin should parse regex permissions.
# If set to true, LuckPerms will detect regex permissions, marked with "r=" at the start of the node, and resolve &
# apply all registered permissions matching the regex. This will only work for plugins that define all of their
# permissions to the server.
# apply all registered permissions matching the regex.
apply-regex: true
# If the plugin should complete and apply shorthand permissions.

View File

@ -40,19 +40,18 @@ public class Patterns {
public static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf('§') + "[0-9A-FK-OR]");
public static final Pattern NODE_CONTEXTS = Pattern.compile("\\(.+\\).*");
public static Pattern compile(String regex) throws PatternSyntaxException {
if (!CACHE.containsKey(regex)) {
Pattern p;
try {
p = Pattern.compile(regex);
} catch (PatternSyntaxException e) {
return null;
}
CACHE.put(regex, p);
public static Pattern compile(String regex) {
try {
return CACHE.computeIfAbsent(regex, s -> {
try {
return Pattern.compile(regex);
} catch (PatternSyntaxException e) {
return null;
}
});
} catch (NullPointerException e) {
return null;
}
return CACHE.get(regex);
}
}

View File

@ -27,10 +27,12 @@ import lombok.Getter;
import lombok.RequiredArgsConstructor;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.constants.Patterns;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
/**
* Calculates and caches permissions
@ -85,6 +87,31 @@ public class PermissionCalculator {
}
}
@AllArgsConstructor
public static class RegexProcessor implements PermissionProcessor {
@Getter
private final Map<String, Boolean> map;
@Override
public Tristate hasPermission(String permission) {
for (Map.Entry<String, Boolean> e : map.entrySet()) {
if (e.getKey().toLowerCase().startsWith("r=")) {
Pattern p = Patterns.compile(e.getKey().substring(2));
if (p == null) {
continue;
}
if (p.matcher(permission).matches()) {
return Tristate.fromBoolean(e.getValue());
}
}
}
return Tristate.UNDEFINED;
}
}
@AllArgsConstructor
public static class WildcardProcessor implements PermissionProcessor {

View File

@ -54,10 +54,15 @@ public class LuckPermsUserSubject extends LuckPermsSubject {
super(user, service);
this.user = user;
List<PermissionProcessor> processors = new ArrayList<>(4);
List<PermissionProcessor> processors = new ArrayList<>(5);
processors.add(new PermissionCalculator.MapProcessor(permissionCache));
processors.add(new SpongeWildcardProcessor(permissionCache));
processors.add(new PermissionCalculator.WildcardProcessor(permissionCache));
if (service.getPlugin().getConfiguration().getApplyWildcards()) {
processors.add(new SpongeWildcardProcessor(permissionCache));
processors.add(new PermissionCalculator.WildcardProcessor(permissionCache));
}
if (service.getPlugin().getConfiguration().getApplyRegex()) {
processors.add(new PermissionCalculator.RegexProcessor(permissionCache));
}
processors.add(new SpongeDefaultsProcessor(service));
calculator = new PermissionCalculator(service.getPlugin(), user.getName(), service.getPlugin().getConfiguration().getDebugPermissionChecks(), processors);

View File

@ -42,8 +42,7 @@ apply-wildcards=true
# If the plugin should parse regex permissions.
# If set to true, LuckPerms will detect regex permissions, marked with "r=" at the start of the node, and resolve &
# apply all registered permissions matching the regex. This will only work for plugins that define all of their
# permissions to the server.
# apply all registered permissions matching the regex.
apply-regex=true
# If the plugin should complete and apply shorthand permissions.