Revert: Use faster wildcard parsing method

This commit is contained in:
Luck 2016-11-21 17:07:13 +00:00
parent 4874f9d051
commit 384fbf5464
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
2 changed files with 24 additions and 34 deletions

View File

@ -26,32 +26,27 @@ import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.common.calculators.PermissionProcessor; import me.lucko.luckperms.common.calculators.PermissionProcessor;
import java.util.Map; import java.util.Map;
import java.util.regex.Pattern;
public class WildcardProcessor implements PermissionProcessor { public class WildcardProcessor implements PermissionProcessor {
private static final Pattern SPLIT = Pattern.compile("\\.");
private Map<String, Boolean> map = null; private Map<String, Boolean> map = null;
@Override @Override
public Tristate hasPermission(String s) { public Tristate hasPermission(String permission) {
if (s.startsWith(".") || !s.contains(".")) { String node = permission;
throw new IllegalArgumentException();
while (true) {
int endIndex = node.lastIndexOf('.');
if (endIndex == -1) {
break;
} }
String[] parts = SPLIT.split(s); node = node.substring(0, endIndex);
StringBuilder sb = new StringBuilder(); if (!node.isEmpty()) {
Boolean b = map.get(node + ".*");
for (int i = parts.length - 2; i >= 0; i--) {
for (int i1 = 0; i1 <= i; i1++) {
sb.append(parts[i1]).append(".");
}
Boolean b = map.get(sb.append("*").toString());
if (b != null) { if (b != null) {
return Tristate.fromBoolean(b); return Tristate.fromBoolean(b);
} }
}
sb.setLength(0);
} }
Boolean b = map.get("'*'"); Boolean b = map.get("'*'");

View File

@ -26,32 +26,27 @@ import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.common.calculators.PermissionProcessor; import me.lucko.luckperms.common.calculators.PermissionProcessor;
import java.util.Map; import java.util.Map;
import java.util.regex.Pattern;
public class SpongeWildcardProcessor implements PermissionProcessor { public class SpongeWildcardProcessor implements PermissionProcessor {
private static final Pattern SPLIT = Pattern.compile("\\.");
private Map<String, Boolean> map = null; private Map<String, Boolean> map = null;
@Override @Override
public Tristate hasPermission(String s) { public Tristate hasPermission(String permission) {
if (s.startsWith(".") || !s.contains(".")) { String node = permission;
throw new IllegalArgumentException();
while (true) {
int endIndex = node.lastIndexOf('.');
if (endIndex == -1) {
break;
} }
String[] parts = SPLIT.split(s); node = node.substring(0, endIndex);
StringBuilder sb = new StringBuilder(); if (!node.isEmpty()) {
Boolean b = map.get(node);
for (int i = parts.length - 2; i >= 0; i--) {
for (int i1 = 0; i1 <= i; i1++) {
sb.append(parts[i1]).append(".");
}
Boolean b = map.get(sb.deleteCharAt(sb.length() - 1).toString());
if (b != null) { if (b != null) {
return Tristate.fromBoolean(b); return Tristate.fromBoolean(b);
} }
}
sb.setLength(0);
} }
return Tristate.UNDEFINED; return Tristate.UNDEFINED;