From a30f4661b2aa9747d180042ef891c786dae8843b Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Thu, 1 May 2025 16:02:52 +0700 Subject: [PATCH] feat: rainbow armor (most useless on the bot but only for when it's unvanished) --- build-number.txt | 2 +- .../java/me/chayapak1/chomens_bot/Bot.java | 2 + .../chayapak1/chomens_bot/Configuration.java | 2 + .../plugins/RainbowArmorPlugin.java | 67 +++++++++++++++++++ src/main/resources/default-config.yml | 3 + 5 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/main/java/me/chayapak1/chomens_bot/plugins/RainbowArmorPlugin.java diff --git a/build-number.txt b/build-number.txt index f8a37503..1e3eb11e 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -3029 \ No newline at end of file +3036 \ No newline at end of file diff --git a/src/main/java/me/chayapak1/chomens_bot/Bot.java b/src/main/java/me/chayapak1/chomens_bot/Bot.java index 42c006f5..3352fb0d 100644 --- a/src/main/java/me/chayapak1/chomens_bot/Bot.java +++ b/src/main/java/me/chayapak1/chomens_bot/Bot.java @@ -114,6 +114,7 @@ public class Bot extends SessionAdapter { public final WhitelistPlugin whitelist; public final PlayersDatabasePlugin playersDatabase; public final IPFilterPlugin ipFilter; + public final RainbowArmorPlugin rainbowArmor; public Bot ( final Configuration.BotOption botOption, @@ -171,6 +172,7 @@ public class Bot extends SessionAdapter { this.whitelist = new WhitelistPlugin(this); this.playersDatabase = new PlayersDatabasePlugin(this); this.ipFilter = new IPFilterPlugin(this); + this.rainbowArmor = new RainbowArmorPlugin(this); } protected void connect () { diff --git a/src/main/java/me/chayapak1/chomens_bot/Configuration.java b/src/main/java/me/chayapak1/chomens_bot/Configuration.java index 9f84f178..87049cb2 100644 --- a/src/main/java/me/chayapak1/chomens_bot/Configuration.java +++ b/src/main/java/me/chayapak1/chomens_bot/Configuration.java @@ -39,6 +39,8 @@ public class Configuration { public boolean announceClearChatUsername = false; + public boolean rainbowArmor = true; + public List trusted = new ArrayList<>(); public SelfCare selfCare = new SelfCare(); diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/RainbowArmorPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/RainbowArmorPlugin.java new file mode 100644 index 00000000..3992cb32 --- /dev/null +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/RainbowArmorPlugin.java @@ -0,0 +1,67 @@ +package me.chayapak1.chomens_bot.plugins; + +import me.chayapak1.chomens_bot.Bot; +import me.chayapak1.chomens_bot.data.listener.Listener; +import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; +import org.geysermc.mcprotocollib.protocol.data.game.item.component.*; +import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundSetCreativeModeSlotPacket; + +import java.awt.*; +import java.util.HashMap; +import java.util.Map; + +public class RainbowArmorPlugin implements Listener { + private static final int[] LEATHER_ARMORS = new int[] { + 896, // helmet + 897, // chestplate + 898, // leggings + 899 // boots + }; + + private final Bot bot; + + private float rainbowHue = 0F; + + public RainbowArmorPlugin (final Bot bot) { + this.bot = bot; + + if (!bot.config.rainbowArmor) return; + + bot.listener.addListener(this); + } + + @Override + public void onTick () { + if (!bot.config.rainbowArmor || !bot.selfCare.visible) return; + + final int increment = 360 / 20; + final Color color = Color.getHSBColor(rainbowHue / 360.0f, 1, 1); + final int rgbColor = color.getRGB() & 0xFFFFFF; + rainbowHue = (rainbowHue + increment) % 360; + + final Map, DataComponent> map = new HashMap<>(); + + final IntComponentType type = DataComponentTypes.DYED_COLOR; + final IntComponentType.IntDataComponentFactory factory = + (IntComponentType.IntDataComponentFactory) type.getDataComponentFactory(); + + map.put( + type, + factory.createPrimitive( + type, + rgbColor + ) + ); + + final DataComponents dataComponents = new DataComponents(map); + + for (int i = 0; i < 4; i++) { + bot.session.send( + new ServerboundSetCreativeModeSlotPacket( + (short) (i + 5), // 5, 6, 7, 8 are armors + new ItemStack(LEATHER_ARMORS[i], 1, dataComponents) + ) + ); + } + } +} diff --git a/src/main/resources/default-config.yml b/src/main/resources/default-config.yml index d96d07ad..6f8eee67 100644 --- a/src/main/resources/default-config.yml +++ b/src/main/resources/default-config.yml @@ -90,6 +90,9 @@ ownerAuthentication: # will tellraw `{player} cleared the chat` announceClearChatUsername: false +# literal rainbow armor using leather armors +rainbowArmor: true + trusted: - 'player name'