Search in sources :

Example 1 with MetaNode

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

the class NodeCommandFactory method undoCommand.

public static String undoCommand(Node node, String holder, HolderType holderType, boolean explicitGlobalContext) {
    StringBuilder sb = new StringBuilder(32);
    sb.append(holderType.toString()).append(' ').append(holder).append(' ');
    if (node instanceof InheritanceNode) {
        // command
        sb.append("parent remove");
        if (node.hasExpiry()) {
            sb.append("temp");
        }
        sb.append(' ');
        // value
        sb.append(((InheritanceNode) node).getGroupName());
    } else if (node.getValue() && node instanceof ChatMetaNode<?, ?>) {
        ChatMetaNode<?, ?> chatNode = (ChatMetaNode<?, ?>) node;
        // command
        sb.append("meta remove");
        if (node.hasExpiry()) {
            sb.append("temp");
        }
        sb.append(chatNode.getMetaType().toString());
        // values
        sb.append(' ').append(chatNode.getPriority()).append(' ');
        appendEscaped(sb, chatNode.getMetaValue());
    } else if (node.getValue() && node instanceof MetaNode) {
        MetaNode metaNode = (MetaNode) node;
        // command
        sb.append("meta unset");
        if (node.hasExpiry()) {
            sb.append("temp");
        }
        sb.append(' ');
        // value
        appendEscaped(sb, metaNode.getMetaKey());
    } else {
        // command
        sb.append("permission unset");
        if (node.hasExpiry()) {
            sb.append("temp");
        }
        sb.append(' ');
        // value
        appendEscaped(sb, node.getKey());
    }
    if (!node.getContexts().isEmpty()) {
        for (Context context : node.getContexts()) {
            sb.append(' ').append(context.getKey()).append("=").append(context.getValue());
        }
    } else if (explicitGlobalContext) {
        sb.append(" global");
    }
    return sb.toString();
}
Also used : Context(net.luckperms.api.context.Context) ChatMetaNode(net.luckperms.api.node.types.ChatMetaNode) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) MetaNode(net.luckperms.api.node.types.MetaNode) ChatMetaNode(net.luckperms.api.node.types.ChatMetaNode)

Example 2 with MetaNode

use of net.luckperms.api.node.types.MetaNode 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 3 with MetaNode

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

the class CalculatedSubject method resolveAllOptions.

public void resolveAllOptions(MetaAccumulator accumulator, QueryOptions filter) {
    SubjectInheritanceGraph graph = new SubjectInheritanceGraph(filter);
    Iterable<CalculatedSubject> traversal = graph.traverse(TraversalAlgorithm.DEPTH_FIRST_PRE_ORDER, this);
    for (CalculatedSubject subject : traversal) {
        for (MetaNode entry : subject.getCombinedOptions(filter).values()) {
            accumulator.accumulateNode(entry);
        }
    }
    accumulator.complete();
}
Also used : MetaNode(net.luckperms.api.node.types.MetaNode) SubjectInheritanceGraph(me.lucko.luckperms.sponge.service.inheritance.SubjectInheritanceGraph)

Example 4 with MetaNode

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

the class MetaInfo method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) {
    if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, target)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    SortedSet<Map.Entry<Integer, PrefixNode>> prefixes = new TreeSet<>(MetaComparator.INSTANCE.reversed());
    SortedSet<Map.Entry<Integer, SuffixNode>> suffixes = new TreeSet<>(MetaComparator.INSTANCE.reversed());
    Set<MetaNode> meta = new LinkedHashSet<>();
    // Collect data
    for (Node node : target.resolveInheritedNodes(NodeType.META_OR_CHAT_META, QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL)) {
        if (node instanceof PrefixNode) {
            PrefixNode pn = (PrefixNode) node;
            prefixes.add(Maps.immutableEntry(pn.getPriority(), pn));
        } else if (node instanceof SuffixNode) {
            SuffixNode sn = (SuffixNode) node;
            suffixes.add(Maps.immutableEntry(sn.getPriority(), sn));
        } else if (node instanceof MetaNode) {
            meta.add((MetaNode) node);
        }
    }
    if (prefixes.isEmpty()) {
        Message.CHAT_META_PREFIX_NONE.send(sender, target);
    } else {
        Message.CHAT_META_PREFIX_HEADER.send(sender, target);
        for (Map.Entry<Integer, PrefixNode> e : prefixes) {
            Message.CHAT_META_ENTRY.send(sender, e.getValue(), target, label);
        }
    }
    if (suffixes.isEmpty()) {
        Message.CHAT_META_SUFFIX_NONE.send(sender, target);
    } else {
        Message.CHAT_META_SUFFIX_HEADER.send(sender, target);
        for (Map.Entry<Integer, SuffixNode> e : suffixes) {
            Message.CHAT_META_ENTRY.send(sender, e.getValue(), target, label);
        }
    }
    if (meta.isEmpty()) {
        Message.META_NONE.send(sender, target);
    } else {
        Message.META_HEADER.send(sender, target);
        for (MetaNode node : meta) {
            Message.META_ENTRY.send(sender, node, target, label);
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SuffixNode(net.luckperms.api.node.types.SuffixNode) PrefixNode(net.luckperms.api.node.types.PrefixNode) ChatMetaNode(net.luckperms.api.node.types.ChatMetaNode) Node(net.luckperms.api.node.Node) MetaNode(net.luckperms.api.node.types.MetaNode) SuffixNode(net.luckperms.api.node.types.SuffixNode) TreeSet(java.util.TreeSet) PrefixNode(net.luckperms.api.node.types.PrefixNode) ChatMetaNode(net.luckperms.api.node.types.ChatMetaNode) MetaNode(net.luckperms.api.node.types.MetaNode) Map(java.util.Map)

Example 5 with MetaNode

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

the class MetaAccumulator method accumulateNode.

// accumulate methods
public void accumulateNode(Node n) {
    ensureState(State.ACCUMULATING);
    // "cancelled out" by assigning a false copy.
    if (!this.seenNodeKeys.add(n.getKey())) {
        return;
    }
    if (!n.getValue()) {
        return;
    }
    if (n instanceof MetaNode) {
        MetaNode mn = (MetaNode) n;
        this.meta.put(mn.getMetaKey(), StringResult.of(mn));
    }
    if (n instanceof PrefixNode) {
        PrefixNode pn = (PrefixNode) n;
        this.prefixes.putIfAbsent(pn.getPriority(), StringResult.of(pn));
        this.prefixAccumulator.offer(pn);
    }
    if (n instanceof SuffixNode) {
        SuffixNode pn = (SuffixNode) n;
        this.suffixes.putIfAbsent(pn.getPriority(), StringResult.of(pn));
        this.suffixAccumulator.offer(pn);
    }
}
Also used : SuffixNode(net.luckperms.api.node.types.SuffixNode) PrefixNode(net.luckperms.api.node.types.PrefixNode) ChatMetaNode(net.luckperms.api.node.types.ChatMetaNode) MetaNode(net.luckperms.api.node.types.MetaNode)

Aggregations

MetaNode (net.luckperms.api.node.types.MetaNode)9 Node (net.luckperms.api.node.Node)4 ChatMetaNode (net.luckperms.api.node.types.ChatMetaNode)4 HashMap (java.util.HashMap)3 InheritanceNode (net.luckperms.api.node.types.InheritanceNode)3 PrefixNode (net.luckperms.api.node.types.PrefixNode)3 SuffixNode (net.luckperms.api.node.types.SuffixNode)3 Map (java.util.Map)2 SubjectInheritanceGraph (me.lucko.luckperms.sponge.service.inheritance.SubjectInheritanceGraph)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 TristateResult (me.lucko.luckperms.common.cacheddata.result.TristateResult)1 YamlLoader (me.lucko.luckperms.common.storage.implementation.file.loader.YamlLoader)1 MetaCheckEvent (me.lucko.luckperms.common.verbose.event.MetaCheckEvent)1 PermissionCheckEvent (me.lucko.luckperms.common.verbose.event.PermissionCheckEvent)1