Search in sources :

Example 6 with TemporaryNodeMergeStrategy

use of net.luckperms.api.model.data.TemporaryNodeMergeStrategy 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

TemporaryNodeMergeStrategy (net.luckperms.api.model.data.TemporaryNodeMergeStrategy)6 Duration (java.time.Duration)5 MutableContextSet (net.luckperms.api.context.MutableContextSet)5 DataMutateResult (net.luckperms.api.model.data.DataMutateResult)5 Group (me.lucko.luckperms.common.model.Group)2 Node (net.luckperms.api.node.Node)2 List (java.util.List)1 OptionalInt (java.util.OptionalInt)1 LoggedAction (me.lucko.luckperms.common.actionlog.LoggedAction)1 MetaAccumulator (me.lucko.luckperms.common.cacheddata.type.MetaAccumulator)1 CommandException (me.lucko.luckperms.common.command.abstraction.CommandException)1 GenericChildCommand (me.lucko.luckperms.common.command.abstraction.GenericChildCommand)1 ArgumentPermissions (me.lucko.luckperms.common.command.access.ArgumentPermissions)1 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)1 CommandSpec (me.lucko.luckperms.common.command.spec.CommandSpec)1 TabCompleter (me.lucko.luckperms.common.command.tabcomplete.TabCompleter)1 TabCompletions (me.lucko.luckperms.common.command.tabcomplete.TabCompletions)1 ArgumentList (me.lucko.luckperms.common.command.utils.ArgumentList)1 StorageAssistant (me.lucko.luckperms.common.command.utils.StorageAssistant)1 ConfigKeys (me.lucko.luckperms.common.config.ConfigKeys)1