Interface DataStore


  • public interface DataStore
    Data type abstraction for permissions data.

    This is the low-level interface used by the engine for querying data. It should perform minimal caching, but is responsible for update notifications.

    Since:
    2.0.0
    • Method Detail

      • name

        String name()
        Get the identifier that refers to this instance of the data store uniquely.

        This is generally user-defined in the configuration.

        Returns:
        The name of the current data store instance.
        Since:
        2.0.0
      • firstRun

        boolean firstRun()
        Get whether or not this is this data store's first run.

        If this is the first run for a data store, PermissionsEx will try to populate it with default data.

        Returns:
        if this is the first run
        Since:
        2.0.0
      • close

        void close()
        Free any resources this data store may be using.
        Since:
        2.0.0
      • getData

        CompletableFuture<ImmutableSubjectDatagetData​(String type,
                                                        String identifier,
                                                        @Nullable Consumer<ImmutableSubjectData> listener)
        Loads the data at the specified type and identifier.

        Implementations of this method do not need to perform any caching.

        Parameters:
        type - The type of subject to get
        identifier - The subject's identifier
        listener - The update listener for this subject
        Returns:
        The relevant subject data
        Since:
        2.0.0
      • getData

        default CompletableFuture<ImmutableSubjectDatagetData​(SubjectRef<?> subject,
                                                                @Nullable Consumer<ImmutableSubjectData> listener)
        Loads the data at the specified type and identifier.

        Implementations of this method do not need to perform any caching.

        Parameters:
        subject - The identity of the subject data is being set for
        listener - The update listener for this subject
        Returns:
        The relevant subject data
        Since:
        2.0.0
      • setData

        CompletableFuture<ImmutableSubjectDatasetData​(String type,
                                                        String identifier,
                                                        @Nullable ImmutableSubjectData data)
        Sets the data at the specified type and identifier.
        Parameters:
        type - The type of subject data is being fetched for
        identifier - The identifier of the subject data is being fetched for
        data - The data to commit to this backend. This being null deletes any data for the given identifier
        Returns:
        A future that can be used to listen for completion of writing the changed data
        Since:
        2.0.0
      • setData

        default CompletableFuture<ImmutableSubjectDatasetData​(SubjectRef<?> subject,
                                                                @Nullable ImmutableSubjectData data)
        Sets the data at the specified type and identifier.
        Parameters:
        subject - The identity of the subject data is being set for
        data - The data to commit to this backend. This being null deletes any data for the given subject
        Returns:
        A future that can be used to listen for completion of writing the changed data
        Since:
        2.0.0
      • moveData

        CompletableFuture<VoidmoveData​(String oldType,
                                         String oldIdentifier,
                                         String newType,
                                         String newIdentifier)
        Move data from one subject to another
        Parameters:
        oldType - The old subject's type
        oldIdentifier - The old subject's identifier
        newType - The new subject's type
        newIdentifier - The new subject's identifier
        Returns:
        A future that will complete when the move is complete
        Since:
        2.0.0
      • moveData

        default CompletableFuture<VoidmoveData​(SubjectRef<?> from,
                                                 SubjectRef<?> to)
        Move data from one subject to another
        Parameters:
        from - the old subject
        to - the new subject
        Returns:
        A future that will complete when the move is complete
        Since:
        2.0.0
      • isRegistered

        CompletableFuture<BooleanisRegistered​(String type,
                                                String identifier)
        Return if the given subject has any data stored in this store.
        Parameters:
        type - The subject's type
        identifier - The subject's identifier
        Returns:
        whether any data is stored
        Since:
        2.0.0
      • isRegistered

        default CompletableFuture<BooleanisRegistered​(SubjectRef<?> subject)
        Return if the given subject has any data stored in this store.
        Parameters:
        subject - the subject to check
        Returns:
        whether any data is stored
        Since:
        2.0.0
      • getAllIdentifiers

        Stream<StringgetAllIdentifiers​(String type)
        Get all subject identifiers for subjects of the given type.
        Parameters:
        type - The type of subject to get identifiers for
        Returns:
        The registered identifiers of subjects of type type
        Since:
        2.0.0
      • getRegisteredTypes

        Set<StringgetRegisteredTypes()
        Return all subject types that contain data
        Returns:
        The registered subject types
        Since:
        2.0.0
      • performBulkOperation

        <T> CompletableFuture<T> performBulkOperation​(Function<DataStore,​T> function)
        Perform a bulk operation on this data store. While this operation is in progress, all writes must be suppressed (meaning changes must be cached in memory until the operation is complete). Bulk operations may be executed asynchronously.
        Type Parameters:
        T - return value type
        Parameters:
        function - The function to call containing the operation.
        Returns:
        a future completing with the result of the operation or an error
        Since:
        2.0.0
      • getRankLadder

        CompletableFuture<RankLaddergetRankLadder​(String ladder,
                                                    @Nullable Consumer<RankLadder> listener)
        Get a specific rank ladder, with a possible update listener.
        Parameters:
        ladder - The ladder to get. Case-insensitive
        listener - The listener to track possible updates
        Returns:
        the ladder
        Since:
        2.0.0
      • hasRankLadder

        CompletableFuture<BooleanhasRankLadder​(String ladder)
        Whether a rank ladder by the given name is present.
        Parameters:
        ladder - The ladder to check. Case-insensitive
        Returns:
        Whether a ladder by the provided name exists
        Since:
        2.0.0
      • setRankLadder

        CompletableFuture<RankLaddersetRankLadder​(String identifier,
                                                    @Nullable RankLadder ladder)
        Set the rank ladder at the given identifier.
        Parameters:
        identifier - The name of the ladder. Case-insensitive for overwriting existing ladders
        ladder - The ladder to update
        Returns:
        a future tracking the status of this operation
        Since:
        2.0.0