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