Re-add regex permissions & actually take note of the config options
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user