Class AnimatedBossbar

java.lang.Object
me.croabeast.takion.message.AnimatedBossbar

public class AnimatedBossbar extends Object
Provides a dynamic, animated BossBar display for players.

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:
  • BossBar
  • Plugin
  • 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 bossbar
      messages - a list of messages to display on the BossBar; leading spaces are stripped for formatting
      colors - a list of BossBar colors to cycle through during the animation
      styles - 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 bossbar
      message - the message to display on the BossBar
      color - the color of the BossBar
      style - the style of the BossBar
    • AnimatedBossbar

      public AnimatedBossbar(org.bukkit.plugin.Plugin plugin, String message)
      Constructs a new AnimatedBossbar with a single message, default color (WHITE), and default style (SOLID).
      Parameters:
      plugin - the plugin instance managing this bossbar
      message - 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 bossbar
      section - the configuration section containing bossbar settings
  • Method Details

    • setMessages

      public AnimatedBossbar setMessages(List<String> messages)
      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

      public AnimatedBossbar setMessages(String... messages)
      Updates the messages using an array of strings.
      Parameters:
      messages - an array of new messages
      Returns:
      this AnimatedBossbar instance (for chaining)
    • setColors

      public AnimatedBossbar setColors(Collection<org.bukkit.boss.BarColor> colors)
      Sets the BossBar colors using a collection of BarColor.
      Parameters:
      colors - a collection of BossBar colors
      Returns:
      this AnimatedBossbar instance (for chaining)
    • setColors

      public AnimatedBossbar setColors(org.bukkit.boss.BarColor... colors)
      Sets the BossBar colors using an array of BarColor.
      Parameters:
      colors - an array of BossBar colors
      Returns:
      this AnimatedBossbar instance (for chaining)
    • setColors

      public AnimatedBossbar setColors(List<String> colors)
      Sets the BossBar colors using a list of strings.

      Each string is parsed into a BarColor. If parsing fails, BarColor.WHITE is used.

      Parameters:
      colors - a list of strings representing colors
      Returns:
      this AnimatedBossbar instance (for chaining)
    • setColors

      public AnimatedBossbar setColors(String... colors)
      Sets the BossBar colors using an array of strings.
      Parameters:
      colors - an array of strings representing colors
      Returns:
      this AnimatedBossbar instance (for chaining)
    • setStyles

      public AnimatedBossbar setStyles(Collection<org.bukkit.boss.BarStyle> styles)
      Sets the BossBar styles using a collection of BarStyle.
      Parameters:
      styles - a collection of BossBar styles
      Returns:
      this AnimatedBossbar instance (for chaining)
    • setStyles

      public AnimatedBossbar setStyles(org.bukkit.boss.BarStyle... styles)
      Sets the BossBar styles using an array of BarStyle.
      Parameters:
      styles - an array of BossBar styles
      Returns:
      this AnimatedBossbar instance (for chaining)
    • setStyles

      public AnimatedBossbar setStyles(List<String> styles)
      Sets the BossBar styles using a list of strings.

      Each string is converted to a BarStyle using the AnimatedBossbar.Holder.styleOf(String) method.

      Parameters:
      styles - a list of strings representing styles
      Returns:
      this AnimatedBossbar instance (for chaining)
    • setStyles

      public AnimatedBossbar setStyles(String... styles)
      Sets the BossBar styles using an array of strings.
      Parameters:
      styles - an array of strings representing styles
      Returns:
      this AnimatedBossbar instance (for chaining)
    • setProgressType

      public AnimatedBossbar setProgressType(AnimatedBossbar.Progress progress)
      Sets the progress animation type.
      Parameters:
      progress - the progress type (INCREASE, DECREASE, or STATIC)
      Returns:
      this AnimatedBossbar instance (for chaining)
    • setProgressType

      public AnimatedBossbar setProgressType(String progress)
      Sets the progress animation type using a string.

      The provided string is converted to uppercase and matched to a AnimatedBossbar.Progress value. 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

      public AnimatedBossbar setSynchronizeElements(Collection<String> elements)
      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

      public AnimatedBossbar setSynchronizeElements(String... elements)
      Sets the synchronized elements using an array of strings.
      Parameters:
      elements - an array of element identifiers
      Returns:
      this AnimatedBossbar instance (for chaining)
    • setRandomElements

      public AnimatedBossbar setRandomElements(Collection<String> elements)
      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

      public AnimatedBossbar setRandomElements(String... elements)
      Sets the randomized elements using an array of strings.
      Parameters:
      elements - an array of element identifiers
      Returns:
      this AnimatedBossbar instance (for chaining)
    • setStaleProgress

      public AnimatedBossbar setStaleProgress(double progress)
      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

      public AnimatedBossbar addViewer(org.bukkit.entity.Player player)
      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

      public AnimatedBossbar addViewers(Collection<? extends org.bukkit.entity.Player> players)
      Adds multiple viewers (players) to this AnimatedBossbar.
      Parameters:
      players - a collection of players to add
      Returns:
      this AnimatedBossbar instance (for chaining)
    • removeViewer

      public AnimatedBossbar removeViewer(org.bukkit.entity.Player player)
      Removes a viewer (player) from this AnimatedBossbar.
      Parameters:
      player - the player to remove
      Returns:
      this AnimatedBossbar instance (for chaining)
    • removeViewers

      public AnimatedBossbar removeViewers(Collection<? extends org.bukkit.entity.Player> players)
      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.Progress setting.

    • 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.