Class BossbarManager

java.lang.Object
java.util.TimerTask
me.remigio07.chatplugin.api.server.bossbar.BossbarManager
All Implemented Interfaces:
Runnable, ChatPluginManager

public abstract class BossbarManager extends TimerTask implements ChatPluginManager
Manager that handles Bossbars.
See Also:
  • Field Details

    • BOSSBAR_ID_PATTERN

      public static final Pattern BOSSBAR_ID_PATTERN
      Pattern representing the allowed bossbar IDs.

      Regex: "^[a-zA-Z0-9-_]{2,36}$"

      See Also:
    • MAX_TITLE_LENGTH

      public static final int MAX_TITLE_LENGTH
      Value representing the max title length.

      Value: 256 on > 1.12.2, 64 otherwise

    • TITLE_TOO_LONG

      public static final String TITLE_TOO_LONG
      String containing the "title too long" text indicator.

      Content: "§cTitle exceeds §f+" + MAX_TITLE_LENGTH + " §cchars"

      See Also:
  • Constructor Details

    • BossbarManager

      public BossbarManager()
  • Method Details

    • isEnabled

      public boolean isEnabled()
      Checks if this manager is enabled.

      Found at: "bossbars.settings.enabled" in ConfigurationType.BOSSBARS

      Specified by:
      isEnabled in interface ChatPluginManager
      Returns:
      Whether this manager is enabled
    • isRandomOrder

      public boolean isRandomOrder()
      Checks if the bossbars should be sent in a random order.

      Found at: "bossbars.settings.random-order" in ConfigurationType.BOSSBARS

      Returns:
      Whether to use a random order
    • shouldAbbreviateLongTitles

      public boolean shouldAbbreviateLongTitles()
      Checks if bossbars' titles should be abbreviated by adding "..." at the end when they are too long to be displayed instead of TITLE_TOO_LONG.

      Found at: "bossbars.settings.abbreviate-long-titles" in ConfigurationType.BOSSBARS

      Returns:
      Whether to abbreviate long titles
    • shouldSendFullToLegacyPlayers

      public boolean shouldSendFullToLegacyPlayers()
      Checks if bossbars sent to legacy (pre-1.9) players should always be full.

      This is a workaround to prevent players from seeing invisible withers in the distance when the bossbar is <= 50%.

      Found at: "bossbars.settings.send-full-to-legacy-players" in ConfigurationType.BOSSBARS

      Returns:
      Whether to send full bossbars to legacy players
    • isLoadingBossbarEnabled

      public boolean isLoadingBossbarEnabled()
      Checks if an animation should be shown while loading the bossbar when a player joins.

      Found at: "bossbars.settings.loading-bossbar.enabled" in ConfigurationType.BOSSBARS

      Returns:
      Whether the loading bossbar is enabled
    • getReflectionWitherTeleportationDistance

      public double getReflectionWitherTeleportationDistance()
      Gets the distance from the player to which the Wither will be teleported to when using reflection.

      Found at: "bossbars.settings.reflection-wither-teleportation.distance" in ConfigurationType.BOSSBARS

      Returns:
      Reflection Wither's teleportation distance
    • getReflectionWitherTeleportationTimeout

      public long getReflectionWitherTeleportationTimeout()
      Gets the timeout between Wither teleportations when using reflection, in milliseconds.

      Found at: "bossbars.settings.reflection-wither-teleportation.timeout-ms" in ConfigurationType.BOSSBARS

      Returns:
      Time between reflection Wither's teleportations
    • getSendingTimeout

      public long getSendingTimeout()
      Gets the timeout between sendings, in milliseconds.

      Found at: "bossbars.settings.sending-timeout-ms" in ConfigurationType.BOSSBARS

      Returns:
      Time between sendings
    • getLoadindBossbarSendingTimeout

      public long getLoadindBossbarSendingTimeout()
      Gets the timeout between sendings while loading the bossbar, in milliseconds.

      Found at: "bossbars.settings.loading-bossbar.sending-timeout-ms" in ConfigurationType.BOSSBARS

      Returns:
      Time between sendings while loading the bossbar
    • getPlaceholderTypes

      public List<PlaceholderType> getPlaceholderTypes()
      Gets the list of placeholder types used to translate Bossbar.getTitles().

      Found at: "bossbars.settings.placeholder-types" in ConfigurationType.BOSSBARS

      Returns:
      Placeholders used to translate titles
    • getEnabledWorlds

      public List<String> getEnabledWorlds()
      Gets the list of enabled worlds.

      Bossbars only apply to their enabled worlds.

      Found at: "bossbars.settings.enabled-worlds" in ConfigurationType.BOSSBARS

      Returns:
      Enabled worlds' list
    • isWorldEnabled

      public boolean isWorldEnabled(String world)
      Checks if a world is contained in the enabled worlds' list.
      Parameters:
      world - Name of the world to check
      Returns:
      Whether the world is enabled
    • getBossbars

      public List<Bossbar> getBossbars()
      Gets the list of loaded bossbars.

      You may modify the returned list.

      Returns:
      Loaded bossbars' list
    • getLoadingBossbarsTasks

      public Map<ChatPluginServerPlayer,Long> getLoadingBossbarsTasks()
      Gets the loading bossbars' tasks' map.

      Do not modify the returned map.

      Returns:
      Loading bossbars' tasks' map
    • getBossbar

      public Bossbar getBossbar(String id)
      Gets a bossbar from getBossbars() by its ID.

      Will return null if the bossbar is not loaded.

      Parameters:
      id - Bossbar's ID, case insensitive
      Returns:
      Loaded bossbar
    • getReflectionBossbarTimer

      public BossbarManager.ReflectionBossbarTimer getReflectionBossbarTimer()
      Gets the current reflection bossbar timer's instance.

      Will return null if reflection is not being used.

      Returns:
      Current reflection bossbar timer's instance
    • getTimerTaskID

      public long getTimerTaskID()
      Gets the run()'s timer's task's ID.

      You can interact with it using TaskManager's methods.

      Returns:
      Sending task's ID
    • getReflectionTimerTaskID

      public long getReflectionTimerTaskID()
      Gets the BossbarManager.ReflectionBossbarTimer.run()'s timer's task's ID.

      You can interact with it using TaskManager's methods.

      Returns:
      Reflection timer's index
    • getTimerIndex

      public int getTimerIndex()
      Gets the run()'s timer's index of getBossbars().
      Returns:
      Timer's index
    • getLastRunTime

      public long getLastRunTime()
      Gets the last time run()'s timer has been run, in milliseconds.
      Returns:
      Timer's last run time
    • isValidBossbarID

      public boolean isValidBossbarID(String bossbarID)
      Checks if the specified String is a valid bossbar ID.
      Parameters:
      bossbarID - Bossbar ID to check
      Returns:
      Whether the specified bossbar ID is valid
      See Also:
    • getInstance

      public static BossbarManager getInstance()
      Gets this manager's instance.
      Returns:
      Manager's instance
    • run

      public abstract void run()
      Automatic bossbar sender, called once every getSendingTimeout() ms.
      Specified by:
      run in interface Runnable
      Specified by:
      run in class TimerTask
    • sendBossbar

      public abstract void sendBossbar(Bossbar bossbar, ChatPluginServerPlayer player)
      Sends a bossbar to a loaded player.

      It will not be sent if Bossbar.isHidden().

      Parameters:
      bossbar - Bossbar to send
      player - Player to send the bossbar to
      See Also:
    • startLoading

      public abstract void startLoading(ChatPluginServerPlayer player)
      Starts displaying the loading bossbar to the specified player.
      Parameters:
      player - Player to display the bossbar to