Skip to content

Commit

Permalink
Merge pull request #635 from KyoriPowered/fix/510
Browse files Browse the repository at this point in the history
  • Loading branch information
zml2008 authored Dec 14, 2021
2 parents 04e84f1 + a79e3ad commit 0a46b2a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void visit(final ElementNode curr) {
} else if (curr instanceof TagNode) {
final TagNode tag = (TagNode) curr;
if (tag.transformation() instanceof ComponentTransformation) {
// PlaceholderTransformation.apply() returns the value of the component placeholder
// ComponentTransformation.apply() returns the value of the component placeholder
ComponentFlattener.textOnly().flatten(tag.transformation().apply(), s -> this.size += s.codePointCount(0, s.length()));
}
}
Expand Down Expand Up @@ -176,6 +176,7 @@ public Component apply(final Component current, final int depth) {
return current.children(Collections.emptyList());
}

this.disableApplyingColorDepth = -1;
if (current instanceof TextComponent && ((TextComponent) current).content().length() > 0) {
final TextComponent textComponent = (TextComponent) current;
final String content = textComponent.content();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.minimessage.placeholder.Placeholder;
import net.kyori.adventure.text.minimessage.placeholder.PlaceholderResolver;
Expand Down Expand Up @@ -1659,11 +1660,28 @@ void testRepeatedResolvingOfStringPlaceholders() {

final Component expected = text("cat makes a sound", RED);

assertParsedEquals(
this.assertParsedEquals(
expected,
input,
miniMessage("animal", "<red><feline>"),
component("feline", text("cat"))
);
}

// https://github.com/KyoriPowered/adventure/issues/510
@Test
void testNestedGradientsDontOverrideColors() {
final String input = "<gradient:#1985ff:#2bc7ff>a<gradient:#00fffb:#00ffc3>b</gradient> <gray>gray</gray></gradient>";

final Component expected = Component.text()
.append(
text("a", color(0x1985ff)),
text("b", color(0x00fffb)),
text(" ", color(0x1e98ff)),
text("gray", NamedTextColor.GRAY)
)
.build();

this.assertParsedEquals(expected, input);
}
}

0 comments on commit 0a46b2a

Please sign in to comment.