use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class ParentClear 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 before = target.normalData().size();
MutableContextSet context = args.getContextOrDefault(0, plugin);
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
if (context.isEmpty()) {
target.removeIf(DataType.NORMAL, null, NodeType.INHERITANCE::matches, true);
} else {
target.removeIf(DataType.NORMAL, context, NodeType.INHERITANCE::matches, true);
}
int changed = before - target.normalData().size();
Message.PARENT_CLEAR_SUCCESS.send(sender, target, context, changed);
LoggedAction.build().source(sender).target(target).description("parent", "clear", context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
}
use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class ParentRemoveTemp 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_ALLOW_SPACE);
Duration duration = args.getDurationOrDefault(1, null);
int fromIndex = duration == null ? 1 : 2;
MutableContextSet context = args.getContextOrDefault(fromIndex, plugin);
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context) || ArgumentPermissions.checkGroup(plugin, sender, groupName, context) || ArgumentPermissions.checkArguments(plugin, sender, permission, groupName)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
DataMutateResult.WithMergedNode result = target.unsetNode(DataType.NORMAL, Inheritance.builder(groupName).expiry(10L).withContext(context).build(), duration);
if (result.getResult().wasSuccessful()) {
Node mergedNode = result.getMergedNode();
// noinspection ConstantConditions
if (mergedNode != null) {
Message.UNSET_TEMP_INHERIT_SUBTRACT_SUCCESS.send(sender, target, Component.text(groupName), mergedNode.getExpiryDuration(), context, duration);
LoggedAction.build().source(sender).target(target).description("parent", "removetemp", groupName, duration, context).build().submit(plugin, sender);
} else {
Message.UNSET_TEMP_INHERIT_SUCCESS.send(sender, target, Component.text(groupName), context);
LoggedAction.build().source(sender).target(target).description("parent", "removetemp", groupName, context).build().submit(plugin, sender);
}
StorageAssistant.save(target, sender, plugin);
} else {
Message.DOES_NOT_TEMP_INHERIT.send(sender, target, Component.text(groupName), context);
}
}
use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class PermissionClear 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 before = target.normalData().size();
MutableContextSet context = args.getContextOrDefault(0, plugin);
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
target.removeIf(DataType.NORMAL, context.isEmpty() ? null : context, NodeType.PERMISSION::matches, false);
int changed = before - target.normalData().size();
Message.PERMISSION_CLEAR_SUCCESS.send(sender, target, context, changed);
LoggedAction.build().source(sender).target(target).description("permission", "clear", context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
}
use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class PermissionUnset 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);
MutableContextSet context = args.getContextOrDefault(1, 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).withContext(context).build();
if (builtNode instanceof InheritanceNode) {
if (ArgumentPermissions.checkGroup(plugin, sender, ((InheritanceNode) builtNode).getGroupName(), context)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
}
DataMutateResult result = target.unsetNode(DataType.NORMAL, builtNode);
if (result.wasSuccessful()) {
Message.UNSETPERMISSION_SUCCESS.send(sender, node, target, context);
LoggedAction.build().source(sender).target(target).description("permission", "unset", node, context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
} else {
Message.DOES_NOT_HAVE_PERMISSION.send(sender, target, node, context);
}
}
use of net.luckperms.api.context.MutableContextSet 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