1
0
mirror of https://github.com/lucko/LuckPerms.git synced 2025-08-29 09:09:51 +02:00

Add modifyTrack method to TrackManager (#3823)

This commit is contained in:
Emilia Kond
2024-01-23 19:44:20 +02:00
committed by GitHub
parent e6599a2662
commit 96008f6338
2 changed files with 35 additions and 0 deletions

View File

@@ -96,6 +96,27 @@ public interface TrackManager {
*/
@NonNull CompletableFuture<Void> deleteTrack(@NonNull Track track);
/**
* Loads (or creates) a track from the plugin's storage provider, applies the given {@code action},
* then saves the track's data back to storage.
*
* <p>This method effectively calls {@link #createAndLoadTrack(String)}, followed by the
* {@code action}, then {@link #saveTrack(Track)}, and returns an encapsulation of the whole
* process as a {@link CompletableFuture}. </p>
*
* @param name the name of the track
* @param action the action to apply to the track
* @return a future to encapsulate the operation
* @since 5.5
*/
default @NonNull CompletableFuture<Void> modifyTrack(@NonNull String name, @NonNull Consumer<? super Track> action) {
/* This default method is overridden in the implementation, and is just here
to demonstrate what this method does in the API sources. */
return createAndLoadTrack(name)
.thenApplyAsync(track -> { action.accept(track); return track; })
.thenCompose(this::saveTrack);
}
/**
* Loads all tracks into memory.
*