diff --git a/api/pom.xml b/api/pom.xml index fed2c6af..046db07b 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -5,7 +5,7 @@ luckperms me.lucko.luckperms - 2.13-SNAPSHOT + 2.14-SNAPSHOT 4.0.0 diff --git a/api/src/main/java/me/lucko/luckperms/api/Datastore.java b/api/src/main/java/me/lucko/luckperms/api/Datastore.java index 92ff2cff..bed07544 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Datastore.java +++ b/api/src/main/java/me/lucko/luckperms/api/Datastore.java @@ -29,226 +29,50 @@ import java.util.UUID; /** * Interface for the internal Datastore instance + * @deprecated as of version 2.14 in favour of {@link Storage}. */ -@SuppressWarnings("unused") +@Deprecated public interface Datastore { String getName(); boolean isAcceptingLogins(); - /** - * Gets the {@link Sync} interface. - * - * All operations through this interface are called immediately and in the same thread as they are called. - * Datastore operations are thread blocking, and Sync operations should not be called on the main server thread. - * @return the sync interface - */ + @Deprecated Sync sync(); - /** - * Gets the {@link Async} interface. - * - * All operations through this interface are called in a new, separate asynchronous thread. - * When the operation is complete, the provided callback method is called, in applicable, in the main server thread. - * @return the async interface - */ + @Deprecated Async async(); - /** - * Gets the {@link Future} interface. - * - * All operations through this interface are called in a new, separate asynchronous thread, similar to {@link Async}. - * The only difference is that instead of providing a callback, a {@link java.util.concurrent.Future} is returned. - * See the Oracle JavaDocs for usage of the Future class. - * @return the future interface - */ + @Deprecated Future future(); - /** - * All operations through this interface are called immediately and in the same thread as they are called. - * Datastore operations are thread blocking, and Sync operations should not be called on the main server thread. - */ + @Deprecated interface Sync { - - /** - * Saves an action to the datastore - * @param entry the log entry to be saved - * @return true if the operation completed successfully. - * @throws NullPointerException if entry is null - */ boolean logAction(LogEntry entry); - - /** - * Loads and returns the log from the datastore - * @return a log instance, could be null - */ Log getLog(); - - /** - * Either loads or creates a user object, and loads it into the plugins internal storage - * @param uuid the uuid of the user - * @param username the users username. (if you want to specify null here, just input "null" as a string.) - * @return true if the operation completed successfully. - * @throws NullPointerException if uuid or username is null - * @throws IllegalArgumentException if either of the parameters are invalid - * @deprecated functionality of this method is taken on by {@link #loadUser(UUID, String)} - */ @Deprecated boolean loadOrCreateUser(UUID uuid, String username); - - /** - * Loads a user from the datastore into the plugins internal storage. - * @param uuid the uuid of the user to load - * @return true if the user exists, and was loaded correctly. - * @throws NullPointerException if uuid is null - * @deprecated replaced by {@link #loadUser(UUID, String)} - */ @Deprecated boolean loadUser(UUID uuid); - - /** - * Loads a user's data into the plugins internal storage. - * @param uuid the uuid of the user to load - * @param username the users username. (if you want to specify null here, just input "null" as a string.) - * @return if the operation was performed successfully - * @throws NullPointerException if uuid or username is null - * @since 2.6 - */ boolean loadUser(UUID uuid, String username); - - /** - * Saves a user object into the datastore. 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. - */ boolean saveUser(User user); - - /** - * Removes users from the datastore who are "default". This is called every time the plugin loads. - * @return true if the operation completed successfully - * @since 2.6 - */ boolean cleanupUsers(); - - /** - * Gets a set all user's UUIDs who are "unique", and aren't just a member of the "default" group. - * @return a set of uuids, or null if the operation failed. - * @since 2.6 - */ Set getUniqueUsers(); - - /** - * Creates and loads a group into the plugins internal 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 - */ boolean createAndLoadGroup(String name); - - /** - * Loads a group into the plugins internal 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 - */ boolean loadGroup(String name); - - /** - * Loads all groups from the datastore into the plugins internal storage - * @return true if the operation completed successfully. - */ boolean loadAllGroups(); - - /** - * Saves a group back to the datastore. 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. - */ boolean saveGroup(Group group); - - /** - * Permanently deletes a group from the datastore - * @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. - */ boolean deleteGroup(Group group); - - /** - * Creates and loads a track into the plugins internal 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 - */ boolean createAndLoadTrack(String name); - - /** - * Loads a track into the plugins internal 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 - */ boolean loadTrack(String name); - - /** - * Loads all tracks from the datastore into the plugins internal storage - * @return true if the operation completed successfully. - */ boolean loadAllTracks(); - - /** - * Saves a track back to the datastore. 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. - */ boolean saveTrack(Track track); - - /** - * Permanently deletes a track from the datastore - * @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. - */ boolean deleteTrack(Track track); - - /** - * Saves UUID caching data to the datastore - * @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 - */ boolean saveUUIDData(String username, 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 - */ UUID getUUID(String username); } - /** - * All operations through this interface are called in a new, separate asynchronous thread. - * When the operation is complete, the provided callback method is called, in applicable, in the main server thread. - * - * See {@link Sync} for method documentation. - */ + @Deprecated interface Async { void logAction(LogEntry entry, Callback callback); void getLog(Callback callback); @@ -274,13 +98,7 @@ public interface Datastore { void getUUID(String username, Callback callback); } - /** - * All operations through this interface are called in a new, separate asynchronous thread, similar to {@link Async}. - * The only difference is that instead of providing a callback, a {@link java.util.concurrent.Future} is returned. - * See the Oracle JavaDocs for usage of the Future class. - * - * See {@link Sync} for method documentation. - */ + @Deprecated interface Future { java.util.concurrent.Future logAction(LogEntry entry); java.util.concurrent.Future getLog(); diff --git a/api/src/main/java/me/lucko/luckperms/api/LPConfiguration.java b/api/src/main/java/me/lucko/luckperms/api/LPConfiguration.java index f73b584f..74737019 100644 --- a/api/src/main/java/me/lucko/luckperms/api/LPConfiguration.java +++ b/api/src/main/java/me/lucko/luckperms/api/LPConfiguration.java @@ -109,7 +109,9 @@ public interface LPConfiguration { /** * @return true if permission checks are being recorded / debugged * @since 2.9 + * @deprecated as this value is now always false. Functionality was replaced by the verbose command. */ + @Deprecated boolean getDebugPermissionChecks(); /** 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 10692175..521dc12a 100644 --- a/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java +++ b/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java @@ -79,11 +79,27 @@ public interface LuckPermsApi { LPConfiguration getConfiguration(); /** - * Gets a wrapped {@link Datastore} instance, with somewhat limited access - * @return a datastore instance + * Gets a wrapped {@link Storage} instance. + * @return a storage instance + * @since 2.14 */ + Storage getStorage(); + + /** + * Gets a wrapped Datastore instance. + * @return a datastore instance + * @deprecated in favour of {@link #getStorage()} + */ + @SuppressWarnings("deprecation") + @Deprecated Datastore getDatastore(); + /** + * Gets the messaging service in use on the platform, if present. + * @return an optional that may contain a messaging service instance. + */ + Optional getMessagingService(); + /** * Gets the {@link Logger} wrapping used by the platform * @return the logger instance @@ -92,7 +108,7 @@ public interface LuckPermsApi { /** * Gets a wrapped {@link UuidCache} instance, providing read access to the LuckPerms internal uuid caching system - * @return a uuidcache instance + * @return a uuid cache instance */ UuidCache getUuidCache(); diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/LPFuture.java b/api/src/main/java/me/lucko/luckperms/api/MessagingService.java similarity index 75% rename from common/src/main/java/me/lucko/luckperms/common/utils/LPFuture.java rename to api/src/main/java/me/lucko/luckperms/api/MessagingService.java index d658486c..7ab870ab 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/LPFuture.java +++ b/api/src/main/java/me/lucko/luckperms/api/MessagingService.java @@ -20,16 +20,18 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.utils; +package me.lucko.luckperms.api; -import com.google.common.util.concurrent.Futures; +/** + * Exposes any networking provider being used on the platform. e.g. Redis + * @since 2.14 + */ +public interface MessagingService { -import java.util.concurrent.Future; - -public interface LPFuture extends Future { - - default T getUnchecked() { - return Futures.getUnchecked(this); - } + /** + * Uses the messaging service to inform other servers about changes. + * This will push the update asynchronously, and this method will return almost immediately. + */ + void pushUpdate(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/Storage.java b/api/src/main/java/me/lucko/luckperms/api/Storage.java new file mode 100644 index 00000000..d9b0978c --- /dev/null +++ b/api/src/main/java/me/lucko/luckperms/api/Storage.java @@ -0,0 +1,217 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * 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 java.util.Set; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executor; +import java.util.function.Consumer; + +/** + * Interface for the internal Storage instance + * + * All methods return {@link CompletableFuture}s, which will be populated with the result once the data has been loaded + * asynchronously. Care should be taken when using the methods to ensure that the main server thread is not blocked. + * + * Methods such as {@link CompletableFuture#get()} and equivalent should not be called on the main server thread. + * If you need to use the result of these operations on the main server thread, please register a callback using + * {@link CompletableFuture#thenAcceptAsync(Consumer, Executor)} and {@link #getSyncExecutor()}. + * + * @since 2.14 + */ +public interface Storage { + + /** + * Get the name of the storage implementation. + * @return the name of the implementation + */ + String getName(); + + /** + * Return whether the storage instance is allowing logins on the platform. + * @return true if logins are enabled + */ + boolean isAcceptingLogins(); + + /** + * Returns an executor which will run all passed runnables on the main server thread. + * @return an executor instance + */ + Executor getSyncExecutor(); + + /** + * Returns an executor which will run all passed runnables asynchronously using the platforms scheduler & thread pools. + * @return an executor instance + */ + Executor getAsyncExecutor(); + + /** + * 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 + */ + CompletableFuture logAction(LogEntry entry); + + /** + * Loads and returns the entire log from storage + * @return a log instance, could be null if loading failed + */ + 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. (if you want to specify null here, just input "null" as a string.) + * @return if the operation completed successfully + * @throws NullPointerException if uuid or username is null + */ + CompletableFuture loadUser(UUID uuid, String username); + + /** + * 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. + */ + CompletableFuture saveUser(User user); + + /** + * Removes users from the main storage who are "default". This is called every time the plugin loads. + * @return true if the operation completed successfully + */ + CompletableFuture cleanupUsers(); + + /** + * 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. + */ + CompletableFuture> getUniqueUsers(); + + /** + * 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 + */ + CompletableFuture createAndLoadGroup(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 + */ + CompletableFuture loadGroup(String name); + + /** + * Loads all groups from the storage into memory + * @return true if the operation completed successfully. + */ + 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. + */ + CompletableFuture saveGroup(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. + */ + CompletableFuture deleteGroup(Group group); + + /** + * 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 + */ + CompletableFuture createAndLoadTrack(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 + */ + CompletableFuture loadTrack(String name); + + /** + * Loads all tracks from the storage into memory + * @return true if the operation completed successfully. + */ + 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. + */ + CompletableFuture saveTrack(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. + */ + CompletableFuture deleteTrack(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 + */ + CompletableFuture saveUUIDData(String username, 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 + */ + CompletableFuture getUUID(String username); + +} diff --git a/api/src/main/java/me/lucko/luckperms/api/UuidCache.java b/api/src/main/java/me/lucko/luckperms/api/UuidCache.java index 9b6756cf..e093837e 100644 --- a/api/src/main/java/me/lucko/luckperms/api/UuidCache.java +++ b/api/src/main/java/me/lucko/luckperms/api/UuidCache.java @@ -32,8 +32,8 @@ import java.util.UUID; * they first join the server, but this UUID will then not be consistent across the network. LuckPerms will instead check * the datastore cache, to get a UUID for a user that is consistent across an entire network. * - *

If you want to get a user object from the datastore using the api on a server in offline mode, you will need to use this cache, - * OR use Datastore#getUUID, for users that are not online. + *

If you want to get a user object from the Storage using the api on a server in offline mode, you will need to use this cache, + * OR use Storage#getUUID, for users that are not online. * *

WARNING: THIS IS ONLY EFFECTIVE FOR ONLINE PLAYERS. USE THE DATASTORE METHODS FOR OFFLINE PLAYERS. */ diff --git a/api/src/main/java/me/lucko/luckperms/api/data/Callback.java b/api/src/main/java/me/lucko/luckperms/api/data/Callback.java index 5a4f5dcd..6e0dac63 100644 --- a/api/src/main/java/me/lucko/luckperms/api/data/Callback.java +++ b/api/src/main/java/me/lucko/luckperms/api/data/Callback.java @@ -28,7 +28,9 @@ import java.util.function.Consumer; * A callback used to wait for the completion of asynchronous operations. * All callbacks are ran on the main server thread. * @param the return type + * @deprecated in favour of {@link Consumer} */ +@Deprecated public interface Callback { /** @@ -55,4 +57,17 @@ public interface Callback { return consumer::accept; } + /** + * Helper method for converting old {@link Callback}s to use the new {@link me.lucko.luckperms.api.Storage} interface. + * @param callback the callback to convert + * @param the return type + * @return a consumer instance + * @since 2.14 + * @deprecated in favour of just using {@link Consumer}s. + */ + @Deprecated + static Consumer convertToConsumer(Callback callback) { + return callback::onComplete; + } + } diff --git a/bukkit-legacy/pom.xml b/bukkit-legacy/pom.xml index 6bc6e8c9..a34b02d2 100644 --- a/bukkit-legacy/pom.xml +++ b/bukkit-legacy/pom.xml @@ -5,7 +5,7 @@ luckperms me.lucko.luckperms - 2.13-SNAPSHOT + 2.14-SNAPSHOT 4.0.0 diff --git a/bukkit-placeholders/pom.xml b/bukkit-placeholders/pom.xml index 722a1a66..27a0133e 100644 --- a/bukkit-placeholders/pom.xml +++ b/bukkit-placeholders/pom.xml @@ -5,7 +5,7 @@ luckperms me.lucko.luckperms - 2.13-SNAPSHOT + 2.14-SNAPSHOT 4.0.0 diff --git a/bukkit/pom.xml b/bukkit/pom.xml index 14a8cbc4..e18b8ace 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -5,7 +5,7 @@ luckperms me.lucko.luckperms - 2.13-SNAPSHOT + 2.14-SNAPSHOT 4.0.0 diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java index c6879548..bf5f1b72 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java @@ -48,7 +48,7 @@ class BukkitListener extends AbstractListener implements Listener { @EventHandler(priority = EventPriority.LOWEST) public void onPlayerPreLogin(AsyncPlayerPreLoginEvent e) { - if (!plugin.isStarted() || !plugin.getDatastore().isAcceptingLogins()) { + if (!plugin.isStarted() || !plugin.getStorage().isAcceptingLogins()) { // The datastore is disabled, prevent players from joining the server e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, Message.LOADING_ERROR.toString()); @@ -61,7 +61,7 @@ class BukkitListener extends AbstractListener implements Listener { @EventHandler(priority = EventPriority.MONITOR) public void onPlayerPreLoginMonitor(AsyncPlayerPreLoginEvent e) { - if (plugin.isStarted() && plugin.getDatastore().isAcceptingLogins() && e.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) { + if (plugin.isStarted() && plugin.getStorage().isAcceptingLogins() && e.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) { // Login event was cancelled by another plugin onLeave(e.getUniqueId()); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java index e6419b08..3ec569c1 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java @@ -49,7 +49,7 @@ import me.lucko.luckperms.common.groups.GroupManager; import me.lucko.luckperms.common.messaging.RedisMessaging; import me.lucko.luckperms.common.runnables.ExpireTemporaryTask; import me.lucko.luckperms.common.runnables.UpdateTask; -import me.lucko.luckperms.common.storage.Datastore; +import me.lucko.luckperms.common.storage.Storage; import me.lucko.luckperms.common.storage.StorageFactory; import me.lucko.luckperms.common.tracks.TrackManager; import me.lucko.luckperms.common.users.UserManager; @@ -68,12 +68,16 @@ import org.bukkit.plugin.java.JavaPlugin; import java.io.File; import java.util.*; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.stream.Collectors; @Getter public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { + private ExecutorService executorService; + private Executor syncExecutor; + private Executor asyncExecutor; private VaultHook vaultHook = null; private final Set ignoringLogs = ConcurrentHashMap.newKeySet(); @@ -81,7 +85,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { private UserManager userManager; private GroupManager groupManager; private TrackManager trackManager; - private Datastore datastore; + private Storage storage; private RedisMessaging redisMessaging = null; private UuidCache uuidCache; private ApiProvider apiProvider; @@ -99,13 +103,12 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { private DebugHandler debugHandler; private BukkitSenderFactory senderFactory; - private ExecutorService executorService; - private boolean schedulerAvailable = false; - @Override public void onEnable() { // Used whilst the server is still starting executorService = Executors.newCachedThreadPool(); + asyncExecutor = executorService; + syncExecutor = r -> getServer().getScheduler().runTask(this, r); log = LogFactory.wrap(getLogger()); debugHandler = new DebugHandler(); @@ -129,7 +132,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { pm.registerEvents(new BukkitListener(this), this); // initialise datastore - datastore = StorageFactory.getDatastore(this, "h2"); + storage = StorageFactory.getInstance(this, "h2"); // initialise redis if (getConfiguration().isRedisEnabled()) { @@ -236,10 +239,9 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { getServer().getOperators().forEach(o -> o.setOp(false)); } - // shutdown the temporary executor when the Bukkit one starts + // replace the temporary executor when the Bukkit one starts getServer().getScheduler().runTaskAsynchronously(this, () -> { - schedulerAvailable = true; - executorService.shutdown(); + asyncExecutor = r -> getServer().getScheduler().runTaskAsynchronously(this, r); }); started = true; @@ -250,7 +252,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { public void onDisable() { started = false; getLog().info("Closing datastore..."); - datastore.shutdown(); + storage.shutdown(); if (redisMessaging != null) { getLog().info("Closing redis..."); @@ -268,16 +270,12 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { @Override public void doAsync(Runnable r) { - if (!schedulerAvailable) { - executorService.submit(r); - } else { - getServer().getScheduler().runTaskAsynchronously(this, r); - } + asyncExecutor.execute(r); } @Override public void doSync(Runnable r) { - getServer().getScheduler().runTask(this, r); + syncExecutor.execute(r); } @Override diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java index c0ac3bcc..47aeb360 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java @@ -122,7 +122,7 @@ public class MigrationBPermissions extends SubCommand { } // Make a LuckPerms group for the one being migrated. - plugin.getDatastore().createAndLoadGroup(groupName).getUnchecked(); + plugin.getStorage().createAndLoadGroup(groupName).join(); me.lucko.luckperms.common.groups.Group lpGroup = plugin.getGroupManager().get(groupName); try { LogEntry.build() @@ -134,7 +134,7 @@ public class MigrationBPermissions extends SubCommand { } migrateHolder(plugin, world, group, lpGroup); - plugin.getDatastore().saveGroup(lpGroup); + plugin.getStorage().saveGroup(lpGroup); } log.info("bPermissions Migration: Migrated " + groupCount + " groups in world " + world.getName() + "."); @@ -158,12 +158,12 @@ public class MigrationBPermissions extends SubCommand { } // Make a LuckPerms user for the one being migrated. - plugin.getDatastore().loadUser(uuid, "null").getUnchecked(); + plugin.getStorage().loadUser(uuid, "null").join(); me.lucko.luckperms.common.users.User lpUser = plugin.getUserManager().get(uuid); migrateHolder(plugin, world, user, lpUser); - plugin.getDatastore().saveUser(lpUser); + plugin.getStorage().saveUser(lpUser); plugin.getUserManager().cleanup(lpUser); } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java index 76d48345..deabc1ff 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java @@ -72,7 +72,7 @@ public class MigrationGroupManager extends SubCommand { GlobalGroups gg = GroupManager.getGlobalGroups(); for (Group g : gg.getGroupList()) { - plugin.getDatastore().createAndLoadGroup(g.getName().toLowerCase()).getUnchecked(); + plugin.getStorage().createAndLoadGroup(g.getName().toLowerCase()).join(); me.lucko.luckperms.common.groups.Group group = plugin.getGroupManager().get(g.getName().toLowerCase()); try { LogEntry.build() @@ -120,7 +120,7 @@ public class MigrationGroupManager extends SubCommand { } } - plugin.getDatastore().saveGroup(group); + plugin.getStorage().saveGroup(group); } Map, Boolean>> users = new HashMap<>(); @@ -195,7 +195,7 @@ public class MigrationGroupManager extends SubCommand { log.info("GroupManager Migration: Found a total of " + users.size() + " users and " + groups.size() + " groups."); for (Map.Entry, Boolean>> e : groups.entrySet()) { - plugin.getDatastore().createAndLoadGroup(e.getKey()).getUnchecked(); + plugin.getStorage().createAndLoadGroup(e.getKey()).join(); me.lucko.luckperms.common.groups.Group group = plugin.getGroupManager().get(e.getKey()); try { LogEntry.build() @@ -234,11 +234,11 @@ public class MigrationGroupManager extends SubCommand { } } - plugin.getDatastore().saveGroup(group); + plugin.getStorage().saveGroup(group); } for (Map.Entry, Boolean>> e : users.entrySet()) { - plugin.getDatastore().loadUser(e.getKey(), "null").getUnchecked(); + plugin.getStorage().loadUser(e.getKey(), "null").join(); me.lucko.luckperms.common.users.User user = plugin.getUserManager().get(e.getKey()); for (Map.Entry, Boolean> n : e.getValue().entrySet()) { @@ -279,7 +279,7 @@ public class MigrationGroupManager extends SubCommand { } catch (ObjectLacksException ignored) {} } - plugin.getDatastore().saveUser(user); + plugin.getStorage().saveUser(user); plugin.getUserManager().cleanup(user); } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java index 6c416a78..bdbdb0d0 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java @@ -100,7 +100,7 @@ public class MigrationPermissionsEx extends SubCommand { maxGroupWeight = Math.max(maxGroupWeight, groupWeight); final String name = group.getName().toLowerCase(); - plugin.getDatastore().createAndLoadGroup(name).getUnchecked(); + plugin.getStorage().createAndLoadGroup(name).join(); Group lpGroup = plugin.getGroupManager().get(name); try { LogEntry.build() @@ -224,7 +224,7 @@ public class MigrationPermissionsEx extends SubCommand { } } - plugin.getDatastore().saveGroup(lpGroup); + plugin.getStorage().saveGroup(lpGroup); } @@ -252,7 +252,7 @@ public class MigrationPermissionsEx extends SubCommand { } userCount++; - plugin.getDatastore().loadUser(u, "null").getUnchecked(); + plugin.getStorage().loadUser(u, "null").join(); User lpUser = plugin.getUserManager().get(u); try { @@ -385,7 +385,7 @@ public class MigrationPermissionsEx extends SubCommand { } plugin.getUserManager().cleanup(lpUser); - plugin.getDatastore().saveUser(lpUser); + plugin.getStorage().saveUser(lpUser); } log.info("PermissionsEx Migration: Migrated " + userCount + " users."); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java index af9bd9f9..29823070 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java @@ -251,7 +251,7 @@ public class MigrationPowerfulPerms extends SubCommand { log.info("PowerfulPerms Migration: Starting group migration."); Map groups = pm.getGroups(); // All versions for (Group g : groups.values()) { - plugin.getDatastore().createAndLoadGroup(g.getName().toLowerCase()).getUnchecked(); + plugin.getStorage().createAndLoadGroup(g.getName().toLowerCase()).join(); final me.lucko.luckperms.common.groups.Group group = plugin.getGroupManager().get(g.getName().toLowerCase()); try { LogEntry.build() @@ -280,7 +280,7 @@ public class MigrationPowerfulPerms extends SubCommand { } } - plugin.getDatastore().saveGroup(group); + plugin.getStorage().saveGroup(group); } log.info("PowerfulPerms Migration: Group migration complete."); @@ -293,7 +293,7 @@ public class MigrationPowerfulPerms extends SubCommand { progress.put(uuid, new CountDownLatch(2)); // Create a LuckPerms user for the UUID - plugin.getDatastore().loadUser(uuid, "null").getUnchecked(); + plugin.getStorage().loadUser(uuid, "null").join(); User user = plugin.getUserManager().get(uuid); // Get a list of Permissions held by the user from the PP API. @@ -304,7 +304,7 @@ public class MigrationPowerfulPerms extends SubCommand { synchronized (progress) { progress.get(uuid).countDown(); if (progress.get(uuid).getCount() == 0) { - plugin.getDatastore().saveUser(user); + plugin.getStorage().saveUser(user); plugin.getUserManager().cleanup(user); } } @@ -427,7 +427,7 @@ public class MigrationPowerfulPerms extends SubCommand { synchronized (progress) { progress.get(uuid).countDown(); if (progress.get(uuid).getCount() == 0) { - plugin.getDatastore().saveUser(user); + plugin.getStorage().saveUser(user); plugin.getUserManager().cleanup(user); } } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java index 58e111b9..4d01b1fa 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java @@ -73,7 +73,7 @@ public class MigrationZPermissions extends SubCommand { // Migrate all groups log.info("zPermissions Migration: Starting group migration."); for (String g : service.getAllGroups()) { - plugin.getDatastore().createAndLoadGroup(g.toLowerCase()).getUnchecked(); + plugin.getStorage().createAndLoadGroup(g.toLowerCase()).join(); Group group = plugin.getGroupManager().get(g.toLowerCase()); try { LogEntry.build() @@ -116,13 +116,13 @@ public class MigrationZPermissions extends SubCommand { } } - plugin.getDatastore().saveGroup(group); + plugin.getStorage().saveGroup(group); } // Migrate all tracks log.info("zPermissions Migration: Starting track migration."); for (String t : service.getAllTracks()) { - plugin.getDatastore().createAndLoadTrack(t.toLowerCase()).getUnchecked(); + plugin.getStorage().createAndLoadTrack(t.toLowerCase()).join(); Track track = plugin.getTrackManager().get(t.toLowerCase()); try { LogEntry.build() @@ -145,13 +145,13 @@ public class MigrationZPermissions extends SubCommand { } } - plugin.getDatastore().saveTrack(track); + plugin.getStorage().saveTrack(track); } // Migrate all users. log.info("zPermissions Migration: Starting user migration."); for (UUID u : service.getAllPlayersUUID()) { - plugin.getDatastore().loadUser(u, "null").getUnchecked(); + plugin.getStorage().loadUser(u, "null").join(); User user = plugin.getUserManager().get(u); for (Map.Entry e : service.getPlayerPermissions(null, null, u).entrySet()) { @@ -244,7 +244,7 @@ public class MigrationZPermissions extends SubCommand { } plugin.getUserManager().cleanup(user); - plugin.getDatastore().saveUser(user); + plugin.getStorage().saveUser(user); } log.info("zPermissions Migration: Success! Completed without any errors."); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java index 5b68c722..5ea2a0c7 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java @@ -82,7 +82,7 @@ public class VaultPermissionHook extends Permission { @Override public boolean isEnabled() { - return plugin.getDatastore().isAcceptingLogins(); + return plugin.getStorage().isAcceptingLogins(); } @Override @@ -132,13 +132,12 @@ public class VaultPermissionHook extends Permission { */ void save(PermissionHolder holder) { if (holder instanceof User) { - - plugin.getDatastore().saveUser(((User) holder), b -> { - ((User) holder).getRefreshBuffer().request(); - }); + plugin.getStorage().saveUser(((User) holder)) + .thenRunAsync(() -> ((User) holder).getRefreshBuffer().request(), plugin.getAsyncExecutor()); } if (holder instanceof Group) { - plugin.getDatastore().saveGroup(((Group) holder), b -> plugin.getUpdateTaskBuffer().request()); + plugin.getStorage().saveGroup(((Group) holder)) + .thenRunAsync(() -> plugin.getUpdateTaskBuffer().request(), plugin.getAsyncExecutor()); } } diff --git a/bungee/pom.xml b/bungee/pom.xml index 1ab60cfc..e042f5c7 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -5,7 +5,7 @@ luckperms me.lucko.luckperms - 2.13-SNAPSHOT + 2.14-SNAPSHOT 4.0.0 diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java index b676d964..df7aef6c 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java @@ -96,28 +96,28 @@ public class BungeeListener extends AbstractListener implements Listener { final PendingConnection c = e.getConnection(); if (!cache.isOnlineMode()) { - UUID uuid = plugin.getDatastore().getUUID(c.getName()).getUnchecked(); + UUID uuid = plugin.getStorage().getUUID(c.getName()).join(); if (uuid != null) { cache.addToCache(c.getUniqueId(), uuid); } else { // No previous data for this player plugin.getApiProvider().fireEventAsync(new UserFirstLoginEvent(c.getUniqueId(), c.getName())); cache.addToCache(c.getUniqueId(), c.getUniqueId()); - plugin.getDatastore().force().saveUUIDData(c.getName(), c.getUniqueId()).getUnchecked(); + plugin.getStorage().force().saveUUIDData(c.getName(), c.getUniqueId()).join(); } } else { - UUID uuid = plugin.getDatastore().getUUID(c.getName()).getUnchecked(); + UUID uuid = plugin.getStorage().getUUID(c.getName()).join(); if (uuid == null) { plugin.getApiProvider().fireEventAsync(new UserFirstLoginEvent(c.getUniqueId(), c.getName())); } // Online mode, no cache needed. This is just for name -> uuid lookup. - plugin.getDatastore().force().saveUUIDData(c.getName(), c.getUniqueId()).getUnchecked(); + plugin.getStorage().force().saveUUIDData(c.getName(), c.getUniqueId()).join(); } // We have to make a new user on this thread whilst the connection is being held, or we get concurrency issues as the Bukkit server // and the BungeeCord server try to make a new user at the same time. - plugin.getDatastore().force().loadUser(cache.getUUID(c.getUniqueId()), c.getName()).getUnchecked(); + plugin.getStorage().force().loadUser(cache.getUUID(c.getUniqueId()), c.getName()).join(); User user = plugin.getUserManager().get(cache.getUUID(c.getUniqueId())); if (user == null) { plugin.getLog().warn("Failed to load user: " + c.getName()); diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java index 90d7c779..58beb55c 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java @@ -44,7 +44,7 @@ import me.lucko.luckperms.common.groups.GroupManager; import me.lucko.luckperms.common.messaging.RedisMessaging; import me.lucko.luckperms.common.runnables.ExpireTemporaryTask; import me.lucko.luckperms.common.runnables.UpdateTask; -import me.lucko.luckperms.common.storage.Datastore; +import me.lucko.luckperms.common.storage.Storage; import me.lucko.luckperms.common.storage.StorageFactory; import me.lucko.luckperms.common.tracks.TrackManager; import me.lucko.luckperms.common.users.UserManager; @@ -62,17 +62,20 @@ import java.util.List; import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @Getter public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { + private Executor executor; + private final Set ignoringLogs = ConcurrentHashMap.newKeySet(); private LPConfiguration configuration; private UserManager userManager; private GroupManager groupManager; private TrackManager trackManager; - private Datastore datastore; + private Storage storage; private RedisMessaging redisMessaging = null; private UuidCache uuidCache; private ApiProvider apiProvider; @@ -88,6 +91,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { @Override public void onEnable() { + executor = r -> getProxy().getScheduler().runAsync(this, r); log = LogFactory.wrap(getLogger()); debugHandler = new DebugHandler(); senderFactory = new BungeeSenderFactory(this); @@ -99,7 +103,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { getProxy().getPluginManager().registerListener(this, new BungeeListener(this)); // initialise datastore - datastore = StorageFactory.getDatastore(this, "h2"); + storage = StorageFactory.getInstance(this, "h2"); // initialise redis if (getConfiguration().isRedisEnabled()) { @@ -183,7 +187,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { @Override public void onDisable() { getLog().info("Closing datastore..."); - datastore.shutdown(); + storage.shutdown(); if (redisMessaging != null) { getLog().info("Closing redis..."); @@ -300,7 +304,17 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { @Override public void doSync(Runnable r) { - r.run(); + doAsync(r); + } + + @Override + public Executor getSyncExecutor() { + return executor; + } + + @Override + public Executor getAsyncExecutor() { + return executor; } @Override diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java b/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java index e1d356cd..25620861 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java @@ -64,7 +64,7 @@ public class MigrationBungeePerms extends SubCommand { groupCount++; // Make a LuckPerms group for the one being migrated - plugin.getDatastore().createAndLoadGroup(g.getName().toLowerCase()).getUnchecked(); + plugin.getStorage().createAndLoadGroup(g.getName().toLowerCase()).join(); me.lucko.luckperms.common.groups.Group group = plugin.getGroupManager().get(g.getName().toLowerCase()); try { LogEntry.build() @@ -174,7 +174,7 @@ public class MigrationBungeePerms extends SubCommand { } } - plugin.getDatastore().saveGroup(group); + plugin.getStorage().saveGroup(group); } log.info("BungeePerms Migration: Migrated " + groupCount + " groups"); @@ -188,7 +188,7 @@ public class MigrationBungeePerms extends SubCommand { userCount++; // Make a LuckPerms user for the one being migrated. - plugin.getDatastore().loadUser(u.getUUID(), "null").getUnchecked(); + plugin.getStorage().loadUser(u.getUUID(), "null").join(); me.lucko.luckperms.common.users.User user = plugin.getUserManager().get(u.getUUID()); // Migrate global perms @@ -289,7 +289,7 @@ public class MigrationBungeePerms extends SubCommand { } } - plugin.getDatastore().saveUser(user); + plugin.getStorage().saveUser(user); plugin.getUserManager().cleanup(user); } diff --git a/common/pom.xml b/common/pom.xml index 4a7b41ba..e3cfdcd5 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -5,7 +5,7 @@ luckperms me.lucko.luckperms - 2.13-SNAPSHOT + 2.14-SNAPSHOT 4.0.0 diff --git a/common/src/main/java/me/lucko/luckperms/common/LuckPermsPlugin.java b/common/src/main/java/me/lucko/luckperms/common/LuckPermsPlugin.java index 65cbef01..426454d6 100644 --- a/common/src/main/java/me/lucko/luckperms/common/LuckPermsPlugin.java +++ b/common/src/main/java/me/lucko/luckperms/common/LuckPermsPlugin.java @@ -36,7 +36,7 @@ import me.lucko.luckperms.common.core.UuidCache; import me.lucko.luckperms.common.data.Importer; import me.lucko.luckperms.common.groups.GroupManager; import me.lucko.luckperms.common.messaging.RedisMessaging; -import me.lucko.luckperms.common.storage.Datastore; +import me.lucko.luckperms.common.storage.Storage; import me.lucko.luckperms.common.tracks.TrackManager; import me.lucko.luckperms.common.users.UserManager; import me.lucko.luckperms.common.utils.BufferedRequest; @@ -47,6 +47,7 @@ import java.io.File; import java.util.List; import java.util.Set; import java.util.UUID; +import java.util.concurrent.Executor; /** * Main internal interface for LuckPerms plugins, providing the base for abstraction throughout the project. @@ -80,10 +81,10 @@ public interface LuckPermsPlugin { LPConfiguration getConfiguration(); /** - * Gets the primary datastore instance. This is likely to be wrapped with extra layers for caching, etc. - * @return the datastore + * Gets the primary data storage instance. This is likely to be wrapped with extra layers for caching, etc. + * @return the storage handler instance */ - Datastore getDatastore(); + Storage getStorage(); /** * Gets the redis messaging instance if present. Could return null if redis is not enabled. @@ -158,6 +159,9 @@ public interface LuckPermsPlugin { */ void doSync(Runnable r); + Executor getSyncExecutor(); + Executor getAsyncExecutor(); + /** * Execute a runnable asynchronously on a loop * @param r the task to run diff --git a/common/src/main/java/me/lucko/luckperms/common/api/ApiProvider.java b/common/src/main/java/me/lucko/luckperms/common/api/ApiProvider.java index 45b30b49..f5499adc 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/ApiProvider.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/ApiProvider.java @@ -71,7 +71,7 @@ public class ApiProvider implements LuckPermsApi { @Override public double getApiVersion() { - return 2.13; + return 2.14; } @Override @@ -99,9 +99,20 @@ public class ApiProvider implements LuckPermsApi { return new LPConfigurationLink(plugin.getConfiguration()); } + @Override + public Storage getStorage() { + return new StorageLink(plugin, plugin.getStorage()); + } + + @SuppressWarnings("deprecation") @Override public Datastore getDatastore() { - return new DatastoreLink(plugin, plugin.getDatastore()); + return new DatastoreLink(plugin, plugin.getStorage()); + } + + @Override + public Optional getMessagingService() { + return Optional.ofNullable(plugin.getRedisMessaging()); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/api/internal/DatastoreLink.java b/common/src/main/java/me/lucko/luckperms/common/api/internal/DatastoreLink.java index 4bb880bd..c962db5f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/internal/DatastoreLink.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/internal/DatastoreLink.java @@ -27,26 +27,29 @@ import lombok.NonNull; import me.lucko.luckperms.api.*; import me.lucko.luckperms.api.data.Callback; import me.lucko.luckperms.common.LuckPermsPlugin; -import me.lucko.luckperms.common.utils.AbstractFuture; +import me.lucko.luckperms.common.storage.Storage; import java.util.Set; import java.util.UUID; +import java.util.concurrent.CompletableFuture; import static me.lucko.luckperms.common.api.internal.Utils.*; /** - * Provides a link between {@link Datastore} and {@link me.lucko.luckperms.common.storage.Datastore} + * Provides a link between {@link Datastore} and {@link Storage} + * + * Note that this class only provides for the old deprecated interface, see {@link StorageLink} for the new one. */ -@SuppressWarnings({"unused", "WeakerAccess"}) +@SuppressWarnings({"unused", "WeakerAccess", "deprecation"}) public class DatastoreLink implements Datastore { private final LuckPermsPlugin plugin; - private final me.lucko.luckperms.common.storage.Datastore master; + private final Storage master; private final Async async; private final Sync sync; private final Future future; - public DatastoreLink(@NonNull LuckPermsPlugin plugin, @NonNull me.lucko.luckperms.common.storage.Datastore master) { + public DatastoreLink(@NonNull LuckPermsPlugin plugin, @NonNull Storage master) { this.plugin = plugin; this.master = master; this.async = new Async(master); @@ -54,12 +57,10 @@ public class DatastoreLink implements Datastore { this.future = new Future(master); } - private static Callback checkCallback(Callback c) { - // If no callback was given, just send an empty one - if (c == null) { - c = Callback.empty(); + private void registerCallback(CompletableFuture fut, Callback c) { + if (c != null) { + fut.thenAcceptAsync(Callback.convertToConsumer(c), plugin.getSyncExecutor()); } - return c; } @Override @@ -89,68 +90,68 @@ public class DatastoreLink implements Datastore { @AllArgsConstructor public class Async implements Datastore.Async { - private final me.lucko.luckperms.common.storage.Datastore master; + private final me.lucko.luckperms.common.storage.Storage master; @Override public void logAction(@NonNull LogEntry entry, Callback callback) { - master.force().logAction(entry, checkCallback(callback)); + registerCallback(master.force().logAction(entry), callback); } @Override - public void getLog(Callback callback) { - master.force().getLog(log -> callback.onComplete(new LogLink(log))); + public void getLog(@NonNull Callback callback) { + master.force().getLog().thenAcceptAsync(log -> callback.onComplete(new LogLink(log)), plugin.getSyncExecutor()); } @Override public void loadOrCreateUser(@NonNull UUID uuid, @NonNull String username, Callback callback) { - master.force().loadUser(uuid, checkUsername(username), checkCallback(callback)); + registerCallback(master.force().loadUser(uuid, checkUsername(username)) , callback); } @Override public void loadUser(@NonNull UUID uuid, Callback callback) { - master.force().loadUser(uuid, "null", checkCallback(callback)); + registerCallback(master.force().loadUser(uuid, "null"), callback); } @Override public void loadUser(@NonNull UUID uuid, @NonNull String username, Callback callback) { - master.force().loadUser(uuid, checkUsername(username), checkCallback(callback)); + registerCallback(master.force().loadUser(uuid, checkUsername(username)), callback); } @Override public void saveUser(@NonNull User user, Callback callback) { checkUser(user); - master.force().saveUser(((UserLink) user).getMaster(), checkCallback(callback)); + registerCallback(master.force().saveUser(((UserLink) user).getMaster()), callback); } @Override public void cleanupUsers(Callback callback) { - master.force().cleanupUsers(checkCallback(callback)); + registerCallback(master.force().cleanupUsers(), callback); } @Override public void getUniqueUsers(Callback> callback) { - master.force().getUniqueUsers(checkCallback(callback)); + registerCallback(master.force().getUniqueUsers(), callback); } @Override public void createAndLoadGroup(@NonNull String name, Callback callback) { - master.force().createAndLoadGroup(checkName(name), checkCallback(callback)); + registerCallback(master.force().createAndLoadGroup(checkName(name)), callback); } @Override public void loadGroup(@NonNull String name, Callback callback) { - master.force().loadGroup(checkName(name), checkCallback(callback)); + registerCallback(master.force().loadGroup(checkName(name)), callback); } @Override public void loadAllGroups(Callback callback) { - master.force().loadAllGroups(checkCallback(callback)); + registerCallback(master.force().loadAllGroups(), callback); } @Override public void saveGroup(@NonNull Group group, Callback callback) { checkGroup(group); - master.force().saveGroup(((GroupLink) group).getMaster(), checkCallback(callback)); + registerCallback(master.force().saveGroup(((GroupLink) group).getMaster()), callback); } @Override @@ -159,59 +160,59 @@ public class DatastoreLink implements Datastore { if (group.getName().equalsIgnoreCase(plugin.getConfiguration().getDefaultGroupName())) { throw new IllegalArgumentException("Cannot delete the default group."); } - master.force().deleteGroup(((GroupLink) group).getMaster(), checkCallback(callback)); + registerCallback(master.force().deleteGroup(((GroupLink) group).getMaster()), callback); } @Override public void createAndLoadTrack(@NonNull String name, Callback callback) { - master.force().createAndLoadTrack(checkName(name), checkCallback(callback)); + registerCallback(master.force().createAndLoadTrack(checkName(name)), callback); } @Override public void loadTrack(@NonNull String name, Callback callback) { - master.force().loadTrack(checkName(name), checkCallback(callback)); + registerCallback(master.force().loadTrack(checkName(name)), callback); } @Override public void loadAllTracks(Callback callback) { - master.force().loadAllTracks(checkCallback(callback)); + registerCallback(master.force().loadAllTracks(), callback); } @Override public void saveTrack(@NonNull Track track, Callback callback) { checkTrack(track); - master.force().saveTrack(((TrackLink) track).getMaster(), checkCallback(callback)); + registerCallback(master.force().saveTrack(((TrackLink) track).getMaster()), callback); } @Override public void deleteTrack(@NonNull Track track, Callback callback) { checkTrack(track); - master.force().deleteTrack(((TrackLink) track).getMaster(), checkCallback(callback)); + registerCallback(master.force().deleteTrack(((TrackLink) track).getMaster()), callback); } @Override public void saveUUIDData(@NonNull String username, @NonNull UUID uuid, Callback callback) { - master.force().saveUUIDData(checkUsername(username), uuid, checkCallback(callback)); + registerCallback(master.force().saveUUIDData(checkUsername(username), uuid), callback); } @Override public void getUUID(@NonNull String username, Callback callback) { - master.force().getUUID(checkUsername(username), checkCallback(callback)); + registerCallback(master.force().getUUID(checkUsername(username)), callback); } } @AllArgsConstructor public class Sync implements Datastore.Sync { - private final me.lucko.luckperms.common.storage.Datastore master; + private final Storage master; @Override public boolean logAction(@NonNull LogEntry entry) { - return master.force().logAction(entry).getUnchecked(); + return master.force().logAction(entry).join(); } @Override public Log getLog() { - me.lucko.luckperms.common.data.Log log = master.force().getLog().getUnchecked(); + me.lucko.luckperms.common.data.Log log = master.force().getLog().join(); if (log == null) { return null; } @@ -220,54 +221,54 @@ public class DatastoreLink implements Datastore { @Override public boolean loadOrCreateUser(@NonNull UUID uuid, @NonNull String username) { - return master.force().loadUser(uuid, checkUsername(username)).getUnchecked(); + return master.force().loadUser(uuid, checkUsername(username)).join(); } @Override public boolean loadUser(@NonNull UUID uuid) { - return master.force().loadUser(uuid, "null").getUnchecked(); + return master.force().loadUser(uuid, "null").join(); } @Override public boolean loadUser(@NonNull UUID uuid, @NonNull String username) { - return master.force().loadUser(uuid, checkUsername(username)).getUnchecked(); + return master.force().loadUser(uuid, checkUsername(username)).join(); } @Override public boolean saveUser(@NonNull User user) { checkUser(user); - return master.force().saveUser(((UserLink) user).getMaster()).getUnchecked(); + return master.force().saveUser(((UserLink) user).getMaster()).join(); } @Override public boolean cleanupUsers() { - return master.force().cleanupUsers().getUnchecked(); + return master.force().cleanupUsers().join(); } @Override public Set getUniqueUsers() { - return master.force().getUniqueUsers().getUnchecked(); + return master.force().getUniqueUsers().join(); } @Override public boolean createAndLoadGroup(@NonNull String name) { - return master.force().createAndLoadGroup(checkName(name)).getUnchecked(); + return master.force().createAndLoadGroup(checkName(name)).join(); } @Override public boolean loadGroup(@NonNull String name) { - return master.force().loadGroup(checkName(name)).getUnchecked(); + return master.force().loadGroup(checkName(name)).join(); } @Override public boolean loadAllGroups() { - return master.force().loadAllGroups().getUnchecked(); + return master.force().loadAllGroups().join(); } @Override public boolean saveGroup(@NonNull Group group) { checkGroup(group); - return master.force().saveGroup(((GroupLink) group).getMaster()).getUnchecked(); + return master.force().saveGroup(((GroupLink) group).getMaster()).join(); } @Override @@ -276,50 +277,50 @@ public class DatastoreLink implements Datastore { if (group.getName().equalsIgnoreCase(plugin.getConfiguration().getDefaultGroupName())) { throw new IllegalArgumentException("Cannot delete the default group."); } - return master.force().deleteGroup(((GroupLink) group).getMaster()).getUnchecked(); + return master.force().deleteGroup(((GroupLink) group).getMaster()).join(); } @Override public boolean createAndLoadTrack(@NonNull String name) { - return master.force().createAndLoadTrack(checkName(name)).getUnchecked(); + return master.force().createAndLoadTrack(checkName(name)).join(); } @Override public boolean loadTrack(@NonNull String name) { - return master.force().loadTrack(checkName(name)).getUnchecked(); + return master.force().loadTrack(checkName(name)).join(); } @Override public boolean loadAllTracks() { - return master.force().loadAllTracks().getUnchecked(); + return master.force().loadAllTracks().join(); } @Override public boolean saveTrack(@NonNull Track track) { checkTrack(track); - return master.force().saveTrack(((TrackLink) track).getMaster()).getUnchecked(); + return master.force().saveTrack(((TrackLink) track).getMaster()).join(); } @Override public boolean deleteTrack(@NonNull Track track) { checkTrack(track); - return master.force().deleteTrack(((TrackLink) track).getMaster()).getUnchecked(); + return master.force().deleteTrack(((TrackLink) track).getMaster()).join(); } @Override public boolean saveUUIDData(@NonNull String username, @NonNull UUID uuid) { - return master.force().saveUUIDData(checkUsername(username), uuid).getUnchecked(); + return master.force().saveUUIDData(checkUsername(username), uuid).join(); } @Override public UUID getUUID(@NonNull String username) { - return master.force().getUUID(checkUsername(username)).getUnchecked(); + return master.force().getUUID(checkUsername(username)).join(); } } @AllArgsConstructor public class Future implements Datastore.Future { - private final me.lucko.luckperms.common.storage.Datastore master; + private final Storage master; @Override public java.util.concurrent.Future logAction(@NonNull LogEntry entry) { @@ -328,9 +329,7 @@ public class DatastoreLink implements Datastore { @Override public java.util.concurrent.Future getLog() { - AbstractFuture fut = new AbstractFuture<>(); - master.force().getLog(log -> fut.complete(new LogLink(log))); - return fut; + return master.force().getLog().thenApply(log -> log == null ? null : new LogLink(log)); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/api/internal/LPConfigurationLink.java b/common/src/main/java/me/lucko/luckperms/common/api/internal/LPConfigurationLink.java index a52e0895..cc362975 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/internal/LPConfigurationLink.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/internal/LPConfigurationLink.java @@ -103,7 +103,7 @@ public class LPConfigurationLink implements LPConfiguration { @Override public boolean getDebugPermissionChecks() { - return false; // Constant TODO depreciate this + return false; } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/api/internal/StorageLink.java b/common/src/main/java/me/lucko/luckperms/common/api/internal/StorageLink.java new file mode 100644 index 00000000..7dbee6ba --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/api/internal/StorageLink.java @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * 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.internal; + +import lombok.AllArgsConstructor; +import lombok.NonNull; +import me.lucko.luckperms.api.*; +import me.lucko.luckperms.common.LuckPermsPlugin; + +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executor; + +import static me.lucko.luckperms.common.api.internal.Utils.*; + +/** + * Provides a link between {@link Storage} and {@link me.lucko.luckperms.common.storage.Storage} + */ +@AllArgsConstructor +public class StorageLink implements Storage { + private final LuckPermsPlugin plugin; + private final me.lucko.luckperms.common.storage.Storage master; + + @Override + public String getName() { + return master.getName(); + } + + @Override + public boolean isAcceptingLogins() { + return master.isAcceptingLogins(); + } + + @Override + public Executor getSyncExecutor() { + return plugin.getSyncExecutor(); + } + + @Override + public Executor getAsyncExecutor() { + return plugin.getAsyncExecutor(); + } + + @Override + public CompletableFuture logAction(@NonNull LogEntry entry) { + return master.force().logAction(entry); + } + + @Override + public CompletableFuture getLog() { + return master.force().getLog().thenApply(log -> log == null ? null : new LogLink(log)); + } + + @Override + public CompletableFuture loadUser(UUID uuid, String username) { + return master.force().loadUser(uuid, checkUsername(username)); + } + + @Override + public CompletableFuture saveUser(User user) { + checkUser(user); + return master.force().saveUser(((UserLink) user).getMaster()); + } + + @Override + public CompletableFuture cleanupUsers() { + return master.force().cleanupUsers(); + } + + @Override + public CompletableFuture> getUniqueUsers() { + return master.force().getUniqueUsers(); + } + + @Override + public CompletableFuture createAndLoadGroup(String name) { + return master.force().createAndLoadGroup(checkName(name)); + } + + @Override + public CompletableFuture loadGroup(String name) { + return master.force().loadGroup(checkName(name)); + } + + @Override + public CompletableFuture loadAllGroups() { + return master.force().loadAllGroups(); + } + + @Override + public CompletableFuture saveGroup(Group group) { + checkGroup(group); + return master.force().saveGroup(((GroupLink) group).getMaster()); + } + + @Override + public CompletableFuture deleteGroup(Group group) { + checkGroup(group); + if (group.getName().equalsIgnoreCase(plugin.getConfiguration().getDefaultGroupName())) { + throw new IllegalArgumentException("Cannot delete the default group."); + } + return master.force().deleteGroup(((GroupLink) group).getMaster()); + } + + @Override + public CompletableFuture createAndLoadTrack(String name) { + return master.force().createAndLoadTrack(checkName(name)); + } + + @Override + public CompletableFuture loadTrack(String name) { + return master.force().loadTrack(checkName(name)); + } + + @Override + public CompletableFuture loadAllTracks() { + return master.force().loadAllTracks(); + } + + @Override + public CompletableFuture saveTrack(Track track) { + checkTrack(track); + return master.force().saveTrack(((TrackLink) track).getMaster()); + } + + @Override + public CompletableFuture deleteTrack(Track track) { + checkTrack(track); + return master.force().deleteTrack(((TrackLink) track).getMaster()); + } + + @Override + public CompletableFuture saveUUIDData(String username, UUID uuid) { + return master.force().saveUUIDData(checkUsername(username), uuid); + } + + @Override + public CompletableFuture getUUID(String username) { + return master.force().getUUID(checkUsername(username)); + } +} diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/SubCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/SubCommand.java index 79a801d7..88013d45 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/SubCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/SubCommand.java @@ -114,7 +114,7 @@ public abstract class SubCommand extends Command { } public static void save(User user, Sender sender, LuckPermsPlugin plugin) { - boolean success = plugin.getDatastore().force().saveUser(user).getUnchecked(); + boolean success = plugin.getStorage().force().saveUser(user).join(); user.getRefreshBuffer().requestDirectly(); if (success) { @@ -125,7 +125,7 @@ public abstract class SubCommand extends Command { } public static void save(Group group, Sender sender, LuckPermsPlugin plugin) { - boolean success = plugin.getDatastore().force().saveGroup(group).getUnchecked(); + boolean success = plugin.getStorage().force().saveGroup(group).join(); plugin.getUpdateTaskBuffer().requestDirectly(); if (success) { @@ -136,7 +136,7 @@ public abstract class SubCommand extends Command { } public static void save(Track track, Sender sender, LuckPermsPlugin plugin) { - boolean success = plugin.getDatastore().force().saveTrack(track).getUnchecked(); + boolean success = plugin.getStorage().force().saveTrack(track).join(); plugin.getUpdateTaskBuffer().requestDirectly(); if (success) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderShowTracks.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderShowTracks.java index 277b7033..d7182492 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderShowTracks.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderShowTracks.java @@ -46,7 +46,7 @@ public class HolderShowTracks extends SubCommand @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T holder, List args, String label) throws CommandException { - if (!plugin.getDatastore().loadAllTracks().getUnchecked()) { + if (!plugin.getStorage().loadAllTracks().join()) { Message.TRACKS_LOAD_ERROR.send(sender); return CommandResult.LOADING_ERROR; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAdd.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAdd.java index 1990dbf5..1d466ec5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAdd.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAdd.java @@ -61,7 +61,7 @@ public class ParentAdd extends SharedSubCommand { String server = ArgumentUtils.handleServer(1, args); String world = ArgumentUtils.handleWorld(2, args); - if (!plugin.getDatastore().loadGroup(groupName).getUnchecked()) { + if (!plugin.getStorage().loadGroup(groupName).join()) { Message.GROUP_DOES_NOT_EXIST.send(sender); return CommandResult.INVALID_ARGS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAddTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAddTemp.java index af33e12f..76574148 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAddTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAddTemp.java @@ -64,7 +64,7 @@ public class ParentAddTemp extends SharedSubCommand { String server = ArgumentUtils.handleServer(2, args); String world = ArgumentUtils.handleWorld(3, args); - if (!plugin.getDatastore().loadGroup(groupName).getUnchecked()) { + if (!plugin.getStorage().loadGroup(groupName).join()) { Message.GROUP_DOES_NOT_EXIST.send(sender); return CommandResult.INVALID_ARGS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSet.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSet.java index 84a4b707..0a70a3df 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSet.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSet.java @@ -62,7 +62,7 @@ public class ParentSet extends SharedSubCommand { String server = ArgumentUtils.handleServer(1, args); String world = ArgumentUtils.handleWorld(2, args); - if (!plugin.getDatastore().loadGroup(groupName).getUnchecked()) { + if (!plugin.getStorage().loadGroup(groupName).join()) { Message.GROUP_DOES_NOT_EXIST.send(sender); return CommandResult.INVALID_ARGS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/CreateGroup.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/CreateGroup.java index 42c5afa0..b8ba7e24 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/CreateGroup.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/CreateGroup.java @@ -57,12 +57,12 @@ public class CreateGroup extends SingleCommand { return CommandResult.INVALID_ARGS; } - if (plugin.getDatastore().loadGroup(groupName).getUnchecked()) { + if (plugin.getStorage().loadGroup(groupName).join()) { Message.GROUP_ALREADY_EXISTS.send(sender); return CommandResult.INVALID_ARGS; } - if (!plugin.getDatastore().createAndLoadGroup(groupName).getUnchecked()) { + if (!plugin.getStorage().createAndLoadGroup(groupName).join()) { Message.CREATE_GROUP_ERROR.send(sender); return CommandResult.FAILURE; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/DeleteGroup.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/DeleteGroup.java index 069fb25d..c80b6d52 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/DeleteGroup.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/DeleteGroup.java @@ -61,7 +61,7 @@ public class DeleteGroup extends SingleCommand { return CommandResult.INVALID_ARGS; } - if (!plugin.getDatastore().loadGroup(groupName).getUnchecked()) { + if (!plugin.getStorage().loadGroup(groupName).join()) { Message.GROUP_DOES_NOT_EXIST.send(sender); return CommandResult.INVALID_ARGS; } @@ -72,7 +72,7 @@ public class DeleteGroup extends SingleCommand { return CommandResult.LOADING_ERROR; } - if (!plugin.getDatastore().deleteGroup(group).getUnchecked()) { + if (!plugin.getStorage().deleteGroup(group).join()) { Message.DELETE_GROUP_ERROR.send(sender); return CommandResult.FAILURE; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupClone.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupClone.java index 8e9ab616..ec396edb 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupClone.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupClone.java @@ -52,12 +52,12 @@ public class GroupClone extends SubCommand { return CommandResult.INVALID_ARGS; } - if (plugin.getDatastore().loadGroup(newGroupName).getUnchecked()) { + if (plugin.getStorage().loadGroup(newGroupName).join()) { Message.GROUP_ALREADY_EXISTS.send(sender); return CommandResult.INVALID_ARGS; } - if (!plugin.getDatastore().createAndLoadGroup(newGroupName).getUnchecked()) { + if (!plugin.getStorage().createAndLoadGroup(newGroupName).join()) { Message.CREATE_GROUP_ERROR.send(sender); return CommandResult.FAILURE; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupMainCommand.java index d5275515..573961bf 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupMainCommand.java @@ -55,7 +55,7 @@ public class GroupMainCommand extends MainCommand { @Override protected Group getTarget(String target, LuckPermsPlugin plugin, Sender sender) { - if (!plugin.getDatastore().loadGroup(target).getUnchecked()) { + if (!plugin.getStorage().loadGroup(target).join()) { Message.GROUP_NOT_FOUND.send(sender); return null; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupRename.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupRename.java index 00b77a45..bc98952a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupRename.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupRename.java @@ -52,12 +52,12 @@ public class GroupRename extends SubCommand { return CommandResult.INVALID_ARGS; } - if (plugin.getDatastore().loadGroup(newGroupName).getUnchecked()) { + if (plugin.getStorage().loadGroup(newGroupName).join()) { Message.GROUP_ALREADY_EXISTS.send(sender); return CommandResult.INVALID_ARGS; } - if (!plugin.getDatastore().createAndLoadGroup(newGroupName).getUnchecked()) { + if (!plugin.getStorage().createAndLoadGroup(newGroupName).join()) { Message.CREATE_GROUP_ERROR.send(sender); return CommandResult.FAILURE; } @@ -68,7 +68,7 @@ public class GroupRename extends SubCommand { return CommandResult.LOADING_ERROR; } - if (!plugin.getDatastore().deleteGroup(group).getUnchecked()) { + if (!plugin.getStorage().deleteGroup(group).join()) { Message.DELETE_GROUP_ERROR.send(sender); return CommandResult.FAILURE; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/ListGroups.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/ListGroups.java index 23ac7080..f887663d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/ListGroups.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/ListGroups.java @@ -43,7 +43,7 @@ public class ListGroups extends SingleCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { - if (!plugin.getDatastore().loadAllGroups().getUnchecked()) { + if (!plugin.getStorage().loadAllGroups().join()) { Message.GROUPS_LOAD_ERROR.send(sender); return CommandResult.LOADING_ERROR; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogMainCommand.java index e7eb5fa5..17bc584f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogMainCommand.java @@ -52,7 +52,7 @@ public class LogMainCommand extends MainCommand { @Override protected Log getTarget(String target, LuckPermsPlugin plugin, Sender sender) { - Log log = plugin.getDatastore().getLog().getUnchecked(); + Log log = plugin.getStorage().getLog().join(); if (log == null) { Message.LOG_LOAD_ERROR.send(sender); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/log/subcommands/LogRecent.java b/common/src/main/java/me/lucko/luckperms/common/commands/log/subcommands/LogRecent.java index 677f2262..a39ea925 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/log/subcommands/LogRecent.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/log/subcommands/LogRecent.java @@ -80,7 +80,7 @@ public class LogRecent extends SubCommand { return CommandResult.INVALID_ARGS; } - UUID uuid = plugin.getDatastore().getUUID(s).getUnchecked(); + UUID uuid = plugin.getStorage().getUUID(s).join(); if (uuid == null) { Message.USER_NOT_FOUND.send(sender); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/log/subcommands/LogUserHistory.java b/common/src/main/java/me/lucko/luckperms/common/commands/log/subcommands/LogUserHistory.java index 5be8eab4..bda5f3f5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/log/subcommands/LogUserHistory.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/log/subcommands/LogUserHistory.java @@ -82,7 +82,7 @@ public class LogUserHistory extends SubCommand { return CommandResult.INVALID_ARGS; } - UUID uuid1 = plugin.getDatastore().getUUID(user).getUnchecked(); + UUID uuid1 = plugin.getStorage().getUUID(user).join(); if (uuid1 == null) { Message.USER_NOT_FOUND.send(sender); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/ExportCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/ExportCommand.java index e705e4fa..e805585c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/ExportCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/ExportCommand.java @@ -33,7 +33,7 @@ import me.lucko.luckperms.common.constants.Constants; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.groups.Group; -import me.lucko.luckperms.common.storage.Datastore; +import me.lucko.luckperms.common.storage.Storage; import me.lucko.luckperms.common.tracks.Track; import me.lucko.luckperms.common.users.User; import me.lucko.luckperms.common.utils.Predicates; @@ -123,14 +123,14 @@ public class ExportCommand extends SingleCommand { // Export users log.info("Export: Exporting all users. Finding a list of unique users to export."); - Datastore ds = plugin.getDatastore(); - Set users = ds.getUniqueUsers().getUnchecked(); + Storage ds = plugin.getStorage(); + Set users = ds.getUniqueUsers().join(); log.info("Export: Found " + users.size() + " unique users to export."); int userCount = 0; for (UUID uuid : users) { userCount++; - plugin.getDatastore().loadUser(uuid, "null").getUnchecked(); + plugin.getStorage().loadUser(uuid, "null").join(); User user = plugin.getUserManager().get(uuid); boolean inDefault = false; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/InfoCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/InfoCommand.java index fa04bb44..c9a110fc 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/InfoCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/InfoCommand.java @@ -46,7 +46,7 @@ public class InfoCommand extends SingleCommand { Message.INFO.send(sender, plugin.getVersion(), plugin.getType().getFriendlyName(), - plugin.getDatastore().getName(), + plugin.getStorage().getName(), c.getServer(), c.getSyncTime(), formatBoolean(c.isIncludingGlobalPerms()), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/NetworkSyncCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/NetworkSyncCommand.java index e5f5e516..eab9fb2d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/NetworkSyncCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/NetworkSyncCommand.java @@ -41,7 +41,7 @@ public class NetworkSyncCommand extends SingleCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { Message.UPDATE_TASK_REQUEST.send(sender); - plugin.getUpdateTaskBuffer().request().getUnchecked(); + plugin.getUpdateTaskBuffer().request().join(); Message.UPDATE_TASK_COMPLETE_NETWORK.send(sender); if (plugin.getRedisMessaging() != null) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/SyncCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/SyncCommand.java index 496f3c97..72fa0d69 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/SyncCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/SyncCommand.java @@ -40,7 +40,7 @@ public class SyncCommand extends SingleCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { Message.UPDATE_TASK_REQUEST.send(sender); - plugin.getUpdateTaskBuffer().request().getUnchecked(); + plugin.getUpdateTaskBuffer().request().join(); Message.UPDATE_TASK_COMPLETE.send(sender); return CommandResult.SUCCESS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/CreateTrack.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/CreateTrack.java index 8f6cdf72..d3fd3889 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/CreateTrack.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/CreateTrack.java @@ -57,12 +57,12 @@ public class CreateTrack extends SingleCommand { return CommandResult.INVALID_ARGS; } - if (plugin.getDatastore().loadTrack(trackName).getUnchecked()) { + if (plugin.getStorage().loadTrack(trackName).join()) { Message.TRACK_ALREADY_EXISTS.send(sender); return CommandResult.INVALID_ARGS; } - if (!plugin.getDatastore().createAndLoadTrack(trackName).getUnchecked()) { + if (!plugin.getStorage().createAndLoadTrack(trackName).join()) { Message.CREATE_TRACK_ERROR.send(sender); return CommandResult.FAILURE; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/DeleteTrack.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/DeleteTrack.java index 52d4ed20..c4bb7d9c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/DeleteTrack.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/DeleteTrack.java @@ -55,7 +55,7 @@ public class DeleteTrack extends SingleCommand { } String trackName = args.get(0).toLowerCase(); - if (!plugin.getDatastore().loadTrack(trackName).getUnchecked()) { + if (!plugin.getStorage().loadTrack(trackName).join()) { Message.TRACK_DOES_NOT_EXIST.send(sender); return CommandResult.INVALID_ARGS; } @@ -66,7 +66,7 @@ public class DeleteTrack extends SingleCommand { return CommandResult.LOADING_ERROR; } - if (!plugin.getDatastore().deleteTrack(track).getUnchecked()) { + if (!plugin.getStorage().deleteTrack(track).join()) { Message.DELETE_TRACK_ERROR.send(sender); return CommandResult.FAILURE; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/ListTracks.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/ListTracks.java index 97c0a798..4f221c02 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/ListTracks.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/ListTracks.java @@ -41,7 +41,7 @@ public class ListTracks extends SingleCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { - if (!plugin.getDatastore().loadAllTracks().getUnchecked()) { + if (!plugin.getStorage().loadAllTracks().join()) { Message.TRACKS_LOAD_ERROR.send(sender); return CommandResult.LOADING_ERROR; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackAppend.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackAppend.java index a45ddbb1..116a0ece 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackAppend.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackAppend.java @@ -56,7 +56,7 @@ public class TrackAppend extends SubCommand { return CommandResult.INVALID_ARGS; } - if (!plugin.getDatastore().loadGroup(groupName).getUnchecked()) { + if (!plugin.getStorage().loadGroup(groupName).join()) { Message.GROUP_DOES_NOT_EXIST.send(sender); return CommandResult.INVALID_ARGS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackClone.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackClone.java index 43f087e0..4810d92b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackClone.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackClone.java @@ -52,12 +52,12 @@ public class TrackClone extends SubCommand { return CommandResult.INVALID_ARGS; } - if (plugin.getDatastore().loadTrack(newTrackName).getUnchecked()) { + if (plugin.getStorage().loadTrack(newTrackName).join()) { Message.TRACK_ALREADY_EXISTS.send(sender); return CommandResult.INVALID_ARGS; } - if (!plugin.getDatastore().createAndLoadTrack(newTrackName).getUnchecked()) { + if (!plugin.getStorage().createAndLoadTrack(newTrackName).join()) { Message.CREATE_TRACK_ERROR.send(sender); return CommandResult.FAILURE; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackInsert.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackInsert.java index 05d2e8c8..07a39747 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackInsert.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackInsert.java @@ -67,7 +67,7 @@ public class TrackInsert extends SubCommand { return CommandResult.INVALID_ARGS; } - if (!plugin.getDatastore().loadGroup(groupName).getUnchecked()) { + if (!plugin.getStorage().loadGroup(groupName).join()) { Message.GROUP_DOES_NOT_EXIST.send(sender); return CommandResult.INVALID_ARGS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackMainCommand.java index 5f6b6a95..8e9f7cf2 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackMainCommand.java @@ -49,7 +49,7 @@ public class TrackMainCommand extends MainCommand { @Override protected Track getTarget(String target, LuckPermsPlugin plugin, Sender sender) { - if (!plugin.getDatastore().loadTrack(target).getUnchecked()) { + if (!plugin.getStorage().loadTrack(target).join()) { Message.TRACK_NOT_FOUND.send(sender); return null; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackRename.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackRename.java index 4e326e58..55c38971 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackRename.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackRename.java @@ -52,12 +52,12 @@ public class TrackRename extends SubCommand { return CommandResult.INVALID_ARGS; } - if (plugin.getDatastore().loadTrack(newTrackName).getUnchecked()) { + if (plugin.getStorage().loadTrack(newTrackName).join()) { Message.TRACK_ALREADY_EXISTS.send(sender); return CommandResult.INVALID_ARGS; } - if (!plugin.getDatastore().createAndLoadTrack(newTrackName).getUnchecked()) { + if (!plugin.getStorage().createAndLoadTrack(newTrackName).join()) { Message.CREATE_TRACK_ERROR.send(sender); return CommandResult.FAILURE; } @@ -68,7 +68,7 @@ public class TrackRename extends SubCommand { return CommandResult.LOADING_ERROR; } - if (!plugin.getDatastore().deleteTrack(track).getUnchecked()) { + if (!plugin.getStorage().deleteTrack(track).join()) { Message.DELETE_TRACK_ERROR.send(sender); return CommandResult.FAILURE; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserDemote.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserDemote.java index 89f4ac03..218a7d33 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserDemote.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserDemote.java @@ -72,7 +72,7 @@ public class UserDemote extends SubCommand { return CommandResult.INVALID_ARGS; } - if (!plugin.getDatastore().loadTrack(trackName).getUnchecked()) { + if (!plugin.getStorage().loadTrack(trackName).join()) { Message.TRACK_DOES_NOT_EXIST.send(sender); return CommandResult.INVALID_ARGS; } @@ -147,7 +147,7 @@ public class UserDemote extends SubCommand { return CommandResult.STATE_ERROR; } - if (!plugin.getDatastore().loadGroup(previous).getUnchecked()) { + if (!plugin.getStorage().loadGroup(previous).join()) { Message.USER_DEMOTE_ERROR_MALFORMED.send(sender, previous); return CommandResult.STATE_ERROR; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserMainCommand.java index 65fcebeb..dd64652e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserMainCommand.java @@ -67,7 +67,7 @@ public class UserMainCommand extends MainCommand { return null; } - u = plugin.getDatastore().getUUID(target).getUnchecked(); + u = plugin.getStorage().getUUID(target).join(); if (u == null) { Message.USER_NOT_FOUND.send(sender); return null; @@ -77,10 +77,10 @@ public class UserMainCommand extends MainCommand { } } - String name = plugin.getDatastore().getName(u).getUnchecked(); + String name = plugin.getStorage().getName(u).join(); if (name == null) name = "null"; - if (!plugin.getDatastore().loadUser(u, name).getUnchecked()) { + if (!plugin.getStorage().loadUser(u, name).join()) { Message.LOADING_ERROR.send(sender); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserPromote.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserPromote.java index 544ea862..c29ba9a8 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserPromote.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserPromote.java @@ -72,7 +72,7 @@ public class UserPromote extends SubCommand { return CommandResult.INVALID_ARGS; } - if (!plugin.getDatastore().loadTrack(trackName).getUnchecked()) { + if (!plugin.getStorage().loadTrack(trackName).join()) { Message.TRACK_DOES_NOT_EXIST.send(sender); return CommandResult.INVALID_ARGS; } @@ -147,7 +147,7 @@ public class UserPromote extends SubCommand { return CommandResult.STATE_ERROR; } - if (!plugin.getDatastore().loadGroup(next).getUnchecked()) { + if (!plugin.getStorage().loadGroup(next).join()) { Message.USER_PROMOTE_ERROR_MALFORMED.send(sender, next); return CommandResult.STATE_ERROR; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/BulkEditGroup.java b/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/BulkEditGroup.java index 4880de79..3f08152b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/BulkEditGroup.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/BulkEditGroup.java @@ -32,7 +32,7 @@ import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.NodeFactory; -import me.lucko.luckperms.common.storage.Datastore; +import me.lucko.luckperms.common.storage.Storage; import me.lucko.luckperms.common.users.User; import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; @@ -40,7 +40,7 @@ import me.lucko.luckperms.exceptions.ObjectLacksException; import java.util.*; -public class BulkEditGroup extends SubCommand { +public class BulkEditGroup extends SubCommand { public BulkEditGroup() { super("group", "Bulk edit group memberships", Permission.USER_BULKCHANGE, Predicates.not(4), Arg.list( @@ -53,7 +53,7 @@ public class BulkEditGroup extends SubCommand { } @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Datastore datastore, List args, String label) throws CommandException { + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Storage storage, List args, String label) throws CommandException { String group = args.get(0); String type = args.get(1).toLowerCase(); String from = args.get(2); @@ -67,10 +67,10 @@ public class BulkEditGroup extends SubCommand { return CommandResult.FAILURE; } - Set uuids = datastore.getUniqueUsers().getUnchecked(); + Set uuids = storage.getUniqueUsers().join(); for (UUID u : uuids) { - plugin.getDatastore().loadUser(u, "null").getUnchecked(); + plugin.getStorage().loadUser(u, "null").join(); User user = plugin.getUserManager().get(u); if (user == null) { continue; @@ -143,7 +143,7 @@ public class BulkEditGroup extends SubCommand { } catch (ObjectAlreadyHasException ignored) {} }); - plugin.getDatastore().saveUser(user); + plugin.getStorage().saveUser(user); plugin.getUserManager().cleanup(user); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/BulkEditPermission.java b/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/BulkEditPermission.java index d39288b5..b5fe0e47 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/BulkEditPermission.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/BulkEditPermission.java @@ -32,7 +32,7 @@ import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.NodeFactory; -import me.lucko.luckperms.common.storage.Datastore; +import me.lucko.luckperms.common.storage.Storage; import me.lucko.luckperms.common.users.User; import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; @@ -40,7 +40,7 @@ import me.lucko.luckperms.exceptions.ObjectLacksException; import java.util.*; -public class BulkEditPermission extends SubCommand { +public class BulkEditPermission extends SubCommand { public BulkEditPermission() { super("permission", "Bulk edit permissions", Permission.USER_BULKCHANGE, Predicates.not(4), Arg.list( @@ -53,7 +53,7 @@ public class BulkEditPermission extends SubCommand { } @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Datastore datastore, List args, String label) throws CommandException { + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Storage storage, List args, String label) throws CommandException { String node = args.get(0); String type = args.get(1).toLowerCase(); String from = args.get(2); @@ -67,10 +67,10 @@ public class BulkEditPermission extends SubCommand { return CommandResult.FAILURE; } - Set uuids = datastore.getUniqueUsers().getUnchecked(); + Set uuids = storage.getUniqueUsers().join(); for (UUID u : uuids) { - plugin.getDatastore().loadUser(u, "null").getUnchecked(); + plugin.getStorage().loadUser(u, "null").join(); User user = plugin.getUserManager().get(u); if (user == null) { continue; @@ -133,7 +133,7 @@ public class BulkEditPermission extends SubCommand { } catch (ObjectAlreadyHasException ignored) {} }); - plugin.getDatastore().saveUser(user); + plugin.getStorage().saveUser(user); plugin.getUserManager().cleanup(user); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/UsersBulkEditMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/UsersBulkEditMainCommand.java index 050cea3e..0bc62e15 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/UsersBulkEditMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/UsersBulkEditMainCommand.java @@ -27,17 +27,17 @@ import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.Command; import me.lucko.luckperms.common.commands.MainCommand; import me.lucko.luckperms.common.commands.sender.Sender; -import me.lucko.luckperms.common.storage.Datastore; +import me.lucko.luckperms.common.storage.Storage; import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; -public class UsersBulkEditMainCommand extends MainCommand { +public class UsersBulkEditMainCommand extends MainCommand { public UsersBulkEditMainCommand() { - super("UsersBulkEdit", "User bulk edit commands", "/%s usersbulkedit", 1, ImmutableList.>builder() + super("UsersBulkEdit", "User bulk edit commands", "/%s usersbulkedit", 1, ImmutableList.>builder() .add(new BulkEditGroup()) .add(new BulkEditPermission()) .build() @@ -45,12 +45,12 @@ public class UsersBulkEditMainCommand extends MainCommand { } @Override - protected Datastore getTarget(String target, LuckPermsPlugin plugin, Sender sender) { - return plugin.getDatastore(); + protected Storage getTarget(String target, LuckPermsPlugin plugin, Sender sender) { + return plugin.getStorage(); } @Override - protected void cleanup(Datastore datastore, LuckPermsPlugin plugin) { + protected void cleanup(Storage storage, LuckPermsPlugin plugin) { } @@ -61,7 +61,7 @@ public class UsersBulkEditMainCommand extends MainCommand { @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - final List> subs = getSubCommands().stream() + final List> subs = getSubCommands().stream() .filter(s -> s.isAuthorized(sender)) .collect(Collectors.toList()); @@ -78,7 +78,7 @@ public class UsersBulkEditMainCommand extends MainCommand { .collect(Collectors.toList()); } - Optional> o = subs.stream() + Optional> o = subs.stream() .filter(s -> s.getName().equalsIgnoreCase(args.get(0))) .limit(1) .findAny(); diff --git a/common/src/main/java/me/lucko/luckperms/common/constants/Message.java b/common/src/main/java/me/lucko/luckperms/common/constants/Message.java index d9c8465b..65da2b98 100644 --- a/common/src/main/java/me/lucko/luckperms/common/constants/Message.java +++ b/common/src/main/java/me/lucko/luckperms/common/constants/Message.java @@ -56,16 +56,16 @@ public enum Message { * Loading / Saving */ USER_NOT_FOUND("&bUser could not be found.", true), - USER_SAVE_SUCCESS("&7(User data was saved to the datastore)", true), + USER_SAVE_SUCCESS("&7(User data was saved to storage)", true), USER_SAVE_ERROR("There was an error whilst saving the user.", true), USER_CREATE_FAIL("There was an error whilst creating a new user.", true), GROUP_NOT_FOUND("&bGroup could not be found.", true), - GROUP_SAVE_SUCCESS("&7(Group data was saved to the datastore)", true), + GROUP_SAVE_SUCCESS("&7(Group data was saved to storage)", true), GROUP_SAVE_ERROR("There was an error whilst saving the group.", true), TRACK_NOT_FOUND("&bTrack could not be found.", true), - TRACK_SAVE_SUCCESS("&7(Track data was saved to the datastore)", true), + TRACK_SAVE_SUCCESS("&7(Track data was saved to storage)", true), TRACK_SAVE_ERROR("There was an error whilst saving the track.", true), diff --git a/common/src/main/java/me/lucko/luckperms/common/data/LogEntry.java b/common/src/main/java/me/lucko/luckperms/common/data/LogEntry.java index fec7786a..eea5b7f8 100644 --- a/common/src/main/java/me/lucko/luckperms/common/data/LogEntry.java +++ b/common/src/main/java/me/lucko/luckperms/common/data/LogEntry.java @@ -48,7 +48,7 @@ public class LogEntry extends me.lucko.luckperms.api.LogEntry { } public void submit(LuckPermsPlugin plugin, Sender sender) { - plugin.getDatastore().logAction(this); + plugin.getStorage().logAction(this); LogNotifyEvent event = new LogNotifyEvent(this); event.setCancelled(!plugin.getConfiguration().isLogNotify()); diff --git a/common/src/main/java/me/lucko/luckperms/common/messaging/RedisMessaging.java b/common/src/main/java/me/lucko/luckperms/common/messaging/RedisMessaging.java index 69ec818e..7893b746 100644 --- a/common/src/main/java/me/lucko/luckperms/common/messaging/RedisMessaging.java +++ b/common/src/main/java/me/lucko/luckperms/common/messaging/RedisMessaging.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.messaging; import lombok.RequiredArgsConstructor; +import me.lucko.luckperms.api.MessagingService; import me.lucko.luckperms.common.LuckPermsPlugin; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; @@ -38,7 +39,7 @@ import java.util.UUID; * Uses Redis to push/receive changes to/from other servers */ @RequiredArgsConstructor -public class RedisMessaging { +public class RedisMessaging implements MessagingService { private static final String CHANNEL = "luckperms"; private final LuckPermsPlugin plugin; @@ -70,6 +71,7 @@ public class RedisMessaging { jedisPool.destroy(); } + @Override public void pushUpdate() { plugin.doAsync(() -> { UUID id = sub.generateId(); diff --git a/common/src/main/java/me/lucko/luckperms/common/runnables/ExpireTemporaryTask.java b/common/src/main/java/me/lucko/luckperms/common/runnables/ExpireTemporaryTask.java index c928dc1e..7b6e0789 100644 --- a/common/src/main/java/me/lucko/luckperms/common/runnables/ExpireTemporaryTask.java +++ b/common/src/main/java/me/lucko/luckperms/common/runnables/ExpireTemporaryTask.java @@ -36,14 +36,14 @@ public class ExpireTemporaryTask implements Runnable { boolean groupChanges = false; for (Group group : plugin.getGroupManager().getAll().values()) { if (group.auditTemporaryPermissions()) { - plugin.getDatastore().saveGroup(group); + plugin.getStorage().saveGroup(group); groupChanges = true; } } for (User user : plugin.getUserManager().getAll().values()) { if (user.auditTemporaryPermissions()) { - plugin.getDatastore().saveUser(user); + plugin.getStorage().saveUser(user); if (!groupChanges) { user.getRefreshBuffer().request(); } diff --git a/common/src/main/java/me/lucko/luckperms/common/runnables/UpdateTask.java b/common/src/main/java/me/lucko/luckperms/common/runnables/UpdateTask.java index a31bdd4b..117e958a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/runnables/UpdateTask.java +++ b/common/src/main/java/me/lucko/luckperms/common/runnables/UpdateTask.java @@ -41,14 +41,14 @@ public class UpdateTask implements Runnable { if (event.isCancelled()) return; // Reload all groups - plugin.getDatastore().loadAllGroups().getUnchecked(); + plugin.getStorage().loadAllGroups().join(); String defaultGroup = plugin.getConfiguration().getDefaultGroupName(); if (!plugin.getGroupManager().isLoaded(defaultGroup)) { - plugin.getDatastore().createAndLoadGroup(defaultGroup).getUnchecked(); + plugin.getStorage().createAndLoadGroup(defaultGroup).join(); } // Reload all tracks - plugin.getDatastore().loadAllTracks().getUnchecked(); + plugin.getStorage().loadAllTracks().join(); // Refresh all online users. plugin.getUserManager().updateAllUsers(); diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/AbstractDatastore.java b/common/src/main/java/me/lucko/luckperms/common/storage/AbstractStorage.java similarity index 66% rename from common/src/main/java/me/lucko/luckperms/common/storage/AbstractDatastore.java rename to common/src/main/java/me/lucko/luckperms/common/storage/AbstractStorage.java index b9d2560f..2227e114 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/AbstractDatastore.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/AbstractStorage.java @@ -32,21 +32,19 @@ import me.lucko.luckperms.common.groups.Group; import me.lucko.luckperms.common.storage.backing.AbstractBacking; import me.lucko.luckperms.common.tracks.Track; import me.lucko.luckperms.common.users.User; -import me.lucko.luckperms.common.utils.AbstractFuture; -import me.lucko.luckperms.common.utils.LPFuture; import java.util.Set; import java.util.UUID; -import java.util.concurrent.Future; +import java.util.concurrent.CompletableFuture; import java.util.function.Supplier; /** - * Converts a {@link AbstractBacking} to use {@link Future}s + * Converts a {@link AbstractBacking} to use {@link CompletableFuture}s */ @RequiredArgsConstructor(access = AccessLevel.PRIVATE) -public class AbstractDatastore implements Datastore { - public static Datastore wrap(LuckPermsPlugin plugin, AbstractBacking backing) { - BufferedOutputDatastore bufferedDs = BufferedOutputDatastore.wrap(TolerantDatastore.wrap(new AbstractDatastore(backing)), 1000L); +public class AbstractStorage implements Storage { + public static Storage wrap(LuckPermsPlugin plugin, AbstractBacking backing) { + BufferedOutputStorage bufferedDs = BufferedOutputStorage.wrap(TolerantStorage.wrap(new AbstractStorage(backing)), 1000L); plugin.doAsyncRepeating(bufferedDs, 10L); return bufferedDs; } @@ -54,112 +52,107 @@ public class AbstractDatastore implements Datastore { @Delegate(types = Delegated.class) private final AbstractBacking backing; - private LPFuture makeFuture(Supplier supplier) { - AbstractFuture future = new AbstractFuture<>(); - backing.doAsync(() -> { - T result = supplier.get(); - future.complete(result); - }); - return future; + private CompletableFuture makeFuture(Supplier supplier) { + return CompletableFuture.supplyAsync(supplier, backing.getPlugin().getAsyncExecutor()); } @Override - public Datastore force() { + public Storage force() { return this; } @Override - public LPFuture logAction(LogEntry entry) { + public CompletableFuture logAction(LogEntry entry) { return makeFuture(() -> backing.logAction(entry)); } @Override - public LPFuture getLog() { + public CompletableFuture getLog() { return makeFuture(backing::getLog); } @Override - public LPFuture loadUser(UUID uuid, String username) { + public CompletableFuture loadUser(UUID uuid, String username) { return makeFuture(() -> backing.loadUser(uuid, username)); } @Override - public LPFuture saveUser(User user) { + public CompletableFuture saveUser(User user) { return makeFuture(() -> backing.saveUser(user)); } @Override - public LPFuture cleanupUsers() { + public CompletableFuture cleanupUsers() { return makeFuture(backing::cleanupUsers); } @Override - public LPFuture> getUniqueUsers() { + public CompletableFuture> getUniqueUsers() { return makeFuture(backing::getUniqueUsers); } @Override - public LPFuture createAndLoadGroup(String name) { + public CompletableFuture createAndLoadGroup(String name) { return makeFuture(() -> backing.createAndLoadGroup(name)); } @Override - public LPFuture loadGroup(String name) { + public CompletableFuture loadGroup(String name) { return makeFuture(() -> backing.loadGroup(name)); } @Override - public LPFuture loadAllGroups() { + public CompletableFuture loadAllGroups() { return makeFuture(backing::loadAllGroups); } @Override - public LPFuture saveGroup(Group group) { + public CompletableFuture saveGroup(Group group) { return makeFuture(() -> backing.saveGroup(group)); } @Override - public LPFuture deleteGroup(Group group) { + public CompletableFuture deleteGroup(Group group) { return makeFuture(() -> backing.deleteGroup(group)); } @Override - public LPFuture createAndLoadTrack(String name) { + public CompletableFuture createAndLoadTrack(String name) { return makeFuture(() -> backing.createAndLoadTrack(name)); } @Override - public LPFuture loadTrack(String name) { + public CompletableFuture loadTrack(String name) { return makeFuture(() -> backing.loadTrack(name)); } @Override - public LPFuture loadAllTracks() { + public CompletableFuture loadAllTracks() { return makeFuture(backing::loadAllTracks); } @Override - public LPFuture saveTrack(Track track) { + public CompletableFuture saveTrack(Track track) { return makeFuture(() -> backing.saveTrack(track)); } @Override - public LPFuture deleteTrack(Track track) { + public CompletableFuture deleteTrack(Track track) { return makeFuture(() -> backing.deleteTrack(track)); } @Override - public LPFuture saveUUIDData(String username, UUID uuid) { + public CompletableFuture saveUUIDData(String username, UUID uuid) { return makeFuture(() -> backing.saveUUIDData(username, uuid)); } @Override - public LPFuture getUUID(String username) { + public CompletableFuture getUUID(String username) { return makeFuture(() -> backing.getUUID(username)); } @Override - public LPFuture getName(UUID uuid) { + public CompletableFuture getName(UUID uuid) { return makeFuture(() -> backing.getName(uuid)); } @@ -167,8 +160,6 @@ public class AbstractDatastore implements Datastore { String getName(); boolean isAcceptingLogins(); void setAcceptingLogins(boolean b); - void doAsync(Runnable r); - void doSync(Runnable r); void init(); void shutdown(); } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/BufferedOutputDatastore.java b/common/src/main/java/me/lucko/luckperms/common/storage/BufferedOutputStorage.java similarity index 75% rename from common/src/main/java/me/lucko/luckperms/common/storage/BufferedOutputDatastore.java rename to common/src/main/java/me/lucko/luckperms/common/storage/BufferedOutputStorage.java index d28418b1..694838e9 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/BufferedOutputDatastore.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/BufferedOutputStorage.java @@ -31,47 +31,47 @@ import me.lucko.luckperms.common.tracks.Track; import me.lucko.luckperms.common.users.User; import me.lucko.luckperms.common.users.UserIdentifier; import me.lucko.luckperms.common.utils.Buffer; -import me.lucko.luckperms.common.utils.LPFuture; import java.util.UUID; +import java.util.concurrent.CompletableFuture; @RequiredArgsConstructor(access = AccessLevel.PRIVATE) -public class BufferedOutputDatastore implements Datastore, Runnable { - public static BufferedOutputDatastore wrap(Datastore datastore, long flushTime) { - return new BufferedOutputDatastore(datastore, flushTime); +public class BufferedOutputStorage implements Storage, Runnable { + public static BufferedOutputStorage wrap(Storage storage, long flushTime) { + return new BufferedOutputStorage(storage, flushTime); } @Getter @Delegate(excludes = Exclude.class) - private final Datastore backing; + private final Storage backing; private final long flushTime; private final Buffer userOutputBuffer = new Buffer() { @Override public Boolean dequeue(User user) { - return backing.saveUser(user).getUnchecked(); + return backing.saveUser(user).join(); } }; private final Buffer groupOutputBuffer = new Buffer() { @Override public Boolean dequeue(Group group) { - return backing.saveGroup(group).getUnchecked(); + return backing.saveGroup(group).join(); } }; private final Buffer trackOutputBuffer = new Buffer() { @Override public Boolean dequeue(Track track) { - return backing.saveTrack(track).getUnchecked(); + return backing.saveTrack(track).join(); } }; private final Buffer uuidDataOutputBuffer = new Buffer() { @Override protected Boolean dequeue(UserIdentifier userIdentifier) { - return backing.saveUUIDData(userIdentifier.getUsername(), userIdentifier.getUuid()).getUnchecked(); + return backing.saveUUIDData(userIdentifier.getUsername(), userIdentifier.getUuid()).join(); } }; @@ -92,7 +92,7 @@ public class BufferedOutputDatastore implements Datastore, Runnable { } @Override - public Datastore force() { + public Storage force() { return backing; } @@ -103,31 +103,31 @@ public class BufferedOutputDatastore implements Datastore, Runnable { } @Override - public LPFuture saveUser(User user) { + public CompletableFuture saveUser(User user) { return userOutputBuffer.enqueue(user); } @Override - public LPFuture saveGroup(Group group) { + public CompletableFuture saveGroup(Group group) { return groupOutputBuffer.enqueue(group); } @Override - public LPFuture saveTrack(Track track) { + public CompletableFuture saveTrack(Track track) { return trackOutputBuffer.enqueue(track); } @Override - public LPFuture saveUUIDData(String username, UUID uuid) { + public CompletableFuture saveUUIDData(String username, UUID uuid) { return uuidDataOutputBuffer.enqueue(UserIdentifier.of(uuid, username)); } private interface Exclude { - Datastore force(); - LPFuture shutdown(); - LPFuture saveUser(User user); - LPFuture saveGroup(Group group); - LPFuture saveTrack(Track track); - LPFuture saveUUIDData(String username, UUID uuid); + Storage force(); + CompletableFuture shutdown(); + CompletableFuture saveUser(User user); + CompletableFuture saveGroup(Group group); + CompletableFuture saveTrack(Track track); + CompletableFuture saveUUIDData(String username, UUID uuid); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/Datastore.java b/common/src/main/java/me/lucko/luckperms/common/storage/Datastore.java deleted file mode 100644 index f4d07899..00000000 --- a/common/src/main/java/me/lucko/luckperms/common/storage/Datastore.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright (c) 2016 Lucko (Luck) - * - * 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.storage; - -import me.lucko.luckperms.api.LogEntry; -import me.lucko.luckperms.api.data.Callback; -import me.lucko.luckperms.common.data.Log; -import me.lucko.luckperms.common.groups.Group; -import me.lucko.luckperms.common.tracks.Track; -import me.lucko.luckperms.common.users.User; -import me.lucko.luckperms.common.utils.LPFuture; - -import java.util.Set; -import java.util.UUID; - -public interface Datastore { - - String getName(); - - boolean isAcceptingLogins(); - void setAcceptingLogins(boolean acceptingLogins); - - /** - * Execute a runnable asynchronously - * @param r the task to run - */ - void doAsync(Runnable r); - - /** - * Execute a runnable synchronously - * @param r the task to run - */ - void doSync(Runnable r); - - Datastore force(); - - void init(); - void shutdown(); - LPFuture logAction(LogEntry entry); - LPFuture getLog(); - LPFuture loadUser(UUID uuid, String username); - LPFuture saveUser(User user); - LPFuture cleanupUsers(); - LPFuture> getUniqueUsers(); - LPFuture createAndLoadGroup(String name); - LPFuture loadGroup(String name); - LPFuture loadAllGroups(); - LPFuture saveGroup(Group group); - LPFuture deleteGroup(Group group); - LPFuture createAndLoadTrack(String name); - LPFuture loadTrack(String name); - LPFuture loadAllTracks(); - LPFuture saveTrack(Track track); - LPFuture deleteTrack(Track track); - LPFuture saveUUIDData(String username, UUID uuid); - LPFuture getUUID(String username); - LPFuture getName(UUID uuid); - - default void logAction(LogEntry entry, Callback callback) { - doAsync(() -> { - boolean result = logAction(entry).getUnchecked(); - doSync(() -> callback.onComplete(result)); - }); - } - - default void getLog(Callback callback) { - doAsync(() -> { - Log result = getLog().getUnchecked(); - doSync(() -> callback.onComplete(result)); - }); - } - - default void loadUser(UUID uuid, String username, Callback callback) { - doAsync(() -> { - boolean result = loadUser(uuid, username).getUnchecked(); - doSync(() -> callback.onComplete(result)); - }); - } - - default void saveUser(User user, Callback callback) { - doAsync(() -> { - boolean result = saveUser(user).getUnchecked(); - doSync(() -> callback.onComplete(result)); - }); - } - - default void cleanupUsers(Callback callback) { - doAsync(() -> { - boolean result = cleanupUsers().getUnchecked(); - doSync(() -> callback.onComplete(result)); - }); - } - - default void getUniqueUsers(Callback> callback) { - doAsync(() -> { - Set result = getUniqueUsers().getUnchecked(); - doSync(() -> callback.onComplete(result)); - }); - } - - default void createAndLoadGroup(String name, Callback callback) { - doAsync(() -> { - boolean result = createAndLoadGroup(name).getUnchecked(); - doSync(() -> callback.onComplete(result)); - }); - } - - default void loadGroup(String name, Callback callback) { - doAsync(() -> { - boolean result = loadGroup(name).getUnchecked(); - doSync(() -> callback.onComplete(result)); - }); - } - - default void loadAllGroups(Callback callback) { - doAsync(() -> { - boolean result = loadAllGroups().getUnchecked(); - doSync(() -> callback.onComplete(result)); - }); - } - - default void saveGroup(Group group, Callback callback) { - doAsync(() -> { - boolean result = saveGroup(group).getUnchecked(); - doSync(() -> callback.onComplete(result)); - }); - } - - default void deleteGroup(Group group, Callback callback) { - doAsync(() -> { - boolean result = deleteGroup(group).getUnchecked(); - doSync(() -> callback.onComplete(result)); - }); - } - - default void createAndLoadTrack(String name, Callback callback) { - doAsync(() -> { - boolean result = createAndLoadTrack(name).getUnchecked(); - doSync(() -> callback.onComplete(result)); - }); - } - - default void loadTrack(String name, Callback callback) { - doAsync(() -> { - boolean result = loadTrack(name).getUnchecked(); - doSync(() -> callback.onComplete(result)); - }); - } - - default void loadAllTracks(Callback callback) { - doAsync(() -> { - boolean result = loadAllTracks().getUnchecked(); - doSync(() -> callback.onComplete(result)); - }); - } - - default void saveTrack(Track track, Callback callback) { - doAsync(() -> { - boolean result = saveTrack(track).getUnchecked(); - doSync(() -> callback.onComplete(result)); - }); - } - - default void deleteTrack(Track track, Callback callback) { - doAsync(() -> { - boolean result = deleteTrack(track).getUnchecked(); - doSync(() -> callback.onComplete(result)); - }); - } - - default void saveUUIDData(String username, UUID uuid, Callback callback) { - doAsync(() -> { - boolean result = saveUUIDData(username, uuid).getUnchecked(); - doSync(() -> callback.onComplete(result)); - }); - } - - default void getUUID(String username, Callback callback) { - doAsync(() -> { - UUID result = getUUID(username).getUnchecked(); - doSync(() -> callback.onComplete(result)); - }); - } - - default void getName(UUID uuid, Callback callback) { - doAsync(() -> { - String result = getName(uuid).getUnchecked(); - doSync(() -> callback.onComplete(result)); - }); - } -} 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 new file mode 100644 index 00000000..2177d335 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/storage/Storage.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * 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.storage; + +import me.lucko.luckperms.api.LogEntry; +import me.lucko.luckperms.common.data.Log; +import me.lucko.luckperms.common.groups.Group; +import me.lucko.luckperms.common.tracks.Track; +import me.lucko.luckperms.common.users.User; + +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; + +/** + * Main interface for all Storage providers. + */ +public interface Storage { + + String getName(); + boolean isAcceptingLogins(); + void setAcceptingLogins(boolean acceptingLogins); + Storage force(); + + void init(); + void shutdown(); + CompletableFuture logAction(LogEntry entry); + CompletableFuture getLog(); + CompletableFuture loadUser(UUID uuid, String username); + CompletableFuture saveUser(User user); + CompletableFuture cleanupUsers(); + CompletableFuture> getUniqueUsers(); + CompletableFuture createAndLoadGroup(String name); + CompletableFuture loadGroup(String name); + CompletableFuture loadAllGroups(); + CompletableFuture saveGroup(Group group); + CompletableFuture deleteGroup(Group group); + CompletableFuture createAndLoadTrack(String name); + CompletableFuture loadTrack(String name); + CompletableFuture loadAllTracks(); + CompletableFuture saveTrack(Track track); + CompletableFuture deleteTrack(Track track); + CompletableFuture saveUUIDData(String username, UUID uuid); + CompletableFuture getUUID(String username); + CompletableFuture getName(UUID uuid); +} diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java b/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java index fb531d0d..6ff3fe80 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java @@ -37,8 +37,8 @@ import java.util.Set; public class StorageFactory { private static final Set TYPES = ImmutableSet.of("json", "yaml", "flatfile", "mongodb", "mysql", "sqlite", "h2"); - public static Datastore getDatastore(LuckPermsPlugin plugin, String defaultMethod) { - Datastore datastore; + public static Storage getInstance(LuckPermsPlugin plugin, String defaultMethod) { + Storage storage; plugin.getLog().info("Detecting storage method..."); if (plugin.getConfiguration().isSplitStorage()) { @@ -63,7 +63,7 @@ public class StorageFactory { backing.put(type, backingFromString(type, plugin)); } - datastore = AbstractDatastore.wrap(plugin, new SplitBacking(plugin, backing, types)); + storage = AbstractStorage.wrap(plugin, new SplitBacking(plugin, backing, types)); } else { String storageMethod = plugin.getConfiguration().getStorageMethod().toLowerCase(); @@ -72,17 +72,17 @@ public class StorageFactory { storageMethod = defaultMethod; } - datastore = fromString(storageMethod, plugin); - plugin.getLog().info("Using " + datastore.getName() + " as storage method."); + storage = fromString(storageMethod, plugin); + plugin.getLog().info("Using " + storage.getName() + " as storage method."); } plugin.getLog().info("Initialising datastore..."); - datastore.init(); - return datastore; + storage.init(); + return storage; } - private static Datastore fromString(String storageMethod, LuckPermsPlugin plugin) { - return AbstractDatastore.wrap(plugin, backingFromString(storageMethod, plugin)); + private static Storage fromString(String storageMethod, LuckPermsPlugin plugin) { + return AbstractStorage.wrap(plugin, backingFromString(storageMethod, plugin)); } private static AbstractBacking backingFromString(String method, LuckPermsPlugin plugin) { diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/TolerantDatastore.java b/common/src/main/java/me/lucko/luckperms/common/storage/TolerantStorage.java similarity index 79% rename from common/src/main/java/me/lucko/luckperms/common/storage/TolerantDatastore.java rename to common/src/main/java/me/lucko/luckperms/common/storage/TolerantStorage.java index b06f3dcd..a467f845 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/TolerantDatastore.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/TolerantStorage.java @@ -30,30 +30,30 @@ import me.lucko.luckperms.common.data.Log; import me.lucko.luckperms.common.groups.Group; import me.lucko.luckperms.common.tracks.Track; import me.lucko.luckperms.common.users.User; -import me.lucko.luckperms.common.utils.LPFuture; import java.util.Set; import java.util.UUID; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.Phaser; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; /** - * A Datastore wrapping that ensures all tasks are completed before {@link Datastore#shutdown()} is called. + * A Datastore wrapping that ensures all tasks are completed before {@link Storage#shutdown()} is called. */ @RequiredArgsConstructor(access = AccessLevel.PRIVATE) -public class TolerantDatastore implements Datastore { - public static TolerantDatastore wrap(Datastore datastore) { - return new TolerantDatastore(datastore); +public class TolerantStorage implements Storage { + public static TolerantStorage wrap(Storage storage) { + return new TolerantStorage(storage); } @Delegate(types = Delegated.class) - private final Datastore backing; + private final Storage backing; private final Phaser phaser = new Phaser(); @Override - public Datastore force() { + public Storage force() { return this; } @@ -70,7 +70,7 @@ public class TolerantDatastore implements Datastore { } @Override - public LPFuture logAction(LogEntry entry) { + public CompletableFuture logAction(LogEntry entry) { phaser.register(); try { return backing.logAction(entry); @@ -80,7 +80,7 @@ public class TolerantDatastore implements Datastore { } @Override - public LPFuture getLog() { + public CompletableFuture getLog() { phaser.register(); try { return backing.getLog(); @@ -90,7 +90,7 @@ public class TolerantDatastore implements Datastore { } @Override - public LPFuture loadUser(UUID uuid, String username) { + public CompletableFuture loadUser(UUID uuid, String username) { phaser.register(); try { return backing.loadUser(uuid, username); @@ -100,7 +100,7 @@ public class TolerantDatastore implements Datastore { } @Override - public LPFuture saveUser(User user) { + public CompletableFuture saveUser(User user) { phaser.register(); try { return backing.saveUser(user); @@ -110,7 +110,7 @@ public class TolerantDatastore implements Datastore { } @Override - public LPFuture cleanupUsers() { + public CompletableFuture cleanupUsers() { phaser.register(); try { return backing.cleanupUsers(); @@ -120,7 +120,7 @@ public class TolerantDatastore implements Datastore { } @Override - public LPFuture> getUniqueUsers() { + public CompletableFuture> getUniqueUsers() { phaser.register(); try { return backing.getUniqueUsers(); @@ -130,7 +130,7 @@ public class TolerantDatastore implements Datastore { } @Override - public LPFuture createAndLoadGroup(String name) { + public CompletableFuture createAndLoadGroup(String name) { phaser.register(); try { return backing.createAndLoadGroup(name); @@ -140,7 +140,7 @@ public class TolerantDatastore implements Datastore { } @Override - public LPFuture loadGroup(String name) { + public CompletableFuture loadGroup(String name) { phaser.register(); try { return backing.loadGroup(name); @@ -150,7 +150,7 @@ public class TolerantDatastore implements Datastore { } @Override - public LPFuture loadAllGroups() { + public CompletableFuture loadAllGroups() { phaser.register(); try { return backing.loadAllGroups(); @@ -160,7 +160,7 @@ public class TolerantDatastore implements Datastore { } @Override - public LPFuture saveGroup(Group group) { + public CompletableFuture saveGroup(Group group) { phaser.register(); try { return backing.saveGroup(group); @@ -170,7 +170,7 @@ public class TolerantDatastore implements Datastore { } @Override - public LPFuture deleteGroup(Group group) { + public CompletableFuture deleteGroup(Group group) { phaser.register(); try { return backing.deleteGroup(group); @@ -180,7 +180,7 @@ public class TolerantDatastore implements Datastore { } @Override - public LPFuture createAndLoadTrack(String name) { + public CompletableFuture createAndLoadTrack(String name) { phaser.register(); try { return backing.createAndLoadTrack(name); @@ -190,7 +190,7 @@ public class TolerantDatastore implements Datastore { } @Override - public LPFuture loadTrack(String name) { + public CompletableFuture loadTrack(String name) { phaser.register(); try { return backing.loadTrack(name); @@ -200,7 +200,7 @@ public class TolerantDatastore implements Datastore { } @Override - public LPFuture loadAllTracks() { + public CompletableFuture loadAllTracks() { phaser.register(); try { return backing.loadAllTracks(); @@ -210,7 +210,7 @@ public class TolerantDatastore implements Datastore { } @Override - public LPFuture saveTrack(Track track) { + public CompletableFuture saveTrack(Track track) { phaser.register(); try { return backing.saveTrack(track); @@ -220,7 +220,7 @@ public class TolerantDatastore implements Datastore { } @Override - public LPFuture deleteTrack(Track track) { + public CompletableFuture deleteTrack(Track track) { phaser.register(); try { return backing.deleteTrack(track); @@ -230,7 +230,7 @@ public class TolerantDatastore implements Datastore { } @Override - public LPFuture saveUUIDData(String username, UUID uuid) { + public CompletableFuture saveUUIDData(String username, UUID uuid) { phaser.register(); try { return backing.saveUUIDData(username, uuid); @@ -240,7 +240,7 @@ public class TolerantDatastore implements Datastore { } @Override - public LPFuture getUUID(String username) { + public CompletableFuture getUUID(String username) { phaser.register(); try { return backing.getUUID(username); @@ -250,7 +250,7 @@ public class TolerantDatastore implements Datastore { } @Override - public LPFuture getName(UUID uuid) { + public CompletableFuture getName(UUID uuid) { phaser.register(); try { return backing.getName(uuid); @@ -263,8 +263,6 @@ public class TolerantDatastore implements Datastore { String getName(); boolean isAcceptingLogins(); void setAcceptingLogins(boolean b); - void doAsync(Runnable r); - void doSync(Runnable r); void init(); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/AbstractBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/AbstractBacking.java index 3768486a..00fab17f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/AbstractBacking.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/AbstractBacking.java @@ -38,6 +38,8 @@ import java.util.UUID; @RequiredArgsConstructor(access = AccessLevel.PROTECTED) public abstract class AbstractBacking { + + @Getter protected final LuckPermsPlugin plugin; @Getter @@ -47,22 +49,6 @@ public abstract class AbstractBacking { @Setter private boolean acceptingLogins = false; - /** - * Execute a runnable asynchronously - * @param r the task to run - */ - public void doAsync(Runnable r) { - plugin.doAsync(r); - } - - /** - * Execute a runnable synchronously - * @param r the task to run - */ - public void doSync(Runnable r) { - plugin.doSync(r); - } - public abstract void init(); public abstract void shutdown(); public abstract boolean logAction(LogEntry entry); diff --git a/common/src/main/java/me/lucko/luckperms/common/users/UserManager.java b/common/src/main/java/me/lucko/luckperms/common/users/UserManager.java index 08f8829d..d64f3c26 100644 --- a/common/src/main/java/me/lucko/luckperms/common/users/UserManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/users/UserManager.java @@ -24,7 +24,6 @@ package me.lucko.luckperms.common.users; import lombok.RequiredArgsConstructor; import me.lucko.luckperms.api.Node; -import me.lucko.luckperms.api.data.Callback; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.utils.AbstractManager; import me.lucko.luckperms.common.utils.Identifiable; @@ -81,7 +80,7 @@ public class UserManager extends AbstractManager { } catch (ObjectAlreadyHasException ignored) {} if (save) { - plugin.getDatastore().saveUser(user, Callback.empty()); + plugin.getStorage().saveUser(user); } return true; @@ -134,7 +133,7 @@ public class UserManager extends AbstractManager { plugin.doAsync(() -> { for (UUID uuid : players) { UUID internal = plugin.getUuidCache().getUUID(uuid); - plugin.getDatastore().loadUser(internal, "null").getUnchecked(); + plugin.getStorage().loadUser(internal, "null").join(); User user = get(internal); user.getRefreshBuffer().request(); } diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/AbstractFuture.java b/common/src/main/java/me/lucko/luckperms/common/utils/AbstractFuture.java deleted file mode 100644 index 65fd6eb0..00000000 --- a/common/src/main/java/me/lucko/luckperms/common/utils/AbstractFuture.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2016 Lucko (Luck) - * - * 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.utils; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -/** - * Basic Future implementation - * @param the return type - */ -public class AbstractFuture implements LPFuture { - private final CountDownLatch latch = new CountDownLatch(1); - private R value; - - public void complete(R r) { - value = r; - latch.countDown(); - } - - @Override - public boolean cancel(boolean mayInterruptIfRunning) { - // Not supported - return false; - } - - @Override - public boolean isCancelled() { - return false; - } - - @Override - public boolean isDone() { - return latch.getCount() == 0; - } - - @Override - public R get() throws InterruptedException { - latch.await(); - return value; - } - - @Override - public R get(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException { - if (latch.await(timeout, unit)) { - return value; - } else { - throw new TimeoutException(); - } - } -} diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/AbstractListener.java b/common/src/main/java/me/lucko/luckperms/common/utils/AbstractListener.java index 927892cd..de4c9808 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/AbstractListener.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/AbstractListener.java @@ -23,7 +23,6 @@ package me.lucko.luckperms.common.utils; import lombok.AllArgsConstructor; -import me.lucko.luckperms.api.data.Callback; import me.lucko.luckperms.api.event.events.UserFirstLoginEvent; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.core.UuidCache; @@ -44,26 +43,26 @@ public class AbstractListener { final UuidCache cache = plugin.getUuidCache(); if (!cache.isOnlineMode()) { - UUID uuid = plugin.getDatastore().force().getUUID(username).getUnchecked(); + UUID uuid = plugin.getStorage().force().getUUID(username).join(); if (uuid != null) { cache.addToCache(u, uuid); } else { // No previous data for this player plugin.getApiProvider().fireEventAsync(new UserFirstLoginEvent(u, username)); cache.addToCache(u, u); - plugin.getDatastore().force().saveUUIDData(username, u, Callback.empty()); + plugin.getStorage().force().saveUUIDData(username, u); } } else { - UUID uuid = plugin.getDatastore().force().getUUID(username).getUnchecked(); + UUID uuid = plugin.getStorage().force().getUUID(username).join(); if (uuid == null) { plugin.getApiProvider().fireEventAsync(new UserFirstLoginEvent(u, username)); } // Online mode, no cache needed. This is just for name -> uuid lookup. - plugin.getDatastore().force().saveUUIDData(username, u, Callback.empty()); + plugin.getStorage().force().saveUUIDData(username, u); } - plugin.getDatastore().force().loadUser(cache.getUUID(u), username).getUnchecked(); + plugin.getStorage().force().loadUser(cache.getUUID(u), username).join(); User user = plugin.getUserManager().get(cache.getUUID(u)); if (user == null) { plugin.getLog().warn("Failed to load user: " + username); @@ -78,7 +77,7 @@ public class AbstractListener { // If they were given a default, persist the new assignments back to the storage. if (save) { - plugin.getDatastore().force().saveUser(user).getUnchecked(); + plugin.getStorage().force().saveUser(user).join(); } user.setupData(false); // Pretty nasty calculation call. Sets up the caching system so data is ready when the user joins. diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/Buffer.java b/common/src/main/java/me/lucko/luckperms/common/utils/Buffer.java index 743ae4ac..c7a5bad2 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/Buffer.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/Buffer.java @@ -27,6 +27,7 @@ import lombok.*; import java.util.LinkedList; import java.util.List; import java.util.ListIterator; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.locks.ReentrantLock; /** @@ -42,7 +43,7 @@ public abstract class Buffer implements Runnable { private final ReentrantLock lock = new ReentrantLock(); private final List> buffer = new LinkedList<>(); - public LPFuture enqueue(@NonNull T t) { + public CompletableFuture enqueue(@NonNull T t) { lock.lock(); try { ListIterator> it = buffer.listIterator(); @@ -60,7 +61,7 @@ public abstract class Buffer implements Runnable { } if (o == null) { - o = new BufferedObject<>(System.currentTimeMillis(), t, new AbstractFuture()); + o = new BufferedObject<>(System.currentTimeMillis(), t, new CompletableFuture()); } else { o.setBufferTime(System.currentTimeMillis()); } @@ -111,7 +112,7 @@ public abstract class Buffer implements Runnable { @Setter private long bufferTime; private final T object; - private final AbstractFuture future; + private final CompletableFuture future; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/BufferedRequest.java b/common/src/main/java/me/lucko/luckperms/common/utils/BufferedRequest.java index 2962102e..2d91c660 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/BufferedRequest.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/BufferedRequest.java @@ -26,8 +26,9 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import java.lang.ref.WeakReference; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executor; import java.util.concurrent.locks.ReentrantLock; -import java.util.function.Consumer; import java.util.function.Supplier; /** @@ -41,12 +42,12 @@ import java.util.function.Supplier; @RequiredArgsConstructor public abstract class BufferedRequest { private final long bufferTimeMillis; - private final Consumer executor; + private final Executor executor; private WeakReference> processor = null; private ReentrantLock lock = new ReentrantLock(); - public LPFuture request() { + public CompletableFuture request() { lock.lock(); try { if (processor != null) { @@ -57,7 +58,7 @@ public abstract class BufferedRequest { } Processor p = new Processor<>(bufferTimeMillis, this::perform); - executor.accept(p); + executor.execute(p); processor = new WeakReference<>(p); return p.get(); @@ -82,7 +83,7 @@ public abstract class BufferedRequest { private final ReentrantLock lock = new ReentrantLock(); private long executionTime; - private final AbstractFuture future = new AbstractFuture<>(); + private final CompletableFuture future = new CompletableFuture(); @Override public void run() { @@ -116,11 +117,11 @@ public abstract class BufferedRequest { future.complete(result); } - public LPFuture get() { + public CompletableFuture get() { return future; } - public LPFuture getAndExtend() { + public CompletableFuture getAndExtend() { lock.lock(); try { executionTime = System.currentTimeMillis() + delayMillis; diff --git a/default-lang.yml b/default-lang.yml index a15d2051..315594f0 100644 --- a/default-lang.yml +++ b/default-lang.yml @@ -21,16 +21,16 @@ does-not-have-temp-permission: "{0} does not have this permission set temporaril user-not-found: "&bUser could not be found." -user-save-success: "&7(User data was saved to the datastore)" +user-save-success: "&7(User data was saved to storage)" user-save-error: "There was an error whilst saving the user." user-create-fail: "There was an error whilst creating a new user." group-not-found: "&bGroup could not be found." -group-save-success: "&7(Group data was saved to the datastore)" +group-save-success: "&7(Group data was saved to storage)" group-save-error: "There was an error whilst saving the group." track-not-found: "&bTrack could not be found." -track-save-success: "&7(Track data was saved to the datastore)" +track-save-success: "&7(Track data was saved to storage)" track-save-error: "There was an error whilst saving the track." diff --git a/pom.xml b/pom.xml index f43107ac..3eecac1e 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.lucko.luckperms luckperms - 2.13-SNAPSHOT + 2.14-SNAPSHOT common api @@ -38,7 +38,7 @@ UTF-8 - 2.13 + 2.14 diff --git a/sponge/pom.xml b/sponge/pom.xml index 2c083d87..da0ac680 100644 --- a/sponge/pom.xml +++ b/sponge/pom.xml @@ -5,7 +5,7 @@ luckperms me.lucko.luckperms - 2.13-SNAPSHOT + 2.14-SNAPSHOT 4.0.0 diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java index 9bcd6981..da2692ba 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java @@ -43,7 +43,7 @@ import me.lucko.luckperms.common.groups.GroupManager; import me.lucko.luckperms.common.messaging.RedisMessaging; import me.lucko.luckperms.common.runnables.ExpireTemporaryTask; import me.lucko.luckperms.common.runnables.UpdateTask; -import me.lucko.luckperms.common.storage.Datastore; +import me.lucko.luckperms.common.storage.Storage; import me.lucko.luckperms.common.storage.StorageFactory; import me.lucko.luckperms.common.tracks.TrackManager; import me.lucko.luckperms.common.users.UserManager; @@ -77,6 +77,7 @@ import java.io.File; import java.nio.file.Path; import java.util.*; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -105,6 +106,8 @@ public class LPSpongePlugin implements LuckPermsPlugin { private Path configDir; private Scheduler scheduler = Sponge.getScheduler(); + private Executor syncExecutor = Sponge.getScheduler().createSyncExecutor(this); + private Executor asyncExecutor = Sponge.getScheduler().createAsyncExecutor(this); private LPTimings timings; private final Set ignoringLogs = ConcurrentHashMap.newKeySet(); @@ -112,7 +115,7 @@ public class LPSpongePlugin implements LuckPermsPlugin { private UserManager userManager; private GroupManager groupManager; private TrackManager trackManager; - private Datastore datastore; + private Storage storage; private RedisMessaging redisMessaging = null; private UuidCache uuidCache; private ApiProvider apiProvider; @@ -141,7 +144,7 @@ public class LPSpongePlugin implements LuckPermsPlugin { Sponge.getEventManager().registerListeners(this, new SpongeListener(this)); // initialise datastore - datastore = StorageFactory.getDatastore(this, "h2"); + storage = StorageFactory.getInstance(this, "h2"); // initialise redis if (getConfiguration().isRedisEnabled()) { @@ -228,7 +231,7 @@ public class LPSpongePlugin implements LuckPermsPlugin { @Listener public void onDisable(GameStoppingServerEvent event) { getLog().info("Closing datastore..."); - datastore.shutdown(); + storage.shutdown(); if (redisMessaging != null) { getLog().info("Closing redis..."); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeListener.java b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeListener.java index 80f9cc09..21f3e0c8 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeListener.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeListener.java @@ -52,7 +52,7 @@ public class SpongeListener extends AbstractListener { @Listener(order = Order.EARLY) public void onClientAuth(ClientConnectionEvent.Auth e) { - if (!plugin.getDatastore().isAcceptingLogins()) { + if (!plugin.getStorage().isAcceptingLogins()) { /* Datastore is disabled, prevent players from joining the server Just don't load their data, they will be kicked at login */ return; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionManager.java b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionManager.java index 690ec8d3..c4bd725a 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionManager.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionManager.java @@ -89,10 +89,10 @@ public class MigrationPermissionManager extends SubCommand { groupCount++; // Make a LuckPerms group for the one being migrated - plugin.getDatastore().createAndLoadGroup(pmGroup.getIdentifier().toLowerCase()).getUnchecked(); + plugin.getStorage().createAndLoadGroup(pmGroup.getIdentifier().toLowerCase()).join(); Group group = plugin.getGroupManager().get(pmGroup.getIdentifier().toLowerCase()); migrateSubject(pmGroup, group); - plugin.getDatastore().saveGroup(group); + plugin.getStorage().saveGroup(group); } log.info("PermissionManager Migration: Migrated " + groupCount + " groups"); @@ -117,10 +117,10 @@ public class MigrationPermissionManager extends SubCommand { } // Make a LuckPerms user for the one being migrated - plugin.getDatastore().loadUser(uuid, "null").getUnchecked(); + plugin.getStorage().loadUser(uuid, "null").join(); User user = plugin.getUserManager().get(uuid); migrateSubject(pmUser, user); - plugin.getDatastore().saveUser(user); + plugin.getStorage().saveUser(user); plugin.getUserManager().cleanup(user); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionsEx.java b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionsEx.java index d8ed57e1..5106a640 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionsEx.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionsEx.java @@ -69,10 +69,10 @@ public class MigrationPermissionsEx extends SubCommand { groupCount++; // Make a LuckPerms group for the one being migrated - plugin.getDatastore().createAndLoadGroup(pexGroup.getIdentifier().toLowerCase()).getUnchecked(); + plugin.getStorage().createAndLoadGroup(pexGroup.getIdentifier().toLowerCase()).join(); Group group = plugin.getGroupManager().get(pexGroup.getIdentifier().toLowerCase()); migrateSubject(pexGroup, group); - plugin.getDatastore().saveGroup(group); + plugin.getStorage().saveGroup(group); } log.info("PermissionsEx Migration: Migrated " + groupCount + " groups"); @@ -88,10 +88,10 @@ public class MigrationPermissionsEx extends SubCommand { } // Make a LuckPerms user for the one being migrated - plugin.getDatastore().loadUser(uuid, "null").getUnchecked(); + plugin.getStorage().loadUser(uuid, "null").join(); User user = plugin.getUserManager().get(uuid); migrateSubject(pexUser, user); - plugin.getDatastore().saveUser(user); + plugin.getStorage().saveUser(user); plugin.getUserManager().cleanup(user); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsSubjectData.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsSubjectData.java index e454d1da..91d34fa9 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsSubjectData.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsSubjectData.java @@ -59,10 +59,12 @@ public class LuckPermsSubjectData implements SubjectData { private void objectSave(PermissionHolder t) { if (t instanceof User) { - service.getPlugin().getDatastore().saveUser(((User) t), b -> ((User) t).getRefreshBuffer().request()); + service.getPlugin().getStorage().saveUser(((User) t)) + .thenRunAsync(() -> ((User) t).getRefreshBuffer().request(), service.getPlugin().getAsyncExecutor()); } if (t instanceof Group) { - service.getPlugin().getDatastore().saveGroup(((Group) t), b -> service.getPlugin().getUpdateTaskBuffer().request()); + service.getPlugin().getStorage().saveGroup((Group) t) + .thenRunAsync(() -> service.getPlugin().getUpdateTaskBuffer().request(), service.getPlugin().getAsyncExecutor()); } } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/collections/GroupCollection.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/collections/GroupCollection.java index 6caea5bf..9cc7faff 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/collections/GroupCollection.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/collections/GroupCollection.java @@ -97,7 +97,7 @@ public class GroupCollection implements SubjectCollection { if (!manager.isLoaded(id)) { service.getPlugin().getLog().warn("Group Subject '" + id + "' was requested, but is not loaded in memory. Loading it from storage now."); long startTime = System.currentTimeMillis(); - service.getPlugin().getDatastore().createAndLoadGroup(id).getUnchecked(); + service.getPlugin().getStorage().createAndLoadGroup(id).join(); service.getPlugin().getLog().warn("Loading '" + id + "' took " + (System.currentTimeMillis() - startTime) + " ms."); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/collections/UserCollection.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/collections/UserCollection.java index ebe9a369..4bf3b7dc 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/collections/UserCollection.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/collections/UserCollection.java @@ -109,7 +109,7 @@ public class UserCollection implements SubjectCollection { if (!manager.isLoaded(UserIdentifier.of(u, null))) { service.getPlugin().getLog().warn("User Subject '" + u + "' was requested, but is not loaded in memory. Loading them from storage now."); long startTime = System.currentTimeMillis(); - service.getPlugin().getDatastore().loadUser(u, "null").getUnchecked(); + service.getPlugin().getStorage().loadUser(u, "null").join(); service.getPlugin().getLog().warn("Loading '" + u + "' took " + (System.currentTimeMillis() - startTime) + " ms."); }