Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
3c1dea3451
@ -2,6 +2,7 @@ package eu.mhsl.craftattack.spawn.appliances.chatMention;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.appliance.ApplianceListener;
|
||||
import eu.mhsl.craftattack.spawn.appliances.settings.Settings;
|
||||
import eu.mhsl.craftattack.spawn.util.text.ComponentUtil;
|
||||
import io.papermc.paper.event.player.AsyncChatDecorateEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
@ -36,7 +37,7 @@ public class ChatMentionListener extends ApplianceListener<ChatMention> {
|
||||
return Component.text(word);
|
||||
}
|
||||
})
|
||||
.reduce((a, b) -> a.append(Component.text(" ")).append(b))
|
||||
.reduce(ComponentUtil::appendWithSpace)
|
||||
.orElseThrow();
|
||||
|
||||
getAppliance().notifyPlayers(mentioned);
|
||||
|
@ -22,6 +22,10 @@ public class ComponentUtil {
|
||||
return Component.text().append(a.appendNewline().append(b)).build();
|
||||
}
|
||||
|
||||
public static TextComponent appendWithSpace(Component a, Component b) {
|
||||
return Component.text().append(a).append(Component.text(" ")).append(b).build();
|
||||
}
|
||||
|
||||
public static Stream<String> lineBreak(String text) {
|
||||
return lineBreak(text, 50);
|
||||
}
|
||||
|
@ -6,12 +6,12 @@ import net.kyori.adventure.text.format.TextColor;
|
||||
import java.awt.*;
|
||||
|
||||
public class RainbowComponent {
|
||||
private int hueOffset = 0;
|
||||
private float hueOffset = 0;
|
||||
private final String text;
|
||||
private final int density;
|
||||
private final int speed;
|
||||
private final float speed;
|
||||
|
||||
public RainbowComponent(String text, int density, int speed) {
|
||||
public RainbowComponent(String text, int density, float speed) {
|
||||
this.text = text;
|
||||
this.density = density;
|
||||
this.speed = speed;
|
||||
@ -19,15 +19,16 @@ public class RainbowComponent {
|
||||
|
||||
public Component getRainbowState() {
|
||||
Component builder = Component.empty();
|
||||
int hue = this.hueOffset;
|
||||
for(char c : text.toCharArray()) {
|
||||
TextColor color = TextColor.color(Color.getHSBColor((float) hue / 360, 1, 1).getRGB());
|
||||
float hue = this.hueOffset;
|
||||
for (char c : text.toCharArray()) {
|
||||
float normalizedHue = (hue % 360) / 360;
|
||||
TextColor color = TextColor.color(Color.getHSBColor(normalizedHue, 1, 1).getRGB());
|
||||
builder = builder.append(Component.text(c).color(color));
|
||||
hue += density;
|
||||
}
|
||||
|
||||
if(this.hueOffset > Byte.MAX_VALUE - speed) this.hueOffset = 0;
|
||||
this.hueOffset += (byte) speed;
|
||||
this.hueOffset = (this.hueOffset + speed) % 360;
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user