From 9424d2d2ba7d07cd186f8254f5578e0be881c0b1 Mon Sep 17 00:00:00 2001 From: Luck Date: Fri, 19 Aug 2016 19:36:04 +0100 Subject: [PATCH] Process shorthand in server/world names --- .../luckperms/core/PermissionHolder.java | 23 +++++++++++++++---- .../luckperms/utils/ArgumentChecker.java | 2 +- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/me/lucko/luckperms/core/PermissionHolder.java b/common/src/main/java/me/lucko/luckperms/core/PermissionHolder.java index 1a35f583..57ab2746 100644 --- a/common/src/main/java/me/lucko/luckperms/core/PermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/core/PermissionHolder.java @@ -701,15 +701,28 @@ public abstract class PermissionHolder { } private boolean matches(String entry, String possibleRegex) { - if (!possibleRegex.toLowerCase().startsWith("r=") || !plugin.getConfiguration().getApplyRegex()) { - return entry.equalsIgnoreCase(possibleRegex); + if (possibleRegex.toLowerCase().startsWith("r=") && plugin.getConfiguration().getApplyRegex()) { + Pattern p = Patterns.compile(possibleRegex.substring(2)); + if (p == null) { + return false; + } + return p.matcher(entry).matches(); } - Pattern p = Patterns.compile(possibleRegex.substring(2)); - if (p == null) { + if (possibleRegex.startsWith("(") && possibleRegex.endsWith(")") && possibleRegex.contains("|")) { + final String bits = possibleRegex.substring(1, possibleRegex.length() - 1); + String[] parts = Patterns.VERTICAL_BAR.split(bits); + + for (String s : parts) { + if (s.equalsIgnoreCase(entry)) { + return true; + } + } + return false; } - return p.matcher(entry).matches(); + + return entry.equalsIgnoreCase(possibleRegex); } private Map applyRegex(Map input, List possibleNodes) { diff --git a/common/src/main/java/me/lucko/luckperms/utils/ArgumentChecker.java b/common/src/main/java/me/lucko/luckperms/utils/ArgumentChecker.java index d1949adf..8bcc675f 100644 --- a/common/src/main/java/me/lucko/luckperms/utils/ArgumentChecker.java +++ b/common/src/main/java/me/lucko/luckperms/utils/ArgumentChecker.java @@ -37,7 +37,7 @@ public class ArgumentChecker { } public static boolean checkServer(String s) { - return s.toLowerCase().startsWith("r=") || Patterns.NON_ALPHA_NUMERIC.matcher(s).find(); + return s.toLowerCase().startsWith("r=") || (s.startsWith("(") && s.endsWith(")") && s.contains("|")) || Patterns.NON_ALPHA_NUMERIC.matcher(s).find(); } public static boolean checkNode(String s) {