diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/DiscordPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/DiscordPlugin.java index babc178..03f7a09 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/DiscordPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/DiscordPlugin.java @@ -51,7 +51,7 @@ public class DiscordPlugin { public void loadedPlugins() { bot.tick.addListener(new TickPlugin.Listener() { @Override - public void onTick() { + public void onAlwaysTick () { onDiscordTick(channelId); } }); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/SelfCarePlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/SelfCarePlugin.java index 48fce0b..19917af 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/SelfCarePlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/SelfCarePlugin.java @@ -1,7 +1,5 @@ package land.chipmunk.chayapak.chomens_bot.plugins; -import com.github.steveice10.mc.protocol.MinecraftProtocol; -import com.github.steveice10.mc.protocol.data.ProtocolState; import com.github.steveice10.mc.protocol.data.game.ClientCommand; import com.github.steveice10.mc.protocol.data.game.entity.EntityEvent; import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; @@ -14,7 +12,6 @@ import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundCl import com.github.steveice10.packetlib.Session; import com.github.steveice10.packetlib.event.session.DisconnectedEvent; import com.github.steveice10.packetlib.packet.Packet; -import com.github.steveice10.packetlib.packet.PacketProtocol; import land.chipmunk.chayapak.chomens_bot.Bot; import land.chipmunk.chayapak.chomens_bot.Configuration; import land.chipmunk.chayapak.chomens_bot.util.ComponentUtilities; @@ -138,15 +135,7 @@ public class SelfCarePlugin extends Bot.Listener { positionPacketsPerSecond = 0; final Runnable task = () -> { - final Session session = bot.session; - final PacketProtocol protocol = session.getPacketProtocol(); - if ( - !session.isConnected() || - ( - protocol instanceof MinecraftProtocol && - ((MinecraftProtocol) protocol).getState() != ProtocolState.GAME - ) - ) return; + if (!bot.loggedIn) return; check(); }; diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/TickPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/TickPlugin.java index 5144268..1e615e0 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/TickPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/TickPlugin.java @@ -1,41 +1,28 @@ package land.chipmunk.chayapak.chomens_bot.plugins; -import com.github.steveice10.packetlib.event.session.ConnectedEvent; -import com.github.steveice10.packetlib.event.session.DisconnectedEvent; import land.chipmunk.chayapak.chomens_bot.Bot; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -public class TickPlugin extends Bot.Listener { +public class TickPlugin { private final Bot bot; - private ScheduledFuture tickTask; - private final List listeners = new ArrayList<>(); public TickPlugin (Bot bot) { this.bot = bot; - bot.addListener(this); - } - - @Override - public void connected(ConnectedEvent event) { - tickTask = bot.executor.scheduleAtFixedRate(this::tick, 0, 50, TimeUnit.MILLISECONDS); + bot.executor.scheduleAtFixedRate(this::tick, 0, 50, TimeUnit.MILLISECONDS); } private void tick () { - for (Listener listener : listeners) { - listener.onTick(); - } - } + for (Listener listener : listeners) listener.onAlwaysTick(); - @Override - public void disconnected (DisconnectedEvent event) { - tickTask.cancel(true); + if (!bot.loggedIn) return; + + for (Listener listener : listeners) listener.onTick(); } public void addListener (Listener listener) { @@ -44,5 +31,6 @@ public class TickPlugin extends Bot.Listener { public static class Listener { public void onTick () {} + public void onAlwaysTick () {} } }