Search in sources :

Example 1 with YamlLoader

use of me.lucko.luckperms.common.storage.implementation.file.loader.YamlLoader in project LuckPerms by lucko.

the class AbstractConfigurateStorage method appendNode.

private void appendNode(ConfigurationNode base, String key, ConfigurationNode attributes, String keyFieldName) {
    ConfigurationNode appended = base.appendListNode();
    if (this.loader instanceof YamlLoader && !key.isEmpty()) {
        // create a map node with a single entry of key --> attributes
        appended.getNode(key).setValue(attributes);
    } else {
        // include the attributes and key in the same map
        appended.getNode(keyFieldName).setValue(key);
        appended.mergeValuesFrom(attributes);
    }
}
Also used : ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) YamlLoader(me.lucko.luckperms.common.storage.implementation.file.loader.YamlLoader)

Example 2 with YamlLoader

use of me.lucko.luckperms.common.storage.implementation.file.loader.YamlLoader 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)

Aggregations

YamlLoader (me.lucko.luckperms.common.storage.implementation.file.loader.YamlLoader)2 ConfigurationNode (ninja.leaping.configurate.ConfigurationNode)2 Node (net.luckperms.api.node.Node)1 ChatMetaNode (net.luckperms.api.node.types.ChatMetaNode)1 InheritanceNode (net.luckperms.api.node.types.InheritanceNode)1 MetaNode (net.luckperms.api.node.types.MetaNode)1