diff --git a/common/src/main/java/me/lucko/luckperms/common/core/model/ImmutableNode.java b/common/src/main/java/me/lucko/luckperms/common/core/model/ImmutableNode.java index 836d05393..8388eeefc 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/model/ImmutableNode.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/model/ImmutableNode.java @@ -61,28 +61,53 @@ public class ImmutableNode implements Node { private static final Pattern META_PATTERN = Pattern.compile("meta\\..*\\..*"); private static boolean shouldApply(String str, boolean applyRegex, String thisStr) { + if (str.equalsIgnoreCase(thisStr)) { + return true; + } + + Set expandedStr = ShorthandParser.parseShorthand(str, false); + Set expandedThisStr = ShorthandParser.parseShorthand(thisStr, false); + if (str.toLowerCase().startsWith("r=") && applyRegex) { Pattern p = Patterns.compile(str.substring(2)); if (p == null) { return false; } - return p.matcher(thisStr).matches(); - } - if (str.startsWith("(") && str.endsWith(")") && str.contains("|")) { - final String bits = str.substring(1, str.length() - 1); - Iterable parts = Splitter.on('|').split(bits); - - for (String s : parts) { - if (s.equalsIgnoreCase(thisStr)) { + for (String s : expandedThisStr) { + if (p.matcher(s).matches()) { return true; } } - return false; } - return thisStr.equalsIgnoreCase(str); + if (thisStr.toLowerCase().startsWith("r=") && applyRegex) { + Pattern p = Patterns.compile(thisStr.substring(2)); + if (p == null) { + return false; + } + + for (String s : expandedStr) { + if (p.matcher(s).matches()) { + return true; + } + } + return false; + } + + if (expandedStr.size() <= 1 && expandedThisStr.size() <= 1) { + return false; + } + + for (String t : expandedThisStr) { + for (String s : expandedStr) { + if (t.equalsIgnoreCase(s)) { + return true; + } + } + } + return false; } @SuppressWarnings("ResultOfMethodCallIgnored") diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/ShorthandParser.java b/common/src/main/java/me/lucko/luckperms/common/utils/ShorthandParser.java index c9ac538c1..c41be933c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/ShorthandParser.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/ShorthandParser.java @@ -44,6 +44,10 @@ public class ShorthandParser { .build(); public static Set parseShorthand(String s) { + return parseShorthand(s, true); + } + + public static Set parseShorthand(String s, boolean removeSelf) { Set results = new HashSet<>(); results.add(s); @@ -68,7 +72,10 @@ public class ShorthandParser { break; } - results.remove(s); + if (removeSelf) { + results.remove(s); + } + return results; }