Interface Objective


public interface Objective
An objective tracks an integer score for each entry it contains.

Entries can be updated by plugins, by in-game commands, or automatically by the game, depending on their Criterion.

  • Method Details

    • builder

      static Objective.Builder builder()
      Creates a new Objective.Builder to build a Objective.
      Returns:
      The new builder
    • name

      String name()
      Gets the name of this Objective.
      Returns:
      The objective's name
    • displayName

      Component displayName()
      Gets the name displayed to players.
      Returns:
      The objective's display name
    • setDisplayName

      void setDisplayName(Component displayName) throws IllegalArgumentException
      Sets the name displayed to players.
      Parameters:
      displayName - Display name to set
      Throws:
      IllegalArgumentException - if displayName is longer than 32 characters (in its legacy representation)
    • criterion

      Criterion criterion()
      Gets the criterion for this objective.
      Returns:
      This objective's criterion
    • displayMode

      ObjectiveDisplayMode displayMode()
      Gets the ObjectiveDisplayMode used to display this objective.
      Returns:
      The ObjectiveDisplayMode used to display this objective
    • setDisplayMode

      void setDisplayMode(ObjectiveDisplayMode displayMode)
      Sets the ObjectiveDisplayMode used to display this objective.
      Parameters:
      displayMode - The ObjectiveDisplayMode used to display this objective
    • scores

      Map<Component,Score> scores()
      Gets the set of Scores for this objective.
      Returns:
      The set of Scores for this objective
    • hasScore

      boolean hasScore(Component name)
      Returns whether this objective has a Score with the given name.
      Parameters:
      name - The name of the Score to check for.
      Returns:
      Whether this objective has a Score with the given name.
    • addScore

      void addScore(Score score) throws IllegalArgumentException
      Adds the specified Score to this objective.
      Parameters:
      score - The Score to add
      Throws:
      IllegalArgumentException - If a Score with the same name exists, or the specified Score has already been added
    • findScore

      default Optional<Score> findScore(Component name)
      Gets an entry's Score for this objective, if it exists.
      Parameters:
      name - The name of the Score to get.
      Returns:
      The Score for te specified Component, if it exists.
    • findOrCreateScore

      Score findOrCreateScore(Component name)
      Gets an entry's Score for this objective.

      If the Score does not exist, it will be created.

      Parameters:
      name - The name of the Score to get
      Returns:
      The Score for the specified Component
    • removeScore

      boolean removeScore(Score score)
      Removes the specified Score from this objective, if present.
      Parameters:
      score - The Score to remove
      Returns:
      Whether the score existed on this objective
    • removeScore

      boolean removeScore(Component name)
      Removes the Score with the specified name from this objective, if present.
      Parameters:
      name - The name of the Score to remove.
      Returns:
      Whether the score existed on this objective
    • scoreboards

      Set<Scoreboard> scoreboards()
      Returns a Set of parent Scoreboards this Objective is registered to.
      Returns:
      A Set of parent Scoreboards this Objective is registered to