From 489d65bf765b97a08e9bd9cde5f29eaac4884095 Mon Sep 17 00:00:00 2001 From: Chipmunk <65827213+ChipmunkMC@users.noreply.github.com> Date: Sun, 21 May 2023 20:18:41 -0400 Subject: [PATCH] self care fix ig --- .../chipmunkbot/plugins/ChatQueueManager.java | 55 +++++++++++++++++++ .../chipmunkbot/plugins/SelfCarePlugin.java | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/main/java/land/chipmunk/chipmunkbot/plugins/ChatQueueManager.java diff --git a/src/main/java/land/chipmunk/chipmunkbot/plugins/ChatQueueManager.java b/src/main/java/land/chipmunk/chipmunkbot/plugins/ChatQueueManager.java new file mode 100644 index 0000000..a32a1fb --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkbot/plugins/ChatQueueManager.java @@ -0,0 +1,55 @@ +package land.chipmunk.chipmunkbot.plugins; + +import land.chipmunk.chipmunkbot.ChipmunkBot; +import land.chipmunk.chipmunkbot.Options; +import com.github.steveice10.packetlib.event.session.SessionListener; +import com.github.steveice10.packetlib.event.session.SessionAdapter; +import com.github.steveice10.packetlib.event.session.DisconnectedEvent; +import com.github.steveice10.mc.protocol.MinecraftProtocol; +import com.github.steveice10.mc.protocol.data.ProtocolState; +import lombok.Getter; +import java.util.ArrayList; +import java.util.List; +import java.util.Timer; +import java.util.TimerTask; + +public class TickLoop extends SessionAdapter { + private Client client; + private Timer timer; + @Getter private List listeners = new ArrayList<>(); + + public TickLoop (ChipmunkBot client, Options options) { + this.client = client; + client.session().addListener((SessionListener) this); + + final TimerTask task = new TimerTask() { + public void run () { + if (((MinecraftProtocol) client.session().getPacketProtocol()).getState() != ProtocolState.GAME) return; + + int cancel = false; + for (Listener listener : listeners) { + if (!listener.onTick()) cancel = true; + } + + if (!c) + } + }; + + timer = new Timer(); + timer.schedule(task, options.chat.queue.interval, options.chat.queue.interval); + } + + public void disconnected (DisconnectedEvent event) { + if (client.reconnectDelay() < 0 && timer != null) { + timer.cancel(); + timer.purge(); + } + } + + public static class Listener { + public void onTick () {} + } + + public void addListener (Listener listener) { listeners.add(listener); } + public void removeListener (Listener listener) { listeners.remove(listener); } +} diff --git a/src/main/java/land/chipmunk/chipmunkbot/plugins/SelfCarePlugin.java b/src/main/java/land/chipmunk/chipmunkbot/plugins/SelfCarePlugin.java index db1f4a8..e8188d6 100644 --- a/src/main/java/land/chipmunk/chipmunkbot/plugins/SelfCarePlugin.java +++ b/src/main/java/land/chipmunk/chipmunkbot/plugins/SelfCarePlugin.java @@ -48,7 +48,7 @@ public class SelfCarePlugin extends SessionAdapter { }; timer = new Timer(); - timer.schedule(task, 70, 70); + timer.schedule(task, 75, 75); } public void tick () {