feat: rainbow armor (most useless on the bot but only for when it's unvanished)

This commit is contained in:
ChomeNS
2025-05-01 16:02:52 +07:00
parent 05601e4cef
commit a30f4661b2
5 changed files with 75 additions and 1 deletions

View File

@@ -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 () {

View File

@@ -39,6 +39,8 @@ public class Configuration {
public boolean announceClearChatUsername = false;
public boolean rainbowArmor = true;
public List<String> trusted = new ArrayList<>();
public SelfCare selfCare = new SelfCare();

View File

@@ -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<DataComponentType<?>, 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)
)
);
}
}
}