Search in sources :

Example 71 with Node

use of net.luckperms.api.node.Node 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)

Example 72 with Node

use of net.luckperms.api.node.Node in project LuckPerms by lucko.

the class PermissionSet 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);
    MutableContextSet context = args.getContextOrDefault(2, 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).build();
    if (builtNode instanceof InheritanceNode) {
        if (ArgumentPermissions.checkGroup(plugin, sender, ((InheritanceNode) builtNode).getGroupName(), context)) {
            Message.COMMAND_NO_PERMISSION.send(sender);
            return;
        }
    }
    DataMutateResult result = target.setNode(DataType.NORMAL, builtNode, true);
    if (result.wasSuccessful()) {
        Message.SETPERMISSION_SUCCESS.send(sender, node, value, target, context);
        LoggedAction.build().source(sender).target(target).description("permission", "set", node, value, context).build().submit(plugin, sender);
        StorageAssistant.save(target, sender, plugin);
    } else {
        Message.ALREADY_HASPERMISSION.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 73 with Node

use of net.luckperms.api.node.Node in project LuckPerms by lucko.

the class LogNotify method isIgnoring.

public static boolean isIgnoring(LuckPermsPlugin plugin, UUID uuid) {
    User user = plugin.getUserManager().getIfLoaded(uuid);
    if (user == null) {
        return false;
    }
    Optional<? extends Node> node = user.normalData().nodesInContext(ImmutableContextSetImpl.EMPTY).stream().filter(n -> n.getKey().equalsIgnoreCase(IGNORE_NODE)).findFirst();
    // if set to false, ignore it, return false
    return node.map(Node::getValue).orElse(false);
}
Also used : ImmutableContextSetImpl(me.lucko.luckperms.common.context.ImmutableContextSetImpl) Log(me.lucko.luckperms.common.actionlog.Log) Sender(me.lucko.luckperms.common.sender.Sender) UUID(java.util.UUID) Message(me.lucko.luckperms.common.locale.Message) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) Permission(me.lucko.luckperms.common.node.types.Permission) Node(net.luckperms.api.node.Node) Predicates(me.lucko.luckperms.common.util.Predicates) Optional(java.util.Optional) CommandSpec(me.lucko.luckperms.common.command.spec.CommandSpec) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) ChildCommand(me.lucko.luckperms.common.command.abstraction.ChildCommand) User(me.lucko.luckperms.common.model.User) ArgumentList(me.lucko.luckperms.common.command.utils.ArgumentList) DataType(net.luckperms.api.model.data.DataType) User(me.lucko.luckperms.common.model.User)

Example 74 with Node

use of net.luckperms.api.node.Node in project LuckPerms by lucko.

the class SearchCommand method sendResult.

private static <T extends Comparable<T>> void sendResult(Sender sender, List<NodeEntry<T, Node>> results, Function<T, String> lookupFunction, Message.Args3<Integer, Integer, Integer> headerMessage, HolderType holderType, String label, int page, Comparison comparison) {
    results = new ArrayList<>(results);
    results.sort(NodeEntryComparator.normal());
    int pageIndex = page - 1;
    List<List<NodeEntry<T, Node>>> pages = Iterators.divideIterable(results, 15);
    if (pageIndex < 0 || pageIndex >= pages.size()) {
        page = 1;
        pageIndex = 0;
    }
    List<NodeEntry<T, Node>> content = pages.get(pageIndex);
    List<Map.Entry<String, NodeEntry<T, Node>>> mappedContent = content.stream().map(hp -> Maps.immutableEntry(lookupFunction.apply(hp.getHolder()), hp)).collect(Collectors.toList());
    // send header
    headerMessage.send(sender, page, pages.size(), results.size());
    for (Map.Entry<String, NodeEntry<T, Node>> ent : mappedContent) {
        Message.SEARCH_NODE_ENTRY.send(sender, comparison != StandardComparison.EQUAL, ent.getValue().getNode(), ent.getKey(), holderType, label, sender.getPlugin());
    }
}
Also used : LoadingMap(me.lucko.luckperms.common.cache.LoadingMap) StandardNodeMatchers(me.lucko.luckperms.common.node.matcher.StandardNodeMatchers) SingleCommand(me.lucko.luckperms.common.command.abstraction.SingleCommand) Constraint(me.lucko.luckperms.common.bulkupdate.comparison.Constraint) TabCompletions(me.lucko.luckperms.common.command.tabcomplete.TabCompletions) Function(java.util.function.Function) Message(me.lucko.luckperms.common.locale.Message) NodeEntryComparator(me.lucko.luckperms.common.node.comparator.NodeEntryComparator) ArrayList(java.util.ArrayList) NodeEntry(me.lucko.luckperms.common.storage.misc.NodeEntry) Map(java.util.Map) 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) HolderType(me.lucko.luckperms.common.model.HolderType) ArgumentList(me.lucko.luckperms.common.command.utils.ArgumentList) StandardComparison(me.lucko.luckperms.common.bulkupdate.comparison.StandardComparison) Comparison(me.lucko.luckperms.common.bulkupdate.comparison.Comparison) Sender(me.lucko.luckperms.common.sender.Sender) UUID(java.util.UUID) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) TabCompleter(me.lucko.luckperms.common.command.tabcomplete.TabCompleter) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) ConstraintNodeMatcher(me.lucko.luckperms.common.node.matcher.ConstraintNodeMatcher) Iterators(me.lucko.luckperms.common.util.Iterators) List(java.util.List) Node(net.luckperms.api.node.Node) Constraint(me.lucko.luckperms.common.bulkupdate.comparison.Constraint) NodeEntry(me.lucko.luckperms.common.storage.misc.NodeEntry) NodeEntry(me.lucko.luckperms.common.storage.misc.NodeEntry) ArrayList(java.util.ArrayList) ArgumentList(me.lucko.luckperms.common.command.utils.ArgumentList) List(java.util.List) LoadingMap(me.lucko.luckperms.common.cache.LoadingMap) Map(java.util.Map)

Aggregations

Node (net.luckperms.api.node.Node)74 InheritanceNode (net.luckperms.api.node.types.InheritanceNode)28 ArrayList (java.util.ArrayList)23 Map (java.util.Map)16 UUID (java.util.UUID)16 ImmutableContextSet (net.luckperms.api.context.ImmutableContextSet)13 NodeEntry (me.lucko.luckperms.common.storage.misc.NodeEntry)12 MetaNode (net.luckperms.api.node.types.MetaNode)12 Group (me.lucko.luckperms.common.model.Group)11 HashMap (java.util.HashMap)10 List (java.util.List)10 PermissionHolder (me.lucko.luckperms.common.model.PermissionHolder)9 Difference (me.lucko.luckperms.common.util.Difference)9 DataType (net.luckperms.api.model.data.DataType)9 Connection (java.sql.Connection)7 User (me.lucko.luckperms.common.model.User)7 MutableContextSet (net.luckperms.api.context.MutableContextSet)7 PrefixNode (net.luckperms.api.node.types.PrefixNode)7 SuffixNode (net.luckperms.api.node.types.SuffixNode)7 IOException (java.io.IOException)6