Cleanup usages of loadUser/loadGroup/loadTrack - eliminate possibility for unloading race condition (#706)
This commit is contained in:
@@ -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<String> 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;
|
||||
|
||||
+2
-7
@@ -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)) {
|
||||
|
||||
+1
-6
@@ -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;
|
||||
|
||||
+1
-6
@@ -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;
|
||||
|
||||
+1
-6
@@ -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;
|
||||
|
||||
+2
-12
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -60,9 +60,7 @@ public class GroupClone extends SubCommand<Group> {
|
||||
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;
|
||||
|
||||
+4
-8
@@ -84,22 +84,18 @@ public class GroupMainCommand extends MainCommand<Group, String> {
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@@ -60,20 +60,15 @@ public class GroupRename extends SubCommand<Group> {
|
||||
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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -56,12 +56,7 @@ public class TrackAppend extends SubCommand<Track> {
|
||||
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;
|
||||
|
||||
@@ -54,9 +54,7 @@ public class TrackClone extends SubCommand<Track> {
|
||||
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;
|
||||
|
||||
@@ -64,12 +64,7 @@ public class TrackInsert extends SubCommand<Track> {
|
||||
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;
|
||||
|
||||
+1
-6
@@ -73,12 +73,7 @@ public class TrackMainCommand extends MainCommand<Track, String> {
|
||||
|
||||
@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;
|
||||
|
||||
@@ -60,20 +60,15 @@ public class TrackRename extends SubCommand<Track> {
|
||||
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) {
|
||||
|
||||
@@ -87,9 +87,7 @@ public class UserClone extends SubCommand<User> {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -71,12 +71,7 @@ public class UserDemote extends SubCommand<User> {
|
||||
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<User> {
|
||||
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;
|
||||
|
||||
+1
-16
@@ -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<User, UserIdentifier> {
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@@ -69,12 +69,7 @@ public class UserPromote extends SubCommand<User> {
|
||||
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;
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user