diff --git a/build-number.txt b/build-number.txt index 6677dc1c..b2b5ccbf 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -2570 \ No newline at end of file +2574 \ No newline at end of file diff --git a/src/main/java/me/chayapak1/chomens_bot/Bot.java b/src/main/java/me/chayapak1/chomens_bot/Bot.java index 8f39b10a..4fe7878e 100644 --- a/src/main/java/me/chayapak1/chomens_bot/Bot.java +++ b/src/main/java/me/chayapak1/chomens_bot/Bot.java @@ -387,7 +387,11 @@ public class Bot extends SessionAdapter { } for (final SessionListener listener : listeners) { - listener.disconnected(disconnectedEvent); + try { + listener.disconnected(disconnectedEvent); + } catch (final Exception e) { + logger.error(e); + } } } diff --git a/src/main/java/me/chayapak1/chomens_bot/Configuration.java b/src/main/java/me/chayapak1/chomens_bot/Configuration.java index a3b10aba..c65ae5d4 100644 --- a/src/main/java/me/chayapak1/chomens_bot/Configuration.java +++ b/src/main/java/me/chayapak1/chomens_bot/Configuration.java @@ -84,7 +84,6 @@ public class Configuration { } public static class Core { - public int refillInterval = (60 * 5) * 1000; // 5 minutes public String customName = "{\"text\":\"@\"}"; } diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/CorePlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/CorePlugin.java index c4e4aa5f..770ce2d3 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/CorePlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/CorePlugin.java @@ -30,7 +30,6 @@ import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.Serv import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @@ -45,8 +44,6 @@ public class CorePlugin public volatile boolean ready = false; - private ScheduledFuture refillTask; - public final Vector3i fromSize; public Vector3i toSize; @@ -76,8 +73,6 @@ public class CorePlugin 15 ); - bot.position.addListener(this); - if (hasRateLimit() && hasReset()) { bot.executor.scheduleAtFixedRate( () -> commandsPerSecond.set(0), @@ -90,6 +85,7 @@ public class CorePlugin bot.addListener(this); bot.world.addListener(this); bot.tick.addListener(this); + bot.position.addListener(this); } @Override @@ -426,7 +422,9 @@ public class CorePlugin if (!ready) { ready = true; - refillTask = bot.executor.scheduleAtFixedRate(this::refill, 0, bot.config.core.refillInterval, TimeUnit.MILLISECONDS); + reset(); + refill(); + for (final Listener listener : listeners) listener.coreReady(); } } @@ -440,10 +438,6 @@ public class CorePlugin @Override public void disconnected (final DisconnectedEvent event) { ready = false; - - refillTask.cancel(false); - - reset(); } public void recalculateRelativePositions () { 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 ea736425..bc6950e4 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/SelfCarePlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/SelfCarePlugin.java @@ -4,7 +4,6 @@ import me.chayapak1.chomens_bot.Bot; import me.chayapak1.chomens_bot.Configuration; import net.kyori.adventure.text.Component; import org.geysermc.mcprotocollib.network.Session; -import org.geysermc.mcprotocollib.network.event.session.DisconnectedEvent; import org.geysermc.mcprotocollib.network.packet.Packet; import org.geysermc.mcprotocollib.protocol.data.game.ClientCommand; import org.geysermc.mcprotocollib.protocol.data.game.entity.EntityEvent; @@ -22,14 +21,11 @@ import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.S import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundPlayerCommandPacket; import java.util.Arrays; -import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; public class SelfCarePlugin extends Bot.Listener implements ChatPlugin.Listener { private final Bot bot; - private ScheduledFuture checkTask; - public boolean visible = false; private int entityId; @@ -154,13 +150,11 @@ public class SelfCarePlugin extends Bot.Listener implements ChatPlugin.Listener muted = false; prefix = false; - final Runnable task = () -> { + bot.executor.scheduleAtFixedRate(() -> { if (!bot.loggedIn) return; check(); - }; - - checkTask = bot.executor.scheduleAtFixedRate(task, 0, bot.config.selfCare.delay, TimeUnit.MILLISECONDS); + }, 0, bot.config.selfCare.delay, TimeUnit.MILLISECONDS); } private void packetReceived (final ClientboundGameEventPacket packet) { @@ -220,9 +214,4 @@ public class SelfCarePlugin extends Bot.Listener implements ChatPlugin.Listener if (bot.options.useChat) bot.chat.sendCommandInstantly(command); else bot.core.run(command); } - - @Override - public void disconnected (final DisconnectedEvent event) { - checkTask.cancel(true); - } } diff --git a/src/main/resources/default-config.yml b/src/main/resources/default-config.yml index eacb6bfd..8121b0e1 100644 --- a/src/main/resources/default-config.yml +++ b/src/main/resources/default-config.yml @@ -106,8 +106,7 @@ namespace: 'default_chomens_bot' # useful when you make a clone of the bot teamName: 'default_chomens_bot' # i recommend having this value the same as namespace core: - refillInterval: 300000 # (60 * 5) * 1000 (5 minutes) - # PLEASE give valid JSON component here else the core don't refill at all + # PLEASE give valid JSON component here customName: '[{"text":"ChomeNS ","color":"yellow"},{"text":"Core","color":"green"},{"text":"™","color":"gold"}]' # https://code.chipmunk.land/ChomeNS/eval-server