Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text-minimessage: Work on interrupting gradients #711

Draft
wants to merge 1 commit into
base: main/4
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
* @since 4.10.0
*/
abstract class AbstractColorChangingTag implements Modifying, Examinable {

private final boolean interrupting = true;
private boolean visited;
private int size = 0;
private int disableApplyingColorDepth = -1;
Expand All @@ -69,12 +69,20 @@ public final void visit(final @NotNull Node current, final int depth) {
throw new IllegalStateException("Color changing tag instances cannot be re-used, return a new one for each resolve");
}

if (this.disableApplyingColorDepth != -1 && depth > this.disableApplyingColorDepth) {
return;
}

if (current instanceof ValueNode) {
final String value = ((ValueNode) current).value();
this.size += value.codePointCount(0, value.length());
} else if (current instanceof TagNode) {
final TagNode tag = (TagNode) current;
if (tag.tag() instanceof Inserting) {
if (this.interrupting && (tag.tag() == this || (tag.tag() instanceof Inserting && ((Inserting) tag.tag()).value().style().color() != null))) {
if (this.disableApplyingColorDepth == -1 || depth < this.disableApplyingColorDepth) {
this.disableApplyingColorDepth = depth + 1;
}
} else if (tag.tag() instanceof Inserting) {
// ComponentTransformation.apply() returns the value of the component placeholder
ComponentFlattener.textOnly().flatten(((Inserting) tag.tag()).value(), s -> this.size += s.codePointCount(0, s.length()));
}
Expand All @@ -85,6 +93,7 @@ public final void visit(final @NotNull Node current, final int depth) {
public final void postVisit() {
// init
this.visited = true;
this.disableApplyingColorDepth = -1;
this.init();
}

Expand All @@ -96,12 +105,14 @@ public final Component apply(final @NotNull Component current, final int depth)
}
// This component has its own color applied, which overrides ours
// We still want to keep track of where we are though if this is text
if (current instanceof TextComponent) {
final String content = ((TextComponent) current).content();
final int len = content.codePointCount(0, content.length());
for (int i = 0; i < len; i++) {
// increment our color index
this.advanceColor();
if (!this.interrupting) {
if (current instanceof TextComponent) {
final String content = ((TextComponent) current).content();
final int len = content.codePointCount(0, content.length());
for (int i = 0; i < len; i++) {
// increment our color index
this.advanceColor();
}
}
}
return current.children(Collections.emptyList());
Expand Down