Search in sources :

Example 1 with MetaCheckEvent

use of me.lucko.luckperms.common.verbose.event.MetaCheckEvent 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 2 with MetaCheckEvent

use of me.lucko.luckperms.common.verbose.event.MetaCheckEvent in project LuckPerms by lucko.

the class VerboseHandler method offerMetaCheckEvent.

/**
 * Offers meta check data to the handler, to be eventually passed onto listeners.
 *
 * <p>The check data is added to a queue to be processed later, to avoid blocking
 * the main thread each time a meta check is made.</p>
 *
 * @param origin the origin of the check
 * @param checkTarget the target of the meta check
 * @param checkQueryOptions the query options used for the check
 * @param key the meta key which was checked for
 * @param result the result of the meta check
 */
public void offerMetaCheckEvent(CheckOrigin origin, VerboseCheckTarget checkTarget, QueryOptions checkQueryOptions, String key, StringResult<?> result) {
    // don't bother even processing the check if there are no listeners registered
    if (!this.listening) {
        return;
    }
    long time = System.currentTimeMillis();
    Throwable trace = new Throwable();
    String thread = Thread.currentThread().getName();
    // add the check data to a queue to be processed later.
    this.queue.offer(new MetaCheckEvent(origin, checkTarget, checkQueryOptions, time, trace, thread, key, result));
}
Also used : MetaCheckEvent(me.lucko.luckperms.common.verbose.event.MetaCheckEvent)

Aggregations

MetaCheckEvent (me.lucko.luckperms.common.verbose.event.MetaCheckEvent)2 ArrayList (java.util.ArrayList)1 TristateResult (me.lucko.luckperms.common.cacheddata.result.TristateResult)1 PermissionCheckEvent (me.lucko.luckperms.common.verbose.event.PermissionCheckEvent)1 Component (net.kyori.adventure.text.Component)1 ComponentLike (net.kyori.adventure.text.ComponentLike)1 Node (net.luckperms.api.node.Node)1 MetaNode (net.luckperms.api.node.types.MetaNode)1