Add modifyUser and modifyGroup convenience API methods

This commit is contained in:
Luck committed 2020-05-10 12:40:20 +01:00
1 parent a19cb71394
commit bcfcb64931
4 files changed
+71 -1

No files matched your search

@@ -102,6 +102,27 @@ public interface GroupManager {
*/
@NonNull CompletableFuture<Void> deleteGroup(@NonNull Group group);
/**
* Loads (or creates) a group from the plugin's storage provider, applies the given
* {@code action}, then saves the group's data back to storage.
*
* <p>This method effectively calls {@link #createAndLoadGroup(String)}, followed by the
* {@code action}, then {@link #saveGroup(Group)}, and returns an encapsulation of the whole
* process as a {@link CompletableFuture}. </p>
*
* @param name the name of the group
* @param action the action to apply to the group
* @return a future to encapsulate the operation
* @since 5.1
*/
default @NonNull CompletableFuture<Void> modifyGroup(@NonNull String name, @NonNull Consumer<? super Group> action) {
/* This default method is overridden in the implementation, and is just here
to demonstrate what this method does in the API sources. */
return createAndLoadGroup(name)
.thenApplyAsync(group -> { action.accept(group); return group; })
.thenCompose(this::saveGroup);
}
/**
* Loads all groups into memory.
*
@@ -63,7 +63,7 @@ public interface UserManager {
/**
* Loads a user from the plugin's storage provider into memory.
*
* @param uniqueId the uuid of the user
* @param uniqueId the uuid of the user
* @param username the username, if known
* @return the resultant user
* @throws NullPointerException if the uuid is null
@@ -115,6 +115,27 @@ public interface UserManager {
*/
@NonNull CompletableFuture<Void> saveUser(@NonNull User user);
/**
* Loads a user from the plugin's storage provider, applies the given {@code action},
* then saves the user's data back to storage.
*
* <p>This method effectively calls {@link #loadUser(UUID)}, followed by the {@code action},
* then {@link #saveUser(User)}, and returns an encapsulation of the whole process as a
* {@link CompletableFuture}. </p>
*
* @param uniqueId the uuid of the user
* @param action the action to apply to the user
* @return a future to encapsulate the operation
* @since 5.1
*/
default @NonNull CompletableFuture<Void> modifyUser(@NonNull UUID uniqueId, @NonNull Consumer<? super User> action) {
/* This default method is overridden in the implementation, and is just here
to demonstrate what this method does in the API sources. */
return loadUser(uniqueId)
.thenApplyAsync(user -> { action.accept(user); return user; })
.thenCompose(this::saveUser);
}
/**
* Saves data about a player to the uuid caching system.
*