Re-add regex permissions & actually take note of the config options
This commit is contained in:
parent
cff1b8a411
commit
b1e34b55f8
@ -59,10 +59,15 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
super(sender);
|
super(sender);
|
||||||
this.parent = 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 PermissionCalculator.MapProcessor(luckPermsPermissions));
|
||||||
processors.add(new AttachmentProcessor(attachmentPermissions));
|
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));
|
processors.add(new BukkitDefaultsProcessor(parent::isOp));
|
||||||
|
|
||||||
calculator = new PermissionCalculator(plugin, parent.getName(), plugin.getConfiguration().getDebugPermissionChecks(), processors);
|
calculator = new PermissionCalculator(plugin, parent.getName(), plugin.getConfiguration().getDebugPermissionChecks(), processors);
|
||||||
|
@ -46,8 +46,7 @@ apply-wildcards: true
|
|||||||
|
|
||||||
# If the plugin should parse regex permissions.
|
# 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 &
|
# 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
|
# apply all registered permissions matching the regex.
|
||||||
# permissions to the server.
|
|
||||||
apply-regex: true
|
apply-regex: true
|
||||||
|
|
||||||
# If the plugin should complete and apply shorthand permissions.
|
# If the plugin should complete and apply shorthand permissions.
|
||||||
|
@ -39,9 +39,14 @@ public class BungeePlayerCache {
|
|||||||
private final Map<String, Boolean> permissions = new ConcurrentHashMap<>();
|
private final Map<String, Boolean> permissions = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public BungeePlayerCache(LuckPermsPlugin plugin, String name) {
|
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.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);
|
calculator = new PermissionCalculator(plugin, name, plugin.getConfiguration().getDebugPermissionChecks(), processors);
|
||||||
}
|
}
|
||||||
|
@ -46,8 +46,7 @@ apply-wildcards: true
|
|||||||
|
|
||||||
# If the plugin should parse regex permissions.
|
# 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 &
|
# 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
|
# apply all registered permissions matching the regex.
|
||||||
# permissions to the server.
|
|
||||||
apply-regex: true
|
apply-regex: true
|
||||||
|
|
||||||
# If the plugin should complete and apply shorthand permissions.
|
# If the plugin should complete and apply shorthand permissions.
|
||||||
|
@ -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 STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf('§') + "[0-9A-FK-OR]");
|
||||||
public static final Pattern NODE_CONTEXTS = Pattern.compile("\\(.+\\).*");
|
public static final Pattern NODE_CONTEXTS = Pattern.compile("\\(.+\\).*");
|
||||||
|
|
||||||
public static Pattern compile(String regex) throws PatternSyntaxException {
|
public static Pattern compile(String regex) {
|
||||||
if (!CACHE.containsKey(regex)) {
|
try {
|
||||||
Pattern p;
|
return CACHE.computeIfAbsent(regex, s -> {
|
||||||
try {
|
try {
|
||||||
p = Pattern.compile(regex);
|
return Pattern.compile(regex);
|
||||||
} catch (PatternSyntaxException e) {
|
} catch (PatternSyntaxException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
CACHE.put(regex, p);
|
} catch (NullPointerException e) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return CACHE.get(regex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,10 +27,12 @@ import lombok.Getter;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import me.lucko.luckperms.LuckPermsPlugin;
|
import me.lucko.luckperms.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.api.Tristate;
|
import me.lucko.luckperms.api.Tristate;
|
||||||
|
import me.lucko.luckperms.constants.Patterns;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates and caches permissions
|
* 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
|
@AllArgsConstructor
|
||||||
public static class WildcardProcessor implements PermissionProcessor {
|
public static class WildcardProcessor implements PermissionProcessor {
|
||||||
|
|
||||||
|
@ -54,10 +54,15 @@ public class LuckPermsUserSubject extends LuckPermsSubject {
|
|||||||
super(user, service);
|
super(user, service);
|
||||||
this.user = user;
|
this.user = user;
|
||||||
|
|
||||||
List<PermissionProcessor> processors = new ArrayList<>(4);
|
List<PermissionProcessor> processors = new ArrayList<>(5);
|
||||||
processors.add(new PermissionCalculator.MapProcessor(permissionCache));
|
processors.add(new PermissionCalculator.MapProcessor(permissionCache));
|
||||||
processors.add(new SpongeWildcardProcessor(permissionCache));
|
if (service.getPlugin().getConfiguration().getApplyWildcards()) {
|
||||||
processors.add(new PermissionCalculator.WildcardProcessor(permissionCache));
|
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));
|
processors.add(new SpongeDefaultsProcessor(service));
|
||||||
|
|
||||||
calculator = new PermissionCalculator(service.getPlugin(), user.getName(), service.getPlugin().getConfiguration().getDebugPermissionChecks(), processors);
|
calculator = new PermissionCalculator(service.getPlugin(), user.getName(), service.getPlugin().getConfiguration().getDebugPermissionChecks(), processors);
|
||||||
|
@ -42,8 +42,7 @@ apply-wildcards=true
|
|||||||
|
|
||||||
# If the plugin should parse regex permissions.
|
# 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 &
|
# 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
|
# apply all registered permissions matching the regex.
|
||||||
# permissions to the server.
|
|
||||||
apply-regex=true
|
apply-regex=true
|
||||||
|
|
||||||
# If the plugin should complete and apply shorthand permissions.
|
# If the plugin should complete and apply shorthand permissions.
|
||||||
|
Loading…
Reference in New Issue
Block a user