From 9c6c35677c1ca0c97d3b38c12c9aab3b93c668b9 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 30 Mar 2025 17:33:57 +0700 Subject: [PATCH] feat: better icu self care, no more spam garbage it actually works pretty well, now it doesn't spam when you cloop tp the bot or something also i have tested cloop tp-ing the bot, and it indeed can't refill the core, not really sure how to fix this, but the bot usually is in vanish anyway and this scenario usually happens with some random person doing clooping `tp @a ` which affects everyone (except if the selector is like `@a[name=!BubbleCode]`) also interestingly the bot can still refill the core while being obd leashed --- build-number.txt | 2 +- .../chomens_bot/plugins/SelfCarePlugin.java | 41 +++++++++++-------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/build-number.txt b/build-number.txt index f337b2e2..5925a753 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -2275 \ No newline at end of file +2277 \ No newline at end of file diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/SelfCarePlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/SelfCarePlugin.java index 6bf5ce2b..986e0339 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/SelfCarePlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/SelfCarePlugin.java @@ -2,8 +2,8 @@ package me.chayapak1.chomens_bot.plugins; import me.chayapak1.chomens_bot.Bot; import me.chayapak1.chomens_bot.Configuration; +import me.chayapak1.chomens_bot.data.player.PlayerEntry; import net.kyori.adventure.text.Component; -import org.cloudburstmc.math.vector.Vector3d; import org.geysermc.mcprotocollib.network.Session; import org.geysermc.mcprotocollib.network.event.session.DisconnectedEvent; import org.geysermc.mcprotocollib.network.packet.Packet; @@ -26,7 +26,10 @@ import java.util.Arrays; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -public class SelfCarePlugin extends Bot.Listener implements ChatPlugin.Listener, PositionPlugin.Listener, TickPlugin.Listener { +public class SelfCarePlugin + extends Bot.Listener + implements ChatPlugin.Listener, CommandSpyPlugin.Listener, PositionPlugin.Listener +{ private final Bot bot; private ScheduledFuture checkTask; @@ -37,7 +40,6 @@ public class SelfCarePlugin extends Bot.Listener implements ChatPlugin.Listener, public GameMode gamemode; public int permissionLevel; - private int positionPacketsPerSecond = 0; private long usernameStartTime = System.currentTimeMillis(); private boolean cspy = false; @@ -53,17 +55,12 @@ public class SelfCarePlugin extends Bot.Listener implements ChatPlugin.Listener, bot.addListener(this); bot.chat.addListener(this); + bot.commandSpy.addListener(this); bot.position.addListener(this); - bot.tick.addListener(this); } @Override - public void onSecondTick () { - positionPacketsPerSecond = 0; - } - - @Override - public boolean systemMessageReceived(Component component, String string, String ansi) { + public boolean systemMessageReceived (Component component, String string, String ansi) { if (string.equals("Successfully enabled CommandSpy")) cspy = true; else if (string.equals("Successfully disabled CommandSpy")) cspy = false; @@ -97,6 +94,23 @@ public class SelfCarePlugin extends Bot.Listener implements ChatPlugin.Listener, return true; } + @Override + public void commandReceived (PlayerEntry sender, String command) { + final String trimmedCommand = command.trim(); + + final String controlPart = " control " + bot.profile.getName(); + + if ( + !bot.config.selfCare.icu.enabled || + ( + !trimmedCommand.equals("/icontrolu:icu" + controlPart) && + !trimmedCommand.equals("/icu" + controlPart) + ) + ) return; + + bot.core.run("essentials:sudo " + sender.profile.getIdAsString() + " icu stop"); + } + public void check () { final Configuration.SelfCare selfCares = bot.config.selfCare; @@ -120,7 +134,6 @@ public class SelfCarePlugin extends Bot.Listener implements ChatPlugin.Listener, else if (selfCares.username && (System.currentTimeMillis() - usernameStartTime) >= 2 * 1000 && !username && kaboom) bot.chat.send("/extras:username " + bot.username); // core - else if (selfCares.icu.enabled && positionPacketsPerSecond > selfCares.icu.positionPacketsPerSecond) bot.core.run("essentials:sudo * icu stop"); else if (hasEssentials) { final String usernameOrBlank = !bot.options.useChat ? bot.username + " " : @@ -158,7 +171,6 @@ public class SelfCarePlugin extends Bot.Listener implements ChatPlugin.Listener, socialspy = false; muted = false; prefix = false; - positionPacketsPerSecond = 0; final Runnable task = () -> { if (!bot.loggedIn) return; @@ -222,11 +234,6 @@ public class SelfCarePlugin extends Bot.Listener implements ChatPlugin.Listener, ); } - @Override - public void positionChange(Vector3d position) { - positionPacketsPerSecond++; - } - private void runEssentialsCommand (String command) { if (bot.options.useChat) bot.chat.sendCommandInstantly(command); else bot.core.run(command);