Use LoadingCache instead of a regular map + more datastore fixes
This commit is contained in:
parent
55a0de7899
commit
33c78e4a17
@ -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();
|
||||
|
@ -222,7 +222,7 @@ public class LPPermissible extends PermissibleBase {
|
||||
}
|
||||
|
||||
if (hasData()) {
|
||||
user.getUserData().invalidateCache();
|
||||
user.getUserData().invalidatePermissionCalculators();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
|
@ -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<UUID> 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<Contexts, PermissionData> permission = new ConcurrentHashMap<>();
|
||||
private final Map<Contexts, MetaData> meta = new ConcurrentHashMap<>();
|
||||
private final LoadingCache<Contexts, PermissionData> permission = CacheBuilder.newBuilder()
|
||||
.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.
|
||||
@ -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<Contexts> 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<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
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<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() {
|
||||
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() + ")");
|
||||
|
@ -162,17 +162,17 @@ public abstract class SubCommand<T> {
|
||||
}
|
||||
|
||||
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<T> {
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public class GroupMainCommand extends MainCommand<Group> {
|
||||
|
||||
@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;
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ public class ListGroups extends SingleMainCommand {
|
||||
|
||||
@Override
|
||||
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);
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
@ -47,12 +47,12 @@ public class GroupClone extends SubCommand<Group> {
|
||||
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;
|
||||
}
|
||||
|
@ -47,12 +47,12 @@ public class GroupRename extends SubCommand<Group> {
|
||||
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<Group> {
|
||||
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;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public class GroupShowTracks extends SubCommand<Group> {
|
||||
|
||||
@Override
|
||||
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);
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public class LogMainCommand extends MainCommand<Log> {
|
||||
|
||||
@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);
|
||||
|
@ -74,7 +74,7 @@ public class LogRecent extends SubCommand<Log> {
|
||||
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);
|
||||
|
@ -76,7 +76,7 @@ public class LogUserHistory extends SubCommand<Log> {
|
||||
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);
|
||||
|
@ -121,7 +121,7 @@ public class MigrationBPermissions extends SubCommand<Object> {
|
||||
}
|
||||
|
||||
// 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<Object> {
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
@ -63,7 +63,7 @@ public class MigrationBungeePerms extends SubCommand<Object> {
|
||||
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<Object> {
|
||||
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
|
||||
|
@ -73,7 +73,7 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
||||
}
|
||||
|
||||
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<Object> {
|
||||
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()) {
|
||||
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<Object> {
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
for (Map.Entry<Map.Entry<String, String>, Boolean> n : e.getValue().entrySet()) {
|
||||
|
@ -102,7 +102,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
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<Object> {
|
||||
}
|
||||
|
||||
userCount++;
|
||||
plugin.getDatastore().loadUser(u, "null").getOrDefault(false);
|
||||
plugin.getDatastore().loadUser(u, "null").getUnchecked();
|
||||
User lpUser = plugin.getUserManager().get(u);
|
||||
|
||||
try {
|
||||
|
@ -246,7 +246,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
||||
log.info("PowerfulPerms Migration: Starting group migration.");
|
||||
Map<Integer, Group> 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<Object> {
|
||||
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.
|
||||
|
@ -72,7 +72,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
||||
// 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<Object> {
|
||||
// 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<Object> {
|
||||
// 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<String, Boolean> e : service.getPlayerPermissions(null, null, u).entrySet()) {
|
||||
|
@ -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<UUID> users = ds.getUniqueUsers().getOrDefault(null);
|
||||
Set<UUID> 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;
|
||||
|
@ -39,7 +39,7 @@ public class SyncCommand extends SingleMainCommand {
|
||||
@Override
|
||||
protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> 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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public class ListTracks extends SingleMainCommand {
|
||||
|
||||
@Override
|
||||
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);
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public class TrackMainCommand extends MainCommand<Track> {
|
||||
|
||||
@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;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public class TrackAppend extends SubCommand<Track> {
|
||||
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;
|
||||
}
|
||||
|
@ -47,12 +47,12 @@ public class TrackClone extends SubCommand<Track> {
|
||||
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;
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ public class TrackInsert extends SubCommand<Track> {
|
||||
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;
|
||||
}
|
||||
|
@ -47,12 +47,12 @@ public class TrackRename extends SubCommand<Track> {
|
||||
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<Track> {
|
||||
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;
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ public class UserMainCommand extends MainCommand<User> {
|
||||
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<User> {
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ public class UserDemote extends SubCommand<User> {
|
||||
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<User> {
|
||||
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;
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ public class UserPromote extends SubCommand<User> {
|
||||
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<User> {
|
||||
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;
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public class UserShowPos extends SubCommand<User> {
|
||||
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;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public class UserShowTracks extends SubCommand<User> {
|
||||
|
||||
@Override
|
||||
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);
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
@ -61,10 +61,10 @@ public class BulkEditGroup extends SubCommand<Datastore> {
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
Set<UUID> uuids = datastore.getUniqueUsers().getOrDefault(null);
|
||||
Set<UUID> 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;
|
||||
|
@ -61,10 +61,10 @@ public class BulkEditPermission extends SubCommand<Datastore> {
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
Set<UUID> uuids = datastore.getUniqueUsers().getOrDefault(null);
|
||||
Set<UUID> 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;
|
||||
|
@ -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();
|
||||
|
@ -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 <T> LPFuture<T> makeFuture(Supplier<T> supplier) {
|
||||
@ -89,11 +93,8 @@ public class AbstractDatastore implements Datastore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public LPFuture<Void> shutdown() {
|
||||
return makeFuture(() -> {
|
||||
backing.shutdown();
|
||||
return null;
|
||||
});
|
||||
public void shutdown() {
|
||||
backing.shutdown();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -50,28 +50,28 @@ public class BufferedOutputDatastore implements Datastore, Runnable {
|
||||
private final Buffer<User, Boolean> userOutputBuffer = new Buffer<User, Boolean>() {
|
||||
@Override
|
||||
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>() {
|
||||
@Override
|
||||
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>() {
|
||||
@Override
|
||||
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>() {
|
||||
@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<Void> shutdown() {
|
||||
public void shutdown() {
|
||||
forceFlush();
|
||||
return backing.shutdown();
|
||||
backing.shutdown();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,7 +57,7 @@ public interface Datastore {
|
||||
}
|
||||
|
||||
void init();
|
||||
LPFuture<Void> shutdown();
|
||||
void shutdown();
|
||||
LPFuture<Boolean> logAction(LogEntry entry);
|
||||
LPFuture<Log> getLog();
|
||||
LPFuture<Boolean> loadUser(UUID uuid, String username);
|
||||
@ -80,133 +80,133 @@ public interface Datastore {
|
||||
|
||||
default void logAction(LogEntry entry, Callback<Boolean> callback) {
|
||||
doAsync(() -> {
|
||||
boolean result = logAction(entry).getOrDefault(false);
|
||||
boolean result = logAction(entry).getUnchecked();
|
||||
doSync(() -> callback.onComplete(result));
|
||||
});
|
||||
}
|
||||
|
||||
default void getLog(Callback<Log> callback) {
|
||||
doAsync(() -> {
|
||||
Log result = getLog().getOrDefault(null);
|
||||
Log result = getLog().getUnchecked();
|
||||
doSync(() -> callback.onComplete(result));
|
||||
});
|
||||
}
|
||||
|
||||
default void loadUser(UUID uuid, String username, Callback<Boolean> 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<Boolean> callback) {
|
||||
doAsync(() -> {
|
||||
boolean result = saveUser(user).getOrDefault(false);
|
||||
boolean result = saveUser(user).getUnchecked();
|
||||
doSync(() -> callback.onComplete(result));
|
||||
});
|
||||
}
|
||||
|
||||
default void cleanupUsers(Callback<Boolean> callback) {
|
||||
doAsync(() -> {
|
||||
boolean result = cleanupUsers().getOrDefault(false);
|
||||
boolean result = cleanupUsers().getUnchecked();
|
||||
doSync(() -> callback.onComplete(result));
|
||||
});
|
||||
}
|
||||
|
||||
default void getUniqueUsers(Callback<Set<UUID>> callback) {
|
||||
doAsync(() -> {
|
||||
Set<UUID> result = getUniqueUsers().getOrDefault(null);
|
||||
Set<UUID> result = getUniqueUsers().getUnchecked();
|
||||
doSync(() -> callback.onComplete(result));
|
||||
});
|
||||
}
|
||||
|
||||
default void createAndLoadGroup(String name, Callback<Boolean> callback) {
|
||||
doAsync(() -> {
|
||||
boolean result = createAndLoadGroup(name).getOrDefault(false);
|
||||
boolean result = createAndLoadGroup(name).getUnchecked();
|
||||
doSync(() -> callback.onComplete(result));
|
||||
});
|
||||
}
|
||||
|
||||
default void loadGroup(String name, Callback<Boolean> callback) {
|
||||
doAsync(() -> {
|
||||
boolean result = loadGroup(name).getOrDefault(false);
|
||||
boolean result = loadGroup(name).getUnchecked();
|
||||
doSync(() -> callback.onComplete(result));
|
||||
});
|
||||
}
|
||||
|
||||
default void loadAllGroups(Callback<Boolean> callback) {
|
||||
doAsync(() -> {
|
||||
boolean result = loadAllGroups().getOrDefault(false);
|
||||
boolean result = loadAllGroups().getUnchecked();
|
||||
doSync(() -> callback.onComplete(result));
|
||||
});
|
||||
}
|
||||
|
||||
default void saveGroup(Group group, Callback<Boolean> callback) {
|
||||
doAsync(() -> {
|
||||
boolean result = saveGroup(group).getOrDefault(false);
|
||||
boolean result = saveGroup(group).getUnchecked();
|
||||
doSync(() -> callback.onComplete(result));
|
||||
});
|
||||
}
|
||||
|
||||
default void deleteGroup(Group group, Callback<Boolean> callback) {
|
||||
doAsync(() -> {
|
||||
boolean result = deleteGroup(group).getOrDefault(false);
|
||||
boolean result = deleteGroup(group).getUnchecked();
|
||||
doSync(() -> callback.onComplete(result));
|
||||
});
|
||||
}
|
||||
|
||||
default void createAndLoadTrack(String name, Callback<Boolean> callback) {
|
||||
doAsync(() -> {
|
||||
boolean result = createAndLoadTrack(name).getOrDefault(false);
|
||||
boolean result = createAndLoadTrack(name).getUnchecked();
|
||||
doSync(() -> callback.onComplete(result));
|
||||
});
|
||||
}
|
||||
|
||||
default void loadTrack(String name, Callback<Boolean> callback) {
|
||||
doAsync(() -> {
|
||||
boolean result = loadTrack(name).getOrDefault(false);
|
||||
boolean result = loadTrack(name).getUnchecked();
|
||||
doSync(() -> callback.onComplete(result));
|
||||
});
|
||||
}
|
||||
|
||||
default void loadAllTracks(Callback<Boolean> callback) {
|
||||
doAsync(() -> {
|
||||
boolean result = loadAllTracks().getOrDefault(false);
|
||||
boolean result = loadAllTracks().getUnchecked();
|
||||
doSync(() -> callback.onComplete(result));
|
||||
});
|
||||
}
|
||||
|
||||
default void saveTrack(Track track, Callback<Boolean> callback) {
|
||||
doAsync(() -> {
|
||||
boolean result = saveTrack(track).getOrDefault(false);
|
||||
boolean result = saveTrack(track).getUnchecked();
|
||||
doSync(() -> callback.onComplete(result));
|
||||
});
|
||||
}
|
||||
|
||||
default void deleteTrack(Track track, Callback<Boolean> 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<Boolean> 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<UUID> callback) {
|
||||
doAsync(() -> {
|
||||
UUID result = getUUID(username).getOrDefault(null);
|
||||
UUID result = getUUID(username).getUnchecked();
|
||||
doSync(() -> callback.onComplete(result));
|
||||
});
|
||||
}
|
||||
|
||||
default void getName(UUID uuid, Callback<String> callback) {
|
||||
doAsync(() -> {
|
||||
String result = getName(uuid).getOrDefault(null);
|
||||
String result = getName(uuid).getUnchecked();
|
||||
doSync(() -> callback.onComplete(result));
|
||||
});
|
||||
}
|
||||
|
@ -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<Void> shutdown() {
|
||||
AbstractFuture<Void> future = new AbstractFuture<>();
|
||||
doAsync(() -> {
|
||||
backing.values().forEach(Datastore::shutdown);
|
||||
future.complete(null);
|
||||
});
|
||||
return future;
|
||||
public void shutdown() {
|
||||
backing.values().forEach(Datastore::shutdown);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ public class TolerantDatastore implements Datastore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public LPFuture<Void> 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
|
||||
|
@ -135,7 +135,7 @@ public class UserManager extends AbstractManager<UserIdentifier, User> {
|
||||
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();
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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<T> extends Future<T> {
|
||||
|
||||
default T getOrDefault(T def) {
|
||||
try {
|
||||
return get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
return def;
|
||||
}
|
||||
default T getUnchecked() {
|
||||
return Futures.getUnchecked(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user