diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java index c5a0abbac..f1b064d8d 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java @@ -314,8 +314,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { for (Player player : getServer().getOnlinePlayers()) { this.scheduler.doAsync(() -> { try { - connectionListener.loadUser(player.getUniqueId(), player.getName()); - User user = getUserManager().getIfLoaded(player.getUniqueId()); + User user = connectionListener.loadUser(player.getUniqueId(), player.getName()); if (user != null) { this.scheduler.doSync(() -> { try { diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java index fce571ab6..1c4214587 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java @@ -27,7 +27,6 @@ package me.lucko.luckperms.bukkit.migration; import de.bananaco.bpermissions.api.Calculable; import de.bananaco.bpermissions.api.CalculableType; -import de.bananaco.bpermissions.api.Group; import de.bananaco.bpermissions.api.Permission; import de.bananaco.bpermissions.api.World; import de.bananaco.bpermissions.api.WorldManager; @@ -41,6 +40,7 @@ import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.locale.CommandSpec; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.logging.ProgressLogger; +import me.lucko.luckperms.common.model.Group; import me.lucko.luckperms.common.model.PermissionHolder; import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.common.node.NodeFactory; @@ -61,13 +61,13 @@ import java.util.concurrent.atomic.AtomicInteger; import static me.lucko.luckperms.common.commands.CommandPermission.MIGRATION; public class MigrationBPermissions extends SubCommand { - private static Field uConfigField; + private static final Field UCONFIG_FIELD; static { try { - uConfigField = Class.forName("de.bananaco.bpermissions.imp.YamlWorld").getDeclaredField("uconfig"); - uConfigField.setAccessible(true); - } catch (Throwable t) { - t.printStackTrace(); + UCONFIG_FIELD = Class.forName("de.bananaco.bpermissions.imp.YamlWorld").getDeclaredField("uconfig"); + UCONFIG_FIELD.setAccessible(true); + } catch (ClassNotFoundException | NoSuchFieldException e) { + throw new ExceptionInInitializerError(e); } } @@ -95,7 +95,7 @@ public class MigrationBPermissions extends SubCommand { YamlConfiguration yamlWorldUsers = null; try { - yamlWorldUsers = (YamlConfiguration) uConfigField.get(world); + yamlWorldUsers = (YamlConfiguration) UCONFIG_FIELD.get(world); } catch (Throwable t) { t.printStackTrace(); } @@ -138,8 +138,7 @@ public class MigrationBPermissions extends SubCommand { } // Make a LuckPerms group for the one being migrated. - plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join(); - me.lucko.luckperms.common.model.Group lpGroup = plugin.getGroupManager().getIfLoaded(groupName); + Group lpGroup = plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join(); MigrationUtils.setGroupWeight(lpGroup, group.getPriority()); migrateHolder(world, group, lpGroup); @@ -162,8 +161,7 @@ public class MigrationBPermissions extends SubCommand { } // Make a LuckPerms user for the one being migrated. - plugin.getStorage().loadUser(uuid, null).join(); - User lpUser = plugin.getUserManager().getIfLoaded(uuid); + User lpUser = plugin.getStorage().loadUser(uuid, null).join(); migrateHolder(world, user, lpUser); @@ -199,14 +197,14 @@ public class MigrationBPermissions extends SubCommand { } // Migrate any inherited groups - for (Group parent : c.getGroups()) { + c.getGroups().forEach(parent -> { String parentName = MigrationUtils.standardizeName(parent.getName()); if (parent.getName().equalsIgnoreCase(world.getDefaultGroup())) { parentName = NodeFactory.DEFAULT_GROUP_NAME; } holder.setPermission(NodeFactory.make(NodeFactory.groupNode(parentName), true, "global", world.getName())); - } + }); // Migrate existing meta for (Map.Entry meta : c.getMeta().entrySet()) { diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java index c636140db..30515a38b 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java @@ -36,6 +36,8 @@ import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.locale.CommandSpec; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.logging.ProgressLogger; +import me.lucko.luckperms.common.model.Group; +import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.common.node.NodeFactory; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.utils.Predicates; @@ -93,9 +95,7 @@ public class MigrationGroupManager extends SubCommand { AtomicInteger globalGroupCount = new AtomicInteger(0); SafeIterator.iterate(gg.getGroupList(), g -> { String groupName = MigrationUtils.standardizeName(g.getName()); - - plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join(); - me.lucko.luckperms.common.model.Group group = plugin.getGroupManager().getIfLoaded(groupName); + Group group = plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join(); for (String node : g.getPermissionList()) { if (node.isEmpty()) continue; @@ -211,8 +211,7 @@ public class MigrationGroupManager extends SubCommand { log.log("Starting group migration."); AtomicInteger groupCount = new AtomicInteger(0); SafeIterator.iterate(groups.entrySet(), e -> { - plugin.getStorage().createAndLoadGroup(e.getKey(), CreationCause.INTERNAL).join(); - me.lucko.luckperms.common.model.Group group = plugin.getGroupManager().getIfLoaded(e.getKey()); + Group group = plugin.getStorage().createAndLoadGroup(e.getKey(), CreationCause.INTERNAL).join(); for (Node node : e.getValue()) { group.setPermission(node); @@ -226,8 +225,7 @@ public class MigrationGroupManager extends SubCommand { log.log("Starting user migration."); AtomicInteger userCount = new AtomicInteger(0); SafeIterator.iterate(users.entrySet(), e -> { - plugin.getStorage().loadUser(e.getKey(), null).join(); - me.lucko.luckperms.common.model.User user = plugin.getUserManager().getIfLoaded(e.getKey()); + User user = plugin.getStorage().loadUser(e.getKey(), null).join(); for (Node node : e.getValue()) { user.setPermission(node); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsBukkit.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsBukkit.java index 2cee395ce..bca686dba 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsBukkit.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsBukkit.java @@ -81,8 +81,7 @@ public class MigrationPermissionsBukkit extends SubCommand { SafeIterator.iterate(groupsSection.getKeys(false), key -> { final String groupName = MigrationUtils.standardizeName(key); - plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join(); - Group lpGroup = plugin.getGroupManager().getIfLoaded(groupName); + Group lpGroup = plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join(); // migrate data if (groupsSection.isConfigurationSection(key)) { @@ -106,8 +105,7 @@ public class MigrationPermissionsBukkit extends SubCommand { return; } - plugin.getStorage().loadUser(uuid, null).join(); - User lpUser = plugin.getUserManager().getIfLoaded(uuid); + User lpUser = plugin.getStorage().loadUser(uuid, null).join(); // migrate data if (usersSection.isConfigurationSection(key)) { diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java index 97a230e5c..78f93123c 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java @@ -96,8 +96,7 @@ public class MigrationPermissionsEx extends SubCommand { int groupWeight = maxWeight - group.getRank(); final String groupName = MigrationUtils.standardizeName(group.getName()); - plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join(); - Group lpGroup = plugin.getGroupManager().getIfLoaded(groupName); + Group lpGroup = plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join(); MigrationUtils.setGroupWeight(lpGroup, groupWeight); @@ -117,8 +116,7 @@ public class MigrationPermissionsEx extends SubCommand { // Migrate all ladders/tracks. log.log("Starting tracks migration."); for (String rankLadder : ladders) { - plugin.getStorage().createAndLoadTrack(rankLadder, CreationCause.INTERNAL).join(); - Track track = plugin.getTrackManager().getIfLoaded(rankLadder); + Track track = plugin.getStorage().createAndLoadTrack(rankLadder, CreationCause.INTERNAL).join(); // Get a list of all groups in a ladder List ladder = manager.getRankLadder(rankLadder).entrySet().stream() @@ -145,8 +143,7 @@ public class MigrationPermissionsEx extends SubCommand { } // load in a user instance - plugin.getStorage().loadUser(u, user.getName()).join(); - User lpUser = plugin.getUserManager().getIfLoaded(u); + User lpUser = plugin.getStorage().loadUser(u, user.getName()).join(); // migrate data migrateEntity(user, lpUser, userWeight); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java index 4bfaa5a66..09edb74aa 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java @@ -162,8 +162,7 @@ public class MigrationPowerfulPerms extends SubCommand { maxWeight.set(Math.max(maxWeight.get(), g.getRank())); String groupName = MigrationUtils.standardizeName(g.getName()); - plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join(); - me.lucko.luckperms.common.model.Group group = plugin.getGroupManager().getIfLoaded(groupName); + me.lucko.luckperms.common.model.Group group = plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join(); MigrationUtils.setGroupWeight(group, g.getRank()); @@ -222,8 +221,7 @@ public class MigrationPowerfulPerms extends SubCommand { SafeIterator.iterate(uuids, uuid -> { // Create a LuckPerms user for the UUID - plugin.getStorage().loadUser(uuid, null).join(); - User user = plugin.getUserManager().getIfLoaded(uuid); + User user = plugin.getStorage().loadUser(uuid, null).join(); List permissions = joinFuture(pm.getPlayerOwnPermissions(uuid)); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java index 23bcdddb9..eb7776c1d 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java @@ -106,8 +106,7 @@ public class MigrationZPermissions extends SubCommand { AtomicInteger maxWeight = new AtomicInteger(0); SafeIterator.iterate(internalService.getEntities(true), entity -> { String groupName = MigrationUtils.standardizeName(entity.getDisplayName()); - plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join(); - Group group = plugin.getGroupManager().getIfLoaded(groupName); + Group group = plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join(); int weight = entity.getPriority(); maxWeight.set(Math.max(maxWeight.get(), weight)); @@ -141,9 +140,7 @@ public class MigrationZPermissions extends SubCommand { AtomicInteger trackCount = new AtomicInteger(0); SafeIterator.iterate(service.getAllTracks(), t -> { String trackName = MigrationUtils.standardizeName(t); - - plugin.getStorage().createAndLoadTrack(trackName, CreationCause.INTERNAL).join(); - Track track = plugin.getTrackManager().getIfLoaded(trackName); + Track track = plugin.getStorage().createAndLoadTrack(trackName, CreationCause.INTERNAL).join(); track.setGroups(service.getTrackGroups(t)); plugin.getStorage().saveTrack(track); @@ -167,8 +164,7 @@ public class MigrationZPermissions extends SubCommand { username = entity.getDisplayName(); } - plugin.getStorage().loadUser(u, username).join(); - User user = plugin.getUserManager().getIfLoaded(u); + User user = plugin.getStorage().loadUser(u, username).join(); // migrate permissions & meta if (entity != null) { diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java b/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java index 377d5cd60..3370cf155 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java @@ -87,8 +87,7 @@ public class MigrationBungeePerms extends SubCommand { // Make a LuckPerms group for the one being migrated String groupName = MigrationUtils.standardizeName(g.getName()); - plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join(); - me.lucko.luckperms.common.model.Group group = plugin.getGroupManager().getIfLoaded(groupName); + me.lucko.luckperms.common.model.Group group = plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join(); MigrationUtils.setGroupWeight(group, groupWeight); migrateHolder(g, g.getInheritances(), groupWeight, group); @@ -112,8 +111,7 @@ public class MigrationBungeePerms extends SubCommand { } // Make a LuckPerms user for the one being migrated. - plugin.getStorage().loadUser(u.getUUID(), u.getName()).join(); - me.lucko.luckperms.common.model.User user = plugin.getUserManager().getIfLoaded(u.getUUID()); + me.lucko.luckperms.common.model.User user = plugin.getStorage().loadUser(u.getUUID(), u.getName()).join(); migrateHolder(u, u.getGroupsString(), userWeight, user); diff --git a/common/src/main/java/me/lucko/luckperms/common/backup/Exporter.java b/common/src/main/java/me/lucko/luckperms/common/backup/Exporter.java index 72cfdadc0..7d3c71ce5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/backup/Exporter.java +++ b/common/src/main/java/me/lucko/luckperms/common/backup/Exporter.java @@ -220,8 +220,7 @@ public class Exporter implements Runnable { // actually export the user. this output will be fed to the writing function when we have all of the user's data. List output = new ArrayList<>(); - this.plugin.getStorage().loadUser(uuid, null).join(); - User user = this.plugin.getUserManager().getIfLoaded(uuid); + User user = this.plugin.getStorage().loadUser(uuid, null).join(); output.add("# Export user: " + user.getUuid().toString() + " - " + user.getName().orElse("unknown username")); boolean inDefault = false; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentAdd.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentAdd.java index f0b8bfff9..d6c7fbb66 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentAdd.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentAdd.java @@ -64,15 +64,10 @@ public class ParentAdd extends SharedSubCommand { String groupName = ArgumentUtils.handleName(0, args); MutableContextSet context = ArgumentUtils.handleContext(1, args, plugin); - if (!plugin.getStorage().loadGroup(groupName).join().isPresent()) { - Message.DOES_NOT_EXIST.send(sender, groupName); - return CommandResult.INVALID_ARGS; - } - - Group group = plugin.getGroupManager().getIfLoaded(groupName); + Group group = plugin.getStorage().loadGroup(groupName).join().orElse(null); if (group == null) { Message.DOES_NOT_EXIST.send(sender, groupName); - return CommandResult.LOADING_ERROR; + return CommandResult.INVALID_ARGS; } if (ArgumentPermissions.checkContext(plugin, sender, permission, context)) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentAddTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentAddTemp.java index 31436c106..34a41caf7 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentAddTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentAddTemp.java @@ -71,12 +71,7 @@ public class ParentAddTemp extends SharedSubCommand { MutableContextSet context = ArgumentUtils.handleContext(2, args, plugin); TemporaryModifier modifier = plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR); - if (!plugin.getStorage().loadGroup(groupName).join().isPresent()) { - Message.DOES_NOT_EXIST.send(sender, groupName); - return CommandResult.INVALID_ARGS; - } - - Group group = plugin.getGroupManager().getIfLoaded(groupName); + Group group = plugin.getStorage().loadGroup(groupName).join().orElse(null); if (group == null) { Message.DOES_NOT_EXIST.send(sender, groupName); return CommandResult.INVALID_ARGS; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentClearTrack.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentClearTrack.java index 3b3672c09..64ebf005b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentClearTrack.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentClearTrack.java @@ -67,12 +67,7 @@ public class ParentClearTrack extends SharedSubCommand { return CommandResult.INVALID_ARGS; } - if (!plugin.getStorage().loadTrack(trackName).join().isPresent()) { - Message.DOES_NOT_EXIST.send(sender, trackName); - return CommandResult.INVALID_ARGS; - } - - Track track = plugin.getTrackManager().getIfLoaded(trackName); + Track track = plugin.getStorage().loadTrack(trackName).join().orElse(null); if (track == null) { Message.DOES_NOT_EXIST.send(sender, trackName); return CommandResult.LOADING_ERROR; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentSet.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentSet.java index 0442fe6c2..dd9d9d54a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentSet.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentSet.java @@ -64,12 +64,7 @@ public class ParentSet extends SharedSubCommand { String groupName = ArgumentUtils.handleName(0, args); MutableContextSet context = ArgumentUtils.handleContext(1, args, plugin); - if (!plugin.getStorage().loadGroup(groupName).join().isPresent()) { - Message.DOES_NOT_EXIST.send(sender, groupName); - return CommandResult.INVALID_ARGS; - } - - Group group = plugin.getGroupManager().getIfLoaded(groupName); + Group group = plugin.getStorage().loadGroup(groupName).join().orElse(null); if (group == null) { Message.DOES_NOT_EXIST.send(sender, groupName); return CommandResult.LOADING_ERROR; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentSetTrack.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentSetTrack.java index 462102979..dfdd03a89 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentSetTrack.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentSetTrack.java @@ -69,12 +69,7 @@ public class ParentSetTrack extends SharedSubCommand { return CommandResult.INVALID_ARGS; } - if (!plugin.getStorage().loadTrack(trackName).join().isPresent()) { - Message.DOES_NOT_EXIST.send(sender, trackName); - return CommandResult.INVALID_ARGS; - } - - Track track = plugin.getTrackManager().getIfLoaded(trackName); + Track track = plugin.getStorage().loadTrack(trackName).join().orElse(null); if (track == null) { Message.DOES_NOT_EXIST.send(sender, trackName); return CommandResult.LOADING_ERROR; @@ -104,12 +99,7 @@ public class ParentSetTrack extends SharedSubCommand { MutableContextSet context = ArgumentUtils.handleContext(2, args, plugin); - if (!plugin.getStorage().loadGroup(groupName).join().isPresent()) { - Message.DOES_NOT_EXIST.send(sender, groupName); - return CommandResult.INVALID_ARGS; - } - - Group group = plugin.getGroupManager().getIfLoaded(groupName); + Group group = plugin.getStorage().loadGroup(groupName).join().orElse(null); if (group == null) { Message.DOES_NOT_EXIST.send(sender, groupName); return CommandResult.LOADING_ERROR; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/DeleteGroup.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/DeleteGroup.java index 661245d59..71afeba5d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/DeleteGroup.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/DeleteGroup.java @@ -62,12 +62,7 @@ public class DeleteGroup extends SingleCommand { return CommandResult.INVALID_ARGS; } - if (!plugin.getStorage().loadGroup(groupName).join().isPresent()) { - Message.DOES_NOT_EXIST.send(sender, groupName); - return CommandResult.INVALID_ARGS; - } - - Group group = plugin.getGroupManager().getIfLoaded(groupName); + Group group = plugin.getStorage().loadGroup(groupName).join().orElse(null); if (group == null) { Message.GROUP_LOAD_ERROR.send(sender); return CommandResult.LOADING_ERROR; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupClone.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupClone.java index a3ca22848..f85f1a6cd 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupClone.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupClone.java @@ -60,9 +60,7 @@ public class GroupClone extends SubCommand { return CommandResult.INVALID_ARGS; } - plugin.getStorage().createAndLoadGroup(newGroupName, CreationCause.COMMAND).join(); - - Group newGroup = plugin.getGroupManager().getIfLoaded(newGroupName); + Group newGroup = plugin.getStorage().createAndLoadGroup(newGroupName, CreationCause.COMMAND).join(); if (newGroup == null) { Message.GROUP_LOAD_ERROR.send(sender); return CommandResult.LOADING_ERROR; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupMainCommand.java index 2e7e9a616..88227c491 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupMainCommand.java @@ -84,22 +84,18 @@ public class GroupMainCommand extends MainCommand { @Override protected Group getTarget(String target, LuckPermsPlugin plugin, Sender sender) { - if (!plugin.getStorage().loadGroup(target).join().isPresent()) { + Group group = plugin.getStorage().loadGroup(target).join().orElse(null); + if (group == null) { // failed to load, but it might be a display name. + group = plugin.getGroupManager().getByDisplayName(target); // nope, not a display name - if (plugin.getGroupManager().getByDisplayName(target) == null) { + if (group == null) { Message.GROUP_NOT_FOUND.send(sender, target); return null; } } - Group group = plugin.getGroupManager().getByDisplayName(target); - if (group == null) { - Message.GROUP_NOT_FOUND.send(sender, target); - return null; - } - group.auditTemporaryPermissions(); return group; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupRename.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupRename.java index b7cfb7898..9d0bfa575 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupRename.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupRename.java @@ -60,20 +60,15 @@ public class GroupRename extends SubCommand { return CommandResult.INVALID_ARGS; } + Group newGroup; try { - plugin.getStorage().createAndLoadGroup(newGroupName, CreationCause.COMMAND).get(); + newGroup = plugin.getStorage().createAndLoadGroup(newGroupName, CreationCause.COMMAND).get(); } catch (Exception e) { e.printStackTrace(); Message.CREATE_ERROR.send(sender, newGroupName); return CommandResult.FAILURE; } - Group newGroup = plugin.getGroupManager().getIfLoaded(newGroupName); - if (newGroup == null) { - Message.GROUP_LOAD_ERROR.send(sender); - return CommandResult.LOADING_ERROR; - } - try { plugin.getStorage().deleteGroup(group, DeletionCause.COMMAND).get(); } catch (Exception e) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/DeleteTrack.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/DeleteTrack.java index 256564958..baf7ae29a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/DeleteTrack.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/DeleteTrack.java @@ -55,12 +55,7 @@ public class DeleteTrack extends SingleCommand { } String trackName = args.get(0).toLowerCase(); - if (!plugin.getStorage().loadTrack(trackName).join().isPresent()) { - Message.DOES_NOT_EXIST.send(sender, trackName); - return CommandResult.INVALID_ARGS; - } - - Track track = plugin.getTrackManager().getIfLoaded(trackName); + Track track = plugin.getStorage().loadTrack(trackName).join().orElse(null); if (track == null) { Message.TRACK_LOAD_ERROR.send(sender); return CommandResult.LOADING_ERROR; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackAppend.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackAppend.java index c1fc8c86b..f8b4d1113 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackAppend.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackAppend.java @@ -56,12 +56,7 @@ public class TrackAppend extends SubCommand { return CommandResult.INVALID_ARGS; } - if (!plugin.getStorage().loadGroup(groupName).join().isPresent()) { - Message.DOES_NOT_EXIST.send(sender, groupName); - return CommandResult.INVALID_ARGS; - } - - Group group = plugin.getGroupManager().getIfLoaded(groupName); + Group group = plugin.getStorage().loadGroup(groupName).join().orElse(null); if (group == null) { Message.DOES_NOT_EXIST.send(sender, groupName); return CommandResult.LOADING_ERROR; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackClone.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackClone.java index b8d322d8d..9b9c52685 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackClone.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackClone.java @@ -54,9 +54,7 @@ public class TrackClone extends SubCommand { return CommandResult.INVALID_ARGS; } - plugin.getStorage().createAndLoadTrack(newTrackName, CreationCause.INTERNAL).join(); - - Track newTrack = plugin.getTrackManager().getIfLoaded(newTrackName); + Track newTrack = plugin.getStorage().createAndLoadTrack(newTrackName, CreationCause.INTERNAL).join(); if (newTrack == null) { Message.TRACK_LOAD_ERROR.send(sender); return CommandResult.LOADING_ERROR; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackInsert.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackInsert.java index 43e016377..596b175c7 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackInsert.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackInsert.java @@ -64,12 +64,7 @@ public class TrackInsert extends SubCommand { return CommandResult.INVALID_ARGS; } - if (!plugin.getStorage().loadGroup(groupName).join().isPresent()) { - Message.DOES_NOT_EXIST.send(sender, groupName); - return CommandResult.INVALID_ARGS; - } - - Group group = plugin.getGroupManager().getIfLoaded(groupName); + Group group = plugin.getStorage().loadGroup(groupName).join().orElse(null); if (group == null) { Message.DOES_NOT_EXIST.send(sender, groupName); return CommandResult.LOADING_ERROR; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackMainCommand.java index 495a2a914..515960a0a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackMainCommand.java @@ -73,12 +73,7 @@ public class TrackMainCommand extends MainCommand { @Override protected Track getTarget(String target, LuckPermsPlugin plugin, Sender sender) { - if (!plugin.getStorage().loadTrack(target).join().isPresent()) { - Message.TRACK_NOT_FOUND.send(sender, target); - return null; - } - - Track track = plugin.getTrackManager().getIfLoaded(target); + Track track = plugin.getStorage().loadTrack(target).join().orElse(null); if (track == null) { Message.TRACK_NOT_FOUND.send(sender, target); return null; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackRename.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackRename.java index 7b6da201f..db35e67ea 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackRename.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackRename.java @@ -60,20 +60,15 @@ public class TrackRename extends SubCommand { return CommandResult.INVALID_ARGS; } + Track newTrack; try { - plugin.getStorage().createAndLoadTrack(newTrackName, CreationCause.COMMAND).get(); + newTrack = plugin.getStorage().createAndLoadTrack(newTrackName, CreationCause.COMMAND).get(); } catch (Exception e) { e.printStackTrace(); Message.CREATE_ERROR.send(sender, newTrackName); return CommandResult.FAILURE; } - Track newTrack = plugin.getTrackManager().getIfLoaded(newTrackName); - if (newTrack == null) { - Message.TRACK_LOAD_ERROR.send(sender); - return CommandResult.LOADING_ERROR; - } - try { plugin.getStorage().deleteTrack(track, DeletionCause.COMMAND).get(); } catch (Exception e) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserClone.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserClone.java index 3d52177bb..e64d4059d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserClone.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserClone.java @@ -87,9 +87,7 @@ public class UserClone extends SubCommand { } } - plugin.getStorage().loadUser(uuid, null).join(); - User otherUser = plugin.getUserManager().getIfLoaded(uuid); - + User otherUser = plugin.getStorage().loadUser(uuid, null).join(); if (otherUser == null) { Message.USER_LOAD_ERROR.send(sender); return CommandResult.LOADING_ERROR; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserDemote.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserDemote.java index 2e24a48e0..c4fe88f48 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserDemote.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserDemote.java @@ -71,12 +71,7 @@ public class UserDemote extends SubCommand { return CommandResult.INVALID_ARGS; } - if (!plugin.getStorage().loadTrack(trackName).join().isPresent()) { - Message.DOES_NOT_EXIST.send(sender, trackName); - return CommandResult.INVALID_ARGS; - } - - Track track = plugin.getTrackManager().getIfLoaded(trackName); + Track track = plugin.getStorage().loadTrack(trackName).join().orElse(null); if (track == null) { Message.DOES_NOT_EXIST.send(sender, trackName); return CommandResult.LOADING_ERROR; @@ -142,12 +137,7 @@ public class UserDemote extends SubCommand { return CommandResult.SUCCESS; } - if (!plugin.getStorage().loadGroup(previous).join().isPresent()) { - Message.USER_DEMOTE_ERROR_MALFORMED.send(sender, previous); - return CommandResult.STATE_ERROR; - } - - Group previousGroup = plugin.getGroupManager().getIfLoaded(previous); + Group previousGroup = plugin.getStorage().loadGroup(previous).join().orElse(null); if (previousGroup == null) { Message.USER_DEMOTE_ERROR_MALFORMED.send(sender, previous); return CommandResult.LOADING_ERROR; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserMainCommand.java index ad4c75cab..5f689e658 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserMainCommand.java @@ -36,7 +36,6 @@ import me.lucko.luckperms.common.commands.impl.generic.other.HolderClear; import me.lucko.luckperms.common.commands.impl.generic.other.HolderEditor; import me.lucko.luckperms.common.commands.impl.generic.other.HolderShowTracks; import me.lucko.luckperms.common.commands.impl.generic.parent.CommandParent; -import me.lucko.luckperms.common.commands.impl.generic.parent.UserSwitchPrimaryGroup; import me.lucko.luckperms.common.commands.impl.generic.permission.CommandPermission; import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.config.ConfigKeys; @@ -118,21 +117,7 @@ public class UserMainCommand extends MainCommand { @Override protected User getTarget(UserIdentifier target, LuckPermsPlugin plugin, Sender sender) { - - try { - plugin.getStorage().loadUser(target.getUuid(), target.getUsername().orElse(null)).get(); - } catch (Exception e) { - e.printStackTrace(); - Message.LOADING_ERROR.send(sender); - return null; - } - - User user = plugin.getUserManager().getIfLoaded(target.getUuid()); - if (user == null) { - Message.LOADING_ERROR.send(sender); - return null; - } - + User user = plugin.getStorage().loadUser(target.getUuid(), target.getUsername().orElse(null)).join(); user.auditTemporaryPermissions(); return user; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserPromote.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserPromote.java index cb0d4c108..ba798e511 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserPromote.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserPromote.java @@ -69,12 +69,7 @@ public class UserPromote extends SubCommand { return CommandResult.INVALID_ARGS; } - if (!plugin.getStorage().loadTrack(trackName).join().isPresent()) { - Message.DOES_NOT_EXIST.send(sender, trackName); - return CommandResult.INVALID_ARGS; - } - - Track track = plugin.getTrackManager().getIfLoaded(trackName); + Track track = plugin.getStorage().loadTrack(trackName).join().orElse(null); if (track == null) { Message.DOES_NOT_EXIST.send(sender, trackName); return CommandResult.LOADING_ERROR; diff --git a/common/src/main/java/me/lucko/luckperms/common/webeditor/WebEditorUtils.java b/common/src/main/java/me/lucko/luckperms/common/webeditor/WebEditorUtils.java index c14dc3830..ee55005fe 100644 --- a/common/src/main/java/me/lucko/luckperms/common/webeditor/WebEditorUtils.java +++ b/common/src/main/java/me/lucko/luckperms/common/webeditor/WebEditorUtils.java @@ -91,8 +91,7 @@ public final class WebEditorUtils { Message.APPLY_EDITS_TARGET_USER_NOT_UUID.send(sender, user); return null; } - plugin.getStorage().loadUser(uuid, null).join(); - User holder = plugin.getUserManager().getIfLoaded(uuid); + User holder = plugin.getStorage().loadUser(uuid, null).join(); if (holder == null) { Message.APPLY_EDITS_TARGET_USER_UNABLE_TO_LOAD.send(sender, uuid.toString()); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionManager.java b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionManager.java index 1eddb8b26..5d5114a2b 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionManager.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionManager.java @@ -106,8 +106,7 @@ public class MigrationPermissionManager extends SubCommand { String pmName = MigrationUtils.standardizeName(pmGroup.getIdentifier()); // Make a LuckPerms group for the one being migrated - plugin.getStorage().createAndLoadGroup(pmName, CreationCause.INTERNAL).join(); - Group group = plugin.getGroupManager().getIfLoaded(pmName); + Group group = plugin.getStorage().createAndLoadGroup(pmName, CreationCause.INTERNAL).join(); migrateSubject(pmGroup, group, 100); plugin.getStorage().saveGroup(group); @@ -126,8 +125,7 @@ public class MigrationPermissionManager extends SubCommand { } // Make a LuckPerms user for the one being migrated - plugin.getStorage().loadUser(uuid, "null").join(); - User user = plugin.getUserManager().getIfLoaded(uuid); + User user = plugin.getStorage().loadUser(uuid, "null").join(); if (user.getEnduringNodes().size() <= 1) { user.clearNodes(false); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionsEx.java b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionsEx.java index d6b6a836c..bcbb02e5c 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionsEx.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionsEx.java @@ -131,8 +131,7 @@ public class MigrationPermissionsEx extends SubCommand { } // Make a LuckPerms group for the one being migrated - plugin.getStorage().createAndLoadGroup(pexName, CreationCause.INTERNAL).join(); - Group group = plugin.getGroupManager().getIfLoaded(pexName); + Group group = plugin.getStorage().createAndLoadGroup(pexName, CreationCause.INTERNAL).join(); migrateSubject(pexGroup, group, weight); plugin.getStorage().saveGroup(group); @@ -153,8 +152,7 @@ public class MigrationPermissionsEx extends SubCommand { // Migrate tracks log.log("Starting track migration."); SafeIterator.iterate(tracks.entrySet(), e -> { - plugin.getStorage().createAndLoadTrack(e.getKey(), CreationCause.INTERNAL).join(); - Track track = plugin.getTrackManager().getIfLoaded(e.getKey()); + Track track = plugin.getStorage().createAndLoadTrack(e.getKey(), CreationCause.INTERNAL).join(); for (String groupName : e.getValue().values()) { Group group = plugin.getGroupManager().getIfLoaded(groupName); if (group != null) { @@ -179,8 +177,7 @@ public class MigrationPermissionsEx extends SubCommand { } // Make a LuckPerms user for the one being migrated - plugin.getStorage().loadUser(uuid, null).join(); - User user = plugin.getUserManager().getIfLoaded(uuid); + User user = plugin.getStorage().loadUser(uuid, null).join(); if (user.getEnduringNodes().size() <= 1) { user.clearNodes(false); }