Search in sources :

Example 1 with ChatMetaNode

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

the class NodeCommandFactory method undoCommand.

public static String undoCommand(Node node, String holder, HolderType holderType, boolean explicitGlobalContext) {
    StringBuilder sb = new StringBuilder(32);
    sb.append(holderType.toString()).append(' ').append(holder).append(' ');
    if (node instanceof InheritanceNode) {
        // command
        sb.append("parent remove");
        if (node.hasExpiry()) {
            sb.append("temp");
        }
        sb.append(' ');
        // value
        sb.append(((InheritanceNode) node).getGroupName());
    } else if (node.getValue() && node instanceof ChatMetaNode<?, ?>) {
        ChatMetaNode<?, ?> chatNode = (ChatMetaNode<?, ?>) node;
        // command
        sb.append("meta remove");
        if (node.hasExpiry()) {
            sb.append("temp");
        }
        sb.append(chatNode.getMetaType().toString());
        // values
        sb.append(' ').append(chatNode.getPriority()).append(' ');
        appendEscaped(sb, chatNode.getMetaValue());
    } else if (node.getValue() && node instanceof MetaNode) {
        MetaNode metaNode = (MetaNode) node;
        // command
        sb.append("meta unset");
        if (node.hasExpiry()) {
            sb.append("temp");
        }
        sb.append(' ');
        // value
        appendEscaped(sb, metaNode.getMetaKey());
    } else {
        // command
        sb.append("permission unset");
        if (node.hasExpiry()) {
            sb.append("temp");
        }
        sb.append(' ');
        // value
        appendEscaped(sb, node.getKey());
    }
    if (!node.getContexts().isEmpty()) {
        for (Context context : node.getContexts()) {
            sb.append(' ').append(context.getKey()).append("=").append(context.getValue());
        }
    } else if (explicitGlobalContext) {
        sb.append(" global");
    }
    return sb.toString();
}
Also used : Context(net.luckperms.api.context.Context) ChatMetaNode(net.luckperms.api.node.types.ChatMetaNode) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) MetaNode(net.luckperms.api.node.types.MetaNode) ChatMetaNode(net.luckperms.api.node.types.ChatMetaNode)

Example 2 with ChatMetaNode

use of net.luckperms.api.node.types.ChatMetaNode 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

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