Search in sources :

Example 1 with PrefixNode

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

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

Example 3 with PrefixNode

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

the class PermissionHolderSubjectData method nodesToOptions.

private static ImmutableMap<String, String> nodesToOptions(Iterable<? extends Node> nodes) {
    Map<String, String> builder = new HashMap<>();
    int maxPrefixPriority = Integer.MIN_VALUE;
    int maxSuffixPriority = Integer.MIN_VALUE;
    for (Node n : nodes) {
        if (!n.getValue())
            continue;
        if (!NodeType.META_OR_CHAT_META.matches(n))
            continue;
        if (n instanceof PrefixNode) {
            PrefixNode pn = (PrefixNode) n;
            if (pn.getPriority() > maxPrefixPriority) {
                builder.put(Prefix.NODE_KEY, pn.getMetaValue());
                maxPrefixPriority = pn.getPriority();
            }
            continue;
        }
        if (n instanceof SuffixNode) {
            SuffixNode sn = (SuffixNode) n;
            if (sn.getPriority() > maxSuffixPriority) {
                builder.put(Suffix.NODE_KEY, sn.getMetaValue());
                maxSuffixPriority = sn.getPriority();
            }
            continue;
        }
        if (n instanceof MetaNode) {
            MetaNode mn = (MetaNode) n;
            builder.put(mn.getMetaKey(), mn.getMetaValue());
        }
    }
    return ImmutableMap.copyOf(builder);
}
Also used : HashMap(java.util.HashMap) SuffixNode(net.luckperms.api.node.types.SuffixNode) PrefixNode(net.luckperms.api.node.types.PrefixNode) Node(net.luckperms.api.node.Node) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) MetaNode(net.luckperms.api.node.types.MetaNode) SuffixNode(net.luckperms.api.node.types.SuffixNode) PrefixNode(net.luckperms.api.node.types.PrefixNode) MetaNode(net.luckperms.api.node.types.MetaNode)

Aggregations

MetaNode (net.luckperms.api.node.types.MetaNode)3 PrefixNode (net.luckperms.api.node.types.PrefixNode)3 SuffixNode (net.luckperms.api.node.types.SuffixNode)3 Node (net.luckperms.api.node.Node)2 ChatMetaNode (net.luckperms.api.node.types.ChatMetaNode)2 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 InheritanceNode (net.luckperms.api.node.types.InheritanceNode)1