Search in sources :

Example 6 with MetaNode

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

the class AbstractConfigurateStorage method writeNodes.

private void writeNodes(ConfigurationNode to, Collection<Node> nodes) {
    ConfigurationNode permissionsSection = ConfigurationNode.root();
    // to save to the file even if it's just an empty list.
    if (this instanceof CombinedConfigurateStorage) {
        permissionsSection.setValue(Collections.emptyList());
    }
    ConfigurationNode parentsSection = ConfigurationNode.root();
    ConfigurationNode prefixesSection = ConfigurationNode.root();
    ConfigurationNode suffixesSection = ConfigurationNode.root();
    ConfigurationNode metaSection = ConfigurationNode.root();
    for (Node n : nodes) {
        // just add a string to the list.
        if (this.loader instanceof YamlLoader && isPlain(n)) {
            if (n instanceof InheritanceNode) {
                parentsSection.appendListNode().setValue(((InheritanceNode) n).getGroupName());
                continue;
            }
            if (!NodeType.META_OR_CHAT_META.matches(n)) {
                permissionsSection.appendListNode().setValue(n.getKey());
                continue;
            }
        }
        if (n instanceof ChatMetaNode<?, ?> && n.getValue()) {
            // handle prefixes / suffixes
            ChatMetaNode<?, ?> chatMeta = (ChatMetaNode<?, ?>) n;
            ConfigurationNode attributes = ConfigurationNode.root();
            attributes.getNode("priority").setValue(chatMeta.getPriority());
            writeAttributesTo(attributes, n, false);
            switch(chatMeta.getMetaType()) {
                case PREFIX:
                    appendNode(prefixesSection, chatMeta.getMetaValue(), attributes, "prefix");
                    break;
                case SUFFIX:
                    appendNode(suffixesSection, chatMeta.getMetaValue(), attributes, "suffix");
                    break;
                default:
                    throw new AssertionError();
            }
        } else if (n instanceof MetaNode && n.getValue()) {
            // handle meta nodes
            MetaNode meta = (MetaNode) n;
            ConfigurationNode attributes = ConfigurationNode.root();
            attributes.getNode("value").setValue(meta.getMetaValue());
            writeAttributesTo(attributes, n, false);
            appendNode(metaSection, meta.getMetaKey(), attributes, "key");
        } else if (n instanceof InheritanceNode && n.getValue()) {
            // handle group nodes
            InheritanceNode inheritance = (InheritanceNode) n;
            ConfigurationNode attributes = ConfigurationNode.root();
            writeAttributesTo(attributes, n, false);
            appendNode(parentsSection, inheritance.getGroupName(), attributes, "group");
        } else {
            // handle regular permissions and negated meta+prefixes+suffixes
            ConfigurationNode attributes = ConfigurationNode.root();
            writeAttributesTo(attributes, n, true);
            appendNode(permissionsSection, n.getKey(), attributes, "permission");
        }
    }
    if (permissionsSection.isList() || this instanceof CombinedConfigurateStorage) {
        to.getNode("permissions").setValue(permissionsSection);
    } else {
        to.removeChild("permissions");
    }
    if (parentsSection.isList()) {
        to.getNode("parents").setValue(parentsSection);
    } else {
        to.removeChild("parents");
    }
    if (prefixesSection.isList()) {
        to.getNode("prefixes").setValue(prefixesSection);
    } else {
        to.removeChild("prefixes");
    }
    if (suffixesSection.isList()) {
        to.getNode("suffixes").setValue(suffixesSection);
    } else {
        to.removeChild("suffixes");
    }
    if (metaSection.isList()) {
        to.getNode("meta").setValue(metaSection);
    } else {
        to.removeChild("meta");
    }
}
Also used : ChatMetaNode(net.luckperms.api.node.types.ChatMetaNode) 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) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) ChatMetaNode(net.luckperms.api.node.types.ChatMetaNode) MetaNode(net.luckperms.api.node.types.MetaNode) YamlLoader(me.lucko.luckperms.common.storage.implementation.file.loader.YamlLoader)

Example 7 with MetaNode

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

the class CalculatedSubject method resolveAllOptions.

public Map<String, String> resolveAllOptions(QueryOptions filter) {
    SubjectInheritanceGraph graph = new SubjectInheritanceGraph(filter);
    Map<String, String> result = new HashMap<>();
    Iterable<CalculatedSubject> traversal = graph.traverse(TraversalAlgorithm.DEPTH_FIRST_PRE_ORDER, this);
    for (CalculatedSubject subject : traversal) {
        for (MetaNode entry : subject.getCombinedOptions(filter).values()) {
            result.putIfAbsent(entry.getMetaKey(), entry.getMetaValue());
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) MetaNode(net.luckperms.api.node.types.MetaNode) SubjectInheritanceGraph(me.lucko.luckperms.sponge.service.inheritance.SubjectInheritanceGraph)

Example 8 with MetaNode

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

the class CalculatedSubjectData method resolveOptions.

public Map<String, MetaNode> resolveOptions(QueryOptions filter) {
    // get relevant entries
    SortedMap<ImmutableContextSet, Map<String, MetaNode>> sorted = new TreeMap<>(ContextSetComparator.reverse());
    for (Map.Entry<ImmutableContextSet, Map<String, String>> entry : this.options.entrySet()) {
        if (!filter.satisfies(entry.getKey(), defaultSatisfyMode())) {
            continue;
        }
        Map<String, MetaNode> nodeMap = new HashMap<>();
        entry.getValue().forEach((key, value) -> {
            MetaNode node = Meta.builder().key(key).value(value).context(entry.getKey()).withMetadata(InheritanceOriginMetadata.KEY, this.inheritanceOrigin).build();
            nodeMap.put(key, node);
        });
        sorted.put(entry.getKey(), nodeMap);
    }
    // flatten
    Map<String, MetaNode> result = new HashMap<>();
    for (Map<String, MetaNode> map : sorted.values()) {
        for (Map.Entry<String, MetaNode> e : map.entrySet()) {
            result.putIfAbsent(e.getKey(), e.getValue());
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MetaNode(net.luckperms.api.node.types.MetaNode) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Example 9 with MetaNode

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

the class PermissionHolderSubjectData method nodesToOptions.

private static ImmutableMap<String, String> nodesToOptions(Iterable<? extends Node> nodes) {
    Map<String, String> builder = new HashMap<>();
    int maxPrefixPriority = Integer.MIN_VALUE;
    int maxSuffixPriority = Integer.MIN_VALUE;
    for (Node n : nodes) {
        if (!n.getValue())
            continue;
        if (!NodeType.META_OR_CHAT_META.matches(n))
            continue;
        if (n instanceof PrefixNode) {
            PrefixNode pn = (PrefixNode) n;
            if (pn.getPriority() > maxPrefixPriority) {
                builder.put(Prefix.NODE_KEY, pn.getMetaValue());
                maxPrefixPriority = pn.getPriority();
            }
            continue;
        }
        if (n instanceof SuffixNode) {
            SuffixNode sn = (SuffixNode) n;
            if (sn.getPriority() > maxSuffixPriority) {
                builder.put(Suffix.NODE_KEY, sn.getMetaValue());
                maxSuffixPriority = sn.getPriority();
            }
            continue;
        }
        if (n instanceof MetaNode) {
            MetaNode mn = (MetaNode) n;
            builder.put(mn.getMetaKey(), mn.getMetaValue());
        }
    }
    return ImmutableMap.copyOf(builder);
}
Also used : HashMap(java.util.HashMap) SuffixNode(net.luckperms.api.node.types.SuffixNode) PrefixNode(net.luckperms.api.node.types.PrefixNode) Node(net.luckperms.api.node.Node) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) MetaNode(net.luckperms.api.node.types.MetaNode) SuffixNode(net.luckperms.api.node.types.SuffixNode) PrefixNode(net.luckperms.api.node.types.PrefixNode) MetaNode(net.luckperms.api.node.types.MetaNode)

Aggregations

MetaNode (net.luckperms.api.node.types.MetaNode)9 Node (net.luckperms.api.node.Node)4 ChatMetaNode (net.luckperms.api.node.types.ChatMetaNode)4 HashMap (java.util.HashMap)3 InheritanceNode (net.luckperms.api.node.types.InheritanceNode)3 PrefixNode (net.luckperms.api.node.types.PrefixNode)3 SuffixNode (net.luckperms.api.node.types.SuffixNode)3 Map (java.util.Map)2 SubjectInheritanceGraph (me.lucko.luckperms.sponge.service.inheritance.SubjectInheritanceGraph)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 TristateResult (me.lucko.luckperms.common.cacheddata.result.TristateResult)1 YamlLoader (me.lucko.luckperms.common.storage.implementation.file.loader.YamlLoader)1 MetaCheckEvent (me.lucko.luckperms.common.verbose.event.MetaCheckEvent)1 PermissionCheckEvent (me.lucko.luckperms.common.verbose.event.PermissionCheckEvent)1