Search in sources :

Example 1 with Node

use of net.luckperms.api.node.Node in project LuckPerms by lucko.

the class AbstractConfigurateStorage method readNodes.

protected static Set<Node> readNodes(ConfigurationNode data) {
    Set<Node> nodes = new HashSet<>();
    for (ConfigurationNode appended : data.getNode("permissions").getChildrenList()) {
        String plainValue = appended.getValue(Types::strictAsString);
        if (plainValue != null && !plainValue.isEmpty()) {
            nodes.add(NodeBuilders.determineMostApplicable(plainValue).build());
            continue;
        }
        NodeEntry entry = parseNode(appended, "permission");
        if (entry == null || entry.key.isEmpty()) {
            continue;
        }
        nodes.add(readAttributes(NodeBuilders.determineMostApplicable(entry.key).value(entry.attributes.getNode("value").getBoolean(true)), entry.attributes));
    }
    for (ConfigurationNode appended : data.getNode("parents").getChildrenList()) {
        String plainValue = appended.getValue(Types::strictAsString);
        if (plainValue != null) {
            nodes.add(Inheritance.builder(plainValue).build());
            continue;
        }
        NodeEntry entry = parseNode(appended, "group");
        if (entry == null || entry.key.isEmpty()) {
            continue;
        }
        nodes.add(readAttributes(Inheritance.builder(entry.key), entry.attributes));
    }
    for (ConfigurationNode appended : data.getNode("prefixes").getChildrenList()) {
        NodeEntry entry = parseNode(appended, "prefix");
        if (entry == null) {
            continue;
        }
        nodes.add(readAttributes(Prefix.builder(entry.key, entry.attributes.getNode("priority").getInt(0)), entry.attributes));
    }
    for (ConfigurationNode appended : data.getNode("suffixes").getChildrenList()) {
        NodeEntry entry = parseNode(appended, "suffix");
        if (entry == null) {
            continue;
        }
        nodes.add(readAttributes(Suffix.builder(entry.key, entry.attributes.getNode("priority").getInt(0)), entry.attributes));
    }
    for (ConfigurationNode appended : data.getNode("meta").getChildrenList()) {
        NodeEntry entry = parseNode(appended, "key");
        if (entry == null || entry.key.isEmpty()) {
            continue;
        }
        nodes.add(readAttributes(Meta.builder(entry.key, entry.attributes.getNode("value").getString("null")), entry.attributes));
    }
    return nodes;
}
Also used : Types(ninja.leaping.configurate.Types) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) ChatMetaNode(net.luckperms.api.node.types.ChatMetaNode) Node(net.luckperms.api.node.Node) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) MetaNode(net.luckperms.api.node.types.MetaNode) HashSet(java.util.HashSet)

Example 2 with Node

use of net.luckperms.api.node.Node in project LuckPerms by lucko.

the class NodeMapMutable method removeMatchingButNotSame.

private static void removeMatchingButNotSame(Iterator<Node> it, Node node, Difference<Node> result) {
    while (it.hasNext()) {
        Node el = it.next();
        if (el != node && node.equals(el, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE)) {
            it.remove();
            result.recordChange(ChangeType.REMOVE, el);
        }
    }
}
Also used : Node(net.luckperms.api.node.Node) InheritanceNode(net.luckperms.api.node.types.InheritanceNode)

Example 3 with Node

use of net.luckperms.api.node.Node in project LuckPerms by lucko.

the class NodeMapMutable method removeExact.

@Override
public Difference<Node> removeExact(Node node) {
    ImmutableContextSet context = node.getContexts();
    Difference<Node> result = new Difference<>();
    this.lock.lock();
    try {
        SortedSet<Node> nodes = this.map.get(context);
        if (nodes == null) {
            return result;
        }
        // try to remove an exact match
        if (nodes.remove(node)) {
            // if we removed something, record to results
            result.recordChange(ChangeType.REMOVE, node);
            // update inheritance map too if necessary
            if (node instanceof InheritanceNode && node.getValue()) {
                SortedSet<InheritanceNode> inhNodes = this.inheritanceMap.get(context);
                if (inhNodes != null) {
                    inhNodes.remove(node);
                }
            }
        }
    } finally {
        this.lock.unlock();
    }
    return result;
}
Also used : Node(net.luckperms.api.node.Node) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) Difference(me.lucko.luckperms.common.util.Difference)

Example 4 with Node

use of net.luckperms.api.node.Node in project LuckPerms by lucko.

the class NodeMapMutable method removeIf.

@Override
public Difference<Node> removeIf(ContextSet contextSet, Predicate<? super Node> predicate) {
    ImmutableContextSet context = contextSet.immutableCopy();
    Difference<Node> result = new Difference<>();
    this.lock.lock();
    try {
        SortedSet<Node> nodes = this.map.get(context);
        if (nodes == null) {
            return result;
        }
        removeMatching(nodes.iterator(), predicate, result);
    } finally {
        this.lock.unlock();
    }
    return result;
}
Also used : Node(net.luckperms.api.node.Node) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) Difference(me.lucko.luckperms.common.util.Difference)

Example 5 with Node

use of net.luckperms.api.node.Node in project LuckPerms by lucko.

the class NodeMapMutable method remove.

@Override
public Difference<Node> remove(Node node) {
    ImmutableContextSet context = node.getContexts();
    Difference<Node> result = new Difference<>();
    this.lock.lock();
    try {
        SortedSet<Node> nodes = this.map.get(context);
        if (nodes == null) {
            return result;
        }
        // remove any nodes that match, record to results
        removeMatching(nodes.iterator(), node, result);
        // update inheritance map too
        if (node instanceof InheritanceNode) {
            SortedSet<InheritanceNode> inhNodes = this.inheritanceMap.get(context);
            if (inhNodes != null) {
                inhNodes.removeIf(el -> node.equals(el, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE));
            }
        }
    } finally {
        this.lock.unlock();
    }
    return result;
}
Also used : Node(net.luckperms.api.node.Node) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) Difference(me.lucko.luckperms.common.util.Difference)

Aggregations

Node (net.luckperms.api.node.Node)74 InheritanceNode (net.luckperms.api.node.types.InheritanceNode)28 ArrayList (java.util.ArrayList)23 Map (java.util.Map)16 UUID (java.util.UUID)16 ImmutableContextSet (net.luckperms.api.context.ImmutableContextSet)13 NodeEntry (me.lucko.luckperms.common.storage.misc.NodeEntry)12 MetaNode (net.luckperms.api.node.types.MetaNode)12 Group (me.lucko.luckperms.common.model.Group)11 HashMap (java.util.HashMap)10 List (java.util.List)10 PermissionHolder (me.lucko.luckperms.common.model.PermissionHolder)9 Difference (me.lucko.luckperms.common.util.Difference)9 DataType (net.luckperms.api.model.data.DataType)9 Connection (java.sql.Connection)7 User (me.lucko.luckperms.common.model.User)7 MutableContextSet (net.luckperms.api.context.MutableContextSet)7 PrefixNode (net.luckperms.api.node.types.PrefixNode)7 SuffixNode (net.luckperms.api.node.types.SuffixNode)7 IOException (java.io.IOException)6