From 33c78e4a17d7b64ee89c25818d821d668e187045 Mon Sep 17 00:00:00 2001 From: Luck Date: Sat, 22 Oct 2016 20:39:26 +0100 Subject: [PATCH] Use LoadingCache instead of a regular map + more datastore fixes --- .../luckperms/bukkit/LPBukkitPlugin.java | 2 +- .../bukkit/inject/LPPermissible.java | 2 +- .../luckperms/bungee/BungeeListener.java | 10 +-- .../common/api/internal/DatastoreLink.java | 40 +++++----- .../luckperms/common/caching/UserData.java | 77 ++++++++++++------- .../calculators/PermissionCalculator.java | 18 +++-- .../luckperms/common/commands/SubCommand.java | 8 +- .../commands/generic/parent/ParentAdd.java | 2 +- .../generic/parent/ParentAddTemp.java | 2 +- .../common/commands/group/CreateGroup.java | 4 +- .../common/commands/group/DeleteGroup.java | 4 +- .../commands/group/GroupMainCommand.java | 2 +- .../common/commands/group/ListGroups.java | 2 +- .../group/subcommands/GroupClone.java | 4 +- .../group/subcommands/GroupRename.java | 6 +- .../group/subcommands/GroupShowTracks.java | 2 +- .../common/commands/log/LogMainCommand.java | 2 +- .../commands/log/subcommands/LogRecent.java | 2 +- .../log/subcommands/LogUserHistory.java | 2 +- .../subcommands/MigrationBPermissions.java | 4 +- .../subcommands/MigrationBungeePerms.java | 4 +- .../subcommands/MigrationGroupManager.java | 6 +- .../subcommands/MigrationPermissionsEx.java | 4 +- .../subcommands/MigrationPowerfulPerms.java | 4 +- .../subcommands/MigrationZPermissions.java | 6 +- .../common/commands/misc/ExportCommand.java | 4 +- .../common/commands/misc/SyncCommand.java | 2 +- .../common/commands/track/CreateTrack.java | 4 +- .../common/commands/track/DeleteTrack.java | 4 +- .../common/commands/track/ListTracks.java | 2 +- .../commands/track/TrackMainCommand.java | 2 +- .../track/subcommands/TrackAppend.java | 2 +- .../track/subcommands/TrackClone.java | 4 +- .../track/subcommands/TrackInsert.java | 2 +- .../track/subcommands/TrackRename.java | 6 +- .../common/commands/user/UserMainCommand.java | 6 +- .../commands/user/subcommands/UserDemote.java | 4 +- .../user/subcommands/UserPromote.java | 4 +- .../user/subcommands/UserShowPos.java | 2 +- .../user/subcommands/UserShowTracks.java | 2 +- .../subcommands/BulkEditGroup.java | 4 +- .../subcommands/BulkEditPermission.java | 4 +- .../common/runnables/UpdateTask.java | 6 +- .../common/storage/AbstractDatastore.java | 17 ++-- .../storage/BufferedOutputDatastore.java | 12 +-- .../luckperms/common/storage/Datastore.java | 40 +++++----- .../common/storage/SplitBacking.java | 10 +-- .../common/storage/StorageFactory.java | 14 ++-- .../common/storage/TolerantDatastore.java | 4 +- .../luckperms/common/users/UserManager.java | 2 +- .../common/utils/AbstractListener.java | 8 +- .../luckperms/common/utils/LPFuture.java | 11 +-- 52 files changed, 210 insertions(+), 191 deletions(-) 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 9b5df273..01114bb6 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java @@ -198,7 +198,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { public void onDisable() { started = false; getLog().info("Closing datastore..."); - datastore.shutdown().getOrDefault(null); + datastore.shutdown(); getLog().info("Unregistering API..."); ApiHandler.unregisterProvider(); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/LPPermissible.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/LPPermissible.java index 0bec27eb..f3ae1b11 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/LPPermissible.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/LPPermissible.java @@ -222,7 +222,7 @@ public class LPPermissible extends PermissibleBase { } if (hasData()) { - user.getUserData().invalidateCache(); + user.getUserData().invalidatePermissionCalculators(); } } 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 41e07102..9a205890 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java @@ -95,28 +95,28 @@ public class BungeeListener extends AbstractListener implements Listener { final PendingConnection c = e.getConnection(); if (!cache.isOnlineMode()) { - UUID uuid = plugin.getDatastore().getUUID(c.getName()).getOrDefault(null); + UUID uuid = plugin.getDatastore().getUUID(c.getName()).getUnchecked(); 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()).getOrDefault(false); + plugin.getDatastore().force().saveUUIDData(c.getName(), c.getUniqueId()).getUnchecked(); } } else { - UUID uuid = plugin.getDatastore().getUUID(c.getName()).getOrDefault(null); + UUID uuid = plugin.getDatastore().getUUID(c.getName()).getUnchecked(); 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()).getOrDefault(false); + plugin.getDatastore().force().saveUUIDData(c.getName(), c.getUniqueId()).getUnchecked(); } // 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()).getOrDefault(false); + plugin.getDatastore().force().loadUser(cache.getUUID(c.getUniqueId()), c.getName()).getUnchecked(); User user = plugin.getUserManager().get(cache.getUUID(c.getUniqueId())); if (user == null) { plugin.getLog().warn("Failed to load user: " + c.getName()); 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 5b90acea..ee70f59b 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 @@ -206,12 +206,12 @@ public class DatastoreLink implements Datastore { @Override public boolean logAction(@NonNull LogEntry entry) { - return master.logAction(entry).getOrDefault(false); + return master.logAction(entry).getUnchecked(); } @Override public Log getLog() { - me.lucko.luckperms.common.data.Log log = master.getLog().getOrDefault(null); + me.lucko.luckperms.common.data.Log log = master.getLog().getUnchecked(); if (log == null) { return null; } @@ -220,54 +220,54 @@ public class DatastoreLink implements Datastore { @Override public boolean loadOrCreateUser(@NonNull UUID uuid, @NonNull String username) { - return master.loadUser(uuid, checkUsername(username)).getOrDefault(false); + return master.loadUser(uuid, checkUsername(username)).getUnchecked(); } @Override public boolean loadUser(@NonNull UUID uuid) { - return master.loadUser(uuid, "null").getOrDefault(false); + return master.loadUser(uuid, "null").getUnchecked(); } @Override public boolean loadUser(@NonNull UUID uuid, @NonNull String username) { - return master.loadUser(uuid, checkUsername(username)).getOrDefault(false); + return master.loadUser(uuid, checkUsername(username)).getUnchecked(); } @Override public boolean saveUser(@NonNull User user) { checkUser(user); - return master.saveUser(((UserLink) user).getMaster()).getOrDefault(false); + return master.saveUser(((UserLink) user).getMaster()).getUnchecked(); } @Override public boolean cleanupUsers() { - return master.cleanupUsers().getOrDefault(false); + return master.cleanupUsers().getUnchecked(); } @Override public Set getUniqueUsers() { - return master.getUniqueUsers().getOrDefault(null); + return master.getUniqueUsers().getUnchecked(); } @Override public boolean createAndLoadGroup(@NonNull String name) { - return master.createAndLoadGroup(checkName(name)).getOrDefault(false); + return master.createAndLoadGroup(checkName(name)).getUnchecked(); } @Override public boolean loadGroup(@NonNull String name) { - return master.loadGroup(checkName(name)).getOrDefault(false); + return master.loadGroup(checkName(name)).getUnchecked(); } @Override public boolean loadAllGroups() { - return master.loadAllGroups().getOrDefault(false); + return master.loadAllGroups().getUnchecked(); } @Override public boolean saveGroup(@NonNull Group group) { checkGroup(group); - return master.saveGroup(((GroupLink) group).getMaster()).getOrDefault(false); + return master.saveGroup(((GroupLink) group).getMaster()).getUnchecked(); } @Override @@ -276,44 +276,44 @@ public class DatastoreLink implements Datastore { if (group.getName().equalsIgnoreCase(plugin.getConfiguration().getDefaultGroupName())) { throw new IllegalArgumentException("Cannot delete the default group."); } - return master.deleteGroup(((GroupLink) group).getMaster()).getOrDefault(false); + return master.deleteGroup(((GroupLink) group).getMaster()).getUnchecked(); } @Override public boolean createAndLoadTrack(@NonNull String name) { - return master.createAndLoadTrack(checkName(name)).getOrDefault(false); + return master.createAndLoadTrack(checkName(name)).getUnchecked(); } @Override public boolean loadTrack(@NonNull String name) { - return master.loadTrack(checkName(name)).getOrDefault(false); + return master.loadTrack(checkName(name)).getUnchecked(); } @Override public boolean loadAllTracks() { - return master.loadAllTracks().getOrDefault(false); + return master.loadAllTracks().getUnchecked(); } @Override public boolean saveTrack(@NonNull Track track) { checkTrack(track); - return master.saveTrack(((TrackLink) track).getMaster()).getOrDefault(false); + return master.saveTrack(((TrackLink) track).getMaster()).getUnchecked(); } @Override public boolean deleteTrack(@NonNull Track track) { checkTrack(track); - return master.deleteTrack(((TrackLink) track).getMaster()).getOrDefault(false); + return master.deleteTrack(((TrackLink) track).getMaster()).getUnchecked(); } @Override public boolean saveUUIDData(@NonNull String username, @NonNull UUID uuid) { - return master.saveUUIDData(checkUsername(username), uuid).getOrDefault(false); + return master.saveUUIDData(checkUsername(username), uuid).getUnchecked(); } @Override public UUID getUUID(@NonNull String username) { - return master.getUUID(checkUsername(username)).getOrDefault(null); + return master.getUUID(checkUsername(username)).getUnchecked(); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/caching/UserData.java b/common/src/main/java/me/lucko/luckperms/common/caching/UserData.java index a95ec2c7..4b3a5acd 100644 --- a/common/src/main/java/me/lucko/luckperms/common/caching/UserData.java +++ b/common/src/main/java/me/lucko/luckperms/common/caching/UserData.java @@ -22,14 +22,18 @@ package me.lucko.luckperms.common.caching; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import com.google.common.collect.ImmutableSet; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; import lombok.RequiredArgsConstructor; import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.common.calculators.CalculatorFactory; import me.lucko.luckperms.common.users.User; -import java.util.Map; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; /** * Holds an easily accessible cache of a user's data in a number of contexts @@ -47,8 +51,33 @@ public class UserData { */ private final CalculatorFactory calculatorFactory; - private final Map permission = new ConcurrentHashMap<>(); - private final Map meta = new ConcurrentHashMap<>(); + private final LoadingCache permission = CacheBuilder.newBuilder() + .build(new CacheLoader() { + @Override + public PermissionData load(Contexts contexts) { + return calculatePermissions(contexts); + } + + @Override + public ListenableFuture reload(Contexts contexts, PermissionData oldData) { + oldData.comparePermissions(user.exportNodes(contexts, true)); + return Futures.immediateFuture(oldData); + } + }); + + private final LoadingCache meta = CacheBuilder.newBuilder() + .build(new CacheLoader() { + @Override + public MetaData load(Contexts contexts) { + return calculateMeta(contexts); + } + + @Override + public ListenableFuture reload(Contexts contexts, MetaData oldData) { + oldData.loadMeta(user.getAllNodes(null, contexts)); + return Futures.immediateFuture(oldData); + } + }); /** * Gets PermissionData from the cache, given a specified context. @@ -57,7 +86,7 @@ public class UserData { * @return a permission data instance */ public PermissionData getPermissionData(Contexts contexts) { - return permission.computeIfAbsent(contexts, this::calculatePermissions); + return permission.getUnchecked(contexts); } /** @@ -67,7 +96,7 @@ public class UserData { * @return a meta data instance */ public MetaData getMetaData(Contexts contexts) { - return meta.computeIfAbsent(contexts, this::calculateMeta); + return meta.getUnchecked(contexts); } /** @@ -98,14 +127,7 @@ public class UserData { * @param contexts the contexts to recalculate in. */ public void recalculatePermissions(Contexts contexts) { - permission.compute(contexts, (c, data) -> { - if (data == null) { - data = new PermissionData(c, user, calculatorFactory); - } - - data.comparePermissions(user.exportNodes(c, true)); - return data; - }); + permission.refresh(contexts); } /** @@ -114,28 +136,23 @@ public class UserData { * @param contexts the contexts to recalculate in. */ public void recalculateMeta(Contexts contexts) { - meta.compute(contexts, (c, data) -> { - if (data == null) { - data = new MetaData(c); - } - - data.loadMeta(user.getAllNodes(null, c)); - return data; - }); + meta.refresh(contexts); } /** * Calls {@link #recalculatePermissions(Contexts)} for all current loaded contexts */ public void recalculatePermissions() { - permission.keySet().forEach(this::recalculatePermissions); + Set keys = ImmutableSet.copyOf(permission.asMap().keySet()); + keys.forEach(permission::refresh); } /** * Calls {@link #recalculateMeta(Contexts)} for all current loaded contexts */ public void recalculateMeta() { - meta.keySet().forEach(this::recalculateMeta); + Set keys = ImmutableSet.copyOf(meta.asMap().keySet()); + keys.forEach(meta::refresh); } /** @@ -152,13 +169,17 @@ public class UserData { * @param contexts the contexts to pre-calculate for */ public void preCalculate(Contexts contexts) { - getPermissionData(contexts); - getMetaData(contexts); + permission.getUnchecked(contexts); + meta.getUnchecked(contexts); } public void invalidateCache() { - permission.clear(); - meta.clear(); + permission.invalidateAll(); + meta.invalidateAll(); + } + + public void invalidatePermissionCalculators() { + permission.asMap().values().forEach(PermissionData::invalidateCache); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/calculators/PermissionCalculator.java b/common/src/main/java/me/lucko/luckperms/common/calculators/PermissionCalculator.java index e1b10dd6..24a0d378 100644 --- a/common/src/main/java/me/lucko/luckperms/common/calculators/PermissionCalculator.java +++ b/common/src/main/java/me/lucko/luckperms/common/calculators/PermissionCalculator.java @@ -22,13 +22,14 @@ package me.lucko.luckperms.common.calculators; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; import lombok.RequiredArgsConstructor; import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.common.LuckPermsPlugin; import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; /** * Calculates and caches permissions @@ -39,15 +40,22 @@ public class PermissionCalculator { private final String objectName; private final boolean debug; private final List processors; - private final Map cache = new ConcurrentHashMap<>(); + + private final LoadingCache cache = CacheBuilder.newBuilder() + .build(new CacheLoader() { + @Override + public Tristate load(String s) { + return lookupPermissionValue(s); + } + }); public void invalidateCache() { - cache.clear(); + cache.invalidateAll(); } public Tristate getPermissionValue(String permission) { permission = permission.toLowerCase(); - Tristate t = cache.computeIfAbsent(permission, this::lookupPermissionValue); + Tristate t = cache.getUnchecked(permission); if (debug) { plugin.getLog().info("Checking if " + objectName + " has permission: " + permission + " - (" + t.toString() + ")"); 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 ab085a30..96eb937e 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 @@ -162,17 +162,17 @@ public abstract class SubCommand { } public static void save(User user, Sender sender, LuckPermsPlugin plugin) { - if (plugin.getDatastore().saveUser(user).getOrDefault(false)) { + if (plugin.getDatastore().saveUser(user).getUnchecked()) { Message.USER_SAVE_SUCCESS.send(sender); } else { Message.USER_SAVE_ERROR.send(sender); } - user.getRefreshBuffer().request().getOrDefault(null); + user.getRefreshBuffer().request().getUnchecked(); } public static void save(Group group, Sender sender, LuckPermsPlugin plugin) { - if (plugin.getDatastore().saveGroup(group).getOrDefault(false)) { + if (plugin.getDatastore().saveGroup(group).getUnchecked()) { Message.GROUP_SAVE_SUCCESS.send(sender); } else { Message.GROUP_SAVE_ERROR.send(sender); @@ -182,7 +182,7 @@ public abstract class SubCommand { } public static void save(Track track, Sender sender, LuckPermsPlugin plugin) { - if (plugin.getDatastore().saveTrack(track).getOrDefault(false)) { + if (plugin.getDatastore().saveTrack(track).getUnchecked()) { Message.TRACK_SAVE_SUCCESS.send(sender); } else { Message.TRACK_SAVE_ERROR.send(sender); 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 feda5054..0a4f9261 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 SecondarySubCommand { return CommandResult.INVALID_ARGS; } - if (!plugin.getDatastore().loadGroup(groupName).getOrDefault(false)) { + if (!plugin.getDatastore().loadGroup(groupName).getUnchecked()) { 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 fcc3b14f..bbeab41e 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 @@ -80,7 +80,7 @@ public class ParentAddTemp extends SecondarySubCommand { return CommandResult.INVALID_ARGS; } - if (!plugin.getDatastore().loadGroup(groupName).getOrDefault(false)) { + if (!plugin.getDatastore().loadGroup(groupName).getUnchecked()) { 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 a6b2330e..9fc0ea66 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 @@ -51,12 +51,12 @@ public class CreateGroup extends SingleMainCommand { return CommandResult.INVALID_ARGS; } - if (plugin.getDatastore().loadGroup(groupName).getOrDefault(false)) { + if (plugin.getDatastore().loadGroup(groupName).getUnchecked()) { Message.GROUP_ALREADY_EXISTS.send(sender); return CommandResult.INVALID_ARGS; } - if (!plugin.getDatastore().createAndLoadGroup(groupName).getOrDefault(false)) { + if (!plugin.getDatastore().createAndLoadGroup(groupName).getUnchecked()) { 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 a712b239..cb2f82f0 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 @@ -55,7 +55,7 @@ public class DeleteGroup extends SingleMainCommand { return CommandResult.INVALID_ARGS; } - if (!plugin.getDatastore().loadGroup(groupName).getOrDefault(false)) { + if (!plugin.getDatastore().loadGroup(groupName).getUnchecked()) { Message.GROUP_DOES_NOT_EXIST.send(sender); return CommandResult.INVALID_ARGS; } @@ -66,7 +66,7 @@ public class DeleteGroup extends SingleMainCommand { return CommandResult.LOADING_ERROR; } - if (!plugin.getDatastore().deleteGroup(group).getOrDefault(false)) { + if (!plugin.getDatastore().deleteGroup(group).getUnchecked()) { Message.DELETE_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 d6a23566..b50ae562 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 @@ -57,7 +57,7 @@ public class GroupMainCommand extends MainCommand { @Override protected Group getTarget(String target, LuckPermsPlugin plugin, Sender sender) { - if (!plugin.getDatastore().loadGroup(target).getOrDefault(false)) { + if (!plugin.getDatastore().loadGroup(target).getUnchecked()) { Message.GROUP_NOT_FOUND.send(sender); return null; } 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 e4c61bda..591a65d7 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 @@ -42,7 +42,7 @@ public class ListGroups extends SingleMainCommand { @Override protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { - if (!plugin.getDatastore().loadAllGroups().getOrDefault(false)) { + if (!plugin.getDatastore().loadAllGroups().getUnchecked()) { Message.GROUPS_LOAD_ERROR.send(sender); return CommandResult.LOADING_ERROR; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupClone.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupClone.java index b5ce0ce3..362cb7f6 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupClone.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupClone.java @@ -47,12 +47,12 @@ public class GroupClone extends SubCommand { return CommandResult.INVALID_ARGS; } - if (plugin.getDatastore().loadGroup(newGroupName).getOrDefault(false)) { + if (plugin.getDatastore().loadGroup(newGroupName).getUnchecked()) { Message.GROUP_ALREADY_EXISTS.send(sender); return CommandResult.INVALID_ARGS; } - if (!plugin.getDatastore().createAndLoadGroup(newGroupName).getOrDefault(false)) { + if (!plugin.getDatastore().createAndLoadGroup(newGroupName).getUnchecked()) { Message.CREATE_GROUP_ERROR.send(sender); return CommandResult.FAILURE; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupRename.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupRename.java index 47c02c3f..c0df717f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupRename.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupRename.java @@ -47,12 +47,12 @@ public class GroupRename extends SubCommand { return CommandResult.INVALID_ARGS; } - if (plugin.getDatastore().loadGroup(newGroupName).getOrDefault(false)) { + if (plugin.getDatastore().loadGroup(newGroupName).getUnchecked()) { Message.GROUP_ALREADY_EXISTS.send(sender); return CommandResult.INVALID_ARGS; } - if (!plugin.getDatastore().createAndLoadGroup(newGroupName).getOrDefault(false)) { + if (!plugin.getDatastore().createAndLoadGroup(newGroupName).getUnchecked()) { Message.CREATE_GROUP_ERROR.send(sender); return CommandResult.FAILURE; } @@ -63,7 +63,7 @@ public class GroupRename extends SubCommand { return CommandResult.LOADING_ERROR; } - if (!plugin.getDatastore().deleteGroup(group).getOrDefault(false)) { + if (!plugin.getDatastore().deleteGroup(group).getUnchecked()) { Message.DELETE_GROUP_ERROR.send(sender); return CommandResult.FAILURE; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupShowTracks.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupShowTracks.java index c4280d65..40414810 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupShowTracks.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupShowTracks.java @@ -39,7 +39,7 @@ public class GroupShowTracks extends SubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List args, String label) { - if (!plugin.getDatastore().loadAllTracks().getOrDefault(false)) { + if (!plugin.getDatastore().loadAllTracks().getUnchecked()) { Message.TRACKS_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 ee999366..33ad42f8 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().getOrDefault(null); + Log log = plugin.getDatastore().getLog().getUnchecked(); 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 a46584e9..95b28a30 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 @@ -74,7 +74,7 @@ public class LogRecent extends SubCommand { return CommandResult.INVALID_ARGS; } - UUID uuid = plugin.getDatastore().getUUID(s).getOrDefault(null); + UUID uuid = plugin.getDatastore().getUUID(s).getUnchecked(); 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 8e2d2839..e502520c 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 @@ -76,7 +76,7 @@ public class LogUserHistory extends SubCommand { return CommandResult.INVALID_ARGS; } - UUID uuid1 = plugin.getDatastore().getUUID(user).getOrDefault(null); + UUID uuid1 = plugin.getDatastore().getUUID(user).getUnchecked(); if (uuid1 == null) { Message.USER_NOT_FOUND.send(sender); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationBPermissions.java b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationBPermissions.java index 410f7794..dfda5c06 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationBPermissions.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationBPermissions.java @@ -121,7 +121,7 @@ public class MigrationBPermissions extends SubCommand { } // Make a LuckPerms group for the one being migrated. - plugin.getDatastore().createAndLoadGroup(groupName).getOrDefault(false); + plugin.getDatastore().createAndLoadGroup(groupName).getUnchecked(); me.lucko.luckperms.common.groups.Group lpGroup = plugin.getGroupManager().get(groupName); try { LogEntry.build() @@ -157,7 +157,7 @@ public class MigrationBPermissions extends SubCommand { } // Make a LuckPerms user for the one being migrated. - plugin.getDatastore().loadUser(uuid, "null").getOrDefault(false); + plugin.getDatastore().loadUser(uuid, "null").getUnchecked(); me.lucko.luckperms.common.users.User lpUser = plugin.getUserManager().get(uuid); migrateHolder(plugin, world, user, lpUser); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationBungeePerms.java b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationBungeePerms.java index 4c2741d4..af104866 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationBungeePerms.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationBungeePerms.java @@ -63,7 +63,7 @@ public class MigrationBungeePerms extends SubCommand { groupCount ++; // Make a LuckPerms group for the one being migrated - plugin.getDatastore().createAndLoadGroup(g.getName().toLowerCase()).getOrDefault(false); + plugin.getDatastore().createAndLoadGroup(g.getName().toLowerCase()).getUnchecked(); me.lucko.luckperms.common.groups.Group group = plugin.getGroupManager().get(g.getName().toLowerCase()); try { LogEntry.build() @@ -187,7 +187,7 @@ public class MigrationBungeePerms extends SubCommand { userCount++; // Make a LuckPerms user for the one being migrated. - plugin.getDatastore().loadUser(u.getUUID(), "null").getOrDefault(false); + plugin.getDatastore().loadUser(u.getUUID(), "null").getUnchecked(); me.lucko.luckperms.common.users.User user = plugin.getUserManager().get(u.getUUID()); // Migrate global perms diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationGroupManager.java b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationGroupManager.java index d9e00d3e..61eebacd 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationGroupManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationGroupManager.java @@ -73,7 +73,7 @@ public class MigrationGroupManager extends SubCommand { } for (Group g : gg.getGroupList()) { - plugin.getDatastore().createAndLoadGroup(g.getName().toLowerCase()).getOrDefault(false); + plugin.getDatastore().createAndLoadGroup(g.getName().toLowerCase()).getUnchecked(); me.lucko.luckperms.common.groups.Group group = plugin.getGroupManager().get(g.getName().toLowerCase()); try { LogEntry.build() @@ -202,7 +202,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()).getOrDefault(false); + plugin.getDatastore().createAndLoadGroup(e.getKey()).getUnchecked(); me.lucko.luckperms.common.groups.Group group = plugin.getGroupManager().get(e.getKey()); try { LogEntry.build() @@ -245,7 +245,7 @@ public class MigrationGroupManager extends SubCommand { } for (Map.Entry, Boolean>> e : users.entrySet()) { - plugin.getDatastore().loadUser(e.getKey(), "null").getOrDefault(false); + plugin.getDatastore().loadUser(e.getKey(), "null").getUnchecked(); me.lucko.luckperms.common.users.User user = plugin.getUserManager().get(e.getKey()); for (Map.Entry, Boolean> n : e.getValue().entrySet()) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationPermissionsEx.java b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationPermissionsEx.java index c9eb9ad1..75f25f39 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationPermissionsEx.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationPermissionsEx.java @@ -102,7 +102,7 @@ public class MigrationPermissionsEx extends SubCommand { maxGroupWeight = Math.max(maxGroupWeight, groupWeight); final String name = group.getName().toLowerCase(); - plugin.getDatastore().createAndLoadGroup(name).getOrDefault(false); + plugin.getDatastore().createAndLoadGroup(name).getUnchecked(); Group lpGroup = plugin.getGroupManager().get(name); try { LogEntry.build() @@ -254,7 +254,7 @@ public class MigrationPermissionsEx extends SubCommand { } userCount++; - plugin.getDatastore().loadUser(u, "null").getOrDefault(false); + plugin.getDatastore().loadUser(u, "null").getUnchecked(); User lpUser = plugin.getUserManager().get(u); try { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationPowerfulPerms.java b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationPowerfulPerms.java index 3cbd7f25..4b2a7003 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationPowerfulPerms.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationPowerfulPerms.java @@ -246,7 +246,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()).getOrDefault(false); + plugin.getDatastore().createAndLoadGroup(g.getName().toLowerCase()).getUnchecked(); final me.lucko.luckperms.common.groups.Group group = plugin.getGroupManager().get(g.getName().toLowerCase()); try { LogEntry.build() @@ -288,7 +288,7 @@ public class MigrationPowerfulPerms extends SubCommand { progress.put(uuid, new CountDownLatch(2)); // Create a LuckPerms user for the UUID - plugin.getDatastore().loadUser(uuid, "null").getOrDefault(false); + plugin.getDatastore().loadUser(uuid, "null").getUnchecked(); User user = plugin.getUserManager().get(uuid); // Get a list of Permissions held by the user from the PP API. diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationZPermissions.java b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationZPermissions.java index e9838ab9..293912c5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationZPermissions.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationZPermissions.java @@ -72,7 +72,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()).getOrDefault(false); + plugin.getDatastore().createAndLoadGroup(g.toLowerCase()).getUnchecked(); Group group = plugin.getGroupManager().get(g.toLowerCase()); try { LogEntry.build() @@ -121,7 +121,7 @@ public class MigrationZPermissions extends SubCommand { // Migrate all tracks log.info("zPermissions Migration: Starting track migration."); for (String t : service.getAllTracks()) { - plugin.getDatastore().createAndLoadTrack(t.toLowerCase()).getOrDefault(false); + plugin.getDatastore().createAndLoadTrack(t.toLowerCase()).getUnchecked(); Track track = plugin.getTrackManager().get(t.toLowerCase()); try { LogEntry.build() @@ -150,7 +150,7 @@ public class MigrationZPermissions extends SubCommand { // Migrate all users. log.info("zPermissions Migration: Starting user migration."); for (UUID u : service.getAllPlayersUUID()) { - plugin.getDatastore().loadUser(u, "null").getOrDefault(false); + plugin.getDatastore().loadUser(u, "null").getUnchecked(); User user = plugin.getUserManager().get(u); for (Map.Entry e : service.getPlayerPermissions(null, null, u).entrySet()) { 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 22e58755..f86a783a 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 @@ -118,13 +118,13 @@ public class ExportCommand extends SingleMainCommand { // Export users log.info("Export: Exporting all users. Finding a list of unique users to export."); Datastore ds = plugin.getDatastore(); - Set users = ds.getUniqueUsers().getOrDefault(null); + Set users = ds.getUniqueUsers().getUnchecked(); log.info("Export: Found " + users.size() + " unique users to export."); int userCount = 0; for (UUID uuid : users) { userCount++; - plugin.getDatastore().loadUser(uuid, "null").getOrDefault(false); + plugin.getDatastore().loadUser(uuid, "null").getUnchecked(); User user = plugin.getUserManager().get(uuid); boolean inDefault = false; 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 ae2cdc27..1442d385 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 @@ -39,7 +39,7 @@ public class SyncCommand extends SingleMainCommand { @Override protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { Message.UPDATE_TASK_REQUEST.send(sender); - plugin.getUpdateTaskBuffer().request().getOrDefault(null); + plugin.getUpdateTaskBuffer().request().getUnchecked(); 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 eda5e134..59734a2f 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 @@ -51,12 +51,12 @@ public class CreateTrack extends SingleMainCommand { return CommandResult.INVALID_ARGS; } - if (plugin.getDatastore().loadTrack(trackName).getOrDefault(false)) { + if (plugin.getDatastore().loadTrack(trackName).getUnchecked()) { Message.TRACK_ALREADY_EXISTS.send(sender); return CommandResult.INVALID_ARGS; } - if (!plugin.getDatastore().createAndLoadTrack(trackName).getOrDefault(false)) { + if (!plugin.getDatastore().createAndLoadTrack(trackName).getUnchecked()) { 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 c27e1b17..9265f58f 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 @@ -49,7 +49,7 @@ public class DeleteTrack extends SingleMainCommand { } String trackName = args.get(0).toLowerCase(); - if (!plugin.getDatastore().loadTrack(trackName).getOrDefault(false)) { + if (!plugin.getDatastore().loadTrack(trackName).getUnchecked()) { Message.TRACK_DOES_NOT_EXIST.send(sender); return CommandResult.INVALID_ARGS; } @@ -60,7 +60,7 @@ public class DeleteTrack extends SingleMainCommand { return CommandResult.LOADING_ERROR; } - if (!plugin.getDatastore().deleteTrack(track).getOrDefault(false)) { + if (!plugin.getDatastore().deleteTrack(track).getUnchecked()) { 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 87c1a9b7..1405d5c6 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 @@ -40,7 +40,7 @@ public class ListTracks extends SingleMainCommand { @Override protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { - if (!plugin.getDatastore().loadAllTracks().getOrDefault(false)) { + if (!plugin.getDatastore().loadAllTracks().getUnchecked()) { Message.TRACKS_LOAD_ERROR.send(sender); return CommandResult.LOADING_ERROR; } 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 13de57e2..27d8e811 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 @@ -50,7 +50,7 @@ public class TrackMainCommand extends MainCommand { @Override protected Track getTarget(String target, LuckPermsPlugin plugin, Sender sender) { - if (!plugin.getDatastore().loadTrack(target).getOrDefault(false)) { + if (!plugin.getDatastore().loadTrack(target).getUnchecked()) { Message.TRACK_NOT_FOUND.send(sender); return null; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackAppend.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackAppend.java index 3e19226d..c360fa8c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackAppend.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackAppend.java @@ -50,7 +50,7 @@ public class TrackAppend extends SubCommand { return CommandResult.INVALID_ARGS; } - if (!plugin.getDatastore().loadGroup(groupName).getOrDefault(false)) { + if (!plugin.getDatastore().loadGroup(groupName).getUnchecked()) { Message.GROUP_DOES_NOT_EXIST.send(sender); return CommandResult.INVALID_ARGS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackClone.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackClone.java index 3180be71..4dfc0e11 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackClone.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackClone.java @@ -47,12 +47,12 @@ public class TrackClone extends SubCommand { return CommandResult.INVALID_ARGS; } - if (plugin.getDatastore().loadTrack(newTrackName).getOrDefault(false)) { + if (plugin.getDatastore().loadTrack(newTrackName).getUnchecked()) { Message.TRACK_ALREADY_EXISTS.send(sender); return CommandResult.INVALID_ARGS; } - if (!plugin.getDatastore().createAndLoadTrack(newTrackName).getOrDefault(false)) { + if (!plugin.getDatastore().createAndLoadTrack(newTrackName).getUnchecked()) { Message.CREATE_TRACK_ERROR.send(sender); return CommandResult.FAILURE; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackInsert.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackInsert.java index d3863ec7..87d14581 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackInsert.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackInsert.java @@ -61,7 +61,7 @@ public class TrackInsert extends SubCommand { return CommandResult.INVALID_ARGS; } - if (!plugin.getDatastore().loadGroup(groupName).getOrDefault(false)) { + if (!plugin.getDatastore().loadGroup(groupName).getUnchecked()) { Message.GROUP_DOES_NOT_EXIST.send(sender); return CommandResult.INVALID_ARGS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackRename.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackRename.java index c6e971c8..27ca0106 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackRename.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackRename.java @@ -47,12 +47,12 @@ public class TrackRename extends SubCommand { return CommandResult.INVALID_ARGS; } - if (plugin.getDatastore().loadTrack(newTrackName).getOrDefault(false)) { + if (plugin.getDatastore().loadTrack(newTrackName).getUnchecked()) { Message.TRACK_ALREADY_EXISTS.send(sender); return CommandResult.INVALID_ARGS; } - if (!plugin.getDatastore().createAndLoadTrack(newTrackName).getOrDefault(false)) { + if (!plugin.getDatastore().createAndLoadTrack(newTrackName).getUnchecked()) { Message.CREATE_TRACK_ERROR.send(sender); return CommandResult.FAILURE; } @@ -63,7 +63,7 @@ public class TrackRename extends SubCommand { return CommandResult.LOADING_ERROR; } - if (!plugin.getDatastore().deleteTrack(track).getOrDefault(false)) { + if (!plugin.getDatastore().deleteTrack(track).getUnchecked()) { Message.DELETE_TRACK_ERROR.send(sender); return CommandResult.FAILURE; } 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 bd235f86..8412457e 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 @@ -70,7 +70,7 @@ public class UserMainCommand extends MainCommand { return null; } - u = plugin.getDatastore().getUUID(target).getOrDefault(null); + u = plugin.getDatastore().getUUID(target).getUnchecked(); if (u == null) { Message.USER_NOT_FOUND.send(sender); return null; @@ -80,10 +80,10 @@ public class UserMainCommand extends MainCommand { } } - String name = plugin.getDatastore().getName(u).getOrDefault(null); + String name = plugin.getDatastore().getName(u).getUnchecked(); if (name == null) name = "null"; - if (!plugin.getDatastore().loadUser(u, name).getOrDefault(false)) { + if (!plugin.getDatastore().loadUser(u, name).getUnchecked()) { Message.LOADING_ERROR.send(sender); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserDemote.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserDemote.java index 68f2aa6c..7d72a8dd 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserDemote.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserDemote.java @@ -54,7 +54,7 @@ public class UserDemote extends SubCommand { return CommandResult.INVALID_ARGS; } - if (!plugin.getDatastore().loadTrack(trackName).getOrDefault(false)) { + if (!plugin.getDatastore().loadTrack(trackName).getUnchecked()) { Message.TRACK_DOES_NOT_EXIST.send(sender); return CommandResult.INVALID_ARGS; } @@ -85,7 +85,7 @@ public class UserDemote extends SubCommand { return CommandResult.STATE_ERROR; } - if (!plugin.getDatastore().loadGroup(previous).getOrDefault(false)) { + if (!plugin.getDatastore().loadGroup(previous).getUnchecked()) { 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/subcommands/UserPromote.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserPromote.java index 2cbfdc2a..937d45ad 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserPromote.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserPromote.java @@ -54,7 +54,7 @@ public class UserPromote extends SubCommand { return CommandResult.INVALID_ARGS; } - if (!plugin.getDatastore().loadTrack(trackName).getOrDefault(false)) { + if (!plugin.getDatastore().loadTrack(trackName).getUnchecked()) { Message.TRACK_DOES_NOT_EXIST.send(sender); return CommandResult.INVALID_ARGS; } @@ -85,7 +85,7 @@ public class UserPromote extends SubCommand { return CommandResult.STATE_ERROR; } - if (!plugin.getDatastore().loadGroup(next).getOrDefault(false)) { + if (!plugin.getDatastore().loadGroup(next).getUnchecked()) { Message.USER_PROMOTE_ERROR_MALFORMED.send(sender, next); return CommandResult.STATE_ERROR; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserShowPos.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserShowPos.java index 9de478d3..391dd5b5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserShowPos.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserShowPos.java @@ -47,7 +47,7 @@ public class UserShowPos extends SubCommand { return CommandResult.INVALID_ARGS; } - if (!plugin.getDatastore().loadTrack(trackName).getOrDefault(false)) { + if (!plugin.getDatastore().loadTrack(trackName).getUnchecked()) { Message.TRACK_DOES_NOT_EXIST.send(sender); return CommandResult.INVALID_ARGS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserShowTracks.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserShowTracks.java index 9b0f1caa..f25afb84 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserShowTracks.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserShowTracks.java @@ -40,7 +40,7 @@ public class UserShowTracks extends SubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List args, String label) { - if (!plugin.getDatastore().loadAllTracks().getOrDefault(false)) { + if (!plugin.getDatastore().loadAllTracks().getUnchecked()) { Message.TRACKS_LOAD_ERROR.send(sender); return CommandResult.LOADING_ERROR; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/subcommands/BulkEditGroup.java b/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/subcommands/BulkEditGroup.java index 722ac1ef..b62a3b2b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/subcommands/BulkEditGroup.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/subcommands/BulkEditGroup.java @@ -61,10 +61,10 @@ public class BulkEditGroup extends SubCommand { return CommandResult.FAILURE; } - Set uuids = datastore.getUniqueUsers().getOrDefault(null); + Set uuids = datastore.getUniqueUsers().getUnchecked(); for (UUID u : uuids) { - plugin.getDatastore().loadUser(u, "null").getOrDefault(false); + plugin.getDatastore().loadUser(u, "null").getUnchecked(); User user = plugin.getUserManager().get(u); if (user == null) { continue; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/subcommands/BulkEditPermission.java b/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/subcommands/BulkEditPermission.java index e389e992..ed104f92 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/subcommands/BulkEditPermission.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/subcommands/BulkEditPermission.java @@ -61,10 +61,10 @@ public class BulkEditPermission extends SubCommand { return CommandResult.FAILURE; } - Set uuids = datastore.getUniqueUsers().getOrDefault(null); + Set uuids = datastore.getUniqueUsers().getUnchecked(); for (UUID u : uuids) { - plugin.getDatastore().loadUser(u, "null").getOrDefault(false); + plugin.getDatastore().loadUser(u, "null").getUnchecked(); User user = plugin.getUserManager().get(u); if (user == null) { continue; 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 4f87eef7..a31bdd4b 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().getOrDefault(false); + plugin.getDatastore().loadAllGroups().getUnchecked(); String defaultGroup = plugin.getConfiguration().getDefaultGroupName(); if (!plugin.getGroupManager().isLoaded(defaultGroup)) { - plugin.getDatastore().createAndLoadGroup(defaultGroup).getOrDefault(false); + plugin.getDatastore().createAndLoadGroup(defaultGroup).getUnchecked(); } // Reload all tracks - plugin.getDatastore().loadAllTracks().getOrDefault(false); + plugin.getDatastore().loadAllTracks().getUnchecked(); // 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/AbstractDatastore.java index 5bc7c1ef..51c9de62 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/AbstractDatastore.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/AbstractDatastore.java @@ -25,6 +25,7 @@ package me.lucko.luckperms.common.storage; import lombok.AccessLevel; import lombok.RequiredArgsConstructor; import me.lucko.luckperms.api.LogEntry; +import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.data.Log; import me.lucko.luckperms.common.groups.Group; import me.lucko.luckperms.common.storage.backing.AbstractBacking; @@ -43,10 +44,13 @@ import java.util.function.Supplier; */ @RequiredArgsConstructor(access = AccessLevel.PRIVATE) public class AbstractDatastore implements Datastore { - public static Datastore wrap(AbstractBacking backing) { - return TolerantDatastore.wrap(new AbstractDatastore(backing)); + + public static Datastore wrap(LuckPermsPlugin plugin, AbstractBacking backing) { + BufferedOutputDatastore bufferedDs = BufferedOutputDatastore.wrap(TolerantDatastore.wrap(new AbstractDatastore(backing)), 1000L); + plugin.doAsyncRepeating(bufferedDs, 10L); + return bufferedDs; } - + private final AbstractBacking backing; private LPFuture makeFuture(Supplier supplier) { @@ -89,11 +93,8 @@ public class AbstractDatastore implements Datastore { } @Override - public LPFuture shutdown() { - return makeFuture(() -> { - backing.shutdown(); - return null; - }); + public void shutdown() { + backing.shutdown(); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/BufferedOutputDatastore.java b/common/src/main/java/me/lucko/luckperms/common/storage/BufferedOutputDatastore.java index 5d331e50..f9f5fec9 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/BufferedOutputDatastore.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/BufferedOutputDatastore.java @@ -50,28 +50,28 @@ public class BufferedOutputDatastore implements Datastore, Runnable { private final Buffer userOutputBuffer = new Buffer() { @Override public Boolean dequeue(User user) { - return backing.saveUser(user).getOrDefault(false); + return backing.saveUser(user).getUnchecked(); } }; private final Buffer groupOutputBuffer = new Buffer() { @Override public Boolean dequeue(Group group) { - return backing.saveGroup(group).getOrDefault(false); + return backing.saveGroup(group).getUnchecked(); } }; private final Buffer trackOutputBuffer = new Buffer() { @Override public Boolean dequeue(Track track) { - return backing.saveTrack(track).getOrDefault(false); + return backing.saveTrack(track).getUnchecked(); } }; private final Buffer uuidDataOutputBuffer = new Buffer() { @Override protected Boolean dequeue(UserIdentifier userIdentifier) { - return backing.saveUUIDData(userIdentifier.getUsername(), userIdentifier.getUuid()).getOrDefault(false); + return backing.saveUUIDData(userIdentifier.getUsername(), userIdentifier.getUuid()).getUnchecked(); } }; @@ -96,9 +96,9 @@ public class BufferedOutputDatastore implements Datastore, Runnable { } @Override - public LPFuture shutdown() { + public void shutdown() { forceFlush(); - return backing.shutdown(); + backing.shutdown(); } @Override 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 index f9a461e5..f2325a1a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/Datastore.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/Datastore.java @@ -57,7 +57,7 @@ public interface Datastore { } void init(); - LPFuture shutdown(); + void shutdown(); LPFuture logAction(LogEntry entry); LPFuture getLog(); LPFuture loadUser(UUID uuid, String username); @@ -80,133 +80,133 @@ public interface Datastore { default void logAction(LogEntry entry, Callback callback) { doAsync(() -> { - boolean result = logAction(entry).getOrDefault(false); + boolean result = logAction(entry).getUnchecked(); doSync(() -> callback.onComplete(result)); }); } default void getLog(Callback callback) { doAsync(() -> { - Log result = getLog().getOrDefault(null); + Log result = getLog().getUnchecked(); doSync(() -> callback.onComplete(result)); }); } default void loadUser(UUID uuid, String username, Callback callback) { doAsync(() -> { - boolean result = loadUser(uuid, username).getOrDefault(false); + boolean result = loadUser(uuid, username).getUnchecked(); doSync(() -> callback.onComplete(result)); }); } default void saveUser(User user, Callback callback) { doAsync(() -> { - boolean result = saveUser(user).getOrDefault(false); + boolean result = saveUser(user).getUnchecked(); doSync(() -> callback.onComplete(result)); }); } default void cleanupUsers(Callback callback) { doAsync(() -> { - boolean result = cleanupUsers().getOrDefault(false); + boolean result = cleanupUsers().getUnchecked(); doSync(() -> callback.onComplete(result)); }); } default void getUniqueUsers(Callback> callback) { doAsync(() -> { - Set result = getUniqueUsers().getOrDefault(null); + Set result = getUniqueUsers().getUnchecked(); doSync(() -> callback.onComplete(result)); }); } default void createAndLoadGroup(String name, Callback callback) { doAsync(() -> { - boolean result = createAndLoadGroup(name).getOrDefault(false); + boolean result = createAndLoadGroup(name).getUnchecked(); doSync(() -> callback.onComplete(result)); }); } default void loadGroup(String name, Callback callback) { doAsync(() -> { - boolean result = loadGroup(name).getOrDefault(false); + boolean result = loadGroup(name).getUnchecked(); doSync(() -> callback.onComplete(result)); }); } default void loadAllGroups(Callback callback) { doAsync(() -> { - boolean result = loadAllGroups().getOrDefault(false); + boolean result = loadAllGroups().getUnchecked(); doSync(() -> callback.onComplete(result)); }); } default void saveGroup(Group group, Callback callback) { doAsync(() -> { - boolean result = saveGroup(group).getOrDefault(false); + boolean result = saveGroup(group).getUnchecked(); doSync(() -> callback.onComplete(result)); }); } default void deleteGroup(Group group, Callback callback) { doAsync(() -> { - boolean result = deleteGroup(group).getOrDefault(false); + boolean result = deleteGroup(group).getUnchecked(); doSync(() -> callback.onComplete(result)); }); } default void createAndLoadTrack(String name, Callback callback) { doAsync(() -> { - boolean result = createAndLoadTrack(name).getOrDefault(false); + boolean result = createAndLoadTrack(name).getUnchecked(); doSync(() -> callback.onComplete(result)); }); } default void loadTrack(String name, Callback callback) { doAsync(() -> { - boolean result = loadTrack(name).getOrDefault(false); + boolean result = loadTrack(name).getUnchecked(); doSync(() -> callback.onComplete(result)); }); } default void loadAllTracks(Callback callback) { doAsync(() -> { - boolean result = loadAllTracks().getOrDefault(false); + boolean result = loadAllTracks().getUnchecked(); doSync(() -> callback.onComplete(result)); }); } default void saveTrack(Track track, Callback callback) { doAsync(() -> { - boolean result = saveTrack(track).getOrDefault(false); + boolean result = saveTrack(track).getUnchecked(); doSync(() -> callback.onComplete(result)); }); } default void deleteTrack(Track track, Callback callback) { doAsync(() -> { - boolean result = deleteTrack(track).getOrDefault(false); + boolean result = deleteTrack(track).getUnchecked(); doSync(() -> callback.onComplete(result)); }); } default void saveUUIDData(String username, UUID uuid, Callback callback) { doAsync(() -> { - boolean result = saveUUIDData(username, uuid).getOrDefault(false); + boolean result = saveUUIDData(username, uuid).getUnchecked(); doSync(() -> callback.onComplete(result)); }); } default void getUUID(String username, Callback callback) { doAsync(() -> { - UUID result = getUUID(username).getOrDefault(null); + UUID result = getUUID(username).getUnchecked(); doSync(() -> callback.onComplete(result)); }); } default void getName(UUID uuid, Callback callback) { doAsync(() -> { - String result = getName(uuid).getOrDefault(null); + String result = getName(uuid).getUnchecked(); doSync(() -> callback.onComplete(result)); }); } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/SplitBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/SplitBacking.java index c0a63c78..52001d7f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/SplitBacking.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/SplitBacking.java @@ -31,7 +31,6 @@ 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.AbstractFuture; import me.lucko.luckperms.common.utils.LPFuture; import java.util.Map; @@ -83,13 +82,8 @@ public class SplitBacking implements Datastore { } @Override - public LPFuture shutdown() { - AbstractFuture future = new AbstractFuture<>(); - doAsync(() -> { - backing.values().forEach(Datastore::shutdown); - future.complete(null); - }); - return future; + public void shutdown() { + backing.values().forEach(Datastore::shutdown); } @Override 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 72294773..982d06dc 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 @@ -84,19 +84,17 @@ public class StorageFactory { private static Datastore fromString(String storageMethod, LuckPermsPlugin plugin) { switch (storageMethod) { case "mysql": - BufferedOutputDatastore bod = BufferedOutputDatastore.wrap(AbstractDatastore.wrap(new MySQLBacking(plugin, plugin.getConfiguration().getDatabaseValues())), 1000L); - plugin.doAsyncRepeating(bod, 10L); - return bod; + return AbstractDatastore.wrap(plugin, new MySQLBacking(plugin, plugin.getConfiguration().getDatabaseValues())); case "sqlite": - return AbstractDatastore.wrap(new SQLiteBacking(plugin, new File(plugin.getDataFolder(), "luckperms.sqlite"))); + return AbstractDatastore.wrap(plugin, new SQLiteBacking(plugin, new File(plugin.getDataFolder(), "luckperms.sqlite"))); case "h2": - return AbstractDatastore.wrap(new H2Backing(plugin, new File(plugin.getDataFolder(), "luckperms.db"))); + return AbstractDatastore.wrap(plugin, new H2Backing(plugin, new File(plugin.getDataFolder(), "luckperms.db"))); case "mongodb": - return AbstractDatastore.wrap(new MongoDBBacking(plugin, plugin.getConfiguration().getDatabaseValues())); + return AbstractDatastore.wrap(plugin, new MongoDBBacking(plugin, plugin.getConfiguration().getDatabaseValues())); case "yaml": - return AbstractDatastore.wrap(new YAMLBacking(plugin, plugin.getDataFolder())); + return AbstractDatastore.wrap(plugin, new YAMLBacking(plugin, plugin.getDataFolder())); default: - return AbstractDatastore.wrap(new JSONBacking(plugin, plugin.getDataFolder())); + return AbstractDatastore.wrap(plugin, new JSONBacking(plugin, plugin.getDataFolder())); } } } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/TolerantDatastore.java b/common/src/main/java/me/lucko/luckperms/common/storage/TolerantDatastore.java index 891b35f8..59b33125 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/TolerantDatastore.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/TolerantDatastore.java @@ -80,7 +80,7 @@ public class TolerantDatastore implements Datastore { } @Override - public LPFuture shutdown() { + public void shutdown() { // Wait for other threads to finish. try { phaser.awaitAdvanceInterruptibly(phaser.getPhase(), 5, TimeUnit.SECONDS); @@ -88,7 +88,7 @@ public class TolerantDatastore implements Datastore { e.printStackTrace(); } - return backing.shutdown(); + backing.shutdown(); } @Override 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 4cee3662..947c7a47 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 @@ -135,7 +135,7 @@ public class UserManager extends AbstractManager { plugin.doAsync(() -> { for (UUID uuid : players) { UUID internal = plugin.getUuidCache().getUUID(uuid); - plugin.getDatastore().loadUser(internal, "null").getOrDefault(false); + plugin.getDatastore().loadUser(internal, "null").getUnchecked(); User user = get(internal); user.getRefreshBuffer().request(); } 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 f63f46b1..96ccf926 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 @@ -41,7 +41,7 @@ public class AbstractListener { final UuidCache cache = plugin.getUuidCache(); if (!cache.isOnlineMode()) { - UUID uuid = plugin.getDatastore().force().getUUID(username).getOrDefault(null); + UUID uuid = plugin.getDatastore().force().getUUID(username).getUnchecked(); if (uuid != null) { cache.addToCache(u, uuid); } else { @@ -51,7 +51,7 @@ public class AbstractListener { plugin.getDatastore().force().saveUUIDData(username, u, Callback.empty()); } } else { - UUID uuid = plugin.getDatastore().getUUID(username).getOrDefault(null); + UUID uuid = plugin.getDatastore().getUUID(username).getUnchecked(); if (uuid == null) { plugin.getApiProvider().fireEventAsync(new UserFirstLoginEvent(u, username)); } @@ -60,7 +60,7 @@ public class AbstractListener { plugin.getDatastore().force().saveUUIDData(username, u, Callback.empty()); } - plugin.getDatastore().force().loadUser(cache.getUUID(u), username).getOrDefault(false); + plugin.getDatastore().force().loadUser(cache.getUUID(u), username).getUnchecked(); User user = plugin.getUserManager().get(cache.getUUID(u)); if (user == null) { plugin.getLog().warn("Failed to load user: " + username); @@ -75,7 +75,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).getOrDefault(false); + plugin.getDatastore().force().saveUser(user).getUnchecked(); } 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/LPFuture.java b/common/src/main/java/me/lucko/luckperms/common/utils/LPFuture.java index ee2f3738..d658486c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/LPFuture.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/LPFuture.java @@ -22,17 +22,14 @@ package me.lucko.luckperms.common.utils; -import java.util.concurrent.ExecutionException; +import com.google.common.util.concurrent.Futures; + import java.util.concurrent.Future; public interface LPFuture extends Future { - default T getOrDefault(T def) { - try { - return get(); - } catch (InterruptedException | ExecutionException e) { - return def; - } + default T getUnchecked() { + return Futures.getUnchecked(this); } }