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 80cb7dd..d5c001f 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 @@ -15,6 +15,7 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import java.util.HashMap; import java.util.Map; import java.util.UUID; +import java.util.concurrent.TimeUnit; // yes this has been rewritten to be not spammy public class BossbarManagerPlugin extends Bot.Listener { @@ -39,6 +40,8 @@ public class BossbarManagerPlugin extends Bot.Listener { BossbarManagerPlugin.this.playerJoined(); } }); + + bot.executor.scheduleAtFixedRate(this::check, 0, 1, TimeUnit.SECONDS); } @Override @@ -90,18 +93,7 @@ public class BossbarManagerPlugin extends Bot.Listener { ) ); } - case REMOVE -> { - for (Map.Entry _bossBar : bossBars.entrySet()) { - final BotBossBar bossBar = _bossBar.getValue(); - - if (bossBar.uuid.equals(packet.getUuid())) { - addBossBar(bossBar.id, bossBar, true); - break; - } - } - - serverBossBars.remove(packet.getUuid()); - } + case REMOVE -> serverBossBars.remove(packet.getUuid()); // self care is at the check function case UPDATE_STYLE -> { final BossBar bossBar = serverBossBars.get(packet.getUuid()); @@ -150,6 +142,15 @@ public class BossbarManagerPlugin extends Bot.Listener { } } + private void check () { + for (Map.Entry _bossBar : bossBars.entrySet()) { + final UUID uuid = _bossBar.getKey(); + final BotBossBar bossBar = _bossBar.getValue(); + + if (!serverBossBars.containsKey(uuid)) addBossBar(bossBar.id, bossBar, true); + } + } + @Override public void connected(ConnectedEvent event) { for (Map.Entry _bossBar : bossBars.entrySet()) {