Interface UserManager


  • public interface UserManager
    Stores the persistent User data of a Player.

    Any Users retrieved from this manager should not be stored, as they may become invalid at any time.

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.util.concurrent.CompletableFuture<java.lang.Boolean> delete​(java.util.UUID uuid)
      Deletes the data associated with a User, if the player is offline.
      boolean exists​(java.util.UUID playerUuid)
      Returns whether data to create a User exists for a given player with a specified UUID.
      java.util.concurrent.CompletableFuture<java.lang.Boolean> forceSave​(java.util.UUID uuid)
      If the implementation supports caching user objects, this will hint to the implementation that the user with the given UUID should be saved to the disk immediately.
      java.util.concurrent.CompletableFuture<java.util.Optional<User>> load​(java.lang.String lastKnownName)
      Gets the data of a User by their last known user name (case-insensitive).
      java.util.concurrent.CompletableFuture<java.util.Optional<User>> load​(java.util.UUID uniqueId)
      Gets the data of a User by their unique id.
      java.util.concurrent.CompletableFuture<java.util.Optional<User>> load​(GameProfile profile)
      Gets the data of a User by their GameProfile.
      java.util.concurrent.CompletableFuture<User> loadOrCreate​(java.util.UUID uuid)
      Gets or creates a persistent User with the given UUID.
      boolean removeFromCache​(java.util.UUID uuid)
      If the implementation supports caching user objects, this will hint to the implementation that the user with the given UUID should no longer be cached.
      java.util.stream.Stream<GameProfile> streamAll()
      Gets a Stream that returns a GameProfile for each stored Users.
      java.util.stream.Stream<GameProfile> streamOfMatches​(java.lang.String lastKnownName)
      Gets a Stream that returns a GameProfile for each stored User whose last known user names start with the given string (case-insensitive).
    • Method Detail

      • load

        java.util.concurrent.CompletableFuture<java.util.Optional<User>> load​(java.util.UUID uniqueId)
        Gets the data of a User by their unique id.
        Parameters:
        uniqueId - The UUID of the user
        Returns:
        User or Optional.empty() if not found
      • load

        java.util.concurrent.CompletableFuture<java.util.Optional<User>> load​(java.lang.String lastKnownName)
        Gets the data of a User by their last known user name (case-insensitive).

        To get the current name of a player, use the GameProfileManager service.

        Parameters:
        lastKnownName - The user name
        Returns:
        User or Optional.empty() if not found
      • load

        java.util.concurrent.CompletableFuture<java.util.Optional<User>> load​(GameProfile profile)
        Gets the data of a User by their GameProfile.
        Parameters:
        profile - The profile
        Returns:
        User or Optional.empty() if not found
      • loadOrCreate

        java.util.concurrent.CompletableFuture<User> loadOrCreate​(java.util.UUID uuid)
        Gets or creates a persistent User with the given UUID.
        Parameters:
        uuid - The UUID of the player to load or create.
        Returns:
        The user object
      • delete

        java.util.concurrent.CompletableFuture<java.lang.Boolean> delete​(java.util.UUID uuid)
        Deletes the data associated with a User, if the player is offline.
        Parameters:
        uuid - The uuid of the user to delete
        Returns:
        true if the deletion was successful
      • removeFromCache

        boolean removeFromCache​(java.util.UUID uuid)
        If the implementation supports caching user objects, this will hint to the implementation that the user with the given UUID should no longer be cached. Any User objects held that this point will become invalid (though developers should not be storing users).

        Be aware, any changes that have been made to the user may not be saved.

        Users that are online will not be affected by this call.

        Parameters:
        uuid - The UUID of the user to save.
        Returns:
        true if the user was removed from a cache.
      • forceSave

        java.util.concurrent.CompletableFuture<java.lang.Boolean> forceSave​(java.util.UUID uuid)
        If the implementation supports caching user objects, this will hint to the implementation that the user with the given UUID should be saved to the disk immediately.

        If an exception is encountered during save, the completed future will be exceptional and the boolean will be null. It is therefore recommended that you check for any exceptions this future holds.

        Parameters:
        uuid - The user to attempt to save.
        Returns:
        A completed future that returns true if the implementation saved the user.
      • exists

        boolean exists​(java.util.UUID playerUuid)
        Returns whether data to create a User exists for a given player with a specified UUID.

        If this is false, then load(UUID) will return an empty optional.

        Parameters:
        playerUuid - The UUID of the player to check.
        Returns:
        If the player has existing user data that can be loaded.
      • streamAll

        java.util.stream.Stream<GameProfile> streamAll()
        Gets a Stream that returns a GameProfile for each stored Users.

        This Stream may contain profiles that only hold a result for Identifiable.uniqueId(), that is, do not return a user's name. Such profiles should thus be treated as incomplete and are no more than an indicator that a User associated with the given UUID exists.

        Similarly, for GameProfiles that are filled and thus contain name data, the profile information is based on the latest information the server holds and no attempt is made to update this information.

        If you require up to date GameProfiles, use the appropriate methods on the GameProfileManager and/or its associated GameProfileManager.

        Use load(GameProfile) to load the User data associated with the associated GameProfile.

        Returns:
        A Stream of GameProfiles
      • streamOfMatches

        java.util.stream.Stream<GameProfile> streamOfMatches​(java.lang.String lastKnownName)
        Gets a Stream that returns a GameProfile for each stored User whose last known user names start with the given string (case-insensitive).

        It is important to note that the names this method uses to perform the matching is based on the latest information the server holds and no attempt is made to update this information.

        If you require up to date GameProfiles, use the appropriate methods on the GameProfileManager and/or its associated GameProfileManager.

        Use load(GameProfile) to load associated User data.

        Parameters:
        lastKnownName - The name to check for
        Returns:
        A Stream of GameProfiles