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 Detail

      • name

        java.lang.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 java.lang.IllegalArgumentException
        Sets the name displayed to players.
        Parameters:
        displayName - Display name to set
        Throws:
        java.lang.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
      • scores

        java.util.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 java.lang.IllegalArgumentException
        Adds the specified Score to this objective.
        Parameters:
        score - The Score to add
        Throws:
        java.lang.IllegalArgumentException - If a Score with the same name exists, or the specified Score has already been added
      • findScore

        default java.util.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