Skip to content

BossBar

Fulminazzo edited this page Oct 17, 2023 · 1 revision

While not being a utility class, BossBar is still a valuable object among the Bukkit assets.
As you might have guessed, it allows to create bossbars across versions (from 1.8 through the latest Minecraft Version)!
Do keep in mind though that features like BarColor, BarStyle and BarFlag were added only in 1.9 and above, therefore they will not be available in 1.8!

Creating a BossBar

Creating a BossBar is trivial, you can simply use one of the many constructors provided:

public BossBar(String title);

public BossBar(String title, String colorName);

public BossBar(String title, String colorName, String styleName);

Since this class tries to emulate the Bukkit BossBar interface, it provides every method available, namely:

  • getTitle();
  • setTitle(String title): (automatically colored);
  • getColor();
  • setColor(String colorName): (requires a String for compatibility reasons);
  • getStyle();
  • setStyle(String styleName): (requires a String for compatibility reasons);
  • getProgress();
  • setProgress(double progress): (has to be a value between 0.0 and 1.0);
  • isVisible();
  • setVisible(boolean visible);
  • show();
  • hide();
  • addPlayer(Player player);
  • removePlayer(Player player);
  • removeAll();
  • getPlayers();
  • addFlag(String flagName): (requires a String for compatibility reasons);
  • removeFlag(String flagName): (requires a String for compatibility reasons);
  • hasFlag(String flagName): (requires a String for compatibility reasons).

TimerBossBar

TimerBossBar is a special implementation of the [Timer class] that allows to create bossbars that decay in time: basically, the timer duration is connected with the BossBar progress, to create a nice visual effect of time expiring.
The usage of this class is similar to BossBar and Timer compared; you start by creating the object:

public TimerBossBar(String title, TimerIntermediateAction... intermediateActions);

public TimerBossBar(String title, String barColor, TimerIntermediateAction... intermediateActions);

public TimerBossBar(String title, String barColor, String barStyle, TimerIntermediateAction... intermediateActions);

Then, you can start it as you normally would with a [Timer object].
From your plugin main class:

@Override
public void onEnable() {
    /* ... */
    TimerBossBar timerBossBar = new TimerBossBar("&c&lSERVER SHUTDOWN!", "RED", "SOLID");
    //NOTE: You will have to manually add players!
    timerBossBar.addPlayer(Bukkit.getPlayer("Fulminazzo"));
    int durationInSeconds = 30;
    timerBossBar.start(this, 30);
    /* ... */
}