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<String,Score> scores()
      Gets the set of Scores for this objective.
      Returns:
      The set of Scores for this objective
    • hasScore

      boolean hasScore(String 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.
    • hasScore

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

      boolean hasScore(GameProfile profile)
      Returns whether this objective has a Score with the given profile.
      Parameters:
      profile - The profile of the Score to check for.
      Returns:
      Whether this objective has a Score with the given profile.
    • 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(String 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 the specified name, if it exists.
    • findOrCreateScore

      Score findOrCreateScore(String 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 name
    • removeScore

      boolean removeScore(String 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
    • findScore

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

      Score findOrCreateScore(Entity entity)
      Gets an entry's Score for this objective.

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

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

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

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

      Score findOrCreateScore(GameProfile profile)
      Gets an entry's Score for this objective.

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

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

      boolean removeScore(GameProfile profile)
      Removes the Score with the specified profile from this objective, if present.
      Parameters:
      profile - The profile of the Score to remove.
      Returns:
      Whether the score existed on this objective
    • 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
    • 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