Search in sources :

Example 11 with ImmutableContextSet

use of me.lucko.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.

the class NodeMap method clear.

void clear(ContextSet contextSet) {
    this.lock.lock();
    try {
        ImmutableContextSet context = contextSet.makeImmutable();
        this.map.removeAll(context);
        this.inheritanceMap.removeAll(context);
    } finally {
        this.lock.unlock();
    }
}
Also used : ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet)

Example 12 with ImmutableContextSet

use of me.lucko.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.

the class NodeMap method remove.

void remove(Node node) {
    this.lock.lock();
    try {
        ImmutableContextSet context = node.getFullContexts().makeImmutable();
        this.map.get(context).removeIf(e -> e.equals(node, StandardNodeEquality.IGNORE_EXPIRY_TIME_AND_VALUE));
        if (node.isGroupNode()) {
            this.inheritanceMap.get(context).removeIf(e -> e.equals(node, StandardNodeEquality.IGNORE_EXPIRY_TIME_AND_VALUE));
        }
    } finally {
        this.lock.unlock();
    }
}
Also used : ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet)

Example 13 with ImmutableContextSet

use of me.lucko.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.

the class NodeMap method removeExact.

private void removeExact(Node node) {
    this.lock.lock();
    try {
        ImmutableContextSet context = node.getFullContexts().makeImmutable();
        this.map.remove(context, node);
        if (node.isGroupNode() && node.getValuePrimitive()) {
            this.inheritanceMap.remove(context, node);
        }
    } finally {
        this.lock.unlock();
    }
}
Also used : ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet)

Example 14 with ImmutableContextSet

use of me.lucko.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.

the class CalculatedSubjectData method resolveParents.

public Set<LPSubjectReference> resolveParents() {
    // get relevant entries
    SortedMap<ImmutableContextSet, Set<LPSubjectReference>> sorted = new TreeMap<>(ContextSetComparator.reverse());
    for (Map.Entry<ImmutableContextSet, Set<LPSubjectReference>> entry : this.parents.entrySet()) {
        sorted.put(entry.getKey(), entry.getValue());
    }
    // flatten
    Set<LPSubjectReference> result = new LinkedHashSet<>();
    for (Set<LPSubjectReference> set : sorted.values()) {
        for (LPSubjectReference e : set) {
            if (!result.contains(e)) {
                result.add(e);
            }
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet) ContextSet(me.lucko.luckperms.api.context.ContextSet) LinkedHashSet(java.util.LinkedHashSet) LPSubjectReference(me.lucko.luckperms.sponge.service.model.LPSubjectReference) ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet) TreeMap(java.util.TreeMap) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 15 with ImmutableContextSet

use of me.lucko.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.

the class HolderSubjectData method getAllOptions.

@Override
public ImmutableMap<ImmutableContextSet, ImmutableMap<String, String>> getAllOptions() {
    Map<ImmutableContextSet, Map<String, String>> options = new HashMap<>();
    Map<ImmutableContextSet, Integer> minPrefixPriority = new HashMap<>();
    Map<ImmutableContextSet, Integer> minSuffixPriority = new HashMap<>();
    for (Node n : this.holder.getNodes(this.type).values()) {
        if (!n.getValuePrimitive())
            continue;
        if (!n.isMeta() && !n.isPrefix() && !n.isSuffix())
            continue;
        ImmutableContextSet immutableContexts = n.getFullContexts().makeImmutable();
        if (!options.containsKey(immutableContexts)) {
            options.put(immutableContexts, new HashMap<>());
            minPrefixPriority.put(immutableContexts, Integer.MIN_VALUE);
            minSuffixPriority.put(immutableContexts, Integer.MIN_VALUE);
        }
        if (n.isPrefix()) {
            Map.Entry<Integer, String> value = n.getPrefix();
            if (value.getKey() > minPrefixPriority.get(immutableContexts)) {
                options.get(immutableContexts).put(NodeFactory.PREFIX_KEY, value.getValue());
                minPrefixPriority.put(immutableContexts, value.getKey());
            }
            continue;
        }
        if (n.isSuffix()) {
            Map.Entry<Integer, String> value = n.getSuffix();
            if (value.getKey() > minSuffixPriority.get(immutableContexts)) {
                options.get(immutableContexts).put(NodeFactory.SUFFIX_KEY, value.getValue());
                minSuffixPriority.put(immutableContexts, value.getKey());
            }
            continue;
        }
        if (n.isMeta()) {
            Map.Entry<String, String> meta = n.getMeta();
            options.get(immutableContexts).put(meta.getKey(), meta.getValue());
        }
    }
    ImmutableMap.Builder<ImmutableContextSet, ImmutableMap<String, String>> map = ImmutableMap.builder();
    for (Map.Entry<ImmutableContextSet, Map<String, String>> e : options.entrySet()) {
        map.put(e.getKey(), ImmutableMap.copyOf(e.getValue()));
    }
    return map.build();
}
Also used : HashMap(java.util.HashMap) Node(me.lucko.luckperms.api.Node) ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

ImmutableContextSet (me.lucko.luckperms.api.context.ImmutableContextSet)27 Map (java.util.Map)10 ImmutableMap (com.google.common.collect.ImmutableMap)9 HashMap (java.util.HashMap)6 LPSubjectReference (me.lucko.luckperms.sponge.service.model.LPSubjectReference)6 Node (me.lucko.luckperms.api.Node)5 ImmutableList (com.google.common.collect.ImmutableList)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 List (java.util.List)3 LPSubject (me.lucko.luckperms.sponge.service.model.LPSubject)3 JsonObject (com.google.gson.JsonObject)2 LinkedHashSet (java.util.LinkedHashSet)2 Set (java.util.Set)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Tristate (me.lucko.luckperms.api.Tristate)2 ContextSet (me.lucko.luckperms.api.context.ContextSet)2 NodeModel (me.lucko.luckperms.common.node.NodeModel)2