fix: bruhify showing ?? for characters like the fire emoji 🔥

This commit is contained in:
ChomeNS
2025-04-22 09:09:55 +07:00
parent 8b4286bc31
commit ceb9bfd34d
2 changed files with 21 additions and 12 deletions

View File

@@ -3,9 +3,14 @@ package me.chayapak1.chomens_bot.plugins;
import me.chayapak1.chomens_bot.Bot;
import me.chayapak1.chomens_bot.data.listener.Listener;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.JoinConfiguration;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.util.HSVLike;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
public class BruhifyPlugin implements Listener {
private final Bot bot;
@@ -21,21 +26,25 @@ public class BruhifyPlugin implements Listener {
@Override
public void onTick () {
if (bruhifyText.isEmpty()) return;
if (bruhifyText.isBlank()) return;
int hue = startHue;
final String displayName = bruhifyText;
final int increment = 360 / Math.max(displayName.length(), 20);
final int increment = 360 / Math.max(bruhifyText.length(), 20);
Component component = Component.empty();
final List<Component> components = new ArrayList<>();
for (final char character : displayName.toCharArray()) {
component = component.append(Component.text(character)
.color(TextColor.color(HSVLike.hsvLike(hue / 360.0f, 1, 1))));
hue = (hue + increment) % 360;
}
final AtomicInteger hue = new AtomicInteger(startHue);
bruhifyText.codePoints()
.forEach(
character -> {
components.add(Component.text(new String(Character.toChars(character)))
.color(TextColor.color(HSVLike.hsvLike(hue.get() / 360.0f, 1, 1))));
hue.set((hue.get() + increment) % 360);
}
);
bot.chat.actionBar(component);
bot.chat.actionBar(
Component.join(JoinConfiguration.noSeparators(), components)
);
startHue = (startHue + increment) % 360;
}