forked from ChomeNS/chomens-bot-java
fix discord not logging after disconnect
This commit is contained in:
parent
5e7f10cb0d
commit
16b19f1c1f
3 changed files with 9 additions and 32 deletions
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
|
|
@ -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<Listener> 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 () {}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue