Search in sources :

Example 6 with MutableContextSet

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);
}
Also used : MutableContextSet(net.luckperms.api.context.MutableContextSet)

Example 7 with MutableContextSet

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);
    }
}
Also used : MutableContextSet(net.luckperms.api.context.MutableContextSet) Node(net.luckperms.api.node.Node) Duration(java.time.Duration) DataMutateResult(net.luckperms.api.model.data.DataMutateResult)

Example 8 with MutableContextSet

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);
}
Also used : MutableContextSet(net.luckperms.api.context.MutableContextSet)

Example 9 with MutableContextSet

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);
    }
}
Also used : MutableContextSet(net.luckperms.api.context.MutableContextSet) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) Node(net.luckperms.api.node.Node) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) DataMutateResult(net.luckperms.api.model.data.DataMutateResult)

Example 10 with MutableContextSet

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());
    }
}
Also used : CommandException(me.lucko.luckperms.common.command.abstraction.CommandException) LoggedAction(me.lucko.luckperms.common.actionlog.LoggedAction) Predicate(java.util.function.Predicate) DataConstraints(me.lucko.luckperms.common.storage.misc.DataConstraints) Set(java.util.Set) Sender(me.lucko.luckperms.common.sender.Sender) TabCompletions(me.lucko.luckperms.common.command.tabcomplete.TabCompletions) StorageAssistant(me.lucko.luckperms.common.command.utils.StorageAssistant) Message(me.lucko.luckperms.common.locale.Message) TabCompleter(me.lucko.luckperms.common.command.tabcomplete.TabCompleter) MutableContextSet(net.luckperms.api.context.MutableContextSet) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) Track(me.lucko.luckperms.common.model.Track) List(java.util.List) DemotionResult(net.luckperms.api.track.DemotionResult) Locale(java.util.Locale) Predicates(me.lucko.luckperms.common.util.Predicates) CommandSpec(me.lucko.luckperms.common.command.spec.CommandSpec) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) ChildCommand(me.lucko.luckperms.common.command.abstraction.ChildCommand) ArgumentPermissions(me.lucko.luckperms.common.command.access.ArgumentPermissions) User(me.lucko.luckperms.common.model.User) ArgumentList(me.lucko.luckperms.common.command.utils.ArgumentList) MutableContextSet(net.luckperms.api.context.MutableContextSet) DemotionResult(net.luckperms.api.track.DemotionResult) Track(me.lucko.luckperms.common.model.Track)

Aggregations

MutableContextSet (net.luckperms.api.context.MutableContextSet)28 DataMutateResult (net.luckperms.api.model.data.DataMutateResult)13 Node (net.luckperms.api.node.Node)8 Duration (java.time.Duration)7 List (java.util.List)6 LoggedAction (me.lucko.luckperms.common.actionlog.LoggedAction)6 CommandException (me.lucko.luckperms.common.command.abstraction.CommandException)6 ArgumentPermissions (me.lucko.luckperms.common.command.access.ArgumentPermissions)6 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)6 CommandSpec (me.lucko.luckperms.common.command.spec.CommandSpec)6 TabCompleter (me.lucko.luckperms.common.command.tabcomplete.TabCompleter)6 TabCompletions (me.lucko.luckperms.common.command.tabcomplete.TabCompletions)6 ArgumentList (me.lucko.luckperms.common.command.utils.ArgumentList)6 StorageAssistant (me.lucko.luckperms.common.command.utils.StorageAssistant)6 Message (me.lucko.luckperms.common.locale.Message)6 Group (me.lucko.luckperms.common.model.Group)6 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)6 Sender (me.lucko.luckperms.common.sender.Sender)6 Predicates (me.lucko.luckperms.common.util.Predicates)6 PermissionHolder (me.lucko.luckperms.common.model.PermissionHolder)5