From 801ce9cbd21a88de364e79ac326729afb77c44c0 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Thu, 25 May 2023 18:38:27 +0700 Subject: [PATCH] add prefix self care and make the self cares configurable more spam ngl,.,.,.,. well i increased the delay a bit but its still spammy,.,. --- .../chipmunk/chipmunkbot/ChipmunkBot.java | 2 +- .../chipmunk/chipmunkbot/Configuration.java | 12 ++++++++ .../chipmunkbot/plugins/SelfCarePlugin.java | 29 +++++++++++++++++-- src/main/resources/default_config.json | 8 +++++ 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/main/java/land/chipmunk/chipmunkbot/ChipmunkBot.java b/src/main/java/land/chipmunk/chipmunkbot/ChipmunkBot.java index d441977..9568d61 100644 --- a/src/main/java/land/chipmunk/chipmunkbot/ChipmunkBot.java +++ b/src/main/java/land/chipmunk/chipmunkbot/ChipmunkBot.java @@ -36,7 +36,7 @@ public class ChipmunkBot extends Client { this.playerCommandHandler = new PlayerCommandHandler(this, options); this.position = new PositionManager(this); this.core = new CommandCore(this, options); - this.selfCare = new SelfCarePlugin(this); + this.selfCare = new SelfCarePlugin(this, options); this.songPlayer = new SongPlayer(this); } } diff --git a/src/main/java/land/chipmunk/chipmunkbot/Configuration.java b/src/main/java/land/chipmunk/chipmunkbot/Configuration.java index beef4d9..a2a8122 100644 --- a/src/main/java/land/chipmunk/chipmunkbot/Configuration.java +++ b/src/main/java/land/chipmunk/chipmunkbot/Configuration.java @@ -23,6 +23,18 @@ public class Configuration { public Core core = new Core(); + public SelfCares selfCares = new SelfCares(); + + public static class SelfCares { + public boolean cspy = true; + public PrefixSelfCare prefix = new PrefixSelfCare(); + + public static class PrefixSelfCare { + public boolean enabled = true; + public String prefix = "&x&c&9&5&3&6&7[&x&f&f&c&0&c&bPrefix: s'&x&c&9&5&3&6&7]"; + } + } + public static class Commands { public String prefix = "default."; public String cspyPrefix = "default."; diff --git a/src/main/java/land/chipmunk/chipmunkbot/plugins/SelfCarePlugin.java b/src/main/java/land/chipmunk/chipmunkbot/plugins/SelfCarePlugin.java index 3e79016..acfe376 100644 --- a/src/main/java/land/chipmunk/chipmunkbot/plugins/SelfCarePlugin.java +++ b/src/main/java/land/chipmunk/chipmunkbot/plugins/SelfCarePlugin.java @@ -18,23 +18,45 @@ import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLo import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundGameEventPacket; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundEntityEventPacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundClientCommandPacket; +import land.chipmunk.chipmunkbot.Configuration; +import land.chipmunk.chipmunkbot.util.ComponentUtilities; import lombok.Getter; import lombok.Setter; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; + import java.util.Timer; import java.util.TimerTask; public class SelfCarePlugin extends SessionAdapter { private final ChipmunkBot client; + private final Configuration.Bot options; @Getter @Setter private GameMode gamemode; @Getter @Setter private int permissionLevel; + + private boolean prefix = false; + private Timer timer; private int entityId; // TODO: Move entity id handling somewhere else - public SelfCarePlugin (ChipmunkBot client) { + public SelfCarePlugin (ChipmunkBot client, Configuration.Bot options) { this.client = client; + this.options = options; client.addListener((SessionListener) this); + client.chat().addListener(new ChatPlugin.Listener() { + @Override + public void systemMessageReceived(Component component, boolean overlay) { + // mabe parse using components? too lazy + final String stringifiedMessage = ComponentUtilities.stringify(component); + + if (stringifiedMessage.equals("You now have the tag: " + options.selfCares.prefix.prefix)) prefix = true; + else if (stringifiedMessage.equals("You no longer have a tag")) prefix = false; + else if (stringifiedMessage.startsWith("You now have the tag: ")) prefix = false; + } + }); + final TimerTask task = new TimerTask() { @Override public void run () { @@ -48,13 +70,14 @@ public class SelfCarePlugin extends SessionAdapter { }; timer = new Timer(); - timer.schedule(task, 75, 75); + timer.schedule(task, 125, 125); } public void tick () { if (permissionLevel < 2) client.chat().command("minecraft:op @s[type=player]"); else if (gamemode != GameMode.CREATIVE) client.chat().command("minecraft:gamemode creative"); - else if (!client.commandSpy().enabled()) client.chat().command("c on"); + else if (!client.commandSpy().enabled() && options.selfCares.cspy) client.chat().command("c on"); + else if (!prefix && options.selfCares.prefix.enabled) client.chat().command("prefix " + options.selfCares.prefix.prefix); } @Override diff --git a/src/main/resources/default_config.json b/src/main/resources/default_config.json index 19c7de2..42c984a 100644 --- a/src/main/resources/default_config.json +++ b/src/main/resources/default_config.json @@ -15,6 +15,14 @@ "cspyPrefix": "default." }, + "selfCares": { + "cspy": true, + "prefix": { + "enabled": true, + "prefix": "&x&c&9&5&3&6&7[&x&f&f&c&0&c&bPrefix: s'&x&c&9&5&3&6&7]" + } + }, + "core": { "enabled": true }