use of me.lucko.luckperms.common.command.utils.ArgumentList in project LuckPerms by lucko.
the class MetaRemoveChatMeta method execute.
@Override
public void execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
int priority = args.getPriority(0);
String meta = args.getOrDefault(1, "null");
ImmutableContextSet context = args.getContextOrDefault(2, plugin).immutableCopy();
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
// Handle bulk removal
if (meta.equalsIgnoreCase("null") || meta.equals("*")) {
target.removeIf(DataType.NORMAL, context, this.type.nodeType().predicate(n -> n.getPriority() == priority && !n.hasExpiry()), false);
Message.BULK_REMOVE_CHATMETA_SUCCESS.send(sender, target, this.type, priority, context);
LoggedAction.build().source(sender).target(target).description("meta", "remove" + this.type.name().toLowerCase(Locale.ROOT), priority, "*", context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
return;
}
DataMutateResult result = target.unsetNode(DataType.NORMAL, this.type.builder(meta, priority).withContext(context).build());
if (result.wasSuccessful()) {
Message.REMOVE_CHATMETA_SUCCESS.send(sender, target, this.type, meta, priority, context);
LoggedAction.build().source(sender).target(target).description("meta", "remove" + this.type.name().toLowerCase(Locale.ROOT), priority, meta, context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
} else {
Message.DOES_NOT_HAVE_CHAT_META.send(sender, target, this.type, meta, priority, context);
}
}
use of me.lucko.luckperms.common.command.utils.ArgumentList in project LuckPerms by lucko.
the class MetaUnset method execute.
@Override
public void execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
String key = args.get(0);
MutableContextSet context = args.getContextOrDefault(1, plugin);
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context) || ArgumentPermissions.checkArguments(plugin, sender, permission, key)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
if (target.removeIf(DataType.NORMAL, context, NodeType.META.predicate(n -> !n.hasExpiry() && n.getMetaKey().equalsIgnoreCase(key)), false)) {
Message.UNSET_META_SUCCESS.send(sender, key, target, context);
LoggedAction.build().source(sender).target(target).description("meta", "unset", key, context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
} else {
Message.DOESNT_HAVE_META.send(sender, target, key, context);
}
}
use of me.lucko.luckperms.common.command.utils.ArgumentList in project LuckPerms by lucko.
the class HolderShowTracks method execute.
@Override
public void execute(LuckPermsPlugin plugin, Sender sender, T target, ArgumentList args, String label) {
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), target)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
try {
plugin.getStorage().loadAllTracks().get();
} catch (Exception e) {
plugin.getLogger().warn("Error whilst loading tracks", e);
Message.TRACKS_LOAD_ERROR.send(sender);
return;
}
List<Map.Entry<Track, Component>> lines = new ArrayList<>();
if (target.getType() == HolderType.USER) {
// if the holder is a user, we want to query parent groups for tracks
Set<InheritanceNode> nodes = target.normalData().inheritanceAsList().stream().filter(Node::getValue).filter(n -> !n.hasExpiry()).collect(Collectors.toSet());
for (InheritanceNode node : nodes) {
String groupName = node.getGroupName();
List<Track> tracks = plugin.getTrackManager().getAll().values().stream().filter(t -> t.containsGroup(groupName)).collect(Collectors.toList());
for (Track track : tracks) {
Component line = Component.text().append(Message.formatContextSetBracketed(node.getContexts(), Component.empty())).append(Component.newline()).append(Message.formatTrackPath(track.getGroups(), groupName)).build();
lines.add(Maps.immutableEntry(track, line));
}
}
} else {
// otherwise, just lookup for the actual group
String groupName = ((Group) target).getName();
List<Track> tracks = plugin.getTrackManager().getAll().values().stream().filter(t -> t.containsGroup(groupName)).collect(Collectors.toList());
for (Track track : tracks) {
lines.add(Maps.immutableEntry(track, Message.formatTrackPath(track.getGroups(), groupName)));
}
}
if (lines.isEmpty()) {
Message.LIST_TRACKS_EMPTY.send(sender, target);
return;
}
Message.LIST_TRACKS.send(sender, target);
for (Map.Entry<Track, Component> line : lines) {
Message.LIST_TRACKS_ENTRY.send(sender, line.getKey().getName(), line.getValue());
}
}
use of me.lucko.luckperms.common.command.utils.ArgumentList in project LuckPerms by lucko.
the class ParentSetTrack method execute.
@Override
public void execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
Message.COMMAND_NO_PERMISSION.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;
}
int index = args.getIntOrDefault(1, -1);
String groupName;
if (index > 0) {
List<String> trackGroups = track.getGroups();
if (index - 1 >= trackGroups.size()) {
Message.DOES_NOT_EXIST.send(sender, String.valueOf(index));
return;
}
groupName = track.getGroups().get(index - 1);
} else {
groupName = args.getLowercase(1, DataConstraints.GROUP_NAME_TEST);
if (!track.containsGroup(groupName)) {
Message.TRACK_DOES_NOT_CONTAIN.send(sender, track.getName(), groupName);
return;
}
}
ImmutableContextSet context = args.getContextOrDefault(2, plugin).immutableCopy();
Group group = StorageAssistant.loadGroup(groupName, sender, plugin, false);
if (group == null) {
return;
}
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context) || ArgumentPermissions.checkGroup(plugin, sender, group, context) || ArgumentPermissions.checkArguments(plugin, sender, permission, track.getName(), group.getName())) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
target.removeIf(DataType.NORMAL, context, NodeType.INHERITANCE.predicate(n -> track.containsGroup(n.getGroupName())), false);
target.setNode(DataType.NORMAL, Inheritance.builder(group.getName()).withContext(context).build(), true);
Message.SET_TRACK_PARENT_SUCCESS.send(sender, target, track.getName(), group, context);
LoggedAction.build().source(sender).target(target).description("parent", "settrack", track.getName(), groupName, context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
}
use of me.lucko.luckperms.common.command.utils.ArgumentList in project LuckPerms by lucko.
the class UserDemote 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 removeFromFirst = !args.remove("--dont-remove-from-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> previousGroupPermissionChecker = s -> !ArgumentPermissions.checkArguments(plugin, sender, getPermission().get(), track.getName(), s) && !ArgumentPermissions.checkGroup(plugin, sender, s, context);
DemotionResult result = track.demote(target, context, previousGroupPermissionChecker, sender, removeFromFirst);
switch(result.getStatus()) {
case NOT_ON_TRACK:
Message.USER_TRACK_ERROR_NOT_CONTAIN_GROUP.send(sender, target, track.getName());
return;
case AMBIGUOUS_CALL:
Message.TRACK_AMBIGUOUS_CALL.send(sender, target);
return;
case UNDEFINED_FAILURE:
Message.COMMAND_NO_PERMISSION.send(sender);
return;
case MALFORMED_TRACK:
Message.USER_DEMOTE_ERROR_MALFORMED.send(sender, result.getGroupTo().get());
return;
case REMOVED_FROM_FIRST_GROUP:
{
if (!removeFromFirst && !result.getGroupFrom().isPresent()) {
Message.USER_DEMOTE_ENDOFTRACK_NOT_REMOVED.send(sender, track.getName(), target);
return;
}
Message.USER_DEMOTE_ENDOFTRACK.send(sender, track.getName(), target, result.getGroupFrom().get());
LoggedAction.build().source(sender).target(target).description("demote", 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_DEMOTE_SUCCESS.send(sender, target, track.getName(), groupFrom, groupTo, context);
if (!dontShowTrackProgress) {
Message.TRACK_PATH_HIGHLIGHTED_PROGRESSION.send(sender, track.getGroups(), groupTo, groupFrom, true);
}
LoggedAction.build().source(sender).target(target).description("demote", track.getName(), context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
return;
}
default:
throw new AssertionError("Unknown status: " + result.getStatus());
}
}
Aggregations