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

fix(text-minimessage): Handle larger raninbow phases correctly #1041

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
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 @@ -47,7 +47,7 @@ final class RainbowTag extends AbstractColorChangingTag {
static final TagResolver RESOLVER = TagResolver.resolver(RAINBOW, RainbowTag::create);

private final boolean reversed;
private final int phase;
private final double dividedPhase;

private int colorIndex = 0;

Expand Down Expand Up @@ -75,7 +75,7 @@ static Tag create(final ArgumentQueue args, final Context ctx) {

private RainbowTag(final boolean reversed, final int phase) {
this.reversed = reversed;
this.phase = phase;
this.dividedPhase = ((double) phase) / 10d;
}

@Override
Expand All @@ -101,25 +101,25 @@ protected void advanceColor() {
@Override
protected TextColor color() {
final float index = this.colorIndex;
final float hue = (index / this.size() + this.phase / 10f) % 1;
final float hue = (float) ((index / this.size() + this.dividedPhase) % 1f);
return TextColor.color(HSVLike.hsvLike(hue, 1f, 1f));
}

@Override
public @NotNull Stream<? extends ExaminableProperty> examinableProperties() {
return Stream.of(ExaminableProperty.of("phase", this.phase));
return Stream.of(ExaminableProperty.of("phase", this.dividedPhase));
}

@Override
public boolean equals(final @Nullable Object other) {
if (this == other) return true;
if (other == null || this.getClass() != other.getClass()) return false;
final RainbowTag that = (RainbowTag) other;
return this.colorIndex == that.colorIndex && this.phase == that.phase;
return this.colorIndex == that.colorIndex && this.dividedPhase == that.dividedPhase;
}

@Override
public int hashCode() {
return Objects.hash(this.colorIndex, this.phase);
return Objects.hash(this.colorIndex, this.dividedPhase);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import static net.kyori.adventure.text.Component.empty;
import static net.kyori.adventure.text.Component.text;
import static net.kyori.adventure.text.Component.textOfChildren;
import static net.kyori.adventure.text.event.ClickEvent.openUrl;
import static net.kyori.adventure.text.format.NamedTextColor.BLACK;
import static net.kyori.adventure.text.format.NamedTextColor.GREEN;
Expand Down Expand Up @@ -352,4 +353,24 @@ void gh147() {
final Component expected1 = text().append(text("y", color(0xff0000)), text("o", color(0x00ffff))).build();
this.assertParsedEquals(expected1, input, component("msg", text("yo")));
}

// https://github.com/KyoriPowered/adventure/issues/1040
@Test
void gh1040() {
final String input = "<rainbow:16777215>||||||||||";
final Component expected = textOfChildren(
text("|", color(0x00ffff)),
text("|", color(0x0065ff)),
text("|", color(0x3200ff)),
text("|", color(0xcc00ff)),
text("|", color(0xff0099)),
text("|", color(0xff0000)),
text("|", color(0xff9900)),
text("|", color(0xccff00)),
text("|", color(0x32ff00)),
text("|", color(0x00ff65))
);

this.assertParsedEquals(expected, input);
}
}