bossbar manager actionbar and enabled

This commit is contained in:
Chayapak 2023-04-14 15:41:38 +07:00
parent ea2bcb1fb0
commit 0aa7fc8e8f

View file

@ -20,6 +20,9 @@ public class BossbarManagerPlugin extends CorePlugin.Listener {
private final Map<String, BossBar> bossBars = new HashMap<>(); private final Map<String, BossBar> bossBars = new HashMap<>();
@Getter @Setter private boolean enabled = true;
@Getter @Setter private boolean actionbar = false;
@Getter @Setter private String bossBarPrefix = "chomens_bot:"; @Getter @Setter private String bossBarPrefix = "chomens_bot:";
@Getter @Setter private String textDisplayPrefix = "chomens_bot_"; @Getter @Setter private String textDisplayPrefix = "chomens_bot_";
@ -42,12 +45,14 @@ public class BossbarManagerPlugin extends CorePlugin.Listener {
} }
public void tick () { public void tick () {
if (!enabled) return;
for (Map.Entry<String, BossBar> _bossBar : bossBars.entrySet()) { for (Map.Entry<String, BossBar> _bossBar : bossBars.entrySet()) {
final String name = _bossBar.getKey(); final String name = _bossBar.getKey();
final BossBar bossBar = _bossBar.getValue(); final BossBar bossBar = _bossBar.getValue();
final String stringifiedComponent = GsonComponentSerializer.gson().serialize(bossBar.name()); final String stringifiedComponent = GsonComponentSerializer.gson().serialize(bossBar.name());
if (!actionbar) {
bot.core().run("minecraft:bossbar add " + bossBarPrefix + name + " \"\""); bot.core().run("minecraft:bossbar add " + bossBarPrefix + name + " \"\"");
bot.core().run("minecraft:bossbar set " + bossBarPrefix + name + " players " + bossBar.players()); bot.core().run("minecraft:bossbar set " + bossBarPrefix + name + " players " + bossBar.players());
bot.core().run("minecraft:bossbar set " + bossBarPrefix + name + " name " + stringifiedComponent); bot.core().run("minecraft:bossbar set " + bossBarPrefix + name + " name " + stringifiedComponent);
@ -56,6 +61,9 @@ public class BossbarManagerPlugin extends CorePlugin.Listener {
bot.core().run("minecraft:bossbar set " + bossBarPrefix + name + " style " + bossBar.style().style); bot.core().run("minecraft:bossbar set " + bossBarPrefix + name + " style " + bossBar.style().style);
bot.core().run("minecraft:bossbar set " + bossBarPrefix + name + " value " + bossBar.value()); bot.core().run("minecraft:bossbar set " + bossBarPrefix + name + " value " + bossBar.value());
bot.core().run("minecraft:bossbar set " + bossBarPrefix + name + " max " + bossBar.max()); bot.core().run("minecraft:bossbar set " + bossBarPrefix + name + " max " + bossBar.max());
} else {
bot.core().run("minecraft:title " + bossBar.players() + " actionbar " + stringifiedComponent);
}
// is there any way instead of using random? // is there any way instead of using random?
bot.core().run("minecraft:data modify entity @e[tag=" + textDisplayPrefix + name + ",limit=1,sort=random] text set value '" + stringifiedComponent.replace("'", "\\\'") + "'"); bot.core().run("minecraft:data modify entity @e[tag=" + textDisplayPrefix + name + ",limit=1,sort=random] text set value '" + stringifiedComponent.replace("'", "\\\'") + "'");