Class AnimatedBossbar
The AnimatedBossbar class creates and manages a collection of BossBars that can display
animated messages, colors, and styles based on a configurable sequence. It supports dynamic updates,
allowing text, color, and style to be cycled over time. Animations can progress in different modes (increase,
decrease, or remain static) and use both random and synchronized selections for messages, colors, and styles.
This class is designed to integrate with Bukkit/Spigot plugins, and it utilizes configuration sections for initializing values. BossBars are cached for efficient management and can be assigned to individual players or groups.
Example usage:
// Create an animated bossbar with custom messages, colors, and styles.
AnimatedBossbar bossbar = new AnimatedBossbar(plugin,
Arrays.asList("Welcome to the server!", "Good Luck!"),
Arrays.asList(BarColor.RED, BarColor.BLUE),
Arrays.asList(BarStyle.SOLID, BarStyle.SEGMENTED_10));
// Add viewers (players) to the bossbar
bossbar.addViewer(player1);
bossbar.addViewer(player2);
// Start the animation with a duration (in seconds)
bossbar.setDuration(10.0).startAnimation();
// Later, when no longer needed:
bossbar.deleteBossBar(); - See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDefines the progress behavior for the animation. -
Constructor Summary
ConstructorsConstructorDescriptionAnimatedBossbar(org.bukkit.plugin.Plugin plugin) Constructs a new AnimatedBossbar with no initial message.AnimatedBossbar(org.bukkit.plugin.Plugin plugin, String message) Constructs a new AnimatedBossbar with a single message, default color (WHITE), and default style (SOLID).AnimatedBossbar(org.bukkit.plugin.Plugin plugin, String message, org.bukkit.boss.BarColor color, org.bukkit.boss.BarStyle style) Constructs a new AnimatedBossbar with a single message, color, and style.AnimatedBossbar(org.bukkit.plugin.Plugin plugin, List<String> messages, List<org.bukkit.boss.BarColor> colors, List<org.bukkit.boss.BarStyle> styles) Constructs a new AnimatedBossbar with the specified plugin, messages, colors, and styles.AnimatedBossbar(org.bukkit.plugin.Plugin plugin, org.bukkit.configuration.ConfigurationSection section) Constructs a new AnimatedBossbar using configuration settings from the provided section. -
Method Summary
Modifier and TypeMethodDescriptionaddViewer(org.bukkit.entity.Player player) Adds a viewer (player) to this AnimatedBossbar.addViewers(Collection<? extends org.bukkit.entity.Player> players) Adds multiple viewers (players) to this AnimatedBossbar.voidDeletes this AnimatedBossbar, stopping any active animations and removing all BossBars.removeViewer(org.bukkit.entity.Player player) Removes a viewer (player) from this AnimatedBossbar.removeViewers(Collection<? extends org.bukkit.entity.Player> players) Removes multiple viewers (players) from this AnimatedBossbar.Sets the BossBar colors using an array of strings.setColors(Collection<org.bukkit.boss.BarColor> colors) Sets the BossBar colors using a collection ofBarColor.Sets the BossBar colors using a list of strings.setColors(org.bukkit.boss.BarColor... colors) Sets the BossBar colors using an array ofBarColor.setMessages(String... messages) Updates the messages using an array of strings.setMessages(List<String> messages) Updates the messages used by this AnimatedBossbar.setProgressType(String progress) Sets the progress animation type using a string.setProgressType(AnimatedBossbar.Progress progress) Sets the progress animation type.setRandomElements(String... elements) Sets the randomized elements using an array of strings.setRandomElements(Collection<String> elements) Sets the elements to be randomized.setStaleProgress(double progress) Sets the "stale" progress value for static progress animations.Sets the BossBar styles using an array of strings.setStyles(Collection<org.bukkit.boss.BarStyle> styles) Sets the BossBar styles using a collection ofBarStyle.Sets the BossBar styles using a list of strings.setStyles(org.bukkit.boss.BarStyle... styles) Sets the BossBar styles using an array ofBarStyle.setSynchronizeElements(String... elements) Sets the synchronized elements using an array of strings.setSynchronizeElements(Collection<String> elements) Sets the elements to be synchronized.voidStarts the animation of the BossBar.voidStops the current animation if it is running.static voidunregister(org.bukkit.entity.Player player) Unregisters a specific player from all AnimatedBossbar instances.static voidUnregisters all players and deletes all AnimatedBossbar instances.
-
Constructor Details
-
AnimatedBossbar
public AnimatedBossbar(org.bukkit.plugin.Plugin plugin, List<String> messages, List<org.bukkit.boss.BarColor> colors, List<org.bukkit.boss.BarStyle> styles) Constructs a new AnimatedBossbar with the specified plugin, messages, colors, and styles.- Parameters:
plugin- the plugin instance that manages this bossbarmessages- a list of messages to display on the BossBar; leading spaces are stripped for formattingcolors- a list of BossBar colors to cycle through during the animationstyles- a list of BossBar styles to cycle through during the animation
-
AnimatedBossbar
public AnimatedBossbar(org.bukkit.plugin.Plugin plugin, String message, org.bukkit.boss.BarColor color, org.bukkit.boss.BarStyle style) Constructs a new AnimatedBossbar with a single message, color, and style.- Parameters:
plugin- the plugin instance managing this bossbarmessage- the message to display on the BossBarcolor- the color of the BossBarstyle- the style of the BossBar
-
AnimatedBossbar
Constructs a new AnimatedBossbar with a single message, default color (WHITE), and default style (SOLID).- Parameters:
plugin- the plugin instance managing this bossbarmessage- the message to display on the BossBar
-
AnimatedBossbar
public AnimatedBossbar(org.bukkit.plugin.Plugin plugin) Constructs a new AnimatedBossbar with no initial message.- Parameters:
plugin- the plugin instance managing this bossbar
-
AnimatedBossbar
public AnimatedBossbar(org.bukkit.plugin.Plugin plugin, org.bukkit.configuration.ConfigurationSection section) Constructs a new AnimatedBossbar using configuration settings from the provided section.- Parameters:
plugin- the plugin instance managing this bossbarsection- the configuration section containing bossbar settings
-
-
Method Details
-
setMessages
Updates the messages used by this AnimatedBossbar.The provided list of messages will replace any existing messages. Leading spaces are stripped from each message.
- Parameters:
messages- a list of new messages- Returns:
- this AnimatedBossbar instance (for chaining)
-
setMessages
Updates the messages using an array of strings.- Parameters:
messages- an array of new messages- Returns:
- this AnimatedBossbar instance (for chaining)
-
setColors
Sets the BossBar colors using a collection ofBarColor.- Parameters:
colors- a collection of BossBar colors- Returns:
- this AnimatedBossbar instance (for chaining)
-
setColors
Sets the BossBar colors using an array ofBarColor.- Parameters:
colors- an array of BossBar colors- Returns:
- this AnimatedBossbar instance (for chaining)
-
setColors
Sets the BossBar colors using a list of strings.Each string is parsed into a
BarColor. If parsing fails,BarColor.WHITEis used.- Parameters:
colors- a list of strings representing colors- Returns:
- this AnimatedBossbar instance (for chaining)
-
setColors
Sets the BossBar colors using an array of strings.- Parameters:
colors- an array of strings representing colors- Returns:
- this AnimatedBossbar instance (for chaining)
-
setStyles
Sets the BossBar styles using a collection ofBarStyle.- Parameters:
styles- a collection of BossBar styles- Returns:
- this AnimatedBossbar instance (for chaining)
-
setStyles
Sets the BossBar styles using an array ofBarStyle.- Parameters:
styles- an array of BossBar styles- Returns:
- this AnimatedBossbar instance (for chaining)
-
setStyles
Sets the BossBar styles using a list of strings.Each string is converted to a
BarStyleusing theAnimatedBossbar.Holder.styleOf(String)method.- Parameters:
styles- a list of strings representing styles- Returns:
- this AnimatedBossbar instance (for chaining)
-
setStyles
Sets the BossBar styles using an array of strings.- Parameters:
styles- an array of strings representing styles- Returns:
- this AnimatedBossbar instance (for chaining)
-
setProgressType
Sets the progress animation type.- Parameters:
progress- the progress type (INCREASE, DECREASE, or STATIC)- Returns:
- this AnimatedBossbar instance (for chaining)
-
setProgressType
Sets the progress animation type using a string.The provided string is converted to uppercase and matched to a
AnimatedBossbar.Progressvalue. If the conversion fails, the current progress type is retained.- Parameters:
progress- a string representing the progress type- Returns:
- this AnimatedBossbar instance (for chaining)
-
setSynchronizeElements
Sets the elements to be synchronized.Synchronized elements update in lockstep across all viewers.
- Parameters:
elements- a collection of element identifiers (e.g., "messages")- Returns:
- this AnimatedBossbar instance (for chaining)
-
setSynchronizeElements
Sets the synchronized elements using an array of strings.- Parameters:
elements- an array of element identifiers- Returns:
- this AnimatedBossbar instance (for chaining)
-
setRandomElements
Sets the elements to be randomized.Randomized elements select their values at random each update.
- Parameters:
elements- a collection of element identifiers (e.g., "colors")- Returns:
- this AnimatedBossbar instance (for chaining)
-
setRandomElements
Sets the randomized elements using an array of strings.- Parameters:
elements- an array of element identifiers- Returns:
- this AnimatedBossbar instance (for chaining)
-
setStaleProgress
Sets the "stale" progress value for static progress animations.The progress value is clamped between 0.0 and 1.0.
- Parameters:
progress- the desired progress value- Returns:
- this AnimatedBossbar instance (for chaining)
-
addViewer
Adds a viewer (player) to this AnimatedBossbar.A new BossBar is created for the player if one does not already exist.
- Parameters:
player- the player to add- Returns:
- this AnimatedBossbar instance (for chaining)
-
addViewers
Adds multiple viewers (players) to this AnimatedBossbar.- Parameters:
players- a collection of players to add- Returns:
- this AnimatedBossbar instance (for chaining)
-
removeViewer
Removes a viewer (player) from this AnimatedBossbar.- Parameters:
player- the player to remove- Returns:
- this AnimatedBossbar instance (for chaining)
-
removeViewers
Removes multiple viewers (players) from this AnimatedBossbar.- Parameters:
players- a collection of players to remove- Returns:
- this AnimatedBossbar instance (for chaining)
-
startAnimation
public void startAnimation()Starts the animation of the BossBar.This method schedules a repeating task that updates the BossBar's title, color, style, and progress according to the configured messages, colors, and styles. The progress of the BossBar can increase, decrease, or remain static depending on the
AnimatedBossbar.Progresssetting. -
stopAnimation
public void stopAnimation()Stops the current animation if it is running.Cancels the scheduled task and resets the task ID to -1.
-
deleteBossBar
public void deleteBossBar()Deletes this AnimatedBossbar, stopping any active animations and removing all BossBars.The AnimatedBossbar instance is also removed from the global cache.
-
unregister
public static void unregister(org.bukkit.entity.Player player) Unregisters a specific player from all AnimatedBossbar instances.This method removes the player from each bossbar in the cache and deletes any AnimatedBossbar that no longer has viewers.
- Parameters:
player- the player to unregister
-
unregisterAll
public static void unregisterAll()Unregisters all players and deletes all AnimatedBossbar instances.This method clears the global cache and removes all active BossBars.
-