mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-28 05:35:26 +01:00
Make more specific wildcards take priority over less specific ones
This commit is contained in:
parent
f52a106165
commit
6ffa6720be
@ -249,9 +249,11 @@ public abstract class PermissionHolder {
|
||||
Map<String, Boolean> perms = new HashMap<>();
|
||||
|
||||
for (Node node : getAllNodesFiltered(context)) {
|
||||
if (node.getPermission().equals("*") || node.getPermission().equals("'*'")) {
|
||||
if (possibleNodes != null && plugin.getConfiguration().getApplyWildcards()) {
|
||||
possibleNodes.forEach(n -> perms.put(n, true));
|
||||
if (possibleNodes != null && !possibleNodes.isEmpty()) {
|
||||
if (node.getPermission().equals("*") || node.getPermission().equals("'*'")) {
|
||||
if (plugin.getConfiguration().getApplyWildcards()) {
|
||||
possibleNodes.forEach(n -> perms.put(n, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -263,10 +265,12 @@ public abstract class PermissionHolder {
|
||||
.forEach(s -> perms.put(s, node.getValue()));
|
||||
}
|
||||
|
||||
if (plugin.getConfiguration().getApplyWildcards()) {
|
||||
node.resolveWildcard(possibleNodes).stream()
|
||||
.filter(s -> !perms.containsKey(s))
|
||||
.forEach(s -> perms.put(s, node.getValue()));
|
||||
if (possibleNodes != null && !possibleNodes.isEmpty()) {
|
||||
if (plugin.getConfiguration().getApplyWildcards()) {
|
||||
node.resolveWildcard(possibleNodes).stream()
|
||||
.filter(s -> !perms.containsKey(s))
|
||||
.forEach(s -> perms.put(s, node.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,14 +30,14 @@ import java.util.Comparator;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class PriorityComparator implements Comparator<Node> {
|
||||
private static final PriorityComparator instance = new PriorityComparator();
|
||||
private static final PriorityComparator INSTANCE = new PriorityComparator();
|
||||
|
||||
public static Comparator<Node> get() {
|
||||
return instance;
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public static Comparator<Node> reverse() {
|
||||
return instance.reversed();
|
||||
return INSTANCE.reversed();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -277,7 +277,6 @@ public class Node implements me.lucko.luckperms.api.Node {
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO move this method to resolve time
|
||||
@Override
|
||||
public List<String> resolveWildcard(List<String> possibleNodes) {
|
||||
if (!isWildcard() || possibleNodes == null) {
|
||||
|
@ -22,7 +22,6 @@
|
||||
|
||||
package me.lucko.luckperms.utils;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -87,36 +86,54 @@ public class PermissionCalculator {
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
public static class WildcardProcessor implements PermissionCalculator.PermissionProcessor {
|
||||
public static class WildcardProcessor implements PermissionProcessor {
|
||||
|
||||
@Getter
|
||||
private final Map<String, Boolean> map;
|
||||
|
||||
@Override
|
||||
public Tristate hasPermission(String permission) {
|
||||
if (map.containsKey("*")) {
|
||||
return Tristate.fromBoolean(map.get("*"));
|
||||
String node = permission;
|
||||
|
||||
while (node.contains(".")) {
|
||||
int endIndex = node.lastIndexOf('.');
|
||||
if (endIndex == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
node = node.substring(0, endIndex);
|
||||
if (!isEmpty(node)) {
|
||||
if (map.containsKey(node + ".*")) {
|
||||
return Tristate.fromBoolean(map.get(node + ".*"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (map.containsKey("'*'")) {
|
||||
return Tristate.fromBoolean(map.get("'*'"));
|
||||
}
|
||||
|
||||
String node = "";
|
||||
Iterable<String> permParts = Splitter.on('.').split(permission);
|
||||
for (String s : permParts) {
|
||||
if (node.equals("")) {
|
||||
node = s;
|
||||
} else {
|
||||
node = node + "." + s;
|
||||
}
|
||||
|
||||
if (map.containsKey(node + ".*")) {
|
||||
return Tristate.fromBoolean(map.get(node + ".*"));
|
||||
}
|
||||
if (map.containsKey("*")) {
|
||||
return Tristate.fromBoolean(map.get("*"));
|
||||
}
|
||||
|
||||
return Tristate.UNDEFINED;
|
||||
}
|
||||
|
||||
private static boolean isEmpty(String s) {
|
||||
if (s.equals("")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
char[] chars = s.toCharArray();
|
||||
for (char c : chars) {
|
||||
if (c != '.') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public interface PermissionProcessor {
|
||||
|
@ -97,29 +97,54 @@ public class LuckPermsUserSubject extends LuckPermsSubject {
|
||||
|
||||
// TODO proper implementation.
|
||||
@AllArgsConstructor
|
||||
private static class SpongeWildcardProcessor implements PermissionCalculator.PermissionProcessor {
|
||||
public static class SpongeWildcardProcessor implements PermissionCalculator.PermissionProcessor {
|
||||
|
||||
@Getter
|
||||
private final Map<String, Boolean> map;
|
||||
|
||||
@Override
|
||||
public me.lucko.luckperms.api.Tristate hasPermission(String permission) {
|
||||
String node = "";
|
||||
Iterable<String> permParts = Splitter.on('.').split(permission);
|
||||
for (String s : permParts) {
|
||||
if (node.equals("")) {
|
||||
node = s;
|
||||
} else {
|
||||
node = node + "." + s;
|
||||
String node = permission;
|
||||
|
||||
while (node.contains(".")) {
|
||||
int endIndex = node.lastIndexOf('.');
|
||||
if (endIndex == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (map.containsKey(node)) {
|
||||
return me.lucko.luckperms.api.Tristate.fromBoolean(map.get(node));
|
||||
node = node.substring(0, endIndex);
|
||||
if (!isEmpty(node)) {
|
||||
if (map.containsKey(node)) {
|
||||
return me.lucko.luckperms.api.Tristate.fromBoolean(map.get(node));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (map.containsKey("'*'")) {
|
||||
return me.lucko.luckperms.api.Tristate.fromBoolean(map.get("'*'"));
|
||||
}
|
||||
|
||||
if (map.containsKey("*")) {
|
||||
return me.lucko.luckperms.api.Tristate.fromBoolean(map.get("*"));
|
||||
}
|
||||
|
||||
return me.lucko.luckperms.api.Tristate.UNDEFINED;
|
||||
}
|
||||
|
||||
private static boolean isEmpty(String s) {
|
||||
if (s.equals("")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
char[] chars = s.toCharArray();
|
||||
for (char c : chars) {
|
||||
if (c != '.') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
|
Loading…
Reference in New Issue
Block a user