Class Sidebar

java.lang.Object
net.minestom.server.scoreboard.Sidebar
All Implemented Interfaces:
Audience, ForwardingAudience, Pointered, PacketGroupingAudience, Scoreboard, Viewable

public class Sidebar extends Object implements Scoreboard
Represents a sidebar which can contain up to 16 Sidebar.ScoreboardLine.

In order to use it you need to create a new instance using the constructor Sidebar(Component) and create new lines with createLine(ScoreboardLine). You can then add a Player to the viewing list using addViewer(Player) and remove him later with removeViewer(Player).

Lines can be modified using their respective identifier using updateLineContent(String, Component) and updateLineScore(String, int).

  • Constructor Details

    • Sidebar

      public Sidebar(@NotNull @NotNull Component title)
      Creates a new sidebar
      Parameters:
      title - The title of the sidebar
  • Method Details

    • setTitle

      public void setTitle(@NotNull @NotNull Component title)
      Changes the Sidebar title
      Parameters:
      title - The new sidebar title
    • createLine

      public void createLine(@NotNull @NotNull Sidebar.ScoreboardLine scoreboardLine)
      Creates a new Sidebar.ScoreboardLine.
      Parameters:
      scoreboardLine - the new scoreboard line
      Throws:
      IllegalStateException - if the sidebar cannot take more line
      IllegalArgumentException - if the sidebar already contains the line scoreboardLine or has a line with the same id
    • updateLineContent

      public void updateLineContent(@NotNull @NotNull String id, @NotNull @NotNull Component content)
      Updates a Sidebar.ScoreboardLine content through the given identifier.
      Parameters:
      id - The identifier of the Sidebar.ScoreboardLine
      content - The new content for the Sidebar.ScoreboardLine
    • updateLineScore

      public void updateLineScore(@NotNull @NotNull String id, int score)
      Updates the score of a Sidebar.ScoreboardLine through the given identifier
      Parameters:
      id - The identifier of the team
      score - The new score for the Sidebar.ScoreboardLine
    • getLine

      @Nullable public @Nullable Sidebar.ScoreboardLine getLine(@NotNull @NotNull String id)
      Gets a Sidebar.ScoreboardLine through the given identifier
      Parameters:
      id - The identifier of the line
      Returns:
      a Sidebar.ScoreboardLine or null
    • getLines

      @NotNull public @NotNull Set<Sidebar.ScoreboardLine> getLines()
      Gets a Set containing all the registered lines.
      Returns:
      an unmodifiable set containing the sidebar's lines
    • removeLine

      public void removeLine(@NotNull @NotNull String id)
      Removes a Sidebar.ScoreboardLine through the given identifier
      Parameters:
      id - the identifier of the Sidebar.ScoreboardLine
    • addViewer

      public boolean addViewer(@NotNull @NotNull Player player)
      Description copied from interface: Viewable
      Adds a viewer.
      Specified by:
      addViewer in interface Viewable
      Parameters:
      player - the viewer to add
      Returns:
      true if the player has been added, false otherwise (could be because he is already a viewer)
    • removeViewer

      public boolean removeViewer(@NotNull @NotNull Player player)
      Description copied from interface: Viewable
      Removes a viewer.
      Specified by:
      removeViewer in interface Viewable
      Parameters:
      player - the viewer to remove
      Returns:
      true if the player has been removed, false otherwise (could be because he was not a viewer)
    • getViewers

      @NotNull public @NotNull Set<Player> getViewers()
      Description copied from interface: Viewable
      Gets all the viewers of this viewable element.
      Specified by:
      getViewers in interface Viewable
      Returns:
      A Set containing all the element's viewers
    • getObjectiveName

      @NotNull public @NotNull String getObjectiveName()
      Description copied from interface: Scoreboard
      Gets the objective name of the scoreboard.
      Specified by:
      getObjectiveName in interface Scoreboard
      Returns:
      the objective name