use of net.luckperms.api.track.PromotionResult in project LuckPerms by lucko.
the class UserPromote method execute.
@Override
public void execute(LuckPermsPlugin plugin, Sender sender, User target, ArgumentList args, String label) throws CommandException {
if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), target)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
boolean addToFirst = !args.remove("--dont-add-to-first");
// if args is empty - use the only/default track
if (args.isEmpty()) {
Set<String> tracks = plugin.getTrackManager().getAll().keySet();
if (tracks.size() == 1) {
args.add(tracks.iterator().next());
} else if (tracks.contains("default")) {
args.add("default");
} else {
Message.USER_TRACK_ERROR_AMBIGUOUS_TRACK_SELECTION.send(sender);
return;
}
}
final String trackName = args.get(0).toLowerCase(Locale.ROOT);
if (!DataConstraints.TRACK_NAME_TEST.test(trackName)) {
Message.TRACK_INVALID_ENTRY.send(sender, trackName);
return;
}
Track track = StorageAssistant.loadTrack(trackName, sender, plugin);
if (track == null) {
return;
}
if (track.getSize() <= 1) {
Message.TRACK_EMPTY.send(sender, track.getName());
return;
}
boolean dontShowTrackProgress = args.remove("-s");
MutableContextSet context = args.getContextOrDefault(1, plugin);
if (ArgumentPermissions.checkContext(plugin, sender, getPermission().get(), context)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
Predicate<String> nextGroupPermissionChecker = s -> !ArgumentPermissions.checkArguments(plugin, sender, getPermission().get(), track.getName(), s) && !ArgumentPermissions.checkGroup(plugin, sender, s, context);
PromotionResult result = track.promote(target, context, nextGroupPermissionChecker, sender, addToFirst);
switch(result.getStatus()) {
case MALFORMED_TRACK:
Message.USER_PROMOTE_ERROR_MALFORMED.send(sender, result.getGroupTo().get());
return;
case UNDEFINED_FAILURE:
Message.COMMAND_NO_PERMISSION.send(sender);
return;
case AMBIGUOUS_CALL:
Message.TRACK_AMBIGUOUS_CALL.send(sender, target);
return;
case END_OF_TRACK:
Message.USER_PROMOTE_ERROR_ENDOFTRACK.send(sender, track.getName(), target);
return;
case ADDED_TO_FIRST_GROUP:
{
if (!addToFirst && !result.getGroupTo().isPresent()) {
Message.USER_PROMOTE_NOT_ON_TRACK.send(sender, target, track.getName());
return;
}
Message.USER_TRACK_ADDED_TO_FIRST.send(sender, target, track.getName(), result.getGroupTo().get(), context);
LoggedAction.build().source(sender).target(target).description("promote", track.getName(), context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
return;
}
case SUCCESS:
{
String groupFrom = result.getGroupFrom().get();
String groupTo = result.getGroupTo().get();
Message.USER_PROMOTE_SUCCESS.send(sender, target, track.getName(), groupFrom, groupTo, context);
if (!dontShowTrackProgress) {
Message.TRACK_PATH_HIGHLIGHTED_PROGRESSION.send(sender, track.getGroups(), groupFrom, groupTo, false);
}
LoggedAction.build().source(sender).target(target).description("promote", track.getName(), context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
return;
}
default:
throw new AssertionError("Unknown status: " + result.getStatus());
}
}
Aggregations