Search in sources :

Example 26 with Node

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

the class WildcardProcessor method refresh.

@Override
public void refresh() {
    ImmutableMap.Builder<String, TristateResult> builder = ImmutableMap.builder();
    for (Map.Entry<String, Node> e : this.sourceMap.entrySet()) {
        String key = e.getKey();
        if (!key.endsWith(WILDCARD_SUFFIX) || key.length() <= 2) {
            continue;
        }
        key = key.substring(0, key.length() - 2);
        TristateResult value = RESULT_FACTORY.result(e.getValue());
        builder.put(key, value);
    }
    this.wildcardPermissions = builder.build();
    Node rootWildcard = this.sourceMap.get(ROOT_WILDCARD);
    if (rootWildcard == null) {
        rootWildcard = this.sourceMap.get(ROOT_WILDCARD_WITH_QUOTES);
    }
    this.rootWildcardState = rootWildcard == null ? TristateResult.UNDEFINED : RESULT_FACTORY.result(rootWildcard);
}
Also used : AbstractNode(me.lucko.luckperms.common.node.AbstractNode) Node(net.luckperms.api.node.Node) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) TristateResult(me.lucko.luckperms.common.cacheddata.result.TristateResult)

Example 27 with Node

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

the class BulkUpdate method apply.

/**
 * Applies this query to the given set of nodes, and returns the result.
 *
 * @param nodes the input nodes
 * @param holderType the holder type the nodes are from
 * @return the transformed nodes, or null if no change was made
 */
@Nullable
public Set<Node> apply(Set<Node> nodes, HolderType holderType) {
    Set<Node> results = new HashSet<>();
    boolean change = false;
    for (Node node : nodes) {
        Node result = apply(node);
        if (result != node) {
            change = true;
        }
        if (result != null) {
            results.add(result);
        }
    }
    if (!change) {
        return null;
    }
    if (this.trackStatistics) {
        this.statistics.incrementAffected(holderType);
    }
    return results;
}
Also used : Node(net.luckperms.api.node.Node) HashSet(java.util.HashSet) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 28 with Node

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

the class VerboseListener method sendNotification.

private void sendNotification(VerboseEvent event) {
    // form a text component from the check trace
    Component component;
    if (event instanceof PermissionCheckEvent) {
        PermissionCheckEvent permissionEvent = (PermissionCheckEvent) event;
        component = Message.VERBOSE_LOG_PERMISSION.build(permissionEvent.getCheckTarget().describe(), permissionEvent.getPermission(), permissionEvent.getResult().result());
    } else if (event instanceof MetaCheckEvent) {
        MetaCheckEvent metaEvent = (MetaCheckEvent) event;
        component = Message.VERBOSE_LOG_META.build(metaEvent.getCheckTarget().describe(), metaEvent.getKey(), String.valueOf(metaEvent.getResult().result()));
    } else {
        throw new IllegalArgumentException("Unknown event type: " + event);
    }
    // just send as a raw message
    if (this.notifiedSender.isConsole()) {
        this.notifiedSender.sendMessage(component);
        return;
    }
    // build the hover text
    List<ComponentLike> hover = new ArrayList<>();
    hover.add(Message.VERBOSE_LOG_HOVER_TYPE.build(event.getType().toString()));
    hover.add(Message.VERBOSE_LOG_HOVER_ORIGIN.build(event.getOrigin().name()));
    Result<?, ?> result = event.getResult();
    if (result instanceof TristateResult) {
        TristateResult tristateResult = (TristateResult) result;
        if (tristateResult.processorClass() != null) {
            hover.add(Message.VERBOSE_LOG_HOVER_PROCESSOR.build(tristateResult.processorClassFriendly()));
        }
    }
    Node node = result.node();
    if (node != null) {
        if (node instanceof MetaNode) {
            hover.add(Message.VERBOSE_LOG_HOVER_CAUSE_META.build((MetaNode) node));
        } else {
            hover.add(Message.VERBOSE_LOG_HOVER_CAUSE.build(node));
        }
    }
    if (event.getCheckQueryOptions().mode() == QueryMode.CONTEXTUAL) {
        hover.add(Message.VERBOSE_LOG_HOVER_CONTEXT.build(event.getCheckQueryOptions().context()));
    }
    hover.add(Message.VERBOSE_LOG_HOVER_THREAD.build(event.getCheckThread()));
    hover.add(Message.VERBOSE_LOG_HOVER_TRACE_TITLE.build());
    Consumer<StackTraceElement> printer = StackTracePrinter.elementToString(str -> hover.add(Message.VERBOSE_LOG_HOVER_TRACE_CONTENT.build(str)));
    int overflow;
    if (shouldFilterStackTrace(event)) {
        overflow = CHAT_FILTERED_PRINTER.process(event.getCheckTrace(), printer);
    } else {
        overflow = CHAT_UNFILTERED_PRINTER.process(event.getCheckTrace(), printer);
    }
    if (overflow != 0) {
        hover.add(Message.VERBOSE_LOG_HOVER_TRACE_OVERFLOW.build(overflow));
    }
    // send the message
    HoverEvent<Component> hoverEvent = HoverEvent.showText(Component.join(Component.newline(), hover));
    this.notifiedSender.sendMessage(component.hoverEvent(hoverEvent));
}
Also used : PermissionCheckEvent(me.lucko.luckperms.common.verbose.event.PermissionCheckEvent) ComponentLike(net.kyori.adventure.text.ComponentLike) Node(net.luckperms.api.node.Node) MetaNode(net.luckperms.api.node.types.MetaNode) ArrayList(java.util.ArrayList) MetaNode(net.luckperms.api.node.types.MetaNode) MetaCheckEvent(me.lucko.luckperms.common.verbose.event.MetaCheckEvent) Component(net.kyori.adventure.text.Component) TristateResult(me.lucko.luckperms.common.cacheddata.result.TristateResult)

Example 29 with Node

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

the class CombinedConfigurateStorage method searchGroupNodes.

@Override
public <N extends Node> List<NodeEntry<String, N>> searchGroupNodes(ConstraintNodeMatcher<N> constraint) throws Exception {
    List<NodeEntry<String, N>> held = new ArrayList<>();
    this.groups.apply(false, true, root -> {
        for (Map.Entry<Object, ? extends ConfigurationNode> entry : root.getChildrenMap().entrySet()) {
            try {
                String holder = entry.getKey().toString();
                ConfigurationNode object = entry.getValue();
                Set<Node> nodes = readNodes(object);
                for (Node e : nodes) {
                    N match = constraint.match(e);
                    if (match != null) {
                        held.add(NodeEntry.of(holder, match));
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    return held;
}
Also used : NodeEntry(me.lucko.luckperms.common.storage.misc.NodeEntry) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) Node(net.luckperms.api.node.Node) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) ArrayList(java.util.ArrayList) Map(java.util.Map) IOException(java.io.IOException)

Example 30 with Node

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

the class CombinedConfigurateStorage method searchUserNodes.

@Override
public <N extends Node> List<NodeEntry<UUID, N>> searchUserNodes(ConstraintNodeMatcher<N> constraint) throws Exception {
    List<NodeEntry<UUID, N>> held = new ArrayList<>();
    this.users.apply(false, true, root -> {
        for (Map.Entry<Object, ? extends ConfigurationNode> entry : root.getChildrenMap().entrySet()) {
            try {
                UUID holder = UUID.fromString(entry.getKey().toString());
                ConfigurationNode object = entry.getValue();
                Set<Node> nodes = readNodes(object);
                for (Node e : nodes) {
                    N match = constraint.match(e);
                    if (match != null) {
                        held.add(NodeEntry.of(holder, match));
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    return held;
}
Also used : NodeEntry(me.lucko.luckperms.common.storage.misc.NodeEntry) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) Node(net.luckperms.api.node.Node) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Map(java.util.Map) IOException(java.io.IOException)

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