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