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);
}
}
}
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);
}
}
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);
}
Aggregations