Search in sources :

Example 1 with Meta

use of me.lucko.luckperms.common.node.types.Meta 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 2 with Meta

use of me.lucko.luckperms.common.node.types.Meta 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

List (java.util.List)2 LoggedAction (me.lucko.luckperms.common.actionlog.LoggedAction)2 CommandException (me.lucko.luckperms.common.command.abstraction.CommandException)2 GenericChildCommand (me.lucko.luckperms.common.command.abstraction.GenericChildCommand)2 ArgumentPermissions (me.lucko.luckperms.common.command.access.ArgumentPermissions)2 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)2 CommandSpec (me.lucko.luckperms.common.command.spec.CommandSpec)2 TabCompleter (me.lucko.luckperms.common.command.tabcomplete.TabCompleter)2 TabCompletions (me.lucko.luckperms.common.command.tabcomplete.TabCompletions)2 ArgumentList (me.lucko.luckperms.common.command.utils.ArgumentList)2 StorageAssistant (me.lucko.luckperms.common.command.utils.StorageAssistant)2 Message (me.lucko.luckperms.common.locale.Message)2 PermissionHolder (me.lucko.luckperms.common.model.PermissionHolder)2 Meta (me.lucko.luckperms.common.node.types.Meta)2 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)2 Sender (me.lucko.luckperms.common.sender.Sender)2 Predicates (me.lucko.luckperms.common.util.Predicates)2 MutableContextSet (net.luckperms.api.context.MutableContextSet)2 DataType (net.luckperms.api.model.data.DataType)2 Node (net.luckperms.api.node.Node)2