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