From a3d20455b11d9dce5d7bf677e0055e94f1bc003e Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 17 Sep 2023 08:25:22 +0700 Subject: [PATCH] bossbar fix?? --- .../chayapak/chomens_bot/data/BotBossBar.java | 16 ++++++++++ .../plugins/BossbarManagerPlugin.java | 32 ++++++++++++------- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/data/BotBossBar.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/data/BotBossBar.java index 5388fc6..b2f0ca8 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/data/BotBossBar.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/data/BotBossBar.java @@ -14,6 +14,8 @@ public class BotBossBar extends BossBar { public final Component secret = Component.text(Math.random() * 69420); + public boolean gotSecret = false; + private final Bot bot; public String id; @@ -49,6 +51,8 @@ public class BotBossBar extends BossBar { } public void setTitle(Component title, boolean force) { + if (!gotSecret) return; + if (ComponentUtilities.isEqual(this.title, title) && !force) return; if (bot.bossbar.actionBar) { @@ -71,6 +75,8 @@ public class BotBossBar extends BossBar { } public void setColor(BossBarColor color, boolean force) { + if (!gotSecret) return; + if (this.color == color && !force) return; this.color = color; @@ -85,6 +91,8 @@ public class BotBossBar extends BossBar { } public void setPlayers(String players) { + if (!gotSecret) return; + if (this.players.equals(players)) return; this.players = players; @@ -99,6 +107,8 @@ public class BotBossBar extends BossBar { setDivision(division, false); } public void setDivision (BossBarDivision _division, boolean force) { + if (!gotSecret) return; + if (this.division == _division && !force) return; this.division = _division; @@ -123,6 +133,8 @@ public class BotBossBar extends BossBar { setValue(value, false); } public void setValue (int value, boolean force) { + if (!gotSecret) return; + if (this.value == value && !force) return; this.value = value; @@ -134,6 +146,8 @@ public class BotBossBar extends BossBar { public boolean visible () { return visible; } public void setVisible (boolean visible) { + if (!gotSecret) return; + if (this.visible == visible) return; this.visible = visible; @@ -148,6 +162,8 @@ public class BotBossBar extends BossBar { setMax(max, false); } public void setMax (long max, boolean force) { + if (!gotSecret) return; + if (this.max == max && !force) return; this.max = max; 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 d5c001f..3b38e35 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 @@ -63,18 +63,22 @@ public class BossbarManagerPlugin extends Bot.Listener { if (ComponentUtilities.isEqual(bossBar.secret, packet.getTitle())) { bossBars.remove(_bossBar.getKey()); + final BotBossBar newBossBar = new BotBossBar( + bossBar.title(), + bossBar.players(), + bossBar.color, + bossBar.division, + bossBar.visible(), + bossBar.max(), + bossBar.value(), + bot + ); + + newBossBar.gotSecret = true; + bossBars.put( packet.getUuid(), - new BotBossBar( - bossBar.title(), - bossBar.players(), - bossBar.color, - bossBar.division, - bossBar.visible(), - bossBar.max(), - bossBar.value(), - bot - ) + newBossBar ); bossBars.get(packet.getUuid()).id = bossBar.id; @@ -117,6 +121,8 @@ public class BossbarManagerPlugin extends Bot.Listener { botBossBar.setTitle(botBossBar.title, true); } else if (botBossBar != null && ComponentUtilities.isEqual(botBossBar.secret, packet.getTitle())) { botBossBar.uuid = packet.getUuid(); + + botBossBar.gotSecret = true; } bossBar.title = packet.getTitle(); @@ -147,7 +153,11 @@ public class BossbarManagerPlugin extends Bot.Listener { final UUID uuid = _bossBar.getKey(); final BotBossBar bossBar = _bossBar.getValue(); - if (!serverBossBars.containsKey(uuid)) addBossBar(bossBar.id, bossBar, true); + if (!serverBossBars.containsKey(uuid)) { + bossBar.gotSecret = false; + + addBossBar(bossBar.id, bossBar, true); + } } }