diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java index b5a536e..be08473 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java @@ -47,6 +47,7 @@ public class Bot { @Getter private final EvalRunnerPlugin eval; @Getter private final ClearChatUsernamePlugin clearChatUsername; @Getter private final TrustedPlugin trusted; + @Getter private final BruhifyPlugin bruhify; public Bot (String host, int port, String _username, boolean kaboom, String serverName, List allBots, Configuration config) { this.host = host; @@ -75,6 +76,7 @@ public class Bot { this.eval = new EvalRunnerPlugin(this); this.clearChatUsername = new ClearChatUsernamePlugin(this); this.trusted = new TrustedPlugin(this); + this.bruhify = new BruhifyPlugin(this); reconnect(); } diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/BruhifyCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/BruhifyCommand.java new file mode 100644 index 0000000..2a0f64e --- /dev/null +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/BruhifyCommand.java @@ -0,0 +1,47 @@ +package land.chipmunk.chayapak.chomens_bot.commands; + +import land.chipmunk.chayapak.chomens_bot.Bot; +import land.chipmunk.chayapak.chomens_bot.command.Command; +import land.chipmunk.chayapak.chomens_bot.command.CommandContext; +import net.kyori.adventure.text.Component; + +import java.util.ArrayList; +import java.util.List; + +public class BruhifyCommand implements Command { + public String name() { return "bruhify"; } + + public String description() { + return "RecycleBot bruhify but actionbar"; + } + + public List usage() { + final List usages = new ArrayList<>(); + usages.add("[{message}]"); + + return usages; + } + + public List alias() { + final List aliases = new ArrayList<>(); + aliases.add(""); + + return aliases; + } + + public int trustLevel() { + return 0; + } + + public Component execute(CommandContext context, String[] args, String[] fullArgs) { + final Bot bot = context.bot(); + + if (args.length == 0) { + bot.bruhify().bruhifyText(""); + } else { + bot.bruhify().bruhifyText(String.join(" ", args)); + } + + return Component.text("success"); + } +} diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/BruhifyPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/BruhifyPlugin.java new file mode 100644 index 0000000..73568fd --- /dev/null +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/BruhifyPlugin.java @@ -0,0 +1,45 @@ +package land.chipmunk.chayapak.chomens_bot.plugins; + +import land.chipmunk.chayapak.chomens_bot.Bot; +import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities; +import lombok.Getter; +import lombok.Setter; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.TextColor; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; + +import java.util.Timer; +import java.util.TimerTask; + +public class BruhifyPlugin { + @Getter @Setter private String bruhifyText = ""; + + private int startHue = 0; + + public BruhifyPlugin (Bot bot) { + final Timer timer = new Timer(); + + timer.schedule(new TimerTask() { + @Override + public void run() { + if (bruhifyText.equals("")) return; + + int hue = startHue; + String displayName = bruhifyText; + int increment = (int)(360.0 / Math.max(displayName.length(), 20)); + + Component component = Component.empty(); + + for (char character : displayName.toCharArray()) { + String color = String.format("#%06x", ColorUtilities.hsvToRgb(hue, 100, 100)); + component = component.append(Component.text(character).color(TextColor.fromHexString(color))); + hue = (hue + increment) % 360; + } + + bot.core().run("minecraft:title @a actionbar " + GsonComponentSerializer.gson().serialize(component)); + + startHue = (startHue + increment) % 360; + } + }, 50, 100); + } +} diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java index fb52a0d..18549da 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java @@ -42,6 +42,7 @@ public class CommandHandlerPlugin { registerCommand(new ServerEvalCommand()); registerCommand(new UUIDCommand()); registerCommand(new TimeCommand()); + registerCommand(new BruhifyCommand()); } public void registerCommand (Command command) { diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/util/ColorUtilities.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/util/ColorUtilities.java new file mode 100644 index 0000000..c7f7616 --- /dev/null +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/util/ColorUtilities.java @@ -0,0 +1,10 @@ +package land.chipmunk.chayapak.chomens_bot.util; + +import java.awt.*; + +public class ColorUtilities { + public static int hsvToRgb (int hue, int saturation, int value) { + Color color = Color.getHSBColor(hue / 360.0f, saturation / 100.0f, value / 100.0f); + return color.getRGB() & 0xFFFFFF; + } +}