Bossbar Commands
Commands for creating and managing custom boss bars displayed to players.
A new bar starts out invisible
/bossbar add mypack:event {text:"Event"} creates a bar that nobody can see yet. It starts white, in the progress style, with a max of 100 and a value of 0. It only shows up once you give it viewers with /bossbar set mypack:event players @a. When someone says their boss bar does not work, this missing step is nearly always the reason.
What you can set
color- blue, green, pink, purple, red, white or yellow. It colors the bar, and the name as well unless the name brings its own color.
style- progress for one smooth bar, or notched_6, notched_10, notched_12 and notched_20 to split it into segments.
maxandvalue- Whole numbers. The max is at least 1 and the value at least 0, and the bar fills to value divided by max.
name- A text component, so it can carry its own color and formatting.
playersandvisible- Who sees the bar, and a switch to hide it without clearing that list.
Timers, and what survives a restart
Bars are saved in level.dat under CustomBossEvents, so they are still there after a restart. For a countdown, keep the number in a scoreboard and copy it into the bar from a tick function:
execute store result bossbar mypack:event value run scoreboard players get #timer event
/bossbar get reads max, players, value or visible back as a command result, which you can store in turn. Clean up with /bossbar remove when the event is over, and /bossbar list shows every bar the world still has. It all needs permission level 2, and /scoreboard and /execute do most of the work in any timer.