Search in sources :

Example 21 with MutableContextSet

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

Example 22 with MutableContextSet

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

Example 23 with MutableContextSet

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());
    }
}
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) PromotionResult(net.luckperms.api.track.PromotionResult) 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) 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) PromotionResult(net.luckperms.api.track.PromotionResult) Track(me.lucko.luckperms.common.model.Track)

Example 24 with MutableContextSet

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);
}
Also used : CommandException(me.lucko.luckperms.common.command.abstraction.CommandException) Meta(me.lucko.luckperms.common.node.types.Meta) LoggedAction(me.lucko.luckperms.common.actionlog.LoggedAction) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) NodeType(net.luckperms.api.node.NodeType) 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) GenericChildCommand(me.lucko.luckperms.common.command.abstraction.GenericChildCommand) TabCompleter(me.lucko.luckperms.common.command.tabcomplete.TabCompleter) MutableContextSet(net.luckperms.api.context.MutableContextSet) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) List(java.util.List) Node(net.luckperms.api.node.Node) Predicates(me.lucko.luckperms.common.util.Predicates) CommandSpec(me.lucko.luckperms.common.command.spec.CommandSpec) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) NodeEqualityPredicate(net.luckperms.api.node.NodeEqualityPredicate) ArgumentPermissions(me.lucko.luckperms.common.command.access.ArgumentPermissions) ArgumentList(me.lucko.luckperms.common.command.utils.ArgumentList) DataType(net.luckperms.api.model.data.DataType) MutableContextSet(net.luckperms.api.context.MutableContextSet) Node(net.luckperms.api.node.Node)

Example 25 with MutableContextSet

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);
    }
}
Also used : CommandException(me.lucko.luckperms.common.command.abstraction.CommandException) Meta(me.lucko.luckperms.common.node.types.Meta) NodeType(net.luckperms.api.node.NodeType) TabCompletions(me.lucko.luckperms.common.command.tabcomplete.TabCompletions) StorageAssistant(me.lucko.luckperms.common.command.utils.StorageAssistant) ConfigKeys(me.lucko.luckperms.common.config.ConfigKeys) Message(me.lucko.luckperms.common.locale.Message) GenericChildCommand(me.lucko.luckperms.common.command.abstraction.GenericChildCommand) MutableContextSet(net.luckperms.api.context.MutableContextSet) TemporaryNodeMergeStrategy(net.luckperms.api.model.data.TemporaryNodeMergeStrategy) Duration(java.time.Duration) Node(net.luckperms.api.node.Node) Predicates(me.lucko.luckperms.common.util.Predicates) CommandSpec(me.lucko.luckperms.common.command.spec.CommandSpec) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) ArgumentList(me.lucko.luckperms.common.command.utils.ArgumentList) DataMutateResult(net.luckperms.api.model.data.DataMutateResult) LoggedAction(me.lucko.luckperms.common.actionlog.LoggedAction) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) Sender(me.lucko.luckperms.common.sender.Sender) TabCompleter(me.lucko.luckperms.common.command.tabcomplete.TabCompleter) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) List(java.util.List) ArgumentPermissions(me.lucko.luckperms.common.command.access.ArgumentPermissions) DataType(net.luckperms.api.model.data.DataType) TemporaryNodeMergeStrategy(net.luckperms.api.model.data.TemporaryNodeMergeStrategy) MutableContextSet(net.luckperms.api.context.MutableContextSet) Node(net.luckperms.api.node.Node) Duration(java.time.Duration) DataMutateResult(net.luckperms.api.model.data.DataMutateResult)

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