Search in sources :

Example 6 with Difference

use of me.lucko.luckperms.common.util.Difference in project LuckPerms by lucko.

the class NodeMapMutable method clear.

@Override
public Difference<Node> clear(ContextSet contextSet) {
    ImmutableContextSet context = contextSet.immutableCopy();
    Difference<Node> result = new Difference<>();
    this.lock.lock();
    try {
        SortedSet<Node> removed = this.map.remove(context);
        if (removed != null) {
            result.recordChanges(ChangeType.REMOVE, removed);
            this.inheritanceMap.remove(context);
        }
    } finally {
        this.lock.unlock();
    }
    return result;
}
Also used : Node(net.luckperms.api.node.Node) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) Difference(me.lucko.luckperms.common.util.Difference)

Example 7 with Difference

use of me.lucko.luckperms.common.util.Difference in project LuckPerms by lucko.

the class NodeMapMutable method applyChanges.

@Override
public Difference<Node> applyChanges(Difference<Node> changes) {
    Difference<Node> result = new Difference<>();
    this.lock.lock();
    try {
        for (Node n : changes.getAdded()) {
            result.mergeFrom(add(n));
        }
        for (Node n : changes.getRemoved()) {
            result.mergeFrom(removeExact(n));
        }
    } finally {
        this.lock.unlock();
    }
    return result;
}
Also used : Node(net.luckperms.api.node.Node) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) Difference(me.lucko.luckperms.common.util.Difference)

Example 8 with Difference

use of me.lucko.luckperms.common.util.Difference in project LuckPerms by lucko.

the class NodeMapMutable method add.

@Override
public Difference<Node> add(Node nodeWithoutInheritanceOrigin) {
    Node node = addInheritanceOrigin(nodeWithoutInheritanceOrigin);
    ImmutableContextSet context = node.getContexts();
    Difference<Node> result = new Difference<>();
    this.lock.lock();
    try {
        SortedSet<Node> nodes = this.map.computeIfAbsent(context, VALUE_SET_SUPPLIER);
        // add the new node to the set - if it was already there, return
        if (!nodes.add(node)) {
            return result;
        }
        // mark that we added the node in the results
        result.recordChange(ChangeType.ADD, node);
        // remove any others that were in the set already with a different value/expiry time
        removeMatchingButNotSame(nodes.iterator(), node, result);
        // update the inheritanceMap too if necessary
        if (node instanceof InheritanceNode) {
            SortedSet<InheritanceNode> inhNodes = this.inheritanceMap.computeIfAbsent(context, INHERITANCE_VALUE_SET_SUPPLIER);
            // remove existing..
            inhNodes.removeIf(el -> node.equals(el, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE));
            // .. & add
            if (node.getValue()) {
                inhNodes.add((InheritanceNode) node);
            }
        }
    } finally {
        this.lock.unlock();
    }
    return result;
}
Also used : Node(net.luckperms.api.node.Node) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) Difference(me.lucko.luckperms.common.util.Difference)

Example 9 with Difference

use of me.lucko.luckperms.common.util.Difference 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

Difference (me.lucko.luckperms.common.util.Difference)9 Node (net.luckperms.api.node.Node)9 InheritanceNode (net.luckperms.api.node.types.InheritanceNode)7 ImmutableContextSet (net.luckperms.api.context.ImmutableContextSet)5 Connection (java.sql.Connection)1 ApiPermissionHolder (me.lucko.luckperms.common.api.implementation.ApiPermissionHolder)1