From 5859c856e20966948780bf930c7db1ce7896b289 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 30 Apr 2023 18:30:33 +0700 Subject: [PATCH] packet queue farded it --- .idea/workspace.xml | 51 ++++++++++++------- .../chipmunk/chayapak/chomens_bot/Bot.java | 14 ----- .../plugins/BossbarManagerPlugin.java | 20 ++------ 3 files changed, 36 insertions(+), 49 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 268012a..deb17c0 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,7 +4,7 @@ - - @@ -481,7 +492,9 @@ - diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java index 249d700..6e40360 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java @@ -84,8 +84,6 @@ public class Bot { Bot.this.ready(); } }); - - executor.scheduleAtFixedRate(this::tick, 0, 10, TimeUnit.MILLISECONDS); } public void ready () { @@ -115,18 +113,6 @@ public class Bot { reconnect(); } - public void sendPacket (Packet packet) { - packetQueue.add(packet); - } - - private void tick () { - if (!loggedIn || packetQueue.size() == 0) return; - - session.send(packetQueue.get(0)); - - packetQueue.remove(0); - } - private void reconnect () { for (Listener listener : listeners) { listener.connecting(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/BossbarManagerPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/BossbarManagerPlugin.java index eb24073..7b75bd9 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/BossbarManagerPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/BossbarManagerPlugin.java @@ -16,7 +16,6 @@ public class BossbarManagerPlugin extends Bot.Listener { private final Bot bot; private ScheduledFuture tickTask; - private ScheduledFuture updateTask; private final Map bossBars = new HashMap<>(); @@ -41,26 +40,11 @@ public class BossbarManagerPlugin extends Bot.Listener { public void ready () { tickTask = bot.executor().scheduleAtFixedRate(this::tick, 0, 50, TimeUnit.MILLISECONDS); - updateTask = bot.executor().scheduleAtFixedRate(this::update, 0, 500, TimeUnit.MILLISECONDS); } @Override public void disconnected(DisconnectedEvent event) { tickTask.cancel(true); - updateTask.cancel(true); - } - - private void update() { - if (!enabled || actionbar) return; - for (Map.Entry _bossBar : bossBars.entrySet()) { - final String name = _bossBar.getKey(); - final BossBar bossBar = _bossBar.getValue(); - createBossBar(name, bossBar.players()); - bot.core().run("minecraft:bossbar set " + bossBarPrefix + name + " color " + bossBar.color().color); - bot.core().run("minecraft:bossbar set " + bossBarPrefix + name + " visible " + bossBar.visible()); - bot.core().run("minecraft:bossbar set " + bossBarPrefix + name + " style " + bossBar.style().style); - bot.core().run("minecraft:bossbar set " + bossBarPrefix + name + " max " + bossBar.max()); - } } public void tick () { @@ -72,6 +56,10 @@ public class BossbarManagerPlugin extends Bot.Listener { final String stringifiedComponent = GsonComponentSerializer.gson().serialize(bossBar.name()); if (!actionbar) { + bot.core().run("minecraft:bossbar set " + bossBarPrefix + name + " color " + bossBar.color().color); + bot.core().run("minecraft:bossbar set " + bossBarPrefix + name + " visible " + bossBar.visible()); + bot.core().run("minecraft:bossbar set " + bossBarPrefix + name + " style " + bossBar.style().style); + bot.core().run("minecraft:bossbar set " + bossBarPrefix + name + " max " + bossBar.max()); bot.core().run("minecraft:bossbar set " + bossBarPrefix + name + " name " + stringifiedComponent); bot.core().run("minecraft:bossbar set " + bossBarPrefix + name + " value " + bossBar.value()); } else {