bring back actionbar bossbar manager

This commit is contained in:
Chayapak 2023-07-10 17:16:12 +07:00
parent 6d241a1a07
commit 79c45b0598
2 changed files with 25 additions and 2 deletions

View file

@ -45,6 +45,12 @@ public class BotBossBar extends BossBar {
public void setTitle (Component title, boolean force) {
if (ComponentUtilities.isEqual(this.title, title) && !force) return;
if (bot.bossbar.actionBar) {
bot.chat.actionBar(title, players);
return;
}
this.title = title;
bot.core.run("minecraft:bossbar set " + id + " name " + GsonComponentSerializer.gson().serialize(title));
@ -58,6 +64,8 @@ public class BotBossBar extends BossBar {
this.color = color;
if (bot.bossbar.actionBar) return;
bot.core.run("minecraft:bossbar set " + id + " color " + (color == BossBarColor.LIME ? "green" : color.name().toLowerCase()));
}
@ -66,6 +74,8 @@ public class BotBossBar extends BossBar {
this.players = players;
if (bot.bossbar.actionBar) return;
bot.core.run("minecraft:bossbar set " + id + " players " + players);
}
@ -87,6 +97,8 @@ public class BotBossBar extends BossBar {
case NOTCHES_10 -> division = "notched_10";
}
if (bot.bossbar.actionBar) return;
bot.core.run("minecraft:bossbar set " + id + " style " + division);
}
@ -98,6 +110,8 @@ public class BotBossBar extends BossBar {
this.value = value;
if (bot.bossbar.actionBar) return;
bot.core.run("minecraft:bossbar set " + id + " value " + value);
}
@ -106,6 +120,8 @@ public class BotBossBar extends BossBar {
this.visible = visible;
if (bot.bossbar.actionBar) return;
bot.core.run("minecraft:bossbar set " + id + " visible " + visible);
}
@ -117,6 +133,8 @@ public class BotBossBar extends BossBar {
this.max = max;
if (bot.bossbar.actionBar) return;
bot.core.run("minecraft:bossbar set " + id + " max " + max);
}
}

View file

@ -23,6 +23,7 @@ public class BossbarManagerPlugin extends Bot.Listener {
private final Map<UUID, BotBossBar> bossBars = new HashMap<>();
public boolean enabled = true;
public boolean actionBar = false;
public final String bossBarPrefix = "chomens_bot:";
@ -45,7 +46,7 @@ public class BossbarManagerPlugin extends Bot.Listener {
}
public void packetReceived(ClientboundBossEventPacket packet) {
if (!enabled || !bot.options.useCore) return;
if (!enabled || actionBar || !bot.options.useCore) return;
try {
switch (packet.getAction()) {
@ -147,6 +148,8 @@ public class BossbarManagerPlugin extends Bot.Listener {
}
private void playerJoined () {
if (!enabled || actionBar || !bot.options.useCore) return;
for (Map.Entry<UUID, BotBossBar> _bossBar : bossBars.entrySet()) {
final BotBossBar bossBar = _bossBar.getValue();
@ -168,6 +171,8 @@ public class BossbarManagerPlugin extends Bot.Listener {
addBossBar(name, bossBar, false);
}
private void addBossBar (String name, BotBossBar bossBar, boolean secret) {
if (actionBar) return;
final String prefix = "minecraft:bossbar set " + name + " ";
final String stringifiedName = GsonComponentSerializer.gson().serialize(secret ? bossBar.secret : bossBar.title);
@ -192,7 +197,7 @@ public class BossbarManagerPlugin extends Bot.Listener {
}
public void remove (String name) {
if (!enabled || !bot.options.useCore) return;
if (!enabled || actionBar || !bot.options.useCore) return;
final Map<UUID, BotBossBar> mapCopy = new HashMap<>(bossBars);