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