bossbar fix??

This commit is contained in:
Chayapak 2023-09-17 08:25:22 +07:00
parent f141b84d49
commit a3d20455b1
2 changed files with 37 additions and 11 deletions

View file

@ -14,6 +14,8 @@ public class BotBossBar extends BossBar {
public final Component secret = Component.text(Math.random() * 69420); public final Component secret = Component.text(Math.random() * 69420);
public boolean gotSecret = false;
private final Bot bot; private final Bot bot;
public String id; public String id;
@ -49,6 +51,8 @@ public class BotBossBar extends BossBar {
} }
public void setTitle(Component title, boolean force) { public void setTitle(Component title, boolean force) {
if (!gotSecret) return;
if (ComponentUtilities.isEqual(this.title, title) && !force) return; if (ComponentUtilities.isEqual(this.title, title) && !force) return;
if (bot.bossbar.actionBar) { if (bot.bossbar.actionBar) {
@ -71,6 +75,8 @@ public class BotBossBar extends BossBar {
} }
public void setColor(BossBarColor color, boolean force) { public void setColor(BossBarColor color, boolean force) {
if (!gotSecret) return;
if (this.color == color && !force) return; if (this.color == color && !force) return;
this.color = color; this.color = color;
@ -85,6 +91,8 @@ public class BotBossBar extends BossBar {
} }
public void setPlayers(String players) { public void setPlayers(String players) {
if (!gotSecret) return;
if (this.players.equals(players)) return; if (this.players.equals(players)) return;
this.players = players; this.players = players;
@ -99,6 +107,8 @@ public class BotBossBar extends BossBar {
setDivision(division, false); setDivision(division, false);
} }
public void setDivision (BossBarDivision _division, boolean force) { public void setDivision (BossBarDivision _division, boolean force) {
if (!gotSecret) return;
if (this.division == _division && !force) return; if (this.division == _division && !force) return;
this.division = _division; this.division = _division;
@ -123,6 +133,8 @@ public class BotBossBar extends BossBar {
setValue(value, false); setValue(value, false);
} }
public void setValue (int value, boolean force) { public void setValue (int value, boolean force) {
if (!gotSecret) return;
if (this.value == value && !force) return; if (this.value == value && !force) return;
this.value = value; this.value = value;
@ -134,6 +146,8 @@ public class BotBossBar extends BossBar {
public boolean visible () { return visible; } public boolean visible () { return visible; }
public void setVisible (boolean visible) { public void setVisible (boolean visible) {
if (!gotSecret) return;
if (this.visible == visible) return; if (this.visible == visible) return;
this.visible = visible; this.visible = visible;
@ -148,6 +162,8 @@ public class BotBossBar extends BossBar {
setMax(max, false); setMax(max, false);
} }
public void setMax (long max, boolean force) { public void setMax (long max, boolean force) {
if (!gotSecret) return;
if (this.max == max && !force) return; if (this.max == max && !force) return;
this.max = max; this.max = max;

View file

@ -63,9 +63,7 @@ public class BossbarManagerPlugin extends Bot.Listener {
if (ComponentUtilities.isEqual(bossBar.secret, packet.getTitle())) { if (ComponentUtilities.isEqual(bossBar.secret, packet.getTitle())) {
bossBars.remove(_bossBar.getKey()); bossBars.remove(_bossBar.getKey());
bossBars.put( final BotBossBar newBossBar = new BotBossBar(
packet.getUuid(),
new BotBossBar(
bossBar.title(), bossBar.title(),
bossBar.players(), bossBar.players(),
bossBar.color, bossBar.color,
@ -74,7 +72,13 @@ public class BossbarManagerPlugin extends Bot.Listener {
bossBar.max(), bossBar.max(),
bossBar.value(), bossBar.value(),
bot bot
) );
newBossBar.gotSecret = true;
bossBars.put(
packet.getUuid(),
newBossBar
); );
bossBars.get(packet.getUuid()).id = bossBar.id; bossBars.get(packet.getUuid()).id = bossBar.id;
@ -117,6 +121,8 @@ public class BossbarManagerPlugin extends Bot.Listener {
botBossBar.setTitle(botBossBar.title, true); botBossBar.setTitle(botBossBar.title, true);
} else if (botBossBar != null && ComponentUtilities.isEqual(botBossBar.secret, packet.getTitle())) { } else if (botBossBar != null && ComponentUtilities.isEqual(botBossBar.secret, packet.getTitle())) {
botBossBar.uuid = packet.getUuid(); botBossBar.uuid = packet.getUuid();
botBossBar.gotSecret = true;
} }
bossBar.title = packet.getTitle(); bossBar.title = packet.getTitle();
@ -147,7 +153,11 @@ public class BossbarManagerPlugin extends Bot.Listener {
final UUID uuid = _bossBar.getKey(); final UUID uuid = _bossBar.getKey();
final BotBossBar bossBar = _bossBar.getValue(); 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);
}
} }
} }