use of net.kyori.adventure.text.minimessage.tag.Modifying 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;
}
Aggregations