mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 03:25:19 +01:00
Allow meta/prefix/suffix nodes to be negated to cancel inheritance (#3020)
This commit is contained in:
parent
b2c76aca7d
commit
9c5a43b487
@ -40,8 +40,10 @@ import net.luckperms.api.node.types.PrefixNode;
|
||||
import net.luckperms.api.node.types.SuffixNode;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
@ -79,6 +81,8 @@ public class MetaAccumulator {
|
||||
private int weight = 0;
|
||||
private String primaryGroup;
|
||||
|
||||
private Set<String> seenNodeKeys = new HashSet<>();
|
||||
|
||||
private final MetaStackDefinition prefixDefinition;
|
||||
private final MetaStackDefinition suffixDefinition;
|
||||
private final MetaStackAccumulator prefixAccumulator;
|
||||
@ -120,6 +124,7 @@ public class MetaAccumulator {
|
||||
if (this.primaryGroup != null && !this.meta.containsKey("primarygroup")) {
|
||||
this.meta.put("primarygroup", this.primaryGroup);
|
||||
}
|
||||
this.seenNodeKeys = null; // free up for GC
|
||||
|
||||
this.state.set(State.COMPLETE);
|
||||
}
|
||||
@ -129,6 +134,16 @@ public class MetaAccumulator {
|
||||
public void accumulateNode(Node n) {
|
||||
ensureState(State.ACCUMULATING);
|
||||
|
||||
// only process distinct nodes once, allows inheritance to be
|
||||
// "cancelled out" by assigning a false copy.
|
||||
if (!this.seenNodeKeys.add(n.getKey())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!n.getValue()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (n instanceof MetaNode) {
|
||||
MetaNode mn = (MetaNode) n;
|
||||
this.meta.put(mn.getMetaKey(), mn.getMetaValue());
|
||||
|
@ -394,7 +394,7 @@ public abstract class PermissionHolder {
|
||||
// accumulate nodes
|
||||
for (DataType dataType : holder.queryOrder(queryOptions)) {
|
||||
holder.getData(dataType).forEach(queryOptions, node -> {
|
||||
if (node.getValue() && NodeType.META_OR_CHAT_META.matches(node)) {
|
||||
if (NodeType.META_OR_CHAT_META.matches(node)) {
|
||||
accumulator.accumulateNode(node);
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user