Skip to content

Boss Bar

This class provides a convenient interface for creating a boss bar with a specified name, progress, color, and overlay style, and for managing the visibility of the boss bar for players in a PlayerList. It encapsulates the ServerBossEvent and provides methods to add/remove players, update progress, set the name, and manage visibility of the boss bar for players in a PlayerList.

BossBarExample.java
package com.example.bossbar;
import dev.matthiesen.matthiesen_core.common.utility.BossBar;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerBossEvent;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.players.PlayerList;
import net.minecraft.world.BossEvent;
public class BossBarExample {
public static BossBar.Builder getBossBar() {
BossBar bossBar = new BossBar(
Component.literal("Boss Bar Example"),
1F,
BossEvent.BossBarColor.GREEN,
BossEvent.BossBarOverlay.PROGRESS
);
return bossBar.getBuilder();
}
// Examples of how to use the BossBar utility class
public static void addPlayerToBossBar(ServerPlayer player) {
getBossBar().addPlayer(player);
}
public static void removePlayerFromBossBar(ServerPlayer player) {
getBossBar().removePlayer(player);
}
public static void updateBossBarProgress(float progress) {
getBossBar().updateProgress(progress);
}
public static void setName(Component component) {
getBossBar().setName(component);
}
public static void verifyPlayerList(PlayerList list) {
getBossBar().verifyPlayerList(list);
}
public static void hideBossBarFromPlayerList(PlayerList list) {
getBossBar().hideBossBarFromPlayerList(list);
}
public static void showBossBarFromPlayerList(PlayerList list) {
getBossBar().showBossBarFromPlayerList(list);
}
}