Search in sources :

Example 1 with ValueNode

use of net.kyori.adventure.text.minimessage.internal.parser.node.ValueNode in project adventure by KyoriPowered.

the class MiniMessageParser method treeToComponent.

@NotNull
Component treeToComponent(@NotNull final ElementNode node, @NotNull final ContextImpl context) {
    Component comp = Component.empty();
    Tag tag = null;
    if (node instanceof ValueNode) {
        comp = Component.text(((ValueNode) node).value());
    } else if (node instanceof TagNode) {
        final TagNode tagNode = (TagNode) node;
        tag = tagNode.tag();
        // special case for gradient and stuff
        if (tag instanceof Modifying) {
            final Modifying modTransformation = (Modifying) tag;
            // first walk the tree
            this.visitModifying(modTransformation, tagNode, 0);
            modTransformation.postVisit();
        }
        if (tag instanceof Inserting) {
            comp = ((Inserting) tag).value();
        }
    }
    if (!node.unsafeChildren().isEmpty()) {
        final List<Component> children = new ArrayList<>(comp.children().size() + node.children().size());
        children.addAll(comp.children());
        for (final ElementNode child : node.unsafeChildren()) {
            children.add(this.treeToComponent(child, context));
        }
        comp = comp.children(children);
    }
    // special case for gradient and stuff
    if (tag instanceof Modifying) {
        comp = this.handleModifying((Modifying) tag, comp, 0);
    }
    final Consumer<String> debug = context.debugOutput();
    if (debug != null) {
        debug.accept("==========\ntreeToComponent \n");
        debug.accept(node.toString());
        debug.accept("\n");
        debug.accept(comp.examine(MultiLineStringExaminer.simpleEscaping()).collect(Collectors.joining("\n")));
        debug.accept("\n==========\n");
    }
    return comp;
}
Also used : Modifying(net.kyori.adventure.text.minimessage.tag.Modifying) ValueNode(net.kyori.adventure.text.minimessage.internal.parser.node.ValueNode) ArrayList(java.util.ArrayList) Tag(net.kyori.adventure.text.minimessage.tag.Tag) Component(net.kyori.adventure.text.Component) ElementNode(net.kyori.adventure.text.minimessage.internal.parser.node.ElementNode) TagNode(net.kyori.adventure.text.minimessage.internal.parser.node.TagNode) Inserting(net.kyori.adventure.text.minimessage.tag.Inserting) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ArrayList (java.util.ArrayList)1 Component (net.kyori.adventure.text.Component)1 ElementNode (net.kyori.adventure.text.minimessage.internal.parser.node.ElementNode)1 TagNode (net.kyori.adventure.text.minimessage.internal.parser.node.TagNode)1 ValueNode (net.kyori.adventure.text.minimessage.internal.parser.node.ValueNode)1 Inserting (net.kyori.adventure.text.minimessage.tag.Inserting)1 Modifying (net.kyori.adventure.text.minimessage.tag.Modifying)1 Tag (net.kyori.adventure.text.minimessage.tag.Tag)1 NotNull (org.jetbrains.annotations.NotNull)1