Don't call events for changes to transient nodes

This commit is contained in:
Luck 2018-01-21 20:31:48 +00:00
parent f18d230ff6
commit e24a482deb
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
2 changed files with 15 additions and 41 deletions

View File

@ -52,6 +52,8 @@ import java.util.TreeSet;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Predicate;
import javax.annotation.Nullable;
/**
* A map of nodes held by a {@link PermissionHolder}.
*
@ -251,7 +253,7 @@ public final class NodeMap {
}
}
boolean auditTemporaryNodes(Set<Node> removed) {
boolean auditTemporaryNodes(@Nullable Set<Node> removed) {
boolean work = false;
this.lock.lock();
@ -260,7 +262,9 @@ public final class NodeMap {
while (it.hasNext()) {
Node entry = it.next();
if (entry.hasExpired()) {
removed.add(entry);
if (removed != null) {
removed.add(entry);
}
work = true;
it.remove();
}

View File

@ -27,7 +27,6 @@ package me.lucko.luckperms.common.model;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
@ -64,7 +63,6 @@ import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -283,18 +281,6 @@ public abstract class PermissionHolder {
invalidateCache();
}
/**
* Merges enduring and transient permissions into one set
*
* @return a set containing the holders enduring and transient permissions
*/
public Set<Node> getOwnNodesSet() {
Set<Node> ret = new LinkedHashSet<>();
this.transientNodes.copyTo(ret);
this.enduringNodes.copyTo(ret);
return ret;
}
public List<Node> getOwnNodes() {
List<Node> ret = new ArrayList<>();
this.transientNodes.copyTo(ret);
@ -694,25 +680,25 @@ public abstract class PermissionHolder {
public boolean auditTemporaryPermissions() {
Set<Node> removed = new HashSet<>();
ImmutableSet<Node> before = ImmutableSet.copyOf(getOwnNodesSet());
// audit temporary nodes first, but don't track ones which are removed
// we don't call events for transient nodes
this.transientNodes.auditTemporaryNodes(null);
if (this.enduringNodes.auditTemporaryNodes(removed) | this.transientNodes.auditTemporaryNodes(removed)) {
invalidateCache();
}
ImmutableCollection<Node> before = getEnduringNodes().values();
if (removed.isEmpty()) {
if (!this.enduringNodes.auditTemporaryNodes(removed)) {
return false;
}
ImmutableSet<Node> after = ImmutableSet.copyOf(getOwnNodesSet());
invalidateCache();
ImmutableCollection<Node> after = getEnduringNodes().values();
for (Node r : removed) {
this.plugin.getEventFactory().handleNodeRemove(r, this, before, after);
}
return true;
}
public Optional<Node> getAlmostEquals(Node node, NodeMapType type) {
private Optional<Node> getAlmostEquals(Node node, NodeMapType type) {
for (Node n : getData(type).immutable().values()) {
if (n.almostEquals(node)) {
return Optional.of(n);
@ -855,12 +841,8 @@ public abstract class PermissionHolder {
return DataMutateResult.ALREADY_HAS;
}
ImmutableCollection<Node> before = getTransientNodes().values();
this.transientNodes.add(node);
invalidateCache();
ImmutableCollection<Node> after = getTransientNodes().values();
this.plugin.getEventFactory().handleNodeAdd(node, this, before, after);
return DataMutateResult.SUCCESS;
}
@ -893,12 +875,8 @@ public abstract class PermissionHolder {
return DataMutateResult.LACKS;
}
ImmutableCollection<Node> before = getTransientNodes().values();
this.transientNodes.remove(node);
invalidateCache();
ImmutableCollection<Node> after = getTransientNodes().values();
this.plugin.getEventFactory().handleNodeRemove(node, this, before, after);
return DataMutateResult.SUCCESS;
}
@ -1024,16 +1002,8 @@ public abstract class PermissionHolder {
}
public boolean clearTransientNodes() {
ImmutableCollection<Node> before = getTransientNodes().values();
this.transientNodes.clear();
invalidateCache();
ImmutableCollection<Node> after = getTransientNodes().values();
if (before.size() == after.size()) {
return false;
}
this.plugin.getEventFactory().handleNodeClear(this, before, after);
return true;
}
@ -1046,7 +1016,7 @@ public abstract class PermissionHolder {
boolean seen = false;
int best = 0;
for (Node n : getEnduringNodes().get(ImmutableContextSet.empty())) {
for (Node n : getOwnNodes(ImmutableContextSet.empty())) {
Integer weight = NodeFactory.parseWeightNode(n.getPermission());
if (weight == null) {
continue;