use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class ParentSet 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 groupName = args.getLowercase(0, DataConstraints.GROUP_NAME_TEST);
MutableContextSet context = args.getContextOrDefault(1, plugin);
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, group.getName())) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
target.removeIf(DataType.NORMAL, context, NodeType.INHERITANCE::matches, false);
target.setNode(DataType.NORMAL, Inheritance.builder(group.getName()).withContext(context).build(), true);
if (target.getType() == HolderType.USER) {
((User) target).getPrimaryGroup().setStoredValue(group.getName());
}
Message.SET_PARENT_SUCCESS.send(sender, target, group, context);
LoggedAction.build().source(sender).target(target).description("parent", "set", group.getName(), context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
}
use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class PermissionSetTemp 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 node = args.get(0);
boolean value = args.getBooleanOrInsert(1, true);
Duration duration = args.getDuration(2);
TemporaryNodeMergeStrategy modifier = args.getTemporaryModifierAndRemove(3).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
MutableContextSet context = args.getContextOrDefault(3, plugin);
if (node.isEmpty()) {
Message.PERMISSION_INVALID_ENTRY_EMPTY.send(sender);
}
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context) || ArgumentPermissions.checkArguments(plugin, sender, permission, node)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
Node builtNode = NodeBuilders.determineMostApplicable(node).value(value).withContext(context).expiry(duration).build();
if (builtNode instanceof InheritanceNode) {
if (ArgumentPermissions.checkGroup(plugin, sender, ((InheritanceNode) builtNode).getGroupName(), context)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
}
DataMutateResult.WithMergedNode result = target.setNode(DataType.NORMAL, builtNode, modifier);
if (result.getResult().wasSuccessful()) {
duration = result.getMergedNode().getExpiryDuration();
Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, value, target, duration, context);
LoggedAction.build().source(sender).target(target).description("permission", "settemp", node, value, duration, context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
} else {
Message.ALREADY_HAS_TEMP_PERMISSION.send(sender, target, node, context);
}
}
use of net.luckperms.api.context.MutableContextSet 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());
}
}
use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class MetaSet 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);
String value = args.get(1);
MutableContextSet context = args.getContextOrDefault(2, 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;
}
Node node = Meta.builder(key, value).withContext(context).build();
if (target.hasNode(DataType.NORMAL, node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE).asBoolean()) {
Message.ALREADY_HAS_META.send(sender, target, key, value, context);
return;
}
target.removeIf(DataType.NORMAL, context, NodeType.META.predicate(n -> !n.hasExpiry() && n.getMetaKey().equalsIgnoreCase(key)), false);
target.setNode(DataType.NORMAL, node, true);
Message.SET_META_SUCCESS.send(sender, key, value, target, context);
LoggedAction.build().source(sender).target(target).description("meta", "set", key, value, context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
}
use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class MetaSetTemp 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);
String value = args.get(1);
Duration duration = args.getDuration(2);
TemporaryNodeMergeStrategy modifier = args.getTemporaryModifierAndRemove(3).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
MutableContextSet context = args.getContextOrDefault(3, 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;
}
Node node = Meta.builder(key, value).withContext(context).expiry(duration).build();
// remove temp meta nodes that have the same key and /different/ value (don't want to remove it if we are accumulating/replacing)
target.removeIf(DataType.NORMAL, context, NodeType.META.predicate(n -> n.hasExpiry() && n.getMetaKey().equalsIgnoreCase(key) && !n.getMetaValue().equals(value)), false);
DataMutateResult.WithMergedNode result = target.setNode(DataType.NORMAL, node, modifier);
if (result.getResult().wasSuccessful()) {
duration = result.getMergedNode().getExpiryDuration();
Message.SET_META_TEMP_SUCCESS.send(sender, key, value, target, duration, context);
LoggedAction.build().source(sender).target(target).description("meta", "settemp", key, value, duration, context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
} else {
Message.ALREADY_HAS_TEMP_META.send(sender, target, key, value, context);
}
}
Aggregations