diff --git a/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java b/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java index bdf96231d..1599b9cb3 100644 --- a/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java +++ b/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java @@ -151,17 +151,6 @@ public interface LuckPermsApi { */ @NonNull LPConfiguration getConfiguration(); - /** - * Gets an object representing the plugins primary {@link Storage} backend. - * - *

The instance propagates calls to the internal DAO (Data Access Object), - * and applies any changes to the storage provider.

- * - * @return a storage instance - * @since 2.14 - */ - @NonNull Storage getStorage(); - /** * Gets the {@link MessagingService}, if present. * diff --git a/api/src/main/java/me/lucko/luckperms/api/Storage.java b/api/src/main/java/me/lucko/luckperms/api/Storage.java deleted file mode 100644 index 48281bfa6..000000000 --- a/api/src/main/java/me/lucko/luckperms/api/Storage.java +++ /dev/null @@ -1,332 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.lucko.luckperms.api; - -import me.lucko.luckperms.api.manager.GroupManager; -import me.lucko.luckperms.api.manager.TrackManager; -import me.lucko.luckperms.api.manager.UserManager; - -import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.checker.nullness.qual.Nullable; - -import java.util.List; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; - -/** - * A means of loading and saving permission data to/from the backend. - * - * @since 2.14 - */ -public interface Storage { - - /** - * Get the name of the storage implementation. - * - * @return the name of the implementation - */ - @NonNull String getName(); - - /** - * Gets whether the storage instance is allowing logins on the platform. - * - * @return true if logins are enabled - * @deprecated as this method always returns true. - */ - @Deprecated - boolean isAcceptingLogins(); - - /** - * Saves an action to storage - * - * @param entry the log entry to be saved - * @return true if the operation completed successfully. - * @throws NullPointerException if entry is null - * @deprecated in favour of {@link ActionLogger#submit(LogEntry)}. - */ - @Deprecated - @NonNull CompletableFuture logAction(@NonNull LogEntry entry); - - /** - * Loads and returns the entire log from storage - * - * @return a log instance, could be null if loading failed - * @deprecated in favour of {@link ActionLogger#getLog()} - */ - @Deprecated - @NonNull CompletableFuture getLog(); - - /** - * Loads a user's data from the main storage into the plugins local storage. - * - * @param uuid the uuid of the user to load - * @param username the users username, or null if it is not known. - * @return if the operation completed successfully - * @throws NullPointerException if uuid is null - * @deprecated in favour of {@link UserManager#loadUser(UUID, String)} - */ - @Deprecated - @NonNull CompletableFuture loadUser(@NonNull UUID uuid, @Nullable String username); - - /** - * Loads a user's data from the main storage into the plugins local storage. - * - * @param uuid the uuid of the user to load - * @return if the operation completed successfully - * @throws NullPointerException if uuid is null - * @deprecated in favour of {@link UserManager#loadUser(UUID)} - */ - @Deprecated - default @NonNull CompletableFuture loadUser(@NonNull UUID uuid) { - return loadUser(uuid, null); - } - - /** - * Saves a user object back to storage. - * - *

You should call this after you make any changes to a user.

- * - * @param user the user to save - * @return true if the operation completed successfully. - * @throws NullPointerException if user is null - * @throws IllegalStateException if the user instance was not obtained from LuckPerms. - * @deprecated in favour of {@link UserManager#saveUser(User)} - */ - @Deprecated - @NonNull CompletableFuture saveUser(@NonNull User user); - - /** - * Gets a set all "unique" user UUIDs. - * - *

"Unique" meaning the user isn't just a member of the "default" group.

- * - * @return a set of uuids, or null if the operation failed. - * @deprecated in favour of {@link UserManager#getUniqueUsers()} - */ - @Deprecated - @NonNull CompletableFuture> getUniqueUsers(); - - /** - * Searches for a list of users with a given permission. - * - * @param permission the permission to search for - * @return a list of held permissions, or null if the operation failed - * @throws NullPointerException if the permission is null - * @since 2.17 - * @deprecated in favour of {@link UserManager#getWithPermission(String)} - */ - @Deprecated - @NonNull CompletableFuture>> getUsersWithPermission(@NonNull String permission); - - /** - * Creates and loads a group into the plugins local storage - * - * @param name the name of the group - * @return true if the operation completed successfully - * @throws NullPointerException if name is null - * @throws IllegalArgumentException if the name is invalid - * @deprecated in favour of {@link GroupManager#createAndLoadGroup(String)} - */ - @Deprecated - @NonNull CompletableFuture createAndLoadGroup(@NonNull String name); - - /** - * Loads a group into the plugins local storage. - * - * @param name the name of the group - * @return true if the operation completed successfully - * @throws NullPointerException if name is null - * @throws IllegalArgumentException if the name is invalid - * @deprecated in favour of {@link GroupManager#loadGroup(String)} - */ - @Deprecated - @NonNull CompletableFuture loadGroup(@NonNull String name); - - /** - * Loads all groups from the storage into memory - * - * @return true if the operation completed successfully. - * @deprecated in favour of {@link GroupManager#loadAllGroups()} - */ - @Deprecated - @NonNull CompletableFuture loadAllGroups(); - - /** - * Saves a group back to storage. - * - *

You should call this after you make any changes to a group.

- * - * @param group the group to save - * @return true if the operation completed successfully. - * @throws NullPointerException if group is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. - * @deprecated in favour of {@link GroupManager#saveGroup(Group)} - */ - @Deprecated - @NonNull CompletableFuture saveGroup(@NonNull Group group); - - /** - * Permanently deletes a group from storage. - * - * @param group the group to delete - * @return true if the operation completed successfully. - * @throws NullPointerException if group is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. - * @deprecated in favour of {@link GroupManager#deleteGroup(Group)} - */ - @Deprecated - @NonNull CompletableFuture deleteGroup(@NonNull Group group); - - /** - * Searches for a list of groups with a given permission. - * - * @param permission the permission to search for - * @return a list of held permissions, or null if the operation failed - * @throws NullPointerException if the permission is null - * @since 2.17 - * @deprecated in favour of {@link GroupManager#getWithPermission(String)} - */ - @Deprecated - @NonNull CompletableFuture>> getGroupsWithPermission(@NonNull String permission); - - /** - * Creates and loads a track into the plugins local storage - * - * @param name the name of the track - * @return true if the operation completed successfully - * @throws NullPointerException if name is null - * @throws IllegalArgumentException if the name is invalid - * @deprecated in favour of {@link TrackManager#createAndLoadTrack(String)} - */ - @Deprecated - @NonNull CompletableFuture createAndLoadTrack(@NonNull String name); - - /** - * Loads a track into the plugins local storage. - * - * @param name the name of the track - * @return true if the operation completed successfully - * @throws NullPointerException if name is null - * @throws IllegalArgumentException if the name is invalid - * @deprecated in favour of {@link TrackManager#loadTrack(String)} - */ - @Deprecated - @NonNull CompletableFuture loadTrack(@NonNull String name); - - /** - * Loads all tracks from the storage into memory - * - * @return true if the operation completed successfully. - * @deprecated in favour of {@link TrackManager#loadAllTracks()} - */ - @Deprecated - @NonNull CompletableFuture loadAllTracks(); - - /** - * Saves a track back to storage. You should call this after you make any changes to a track. - * - * @param track the track to save - * @return true if the operation completed successfully. - * @throws NullPointerException if track is null - * @throws IllegalStateException if the track instance was not obtained from LuckPerms. - * @deprecated in favour of {@link TrackManager#saveTrack(Track)} - */ - @Deprecated - @NonNull CompletableFuture saveTrack(@NonNull Track track); - - /** - * Permanently deletes a track from storage - * - * @param track the track to delete - * @return true if the operation completed successfully. - * @throws NullPointerException if track is null - * @throws IllegalStateException if the track instance was not obtained from LuckPerms. - * @deprecated in favour of {@link TrackManager#deleteTrack(Track)} - */ - @Deprecated - @NonNull CompletableFuture deleteTrack(@NonNull Track track); - - /** - * Saves UUID caching data to the global cache - * - * @param username the users username - * @param uuid the users mojang unique id - * @return true if the operation completed successfully. - * @throws NullPointerException if either parameters are null - * @throws IllegalArgumentException if the username is invalid - * @deprecated in favour of {@link UserManager#savePlayerData(UUID, String)} - */ - @NonNull CompletableFuture saveUUIDData(@NonNull String username, @NonNull UUID uuid); - - /** - * Gets a UUID from a username - * - * @param username the corresponding username - * @return a uuid object, could be null - * @throws NullPointerException if either parameters are null - * @throws IllegalArgumentException if the username is invalid - * @deprecated in favour of {@link UserManager#lookupUuid(String)} - */ - @NonNull CompletableFuture getUUID(@NonNull String username); - - /** - * Gets a username from a UUID - * - * @param uuid the corresponding uuid - * @return a name string, could be null - * @throws NullPointerException if either parameters are null - * @since 2.17 - * @deprecated in favour of {@link UserManager#lookupUsername(UUID)} - */ - @NonNull @Deprecated CompletableFuture getName(@NonNull UUID uuid); - - /** - * Returns an executor which will run all passed runnables on the - * main server thread. - * - *

This method is deprecated as plugins should create and use their own - * executor instances.

- * - * @return an executor instance - * @deprecated as plugins should create their own executors - */ - @NonNull @Deprecated Executor getSyncExecutor(); - - /** - * Returns an executor which will run all passed runnables asynchronously - * using the platforms scheduler and thread pools. - * - *

This method is deprecated as plugins should create and use their own - * executor instances.

- * - * @return an executor instance - * @deprecated as plugins should create their own executors - */ - @NonNull @Deprecated Executor getAsyncExecutor(); - -} diff --git a/common/src/main/java/me/lucko/luckperms/common/api/LuckPermsApiProvider.java b/common/src/main/java/me/lucko/luckperms/common/api/LuckPermsApiProvider.java index 4df531ed4..794372715 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/LuckPermsApiProvider.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/LuckPermsApiProvider.java @@ -30,7 +30,6 @@ import me.lucko.luckperms.api.LPConfiguration; import me.lucko.luckperms.api.LuckPermsApi; import me.lucko.luckperms.api.MessagingService; import me.lucko.luckperms.api.NodeFactory; -import me.lucko.luckperms.api.Storage; import me.lucko.luckperms.api.context.ContextManager; import me.lucko.luckperms.api.event.EventBus; import me.lucko.luckperms.api.manager.CachedDataManager; @@ -129,11 +128,6 @@ public class LuckPermsApiProvider implements LuckPermsApi { return this.plugin.getConfiguration().getDelegate(); } - @Override - public @NonNull Storage getStorage() { - return this.plugin.getStorage().getApiDelegate(); - } - @Override public @NonNull Optional getMessagingService() { return this.plugin.getMessagingService().map(ApiMessagingService::new); diff --git a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiStorage.java b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiStorage.java deleted file mode 100644 index 73e77412c..000000000 --- a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiStorage.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.lucko.luckperms.common.api.implementation; - -import me.lucko.luckperms.api.Group; -import me.lucko.luckperms.api.HeldPermission; -import me.lucko.luckperms.api.Log; -import me.lucko.luckperms.api.LogEntry; -import me.lucko.luckperms.api.Track; -import me.lucko.luckperms.api.User; -import me.lucko.luckperms.common.plugin.LuckPermsPlugin; -import me.lucko.luckperms.common.storage.Storage; - -import org.checkerframework.checker.nullness.qual.NonNull; - -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; -import java.util.function.Function; - -public class ApiStorage implements me.lucko.luckperms.api.Storage { - private static final Function CONSUME_EXCEPTION = throwable -> { - throwable.printStackTrace(); - return false; - }; - - private static Function consumeExceptionToFalse() { - return CONSUME_EXCEPTION; - } - - private static Function consumeExceptionToNull() { - return throwable -> { - throwable.printStackTrace(); - return null; - }; - } - - private final LuckPermsPlugin plugin; - private final Storage handle; - - public ApiStorage(LuckPermsPlugin plugin, Storage handle) { - this.plugin = plugin; - this.handle = handle; - } - - @Override - public @NonNull String getName() { - return this.handle.getName(); - } - - @Override - public boolean isAcceptingLogins() { - return true; - } - - @Override - public @NonNull Executor getSyncExecutor() { - return this.plugin.getBootstrap().getScheduler().sync(); - } - - @Override - public @NonNull Executor getAsyncExecutor() { - return this.plugin.getBootstrap().getScheduler().async(); - } - - @Override - public @NonNull CompletableFuture logAction(@NonNull LogEntry entry) { - return this.plugin.getApiProvider().getActionLogger().submitToStorage(entry) - .thenApply(r -> true) - .exceptionally(consumeExceptionToFalse()); - } - - @Override - public @NonNull CompletableFuture getLog() { - return this.plugin.getApiProvider().getActionLogger().getLog().exceptionally(consumeExceptionToNull()); - } - - @Override - public @NonNull CompletableFuture loadUser(@NonNull UUID uuid, String username) { - return this.plugin.getApiProvider().getUserManager().loadUser(uuid, username) - .thenApply(r -> true) - .exceptionally(consumeExceptionToFalse()); - } - - @Override - public @NonNull CompletableFuture saveUser(@NonNull User user) { - return this.plugin.getApiProvider().getUserManager().saveUser(user) - .thenApply(r -> true) - .exceptionally(consumeExceptionToFalse()); - } - - @Override - public @NonNull CompletableFuture> getUniqueUsers() { - return this.plugin.getApiProvider().getUserManager().getUniqueUsers().exceptionally(consumeExceptionToNull()); - } - - @Override - public @NonNull CompletableFuture>> getUsersWithPermission(@NonNull String permission) { - return this.plugin.getApiProvider().getUserManager().getWithPermission(permission).exceptionally(consumeExceptionToNull()); - } - - @Override - public @NonNull CompletableFuture createAndLoadGroup(@NonNull String name) { - return this.plugin.getApiProvider().getGroupManager().createAndLoadGroup(name) - .thenApply(r -> true) - .exceptionally(consumeExceptionToFalse()); - } - - @Override - public @NonNull CompletableFuture loadGroup(@NonNull String name) { - return this.plugin.getApiProvider().getGroupManager().loadGroup(name) - .thenApply(Optional::isPresent) - .exceptionally(consumeExceptionToFalse()); - } - - @Override - public @NonNull CompletableFuture loadAllGroups() { - return this.plugin.getApiProvider().getGroupManager().loadAllGroups() - .thenApply(r -> true) - .exceptionally(consumeExceptionToFalse()); - } - - @Override - public @NonNull CompletableFuture saveGroup(@NonNull Group group) { - return this.plugin.getApiProvider().getGroupManager().saveGroup(group) - .thenApply(r -> true) - .exceptionally(consumeExceptionToFalse()); - } - - @Override - public @NonNull CompletableFuture deleteGroup(@NonNull Group group) { - return this.plugin.getApiProvider().getGroupManager().deleteGroup(group) - .thenApply(r -> true) - .exceptionally(consumeExceptionToFalse()); - } - - @Override - public @NonNull CompletableFuture>> getGroupsWithPermission(@NonNull String permission) { - return this.plugin.getApiProvider().getGroupManager().getWithPermission(permission) - .exceptionally(consumeExceptionToNull()); - } - - @Override - public @NonNull CompletableFuture createAndLoadTrack(@NonNull String name) { - return this.plugin.getApiProvider().getTrackManager().createAndLoadTrack(name) - .thenApply(r -> true) - .exceptionally(consumeExceptionToFalse()); - } - - @Override - public @NonNull CompletableFuture loadTrack(@NonNull String name) { - return this.plugin.getApiProvider().getTrackManager().loadTrack(name) - .thenApply(Optional::isPresent) - .exceptionally(consumeExceptionToFalse()); - } - - @Override - public @NonNull CompletableFuture loadAllTracks() { - return this.plugin.getApiProvider().getTrackManager().loadAllTracks() - .thenApply(r -> true) - .exceptionally(consumeExceptionToFalse()); - } - - @Override - public @NonNull CompletableFuture saveTrack(@NonNull Track track) { - return this.plugin.getApiProvider().getTrackManager().saveTrack(track) - .thenApply(r -> true) - .exceptionally(consumeExceptionToFalse()); - } - - @Override - public @NonNull CompletableFuture deleteTrack(@NonNull Track track) { - return this.plugin.getApiProvider().getTrackManager().deleteTrack(track) - .thenApply(r -> true) - .exceptionally(consumeExceptionToFalse()); - } - - @Override - public @NonNull CompletableFuture saveUUIDData(@NonNull String username, @NonNull UUID uuid) { - return this.plugin.getApiProvider().getUserManager().savePlayerData(uuid, username) - .thenApply(r -> true) - .exceptionally(consumeExceptionToFalse()); - } - - @Override - public @NonNull CompletableFuture getUUID(@NonNull String username) { - return this.plugin.getApiProvider().getUserManager().lookupUuid(username).exceptionally(consumeExceptionToNull()); - } - - @Override - public @NonNull CompletableFuture getName(@NonNull UUID uuid) { - return this.plugin.getApiProvider().getUserManager().lookupUsername(uuid).exceptionally(consumeExceptionToNull()); - } -} diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/Storage.java b/common/src/main/java/me/lucko/luckperms/common/storage/Storage.java index 8369e16bd..40d4a879b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/Storage.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/Storage.java @@ -33,7 +33,6 @@ import me.lucko.luckperms.api.PlayerSaveResult; import me.lucko.luckperms.api.event.cause.CreationCause; import me.lucko.luckperms.api.event.cause.DeletionCause; import me.lucko.luckperms.common.actionlog.Log; -import me.lucko.luckperms.common.api.implementation.ApiStorage; import me.lucko.luckperms.common.bulkupdate.BulkUpdate; import me.lucko.luckperms.common.bulkupdate.comparison.Constraint; import me.lucko.luckperms.common.model.Group; @@ -59,22 +58,15 @@ public class Storage { private final LuckPermsPlugin plugin; private final StorageImplementation implementation; - private final ApiStorage apiDelegate; - public Storage(LuckPermsPlugin plugin, StorageImplementation implementation) { this.plugin = plugin; this.implementation = implementation; - this.apiDelegate = new ApiStorage(plugin, this); } public StorageImplementation getImplementation() { return this.implementation; } - public ApiStorage getApiDelegate() { - return this.apiDelegate; - } - private CompletableFuture makeFuture(Callable supplier) { return CompletableFuture.supplyAsync(() -> { try {