Skip to content

Commit

Permalink
Merge pull request #1041 from KyoriPowered/fix/1040
Browse files Browse the repository at this point in the history
fix(text-minimessage): Handle larger raninbow phases correctly
  • Loading branch information
zml2008 authored Feb 27, 2024
2 parents 7aae30f + 004cb65 commit aeaeb99
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
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);
}
}

0 comments on commit aeaeb99

Please sign in to comment.