Boss bars are visual elements displayed at the top of the player's screen, typically used to show
boss health, progress indicators, or status information. Allay provides a flexible API for creating
and managing boss bars.
BossBarViewer is an interface implemented by entities that can view boss bars. The Player
interface extends BossBarViewer, so players can view boss bars directly.
importorg.allaymc.api.bossbar.BossBar;importorg.allaymc.api.bossbar.BossBarColor;importorg.allaymc.api.bossbar.BossBarStyle;// Create a new boss barBossBarbossBar=BossBar.create();// Configure the boss barbossBar.setTitle("Boss Fight!");bossBar.setProgress(1.0f);// Full barbossBar.setColor(BossBarColor.RED);bossBar.setStyle(BossBarStyle.SEGMENTED_10);
importorg.allaymc.api.bossbar.BossBar;importorg.allaymc.api.entity.interfaces.EntityPlayer;publicvoidshowBossBarToPlayer(EntityPlayerplayer){BossBarbossBar=BossBar.create();bossBar.setTitle("Dragon Health");bossBar.setColor(BossBarColor.PURPLE);bossBar.setProgress(0.75f);// 75% full// Show the boss bar to the playerbossBar.addViewer(player);}
importorg.allaymc.api.bossbar.BossBar;importorg.allaymc.api.bossbar.BossBarColor;publicclassBossHealthBar{privatefinalBossBarbossBar;privatefloatmaxHealth;privatefloatcurrentHealth;publicBossHealthBar(StringbossName,floatmaxHealth){this.bossBar=BossBar.create();this.bossBar.setTitle(bossName);this.bossBar.setColor(BossBarColor.RED);this.maxHealth=maxHealth;this.currentHealth=maxHealth;}publicvoiddamage(floatamount){currentHealth=Math.max(0,currentHealth-amount);// Update progress - all viewers will see the changebossBar.setProgress(currentHealth/maxHealth);// Change color based on healthif(currentHealth/maxHealth<0.25f){bossBar.setColor(BossBarColor.YELLOW);}}publicvoidaddViewer(EntityPlayerplayer){bossBar.addViewer(player);}publicvoidremoveViewer(EntityPlayerplayer){bossBar.removeViewer(player);}}
importorg.allaymc.api.bossbar.BossBar;importorg.allaymc.api.bossbar.BossBarColor;importorg.allaymc.api.bossbar.BossBarStyle;importorg.allaymc.api.entity.interfaces.EntityPlayer;publicclassLoadingBar{privatefinalBossBarbossBar;publicLoadingBar(){this.bossBar=BossBar.create();this.bossBar.setTitle("Loading...");this.bossBar.setProgress(0f);this.bossBar.setColor(BossBarColor.GREEN);this.bossBar.setStyle(BossBarStyle.SEGMENTED_10);}publicvoidshow(EntityPlayerplayer){bossBar.addViewer(player);}publicvoidupdateProgress(floatprogress,Stringmessage){bossBar.setProgress(Math.min(1f,Math.max(0f,progress)));bossBar.setTitle(message);}publicvoidcomplete(EntityPlayerplayer){bossBar.setTitle("Complete!");bossBar.setProgress(1f);// Remove after completionbossBar.removeViewer(player);}}
importorg.allaymc.api.bossbar.BossBar;importorg.allaymc.api.bossbar.BossBarColor;importorg.allaymc.api.entity.interfaces.EntityPlayer;importorg.allaymc.api.server.Server;importjava.util.Set;publicclassEventTimer{privatefinalBossBarbossBar;privatefinalSet<EntityPlayer>participants;privatefinalinttotalSeconds;privateintremainingSeconds;publicEventTimer(StringeventName,intseconds,Set<EntityPlayer>participants){this.bossBar=BossBar.create();this.bossBar.setTitle(eventName+" - "+formatTime(seconds));this.bossBar.setProgress(1f);this.bossBar.setColor(BossBarColor.BLUE);this.participants=participants;this.totalSeconds=seconds;this.remainingSeconds=seconds;// Add all participants as viewersparticipants.forEach(bossBar::addViewer);}publicvoidtick(){remainingSeconds--;floatprogress=(float)remainingSeconds/totalSeconds;bossBar.setProgress(progress);bossBar.setTitle("Event ends in "+formatTime(remainingSeconds));// Change color as time runs outif(progress<0.25f){bossBar.setColor(BossBarColor.RED);}elseif(progress<0.5f){bossBar.setColor(BossBarColor.YELLOW);}if(remainingSeconds<=0){end();}}publicvoidend(){bossBar.removeAllViewers();}privateStringformatTime(intseconds){returnString.format("%d:%02d",seconds/60,seconds%60);}}
importorg.allaymc.api.bossbar.BossBar;importorg.allaymc.api.bossbar.BossBarColor;importorg.allaymc.api.bossbar.BossBarStyle;importorg.allaymc.api.entity.interfaces.EntityPlayer;importjava.util.Collection;publicclassBossFight{privatefinalBossBarhealthBar;privatefloatbossHealth=100f;privatefinalfloatmaxHealth=100f;publicBossFight(StringbossName){this.healthBar=BossBar.create();this.healthBar.setTitle(bossName);this.healthBar.setProgress(1f);this.healthBar.setColor(BossBarColor.PURPLE);this.healthBar.setStyle(BossBarStyle.SEGMENTED_20);this.healthBar.setDarkenSky(true);// Darken sky for dramatic effect}publicvoidplayerEnterArena(EntityPlayerplayer){healthBar.addViewer(player);}publicvoidplayerLeaveArena(EntityPlayerplayer){healthBar.removeViewer(player);}publicvoiddamageBoss(floatdamage){bossHealth=Math.max(0,bossHealth-damage);healthBar.setProgress(bossHealth/maxHealth);// Visual feedback based on healthif(bossHealth/maxHealth<0.2f){healthBar.setColor(BossBarColor.RED);healthBar.setTitle("Enraged Boss!");}elseif(bossHealth/maxHealth<0.5f){healthBar.setColor(BossBarColor.YELLOW);}}publicbooleanisBossDefeated(){returnbossHealth<=0;}publicvoidendFight(){healthBar.removeAllViewers();}publicCollection<?>getViewers(){returnhealthBar.getViewers();}}
Boss bars are not automatically cleaned up. Make sure to call removeViewer() or
removeAllViewers() when you no longer need to display the boss bar to avoid memory leaks.
Progress Range
The progress value must be between 0.0 and 1.0 (inclusive). Values outside this range will
throw an exception.
Darken Sky Effect
The setDarkenSky(true) option creates a dramatic visual effect similar to the Wither or
Ender Dragon boss fights. Use it sparingly for special events.
Automatic Updates
When you modify any property of a boss bar (title, progress, color, style, darkenSky),
all current viewers will automatically see the changes. You don't need to manually refresh
the display.