Search in sources :

Example 1 with ApiPermissionHolder

use of me.lucko.luckperms.common.api.implementation.ApiPermissionHolder in project LuckPerms by lucko.

the class EventDispatcher method dispatchNodeClear.

public void dispatchNodeClear(PermissionHolder target, DataType dataType, Difference<Node> changes) {
    if (!this.eventBus.shouldPost(NodeClearEvent.class)) {
        return;
    }
    if (changes.isEmpty()) {
        return;
    }
    ApiPermissionHolder proxy = proxy(target);
    ImmutableSet<Node> state = target.getData(dataType).asImmutableSet();
    // call clear event
    ImmutableSet<Node> nodes = ImmutableSet.copyOf(changes.getRemoved());
    postAsync(NodeClearEvent.class, proxy, dataType, state, nodes);
    // call add event if needed for any nodes that were added
    for (Node added : changes.getAdded()) {
        postAsync(NodeAddEvent.class, proxy, dataType, state, added);
    }
}
Also used : NodeClearEvent(net.luckperms.api.event.node.NodeClearEvent) Node(net.luckperms.api.node.Node) ApiPermissionHolder(me.lucko.luckperms.common.api.implementation.ApiPermissionHolder)

Example 2 with ApiPermissionHolder

use of me.lucko.luckperms.common.api.implementation.ApiPermissionHolder in project LuckPerms by lucko.

the class EventDispatcher method dispatchNodeChanges.

public void dispatchNodeChanges(PermissionHolder target, DataType dataType, Difference<Node> changes) {
    if (!this.eventBus.shouldPost(NodeAddEvent.class) && !this.eventBus.shouldPost(NodeRemoveEvent.class)) {
        return;
    }
    if (changes.isEmpty()) {
        return;
    }
    ApiPermissionHolder proxy = proxy(target);
    ImmutableSet<Node> state = target.getData(dataType).asImmutableSet();
    // call an event for each recorded change
    for (Difference.Change<Node> change : changes.getChanges()) {
        Class<? extends NodeMutateEvent> type = change.type() == Difference.ChangeType.ADD ? NodeAddEvent.class : NodeRemoveEvent.class;
        postAsync(type, proxy, dataType, state, change.value());
    }
}
Also used : Node(net.luckperms.api.node.Node) Difference(me.lucko.luckperms.common.util.Difference) ApiPermissionHolder(me.lucko.luckperms.common.api.implementation.ApiPermissionHolder)

Aggregations

ApiPermissionHolder (me.lucko.luckperms.common.api.implementation.ApiPermissionHolder)2 Node (net.luckperms.api.node.Node)2 Difference (me.lucko.luckperms.common.util.Difference)1 NodeClearEvent (net.luckperms.api.event.node.NodeClearEvent)1