Class Sidebar

java.lang.Object
tk.airshipcraft.commonlib.gui.objects.Sidebar

public class Sidebar extends Object
Represents a sidebar scoreboard in Minecraft, displayed on the side of a player's screen. This class facilitates the creation and management of custom scoreboard objectives and scores, allowing for dynamic updating and display of information to players. It includes methods for adding, removing, and manipulating scores and text on the sidebar.
Since:
2023-04-11
Version:
1.0.0
Author:
Locutusque, notzune
  • Constructor Summary

    Constructors
    Constructor
    Description
    Sidebar(String title)
    Initializes a new Sidebar instance with a given title.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(String text)
    Adds a line of text to the sidebar using the next available score.
    void
    add(String text, int score)
    Adds a line of text with a specified score to the sidebar.
    void
    applyStyle(org.bukkit.ChatColor color, org.bukkit.ChatColor style)
    Applies a specified color and style to the sidebar's title and text lines.
    void
    Clears all lines of text from the sidebar.
    void
    decrementScore(String text, int amount)
    Decrements the score of a given line by a specified amount.
    org.bukkit.scoreboard.Scoreboard
    Retrieves the underlying Scoreboard object associated with this sidebar.
    getTextFromLine(int line)
    Retrieves the text of a specific line from the sidebar.
    void
    hide(org.bukkit.entity.Player player)
    Hides the sidebar from a specific player, reverting to their main scoreboard.
    void
    incrementScore(String text, int amount)
    Increments the score of a given line by a specified amount.
    boolean
    isLineEmpty(int line)
    Checks if a specific line on the sidebar is empty (i.e., has no set text).
    void
    remove(String text)
    Removes a specific line of text from the sidebar.
    void
    renameLine(String oldText, String newText)
    Renames an existing line or adds it if it does not exist.
    void
    setLine(String text, int score)
    Sets or updates the score for a specific line of text.
    void
    show(org.bukkit.entity.Player player)
    Shows the sidebar to a specific player.
    void
    Updates the display name of the sidebar.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Sidebar

      public Sidebar(String title)
      Initializes a new Sidebar instance with a given title.
      Parameters:
      title - The title to be displayed at the top of the sidebar.
  • Method Details

    • add

      public void add(String text, int score)
      Adds a line of text with a specified score to the sidebar. Updates the score of the text if it already exists.
      Parameters:
      text - The text to be displayed as a line on the sidebar.
      score - The score to order the line on the sidebar.
    • add

      public void add(String text)
      Adds a line of text to the sidebar using the next available score.
      Parameters:
      text - The text to be added as a line on the sidebar.
    • remove

      public void remove(String text)
      Removes a specific line of text from the sidebar.
      Parameters:
      text - The text line to be removed from the sidebar.
    • setLine

      public void setLine(String text, int score)
      Sets or updates the score for a specific line of text. If the text does not exist, it is added to the sidebar.
      Parameters:
      text - The text line to update.
      score - The new score to assign to the text line.
    • clear

      public void clear()
      Clears all lines of text from the sidebar.
    • applyStyle

      public void applyStyle(org.bukkit.ChatColor color, org.bukkit.ChatColor style)
      Applies a specified color and style to the sidebar's title and text lines.
      Parameters:
      color - The ChatColor to apply to the sidebar text.
      style - The ChatColor style (e.g., bold, italic) to apply to the sidebar text.
    • show

      public void show(org.bukkit.entity.Player player)
      Shows the sidebar to a specific player.
      Parameters:
      player - The player to whom the sidebar will be displayed.
    • hide

      public void hide(org.bukkit.entity.Player player)
      Hides the sidebar from a specific player, reverting to their main scoreboard.
      Parameters:
      player - The player from whom the sidebar will be hidden.
    • getTextFromLine

      public String getTextFromLine(int line)
      Retrieves the text of a specific line from the sidebar.
      Parameters:
      line - The line number from which to retrieve the text.
      Returns:
      The text of the specified line, or null if no text is set at that line.
    • isLineEmpty

      public boolean isLineEmpty(int line)
      Checks if a specific line on the sidebar is empty (i.e., has no set text).
      Parameters:
      line - The line number to check.
      Returns:
      true if the line is empty, false otherwise.
    • renameLine

      public void renameLine(String oldText, String newText)
      Renames an existing line or adds it if it does not exist.
      Parameters:
      oldText - The current text of the line to find and rename.
      newText - The new text to replace the existing text.
    • incrementScore

      public void incrementScore(String text, int amount)
      Increments the score of a given line by a specified amount.
      Parameters:
      text - The text line whose score is to be incremented.
      amount - The amount by which to increment the score.
    • decrementScore

      public void decrementScore(String text, int amount)
      Decrements the score of a given line by a specified amount.
      Parameters:
      text - The text line whose score is to be decremented.
      amount - The amount by which to decrement the score.
    • updateDisplayName

      public void updateDisplayName(String name)
      Updates the display name of the sidebar.
      Parameters:
      name - The new display name for the sidebar.
    • getScoreboard

      public org.bukkit.scoreboard.Scoreboard getScoreboard()
      Retrieves the underlying Scoreboard object associated with this sidebar.
      Returns:
      The Scoreboard object.