Use LoadingCache instead of a regular map + more datastore fixes

This commit is contained in:
Luck 2016-10-22 20:39:26 +01:00
parent 55a0de7899
commit 33c78e4a17
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
52 changed files with 210 additions and 191 deletions

View File

@ -198,7 +198,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
public void onDisable() { public void onDisable() {
started = false; started = false;
getLog().info("Closing datastore..."); getLog().info("Closing datastore...");
datastore.shutdown().getOrDefault(null); datastore.shutdown();
getLog().info("Unregistering API..."); getLog().info("Unregistering API...");
ApiHandler.unregisterProvider(); ApiHandler.unregisterProvider();

View File

@ -222,7 +222,7 @@ public class LPPermissible extends PermissibleBase {
} }
if (hasData()) { if (hasData()) {
user.getUserData().invalidateCache(); user.getUserData().invalidatePermissionCalculators();
} }
} }

View File

@ -95,28 +95,28 @@ public class BungeeListener extends AbstractListener implements Listener {
final PendingConnection c = e.getConnection(); final PendingConnection c = e.getConnection();
if (!cache.isOnlineMode()) { if (!cache.isOnlineMode()) {
UUID uuid = plugin.getDatastore().getUUID(c.getName()).getOrDefault(null); UUID uuid = plugin.getDatastore().getUUID(c.getName()).getUnchecked();
if (uuid != null) { if (uuid != null) {
cache.addToCache(c.getUniqueId(), uuid); cache.addToCache(c.getUniqueId(), uuid);
} else { } else {
// No previous data for this player // No previous data for this player
plugin.getApiProvider().fireEventAsync(new UserFirstLoginEvent(c.getUniqueId(), c.getName())); plugin.getApiProvider().fireEventAsync(new UserFirstLoginEvent(c.getUniqueId(), c.getName()));
cache.addToCache(c.getUniqueId(), c.getUniqueId()); 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 { } else {
UUID uuid = plugin.getDatastore().getUUID(c.getName()).getOrDefault(null); UUID uuid = plugin.getDatastore().getUUID(c.getName()).getUnchecked();
if (uuid == null) { if (uuid == null) {
plugin.getApiProvider().fireEventAsync(new UserFirstLoginEvent(c.getUniqueId(), c.getName())); plugin.getApiProvider().fireEventAsync(new UserFirstLoginEvent(c.getUniqueId(), c.getName()));
} }
// Online mode, no cache needed. This is just for name -> uuid lookup. // 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 // 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. // 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())); User user = plugin.getUserManager().get(cache.getUUID(c.getUniqueId()));
if (user == null) { if (user == null) {
plugin.getLog().warn("Failed to load user: " + c.getName()); plugin.getLog().warn("Failed to load user: " + c.getName());

View File

@ -206,12 +206,12 @@ public class DatastoreLink implements Datastore {
@Override @Override
public boolean logAction(@NonNull LogEntry entry) { public boolean logAction(@NonNull LogEntry entry) {
return master.logAction(entry).getOrDefault(false); return master.logAction(entry).getUnchecked();
} }
@Override @Override
public Log getLog() { 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) { if (log == null) {
return null; return null;
} }
@ -220,54 +220,54 @@ public class DatastoreLink implements Datastore {
@Override @Override
public boolean loadOrCreateUser(@NonNull UUID uuid, @NonNull String username) { 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 @Override
public boolean loadUser(@NonNull UUID uuid) { public boolean loadUser(@NonNull UUID uuid) {
return master.loadUser(uuid, "null").getOrDefault(false); return master.loadUser(uuid, "null").getUnchecked();
} }
@Override @Override
public boolean loadUser(@NonNull UUID uuid, @NonNull String username) { 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 @Override
public boolean saveUser(@NonNull User user) { public boolean saveUser(@NonNull User user) {
checkUser(user); checkUser(user);
return master.saveUser(((UserLink) user).getMaster()).getOrDefault(false); return master.saveUser(((UserLink) user).getMaster()).getUnchecked();
} }
@Override @Override
public boolean cleanupUsers() { public boolean cleanupUsers() {
return master.cleanupUsers().getOrDefault(false); return master.cleanupUsers().getUnchecked();
} }
@Override @Override
public Set<UUID> getUniqueUsers() { public Set<UUID> getUniqueUsers() {
return master.getUniqueUsers().getOrDefault(null); return master.getUniqueUsers().getUnchecked();
} }
@Override @Override
public boolean createAndLoadGroup(@NonNull String name) { public boolean createAndLoadGroup(@NonNull String name) {
return master.createAndLoadGroup(checkName(name)).getOrDefault(false); return master.createAndLoadGroup(checkName(name)).getUnchecked();
} }
@Override @Override
public boolean loadGroup(@NonNull String name) { public boolean loadGroup(@NonNull String name) {
return master.loadGroup(checkName(name)).getOrDefault(false); return master.loadGroup(checkName(name)).getUnchecked();
} }
@Override @Override
public boolean loadAllGroups() { public boolean loadAllGroups() {
return master.loadAllGroups().getOrDefault(false); return master.loadAllGroups().getUnchecked();
} }
@Override @Override
public boolean saveGroup(@NonNull Group group) { public boolean saveGroup(@NonNull Group group) {
checkGroup(group); checkGroup(group);
return master.saveGroup(((GroupLink) group).getMaster()).getOrDefault(false); return master.saveGroup(((GroupLink) group).getMaster()).getUnchecked();
} }
@Override @Override
@ -276,44 +276,44 @@ public class DatastoreLink implements Datastore {
if (group.getName().equalsIgnoreCase(plugin.getConfiguration().getDefaultGroupName())) { if (group.getName().equalsIgnoreCase(plugin.getConfiguration().getDefaultGroupName())) {
throw new IllegalArgumentException("Cannot delete the default group."); throw new IllegalArgumentException("Cannot delete the default group.");
} }
return master.deleteGroup(((GroupLink) group).getMaster()).getOrDefault(false); return master.deleteGroup(((GroupLink) group).getMaster()).getUnchecked();
} }
@Override @Override
public boolean createAndLoadTrack(@NonNull String name) { public boolean createAndLoadTrack(@NonNull String name) {
return master.createAndLoadTrack(checkName(name)).getOrDefault(false); return master.createAndLoadTrack(checkName(name)).getUnchecked();
} }
@Override @Override
public boolean loadTrack(@NonNull String name) { public boolean loadTrack(@NonNull String name) {
return master.loadTrack(checkName(name)).getOrDefault(false); return master.loadTrack(checkName(name)).getUnchecked();
} }
@Override @Override
public boolean loadAllTracks() { public boolean loadAllTracks() {
return master.loadAllTracks().getOrDefault(false); return master.loadAllTracks().getUnchecked();
} }
@Override @Override
public boolean saveTrack(@NonNull Track track) { public boolean saveTrack(@NonNull Track track) {
checkTrack(track); checkTrack(track);
return master.saveTrack(((TrackLink) track).getMaster()).getOrDefault(false); return master.saveTrack(((TrackLink) track).getMaster()).getUnchecked();
} }
@Override @Override
public boolean deleteTrack(@NonNull Track track) { public boolean deleteTrack(@NonNull Track track) {
checkTrack(track); checkTrack(track);
return master.deleteTrack(((TrackLink) track).getMaster()).getOrDefault(false); return master.deleteTrack(((TrackLink) track).getMaster()).getUnchecked();
} }
@Override @Override
public boolean saveUUIDData(@NonNull String username, @NonNull UUID uuid) { 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 @Override
public UUID getUUID(@NonNull String username) { public UUID getUUID(@NonNull String username) {
return master.getUUID(checkUsername(username)).getOrDefault(null); return master.getUUID(checkUsername(username)).getUnchecked();
} }
} }

View File

@ -22,14 +22,18 @@
package me.lucko.luckperms.common.caching; 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 lombok.RequiredArgsConstructor;
import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.common.calculators.CalculatorFactory; import me.lucko.luckperms.common.calculators.CalculatorFactory;
import me.lucko.luckperms.common.users.User; import me.lucko.luckperms.common.users.User;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/** /**
* Holds an easily accessible cache of a user's data in a number of contexts * 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 CalculatorFactory calculatorFactory;
private final Map<Contexts, PermissionData> permission = new ConcurrentHashMap<>(); private final LoadingCache<Contexts, PermissionData> permission = CacheBuilder.newBuilder()
private final Map<Contexts, MetaData> meta = new ConcurrentHashMap<>(); .build(new CacheLoader<Contexts, PermissionData>() {
@Override
public PermissionData load(Contexts contexts) {
return calculatePermissions(contexts);
}
@Override
public ListenableFuture<PermissionData> reload(Contexts contexts, PermissionData oldData) {
oldData.comparePermissions(user.exportNodes(contexts, true));
return Futures.immediateFuture(oldData);
}
});
private final LoadingCache<Contexts, MetaData> meta = CacheBuilder.newBuilder()
.build(new CacheLoader<Contexts, MetaData>() {
@Override
public MetaData load(Contexts contexts) {
return calculateMeta(contexts);
}
@Override
public ListenableFuture<MetaData> reload(Contexts contexts, MetaData oldData) {
oldData.loadMeta(user.getAllNodes(null, contexts));
return Futures.immediateFuture(oldData);
}
});
/** /**
* Gets PermissionData from the cache, given a specified context. * Gets PermissionData from the cache, given a specified context.
@ -57,7 +86,7 @@ public class UserData {
* @return a permission data instance * @return a permission data instance
*/ */
public PermissionData getPermissionData(Contexts contexts) { 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 * @return a meta data instance
*/ */
public MetaData getMetaData(Contexts contexts) { 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. * @param contexts the contexts to recalculate in.
*/ */
public void recalculatePermissions(Contexts contexts) { public void recalculatePermissions(Contexts contexts) {
permission.compute(contexts, (c, data) -> { permission.refresh(contexts);
if (data == null) {
data = new PermissionData(c, user, calculatorFactory);
}
data.comparePermissions(user.exportNodes(c, true));
return data;
});
} }
/** /**
@ -114,28 +136,23 @@ public class UserData {
* @param contexts the contexts to recalculate in. * @param contexts the contexts to recalculate in.
*/ */
public void recalculateMeta(Contexts contexts) { public void recalculateMeta(Contexts contexts) {
meta.compute(contexts, (c, data) -> { meta.refresh(contexts);
if (data == null) {
data = new MetaData(c);
}
data.loadMeta(user.getAllNodes(null, c));
return data;
});
} }
/** /**
* Calls {@link #recalculatePermissions(Contexts)} for all current loaded contexts * Calls {@link #recalculatePermissions(Contexts)} for all current loaded contexts
*/ */
public void recalculatePermissions() { public void recalculatePermissions() {
permission.keySet().forEach(this::recalculatePermissions); Set<Contexts> keys = ImmutableSet.copyOf(permission.asMap().keySet());
keys.forEach(permission::refresh);
} }
/** /**
* Calls {@link #recalculateMeta(Contexts)} for all current loaded contexts * Calls {@link #recalculateMeta(Contexts)} for all current loaded contexts
*/ */
public void recalculateMeta() { public void recalculateMeta() {
meta.keySet().forEach(this::recalculateMeta); Set<Contexts> 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 * @param contexts the contexts to pre-calculate for
*/ */
public void preCalculate(Contexts contexts) { public void preCalculate(Contexts contexts) {
getPermissionData(contexts); permission.getUnchecked(contexts);
getMetaData(contexts); meta.getUnchecked(contexts);
} }
public void invalidateCache() { public void invalidateCache() {
permission.clear(); permission.invalidateAll();
meta.clear(); meta.invalidateAll();
}
public void invalidatePermissionCalculators() {
permission.asMap().values().forEach(PermissionData::invalidateCache);
} }
} }

View File

@ -22,13 +22,14 @@
package me.lucko.luckperms.common.calculators; 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 lombok.RequiredArgsConstructor;
import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.LuckPermsPlugin;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/** /**
* Calculates and caches permissions * Calculates and caches permissions
@ -39,15 +40,22 @@ public class PermissionCalculator {
private final String objectName; private final String objectName;
private final boolean debug; private final boolean debug;
private final List<PermissionProcessor> processors; private final List<PermissionProcessor> processors;
private final Map<String, Tristate> cache = new ConcurrentHashMap<>();
private final LoadingCache<String, Tristate> cache = CacheBuilder.newBuilder()
.build(new CacheLoader<String, Tristate>() {
@Override
public Tristate load(String s) {
return lookupPermissionValue(s);
}
});
public void invalidateCache() { public void invalidateCache() {
cache.clear(); cache.invalidateAll();
} }
public Tristate getPermissionValue(String permission) { public Tristate getPermissionValue(String permission) {
permission = permission.toLowerCase(); permission = permission.toLowerCase();
Tristate t = cache.computeIfAbsent(permission, this::lookupPermissionValue); Tristate t = cache.getUnchecked(permission);
if (debug) { if (debug) {
plugin.getLog().info("Checking if " + objectName + " has permission: " + permission + " - (" + t.toString() + ")"); plugin.getLog().info("Checking if " + objectName + " has permission: " + permission + " - (" + t.toString() + ")");

View File

@ -162,17 +162,17 @@ public abstract class SubCommand<T> {
} }
public static void save(User user, Sender sender, LuckPermsPlugin plugin) { 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); Message.USER_SAVE_SUCCESS.send(sender);
} else { } else {
Message.USER_SAVE_ERROR.send(sender); 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) { 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); Message.GROUP_SAVE_SUCCESS.send(sender);
} else { } else {
Message.GROUP_SAVE_ERROR.send(sender); Message.GROUP_SAVE_ERROR.send(sender);
@ -182,7 +182,7 @@ public abstract class SubCommand<T> {
} }
public static void save(Track track, Sender sender, LuckPermsPlugin plugin) { 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); Message.TRACK_SAVE_SUCCESS.send(sender);
} else { } else {
Message.TRACK_SAVE_ERROR.send(sender); Message.TRACK_SAVE_ERROR.send(sender);

View File

@ -61,7 +61,7 @@ public class ParentAdd extends SecondarySubCommand {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (!plugin.getDatastore().loadGroup(groupName).getOrDefault(false)) { if (!plugin.getDatastore().loadGroup(groupName).getUnchecked()) {
Message.GROUP_DOES_NOT_EXIST.send(sender); Message.GROUP_DOES_NOT_EXIST.send(sender);
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }

View File

@ -80,7 +80,7 @@ public class ParentAddTemp extends SecondarySubCommand {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (!plugin.getDatastore().loadGroup(groupName).getOrDefault(false)) { if (!plugin.getDatastore().loadGroup(groupName).getUnchecked()) {
Message.GROUP_DOES_NOT_EXIST.send(sender); Message.GROUP_DOES_NOT_EXIST.send(sender);
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }

View File

@ -51,12 +51,12 @@ public class CreateGroup extends SingleMainCommand {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (plugin.getDatastore().loadGroup(groupName).getOrDefault(false)) { if (plugin.getDatastore().loadGroup(groupName).getUnchecked()) {
Message.GROUP_ALREADY_EXISTS.send(sender); Message.GROUP_ALREADY_EXISTS.send(sender);
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (!plugin.getDatastore().createAndLoadGroup(groupName).getOrDefault(false)) { if (!plugin.getDatastore().createAndLoadGroup(groupName).getUnchecked()) {
Message.CREATE_GROUP_ERROR.send(sender); Message.CREATE_GROUP_ERROR.send(sender);
return CommandResult.FAILURE; return CommandResult.FAILURE;
} }

View File

@ -55,7 +55,7 @@ public class DeleteGroup extends SingleMainCommand {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (!plugin.getDatastore().loadGroup(groupName).getOrDefault(false)) { if (!plugin.getDatastore().loadGroup(groupName).getUnchecked()) {
Message.GROUP_DOES_NOT_EXIST.send(sender); Message.GROUP_DOES_NOT_EXIST.send(sender);
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
@ -66,7 +66,7 @@ public class DeleteGroup extends SingleMainCommand {
return CommandResult.LOADING_ERROR; return CommandResult.LOADING_ERROR;
} }
if (!plugin.getDatastore().deleteGroup(group).getOrDefault(false)) { if (!plugin.getDatastore().deleteGroup(group).getUnchecked()) {
Message.DELETE_GROUP_ERROR.send(sender); Message.DELETE_GROUP_ERROR.send(sender);
return CommandResult.FAILURE; return CommandResult.FAILURE;
} }

View File

@ -57,7 +57,7 @@ public class GroupMainCommand extends MainCommand<Group> {
@Override @Override
protected Group getTarget(String target, LuckPermsPlugin plugin, Sender sender) { 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); Message.GROUP_NOT_FOUND.send(sender);
return null; return null;
} }

View File

@ -42,7 +42,7 @@ public class ListGroups extends SingleMainCommand {
@Override @Override
protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) { protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
if (!plugin.getDatastore().loadAllGroups().getOrDefault(false)) { if (!plugin.getDatastore().loadAllGroups().getUnchecked()) {
Message.GROUPS_LOAD_ERROR.send(sender); Message.GROUPS_LOAD_ERROR.send(sender);
return CommandResult.LOADING_ERROR; return CommandResult.LOADING_ERROR;
} }

View File

@ -47,12 +47,12 @@ public class GroupClone extends SubCommand<Group> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (plugin.getDatastore().loadGroup(newGroupName).getOrDefault(false)) { if (plugin.getDatastore().loadGroup(newGroupName).getUnchecked()) {
Message.GROUP_ALREADY_EXISTS.send(sender); Message.GROUP_ALREADY_EXISTS.send(sender);
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (!plugin.getDatastore().createAndLoadGroup(newGroupName).getOrDefault(false)) { if (!plugin.getDatastore().createAndLoadGroup(newGroupName).getUnchecked()) {
Message.CREATE_GROUP_ERROR.send(sender); Message.CREATE_GROUP_ERROR.send(sender);
return CommandResult.FAILURE; return CommandResult.FAILURE;
} }

View File

@ -47,12 +47,12 @@ public class GroupRename extends SubCommand<Group> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (plugin.getDatastore().loadGroup(newGroupName).getOrDefault(false)) { if (plugin.getDatastore().loadGroup(newGroupName).getUnchecked()) {
Message.GROUP_ALREADY_EXISTS.send(sender); Message.GROUP_ALREADY_EXISTS.send(sender);
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (!plugin.getDatastore().createAndLoadGroup(newGroupName).getOrDefault(false)) { if (!plugin.getDatastore().createAndLoadGroup(newGroupName).getUnchecked()) {
Message.CREATE_GROUP_ERROR.send(sender); Message.CREATE_GROUP_ERROR.send(sender);
return CommandResult.FAILURE; return CommandResult.FAILURE;
} }
@ -63,7 +63,7 @@ public class GroupRename extends SubCommand<Group> {
return CommandResult.LOADING_ERROR; return CommandResult.LOADING_ERROR;
} }
if (!plugin.getDatastore().deleteGroup(group).getOrDefault(false)) { if (!plugin.getDatastore().deleteGroup(group).getUnchecked()) {
Message.DELETE_GROUP_ERROR.send(sender); Message.DELETE_GROUP_ERROR.send(sender);
return CommandResult.FAILURE; return CommandResult.FAILURE;
} }

View File

@ -39,7 +39,7 @@ public class GroupShowTracks extends SubCommand<Group> {
@Override @Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
if (!plugin.getDatastore().loadAllTracks().getOrDefault(false)) { if (!plugin.getDatastore().loadAllTracks().getUnchecked()) {
Message.TRACKS_LOAD_ERROR.send(sender); Message.TRACKS_LOAD_ERROR.send(sender);
return CommandResult.LOADING_ERROR; return CommandResult.LOADING_ERROR;
} }

View File

@ -52,7 +52,7 @@ public class LogMainCommand extends MainCommand<Log> {
@Override @Override
protected Log getTarget(String target, LuckPermsPlugin plugin, Sender sender) { 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) { if (log == null) {
Message.LOG_LOAD_ERROR.send(sender); Message.LOG_LOAD_ERROR.send(sender);

View File

@ -74,7 +74,7 @@ public class LogRecent extends SubCommand<Log> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
UUID uuid = plugin.getDatastore().getUUID(s).getOrDefault(null); UUID uuid = plugin.getDatastore().getUUID(s).getUnchecked();
if (uuid == null) { if (uuid == null) {
Message.USER_NOT_FOUND.send(sender); Message.USER_NOT_FOUND.send(sender);

View File

@ -76,7 +76,7 @@ public class LogUserHistory extends SubCommand<Log> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
UUID uuid1 = plugin.getDatastore().getUUID(user).getOrDefault(null); UUID uuid1 = plugin.getDatastore().getUUID(user).getUnchecked();
if (uuid1 == null) { if (uuid1 == null) {
Message.USER_NOT_FOUND.send(sender); Message.USER_NOT_FOUND.send(sender);

View File

@ -121,7 +121,7 @@ public class MigrationBPermissions extends SubCommand<Object> {
} }
// Make a LuckPerms group for the one being migrated. // 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); me.lucko.luckperms.common.groups.Group lpGroup = plugin.getGroupManager().get(groupName);
try { try {
LogEntry.build() LogEntry.build()
@ -157,7 +157,7 @@ public class MigrationBPermissions extends SubCommand<Object> {
} }
// Make a LuckPerms user for the one being migrated. // 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); me.lucko.luckperms.common.users.User lpUser = plugin.getUserManager().get(uuid);
migrateHolder(plugin, world, user, lpUser); migrateHolder(plugin, world, user, lpUser);

View File

@ -63,7 +63,7 @@ public class MigrationBungeePerms extends SubCommand<Object> {
groupCount ++; groupCount ++;
// Make a LuckPerms group for the one being migrated // 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()); me.lucko.luckperms.common.groups.Group group = plugin.getGroupManager().get(g.getName().toLowerCase());
try { try {
LogEntry.build() LogEntry.build()
@ -187,7 +187,7 @@ public class MigrationBungeePerms extends SubCommand<Object> {
userCount++; userCount++;
// Make a LuckPerms user for the one being migrated. // 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()); me.lucko.luckperms.common.users.User user = plugin.getUserManager().get(u.getUUID());
// Migrate global perms // Migrate global perms

View File

@ -73,7 +73,7 @@ public class MigrationGroupManager extends SubCommand<Object> {
} }
for (Group g : gg.getGroupList()) { 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()); me.lucko.luckperms.common.groups.Group group = plugin.getGroupManager().get(g.getName().toLowerCase());
try { try {
LogEntry.build() LogEntry.build()
@ -202,7 +202,7 @@ public class MigrationGroupManager extends SubCommand<Object> {
log.info("GroupManager Migration: Found a total of " + users.size() + " users and " + groups.size() + " groups."); log.info("GroupManager Migration: Found a total of " + users.size() + " users and " + groups.size() + " groups.");
for (Map.Entry<String, Map<Map.Entry<String, String>, Boolean>> e : groups.entrySet()) { for (Map.Entry<String, Map<Map.Entry<String, String>, 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()); me.lucko.luckperms.common.groups.Group group = plugin.getGroupManager().get(e.getKey());
try { try {
LogEntry.build() LogEntry.build()
@ -245,7 +245,7 @@ public class MigrationGroupManager extends SubCommand<Object> {
} }
for (Map.Entry<UUID, Map<Map.Entry<String, String>, Boolean>> e : users.entrySet()) { for (Map.Entry<UUID, Map<Map.Entry<String, String>, 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()); me.lucko.luckperms.common.users.User user = plugin.getUserManager().get(e.getKey());
for (Map.Entry<Map.Entry<String, String>, Boolean> n : e.getValue().entrySet()) { for (Map.Entry<Map.Entry<String, String>, Boolean> n : e.getValue().entrySet()) {

View File

@ -102,7 +102,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
maxGroupWeight = Math.max(maxGroupWeight, groupWeight); maxGroupWeight = Math.max(maxGroupWeight, groupWeight);
final String name = group.getName().toLowerCase(); final String name = group.getName().toLowerCase();
plugin.getDatastore().createAndLoadGroup(name).getOrDefault(false); plugin.getDatastore().createAndLoadGroup(name).getUnchecked();
Group lpGroup = plugin.getGroupManager().get(name); Group lpGroup = plugin.getGroupManager().get(name);
try { try {
LogEntry.build() LogEntry.build()
@ -254,7 +254,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
} }
userCount++; userCount++;
plugin.getDatastore().loadUser(u, "null").getOrDefault(false); plugin.getDatastore().loadUser(u, "null").getUnchecked();
User lpUser = plugin.getUserManager().get(u); User lpUser = plugin.getUserManager().get(u);
try { try {

View File

@ -246,7 +246,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
log.info("PowerfulPerms Migration: Starting group migration."); log.info("PowerfulPerms Migration: Starting group migration.");
Map<Integer, Group> groups = pm.getGroups(); // All versions Map<Integer, Group> groups = pm.getGroups(); // All versions
for (Group g : groups.values()) { 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()); final me.lucko.luckperms.common.groups.Group group = plugin.getGroupManager().get(g.getName().toLowerCase());
try { try {
LogEntry.build() LogEntry.build()
@ -288,7 +288,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
progress.put(uuid, new CountDownLatch(2)); progress.put(uuid, new CountDownLatch(2));
// Create a LuckPerms user for the UUID // 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); User user = plugin.getUserManager().get(uuid);
// Get a list of Permissions held by the user from the PP API. // Get a list of Permissions held by the user from the PP API.

View File

@ -72,7 +72,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
// Migrate all groups // Migrate all groups
log.info("zPermissions Migration: Starting group migration."); log.info("zPermissions Migration: Starting group migration.");
for (String g : service.getAllGroups()) { 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()); Group group = plugin.getGroupManager().get(g.toLowerCase());
try { try {
LogEntry.build() LogEntry.build()
@ -121,7 +121,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
// Migrate all tracks // Migrate all tracks
log.info("zPermissions Migration: Starting track migration."); log.info("zPermissions Migration: Starting track migration.");
for (String t : service.getAllTracks()) { 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()); Track track = plugin.getTrackManager().get(t.toLowerCase());
try { try {
LogEntry.build() LogEntry.build()
@ -150,7 +150,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
// Migrate all users. // Migrate all users.
log.info("zPermissions Migration: Starting user migration."); log.info("zPermissions Migration: Starting user migration.");
for (UUID u : service.getAllPlayersUUID()) { for (UUID u : service.getAllPlayersUUID()) {
plugin.getDatastore().loadUser(u, "null").getOrDefault(false); plugin.getDatastore().loadUser(u, "null").getUnchecked();
User user = plugin.getUserManager().get(u); User user = plugin.getUserManager().get(u);
for (Map.Entry<String, Boolean> e : service.getPlayerPermissions(null, null, u).entrySet()) { for (Map.Entry<String, Boolean> e : service.getPlayerPermissions(null, null, u).entrySet()) {

View File

@ -118,13 +118,13 @@ public class ExportCommand extends SingleMainCommand {
// Export users // Export users
log.info("Export: Exporting all users. Finding a list of unique users to export."); log.info("Export: Exporting all users. Finding a list of unique users to export.");
Datastore ds = plugin.getDatastore(); Datastore ds = plugin.getDatastore();
Set<UUID> users = ds.getUniqueUsers().getOrDefault(null); Set<UUID> users = ds.getUniqueUsers().getUnchecked();
log.info("Export: Found " + users.size() + " unique users to export."); log.info("Export: Found " + users.size() + " unique users to export.");
int userCount = 0; int userCount = 0;
for (UUID uuid : users) { for (UUID uuid : users) {
userCount++; userCount++;
plugin.getDatastore().loadUser(uuid, "null").getOrDefault(false); plugin.getDatastore().loadUser(uuid, "null").getUnchecked();
User user = plugin.getUserManager().get(uuid); User user = plugin.getUserManager().get(uuid);
boolean inDefault = false; boolean inDefault = false;

View File

@ -39,7 +39,7 @@ public class SyncCommand extends SingleMainCommand {
@Override @Override
protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) { protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
Message.UPDATE_TASK_REQUEST.send(sender); Message.UPDATE_TASK_REQUEST.send(sender);
plugin.getUpdateTaskBuffer().request().getOrDefault(null); plugin.getUpdateTaskBuffer().request().getUnchecked();
Message.UPDATE_TASK_COMPLETE.send(sender); Message.UPDATE_TASK_COMPLETE.send(sender);
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} }

View File

@ -51,12 +51,12 @@ public class CreateTrack extends SingleMainCommand {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (plugin.getDatastore().loadTrack(trackName).getOrDefault(false)) { if (plugin.getDatastore().loadTrack(trackName).getUnchecked()) {
Message.TRACK_ALREADY_EXISTS.send(sender); Message.TRACK_ALREADY_EXISTS.send(sender);
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (!plugin.getDatastore().createAndLoadTrack(trackName).getOrDefault(false)) { if (!plugin.getDatastore().createAndLoadTrack(trackName).getUnchecked()) {
Message.CREATE_TRACK_ERROR.send(sender); Message.CREATE_TRACK_ERROR.send(sender);
return CommandResult.FAILURE; return CommandResult.FAILURE;
} }

View File

@ -49,7 +49,7 @@ public class DeleteTrack extends SingleMainCommand {
} }
String trackName = args.get(0).toLowerCase(); 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); Message.TRACK_DOES_NOT_EXIST.send(sender);
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
@ -60,7 +60,7 @@ public class DeleteTrack extends SingleMainCommand {
return CommandResult.LOADING_ERROR; return CommandResult.LOADING_ERROR;
} }
if (!plugin.getDatastore().deleteTrack(track).getOrDefault(false)) { if (!plugin.getDatastore().deleteTrack(track).getUnchecked()) {
Message.DELETE_TRACK_ERROR.send(sender); Message.DELETE_TRACK_ERROR.send(sender);
return CommandResult.FAILURE; return CommandResult.FAILURE;
} }

View File

@ -40,7 +40,7 @@ public class ListTracks extends SingleMainCommand {
@Override @Override
protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) { protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
if (!plugin.getDatastore().loadAllTracks().getOrDefault(false)) { if (!plugin.getDatastore().loadAllTracks().getUnchecked()) {
Message.TRACKS_LOAD_ERROR.send(sender); Message.TRACKS_LOAD_ERROR.send(sender);
return CommandResult.LOADING_ERROR; return CommandResult.LOADING_ERROR;
} }

View File

@ -50,7 +50,7 @@ public class TrackMainCommand extends MainCommand<Track> {
@Override @Override
protected Track getTarget(String target, LuckPermsPlugin plugin, Sender sender) { 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); Message.TRACK_NOT_FOUND.send(sender);
return null; return null;
} }

View File

@ -50,7 +50,7 @@ public class TrackAppend extends SubCommand<Track> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (!plugin.getDatastore().loadGroup(groupName).getOrDefault(false)) { if (!plugin.getDatastore().loadGroup(groupName).getUnchecked()) {
Message.GROUP_DOES_NOT_EXIST.send(sender); Message.GROUP_DOES_NOT_EXIST.send(sender);
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }

View File

@ -47,12 +47,12 @@ public class TrackClone extends SubCommand<Track> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (plugin.getDatastore().loadTrack(newTrackName).getOrDefault(false)) { if (plugin.getDatastore().loadTrack(newTrackName).getUnchecked()) {
Message.TRACK_ALREADY_EXISTS.send(sender); Message.TRACK_ALREADY_EXISTS.send(sender);
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (!plugin.getDatastore().createAndLoadTrack(newTrackName).getOrDefault(false)) { if (!plugin.getDatastore().createAndLoadTrack(newTrackName).getUnchecked()) {
Message.CREATE_TRACK_ERROR.send(sender); Message.CREATE_TRACK_ERROR.send(sender);
return CommandResult.FAILURE; return CommandResult.FAILURE;
} }

View File

@ -61,7 +61,7 @@ public class TrackInsert extends SubCommand<Track> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (!plugin.getDatastore().loadGroup(groupName).getOrDefault(false)) { if (!plugin.getDatastore().loadGroup(groupName).getUnchecked()) {
Message.GROUP_DOES_NOT_EXIST.send(sender); Message.GROUP_DOES_NOT_EXIST.send(sender);
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }

View File

@ -47,12 +47,12 @@ public class TrackRename extends SubCommand<Track> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (plugin.getDatastore().loadTrack(newTrackName).getOrDefault(false)) { if (plugin.getDatastore().loadTrack(newTrackName).getUnchecked()) {
Message.TRACK_ALREADY_EXISTS.send(sender); Message.TRACK_ALREADY_EXISTS.send(sender);
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (!plugin.getDatastore().createAndLoadTrack(newTrackName).getOrDefault(false)) { if (!plugin.getDatastore().createAndLoadTrack(newTrackName).getUnchecked()) {
Message.CREATE_TRACK_ERROR.send(sender); Message.CREATE_TRACK_ERROR.send(sender);
return CommandResult.FAILURE; return CommandResult.FAILURE;
} }
@ -63,7 +63,7 @@ public class TrackRename extends SubCommand<Track> {
return CommandResult.LOADING_ERROR; return CommandResult.LOADING_ERROR;
} }
if (!plugin.getDatastore().deleteTrack(track).getOrDefault(false)) { if (!plugin.getDatastore().deleteTrack(track).getUnchecked()) {
Message.DELETE_TRACK_ERROR.send(sender); Message.DELETE_TRACK_ERROR.send(sender);
return CommandResult.FAILURE; return CommandResult.FAILURE;
} }

View File

@ -70,7 +70,7 @@ public class UserMainCommand extends MainCommand<User> {
return null; return null;
} }
u = plugin.getDatastore().getUUID(target).getOrDefault(null); u = plugin.getDatastore().getUUID(target).getUnchecked();
if (u == null) { if (u == null) {
Message.USER_NOT_FOUND.send(sender); Message.USER_NOT_FOUND.send(sender);
return null; return null;
@ -80,10 +80,10 @@ public class UserMainCommand extends MainCommand<User> {
} }
} }
String name = plugin.getDatastore().getName(u).getOrDefault(null); String name = plugin.getDatastore().getName(u).getUnchecked();
if (name == null) name = "null"; 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); Message.LOADING_ERROR.send(sender);
} }

View File

@ -54,7 +54,7 @@ public class UserDemote extends SubCommand<User> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (!plugin.getDatastore().loadTrack(trackName).getOrDefault(false)) { if (!plugin.getDatastore().loadTrack(trackName).getUnchecked()) {
Message.TRACK_DOES_NOT_EXIST.send(sender); Message.TRACK_DOES_NOT_EXIST.send(sender);
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
@ -85,7 +85,7 @@ public class UserDemote extends SubCommand<User> {
return CommandResult.STATE_ERROR; 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); Message.USER_DEMOTE_ERROR_MALFORMED.send(sender, previous);
return CommandResult.STATE_ERROR; return CommandResult.STATE_ERROR;
} }

View File

@ -54,7 +54,7 @@ public class UserPromote extends SubCommand<User> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (!plugin.getDatastore().loadTrack(trackName).getOrDefault(false)) { if (!plugin.getDatastore().loadTrack(trackName).getUnchecked()) {
Message.TRACK_DOES_NOT_EXIST.send(sender); Message.TRACK_DOES_NOT_EXIST.send(sender);
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
@ -85,7 +85,7 @@ public class UserPromote extends SubCommand<User> {
return CommandResult.STATE_ERROR; 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); Message.USER_PROMOTE_ERROR_MALFORMED.send(sender, next);
return CommandResult.STATE_ERROR; return CommandResult.STATE_ERROR;
} }

View File

@ -47,7 +47,7 @@ public class UserShowPos extends SubCommand<User> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (!plugin.getDatastore().loadTrack(trackName).getOrDefault(false)) { if (!plugin.getDatastore().loadTrack(trackName).getUnchecked()) {
Message.TRACK_DOES_NOT_EXIST.send(sender); Message.TRACK_DOES_NOT_EXIST.send(sender);
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }

View File

@ -40,7 +40,7 @@ public class UserShowTracks extends SubCommand<User> {
@Override @Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
if (!plugin.getDatastore().loadAllTracks().getOrDefault(false)) { if (!plugin.getDatastore().loadAllTracks().getUnchecked()) {
Message.TRACKS_LOAD_ERROR.send(sender); Message.TRACKS_LOAD_ERROR.send(sender);
return CommandResult.LOADING_ERROR; return CommandResult.LOADING_ERROR;
} }

View File

@ -61,10 +61,10 @@ public class BulkEditGroup extends SubCommand<Datastore> {
return CommandResult.FAILURE; return CommandResult.FAILURE;
} }
Set<UUID> uuids = datastore.getUniqueUsers().getOrDefault(null); Set<UUID> uuids = datastore.getUniqueUsers().getUnchecked();
for (UUID u : uuids) { for (UUID u : uuids) {
plugin.getDatastore().loadUser(u, "null").getOrDefault(false); plugin.getDatastore().loadUser(u, "null").getUnchecked();
User user = plugin.getUserManager().get(u); User user = plugin.getUserManager().get(u);
if (user == null) { if (user == null) {
continue; continue;

View File

@ -61,10 +61,10 @@ public class BulkEditPermission extends SubCommand<Datastore> {
return CommandResult.FAILURE; return CommandResult.FAILURE;
} }
Set<UUID> uuids = datastore.getUniqueUsers().getOrDefault(null); Set<UUID> uuids = datastore.getUniqueUsers().getUnchecked();
for (UUID u : uuids) { for (UUID u : uuids) {
plugin.getDatastore().loadUser(u, "null").getOrDefault(false); plugin.getDatastore().loadUser(u, "null").getUnchecked();
User user = plugin.getUserManager().get(u); User user = plugin.getUserManager().get(u);
if (user == null) { if (user == null) {
continue; continue;

View File

@ -41,14 +41,14 @@ public class UpdateTask implements Runnable {
if (event.isCancelled()) return; if (event.isCancelled()) return;
// Reload all groups // Reload all groups
plugin.getDatastore().loadAllGroups().getOrDefault(false); plugin.getDatastore().loadAllGroups().getUnchecked();
String defaultGroup = plugin.getConfiguration().getDefaultGroupName(); String defaultGroup = plugin.getConfiguration().getDefaultGroupName();
if (!plugin.getGroupManager().isLoaded(defaultGroup)) { if (!plugin.getGroupManager().isLoaded(defaultGroup)) {
plugin.getDatastore().createAndLoadGroup(defaultGroup).getOrDefault(false); plugin.getDatastore().createAndLoadGroup(defaultGroup).getUnchecked();
} }
// Reload all tracks // Reload all tracks
plugin.getDatastore().loadAllTracks().getOrDefault(false); plugin.getDatastore().loadAllTracks().getUnchecked();
// Refresh all online users. // Refresh all online users.
plugin.getUserManager().updateAllUsers(); plugin.getUserManager().updateAllUsers();

View File

@ -25,6 +25,7 @@ package me.lucko.luckperms.common.storage;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import me.lucko.luckperms.api.LogEntry; import me.lucko.luckperms.api.LogEntry;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.data.Log; import me.lucko.luckperms.common.data.Log;
import me.lucko.luckperms.common.groups.Group; import me.lucko.luckperms.common.groups.Group;
import me.lucko.luckperms.common.storage.backing.AbstractBacking; import me.lucko.luckperms.common.storage.backing.AbstractBacking;
@ -43,8 +44,11 @@ import java.util.function.Supplier;
*/ */
@RequiredArgsConstructor(access = AccessLevel.PRIVATE) @RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public class AbstractDatastore implements Datastore { 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 final AbstractBacking backing;
@ -89,11 +93,8 @@ public class AbstractDatastore implements Datastore {
} }
@Override @Override
public LPFuture<Void> shutdown() { public void shutdown() {
return makeFuture(() -> {
backing.shutdown(); backing.shutdown();
return null;
});
} }
@Override @Override

View File

@ -50,28 +50,28 @@ public class BufferedOutputDatastore implements Datastore, Runnable {
private final Buffer<User, Boolean> userOutputBuffer = new Buffer<User, Boolean>() { private final Buffer<User, Boolean> userOutputBuffer = new Buffer<User, Boolean>() {
@Override @Override
public Boolean dequeue(User user) { public Boolean dequeue(User user) {
return backing.saveUser(user).getOrDefault(false); return backing.saveUser(user).getUnchecked();
} }
}; };
private final Buffer<Group, Boolean> groupOutputBuffer = new Buffer<Group, Boolean>() { private final Buffer<Group, Boolean> groupOutputBuffer = new Buffer<Group, Boolean>() {
@Override @Override
public Boolean dequeue(Group group) { public Boolean dequeue(Group group) {
return backing.saveGroup(group).getOrDefault(false); return backing.saveGroup(group).getUnchecked();
} }
}; };
private final Buffer<Track, Boolean> trackOutputBuffer = new Buffer<Track, Boolean>() { private final Buffer<Track, Boolean> trackOutputBuffer = new Buffer<Track, Boolean>() {
@Override @Override
public Boolean dequeue(Track track) { public Boolean dequeue(Track track) {
return backing.saveTrack(track).getOrDefault(false); return backing.saveTrack(track).getUnchecked();
} }
}; };
private final Buffer<UserIdentifier, Boolean> uuidDataOutputBuffer = new Buffer<UserIdentifier, Boolean>() { private final Buffer<UserIdentifier, Boolean> uuidDataOutputBuffer = new Buffer<UserIdentifier, Boolean>() {
@Override @Override
protected Boolean dequeue(UserIdentifier userIdentifier) { 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 @Override
public LPFuture<Void> shutdown() { public void shutdown() {
forceFlush(); forceFlush();
return backing.shutdown(); backing.shutdown();
} }
@Override @Override

View File

@ -57,7 +57,7 @@ public interface Datastore {
} }
void init(); void init();
LPFuture<Void> shutdown(); void shutdown();
LPFuture<Boolean> logAction(LogEntry entry); LPFuture<Boolean> logAction(LogEntry entry);
LPFuture<Log> getLog(); LPFuture<Log> getLog();
LPFuture<Boolean> loadUser(UUID uuid, String username); LPFuture<Boolean> loadUser(UUID uuid, String username);
@ -80,133 +80,133 @@ public interface Datastore {
default void logAction(LogEntry entry, Callback<Boolean> callback) { default void logAction(LogEntry entry, Callback<Boolean> callback) {
doAsync(() -> { doAsync(() -> {
boolean result = logAction(entry).getOrDefault(false); boolean result = logAction(entry).getUnchecked();
doSync(() -> callback.onComplete(result)); doSync(() -> callback.onComplete(result));
}); });
} }
default void getLog(Callback<Log> callback) { default void getLog(Callback<Log> callback) {
doAsync(() -> { doAsync(() -> {
Log result = getLog().getOrDefault(null); Log result = getLog().getUnchecked();
doSync(() -> callback.onComplete(result)); doSync(() -> callback.onComplete(result));
}); });
} }
default void loadUser(UUID uuid, String username, Callback<Boolean> callback) { default void loadUser(UUID uuid, String username, Callback<Boolean> callback) {
doAsync(() -> { doAsync(() -> {
boolean result = loadUser(uuid, username).getOrDefault(false); boolean result = loadUser(uuid, username).getUnchecked();
doSync(() -> callback.onComplete(result)); doSync(() -> callback.onComplete(result));
}); });
} }
default void saveUser(User user, Callback<Boolean> callback) { default void saveUser(User user, Callback<Boolean> callback) {
doAsync(() -> { doAsync(() -> {
boolean result = saveUser(user).getOrDefault(false); boolean result = saveUser(user).getUnchecked();
doSync(() -> callback.onComplete(result)); doSync(() -> callback.onComplete(result));
}); });
} }
default void cleanupUsers(Callback<Boolean> callback) { default void cleanupUsers(Callback<Boolean> callback) {
doAsync(() -> { doAsync(() -> {
boolean result = cleanupUsers().getOrDefault(false); boolean result = cleanupUsers().getUnchecked();
doSync(() -> callback.onComplete(result)); doSync(() -> callback.onComplete(result));
}); });
} }
default void getUniqueUsers(Callback<Set<UUID>> callback) { default void getUniqueUsers(Callback<Set<UUID>> callback) {
doAsync(() -> { doAsync(() -> {
Set<UUID> result = getUniqueUsers().getOrDefault(null); Set<UUID> result = getUniqueUsers().getUnchecked();
doSync(() -> callback.onComplete(result)); doSync(() -> callback.onComplete(result));
}); });
} }
default void createAndLoadGroup(String name, Callback<Boolean> callback) { default void createAndLoadGroup(String name, Callback<Boolean> callback) {
doAsync(() -> { doAsync(() -> {
boolean result = createAndLoadGroup(name).getOrDefault(false); boolean result = createAndLoadGroup(name).getUnchecked();
doSync(() -> callback.onComplete(result)); doSync(() -> callback.onComplete(result));
}); });
} }
default void loadGroup(String name, Callback<Boolean> callback) { default void loadGroup(String name, Callback<Boolean> callback) {
doAsync(() -> { doAsync(() -> {
boolean result = loadGroup(name).getOrDefault(false); boolean result = loadGroup(name).getUnchecked();
doSync(() -> callback.onComplete(result)); doSync(() -> callback.onComplete(result));
}); });
} }
default void loadAllGroups(Callback<Boolean> callback) { default void loadAllGroups(Callback<Boolean> callback) {
doAsync(() -> { doAsync(() -> {
boolean result = loadAllGroups().getOrDefault(false); boolean result = loadAllGroups().getUnchecked();
doSync(() -> callback.onComplete(result)); doSync(() -> callback.onComplete(result));
}); });
} }
default void saveGroup(Group group, Callback<Boolean> callback) { default void saveGroup(Group group, Callback<Boolean> callback) {
doAsync(() -> { doAsync(() -> {
boolean result = saveGroup(group).getOrDefault(false); boolean result = saveGroup(group).getUnchecked();
doSync(() -> callback.onComplete(result)); doSync(() -> callback.onComplete(result));
}); });
} }
default void deleteGroup(Group group, Callback<Boolean> callback) { default void deleteGroup(Group group, Callback<Boolean> callback) {
doAsync(() -> { doAsync(() -> {
boolean result = deleteGroup(group).getOrDefault(false); boolean result = deleteGroup(group).getUnchecked();
doSync(() -> callback.onComplete(result)); doSync(() -> callback.onComplete(result));
}); });
} }
default void createAndLoadTrack(String name, Callback<Boolean> callback) { default void createAndLoadTrack(String name, Callback<Boolean> callback) {
doAsync(() -> { doAsync(() -> {
boolean result = createAndLoadTrack(name).getOrDefault(false); boolean result = createAndLoadTrack(name).getUnchecked();
doSync(() -> callback.onComplete(result)); doSync(() -> callback.onComplete(result));
}); });
} }
default void loadTrack(String name, Callback<Boolean> callback) { default void loadTrack(String name, Callback<Boolean> callback) {
doAsync(() -> { doAsync(() -> {
boolean result = loadTrack(name).getOrDefault(false); boolean result = loadTrack(name).getUnchecked();
doSync(() -> callback.onComplete(result)); doSync(() -> callback.onComplete(result));
}); });
} }
default void loadAllTracks(Callback<Boolean> callback) { default void loadAllTracks(Callback<Boolean> callback) {
doAsync(() -> { doAsync(() -> {
boolean result = loadAllTracks().getOrDefault(false); boolean result = loadAllTracks().getUnchecked();
doSync(() -> callback.onComplete(result)); doSync(() -> callback.onComplete(result));
}); });
} }
default void saveTrack(Track track, Callback<Boolean> callback) { default void saveTrack(Track track, Callback<Boolean> callback) {
doAsync(() -> { doAsync(() -> {
boolean result = saveTrack(track).getOrDefault(false); boolean result = saveTrack(track).getUnchecked();
doSync(() -> callback.onComplete(result)); doSync(() -> callback.onComplete(result));
}); });
} }
default void deleteTrack(Track track, Callback<Boolean> callback) { default void deleteTrack(Track track, Callback<Boolean> callback) {
doAsync(() -> { doAsync(() -> {
boolean result = deleteTrack(track).getOrDefault(false); boolean result = deleteTrack(track).getUnchecked();
doSync(() -> callback.onComplete(result)); doSync(() -> callback.onComplete(result));
}); });
} }
default void saveUUIDData(String username, UUID uuid, Callback<Boolean> callback) { default void saveUUIDData(String username, UUID uuid, Callback<Boolean> callback) {
doAsync(() -> { doAsync(() -> {
boolean result = saveUUIDData(username, uuid).getOrDefault(false); boolean result = saveUUIDData(username, uuid).getUnchecked();
doSync(() -> callback.onComplete(result)); doSync(() -> callback.onComplete(result));
}); });
} }
default void getUUID(String username, Callback<UUID> callback) { default void getUUID(String username, Callback<UUID> callback) {
doAsync(() -> { doAsync(() -> {
UUID result = getUUID(username).getOrDefault(null); UUID result = getUUID(username).getUnchecked();
doSync(() -> callback.onComplete(result)); doSync(() -> callback.onComplete(result));
}); });
} }
default void getName(UUID uuid, Callback<String> callback) { default void getName(UUID uuid, Callback<String> callback) {
doAsync(() -> { doAsync(() -> {
String result = getName(uuid).getOrDefault(null); String result = getName(uuid).getUnchecked();
doSync(() -> callback.onComplete(result)); doSync(() -> callback.onComplete(result));
}); });
} }

View File

@ -31,7 +31,6 @@ import me.lucko.luckperms.common.data.Log;
import me.lucko.luckperms.common.groups.Group; import me.lucko.luckperms.common.groups.Group;
import me.lucko.luckperms.common.tracks.Track; import me.lucko.luckperms.common.tracks.Track;
import me.lucko.luckperms.common.users.User; import me.lucko.luckperms.common.users.User;
import me.lucko.luckperms.common.utils.AbstractFuture;
import me.lucko.luckperms.common.utils.LPFuture; import me.lucko.luckperms.common.utils.LPFuture;
import java.util.Map; import java.util.Map;
@ -83,13 +82,8 @@ public class SplitBacking implements Datastore {
} }
@Override @Override
public LPFuture<Void> shutdown() { public void shutdown() {
AbstractFuture<Void> future = new AbstractFuture<>();
doAsync(() -> {
backing.values().forEach(Datastore::shutdown); backing.values().forEach(Datastore::shutdown);
future.complete(null);
});
return future;
} }
@Override @Override

View File

@ -84,19 +84,17 @@ public class StorageFactory {
private static Datastore fromString(String storageMethod, LuckPermsPlugin plugin) { private static Datastore fromString(String storageMethod, LuckPermsPlugin plugin) {
switch (storageMethod) { switch (storageMethod) {
case "mysql": case "mysql":
BufferedOutputDatastore bod = BufferedOutputDatastore.wrap(AbstractDatastore.wrap(new MySQLBacking(plugin, plugin.getConfiguration().getDatabaseValues())), 1000L); return AbstractDatastore.wrap(plugin, new MySQLBacking(plugin, plugin.getConfiguration().getDatabaseValues()));
plugin.doAsyncRepeating(bod, 10L);
return bod;
case "sqlite": 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": 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": case "mongodb":
return AbstractDatastore.wrap(new MongoDBBacking(plugin, plugin.getConfiguration().getDatabaseValues())); return AbstractDatastore.wrap(plugin, new MongoDBBacking(plugin, plugin.getConfiguration().getDatabaseValues()));
case "yaml": case "yaml":
return AbstractDatastore.wrap(new YAMLBacking(plugin, plugin.getDataFolder())); return AbstractDatastore.wrap(plugin, new YAMLBacking(plugin, plugin.getDataFolder()));
default: default:
return AbstractDatastore.wrap(new JSONBacking(plugin, plugin.getDataFolder())); return AbstractDatastore.wrap(plugin, new JSONBacking(plugin, plugin.getDataFolder()));
} }
} }
} }

View File

@ -80,7 +80,7 @@ public class TolerantDatastore implements Datastore {
} }
@Override @Override
public LPFuture<Void> shutdown() { public void shutdown() {
// Wait for other threads to finish. // Wait for other threads to finish.
try { try {
phaser.awaitAdvanceInterruptibly(phaser.getPhase(), 5, TimeUnit.SECONDS); phaser.awaitAdvanceInterruptibly(phaser.getPhase(), 5, TimeUnit.SECONDS);
@ -88,7 +88,7 @@ public class TolerantDatastore implements Datastore {
e.printStackTrace(); e.printStackTrace();
} }
return backing.shutdown(); backing.shutdown();
} }
@Override @Override

View File

@ -135,7 +135,7 @@ public class UserManager extends AbstractManager<UserIdentifier, User> {
plugin.doAsync(() -> { plugin.doAsync(() -> {
for (UUID uuid : players) { for (UUID uuid : players) {
UUID internal = plugin.getUuidCache().getUUID(uuid); UUID internal = plugin.getUuidCache().getUUID(uuid);
plugin.getDatastore().loadUser(internal, "null").getOrDefault(false); plugin.getDatastore().loadUser(internal, "null").getUnchecked();
User user = get(internal); User user = get(internal);
user.getRefreshBuffer().request(); user.getRefreshBuffer().request();
} }

View File

@ -41,7 +41,7 @@ public class AbstractListener {
final UuidCache cache = plugin.getUuidCache(); final UuidCache cache = plugin.getUuidCache();
if (!cache.isOnlineMode()) { if (!cache.isOnlineMode()) {
UUID uuid = plugin.getDatastore().force().getUUID(username).getOrDefault(null); UUID uuid = plugin.getDatastore().force().getUUID(username).getUnchecked();
if (uuid != null) { if (uuid != null) {
cache.addToCache(u, uuid); cache.addToCache(u, uuid);
} else { } else {
@ -51,7 +51,7 @@ public class AbstractListener {
plugin.getDatastore().force().saveUUIDData(username, u, Callback.empty()); plugin.getDatastore().force().saveUUIDData(username, u, Callback.empty());
} }
} else { } else {
UUID uuid = plugin.getDatastore().getUUID(username).getOrDefault(null); UUID uuid = plugin.getDatastore().getUUID(username).getUnchecked();
if (uuid == null) { if (uuid == null) {
plugin.getApiProvider().fireEventAsync(new UserFirstLoginEvent(u, username)); 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().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)); User user = plugin.getUserManager().get(cache.getUUID(u));
if (user == null) { if (user == null) {
plugin.getLog().warn("Failed to load user: " + username); 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 they were given a default, persist the new assignments back to the storage.
if (save) { 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. user.setupData(false); // Pretty nasty calculation call. Sets up the caching system so data is ready when the user joins.

View File

@ -22,17 +22,14 @@
package me.lucko.luckperms.common.utils; package me.lucko.luckperms.common.utils;
import java.util.concurrent.ExecutionException; import com.google.common.util.concurrent.Futures;
import java.util.concurrent.Future; import java.util.concurrent.Future;
public interface LPFuture<T> extends Future<T> { public interface LPFuture<T> extends Future<T> {
default T getOrDefault(T def) { default T getUnchecked() {
try { return Futures.getUnchecked(this);
return get();
} catch (InterruptedException | ExecutionException e) {
return def;
}
} }
} }