mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-28 05:35:26 +01:00
Don't call events for changes to transient nodes
This commit is contained in:
parent
f18d230ff6
commit
e24a482deb
@ -52,6 +52,8 @@ import java.util.TreeSet;
|
|||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A map of nodes held by a {@link PermissionHolder}.
|
* 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;
|
boolean work = false;
|
||||||
|
|
||||||
this.lock.lock();
|
this.lock.lock();
|
||||||
@ -260,7 +262,9 @@ public final class NodeMap {
|
|||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Node entry = it.next();
|
Node entry = it.next();
|
||||||
if (entry.hasExpired()) {
|
if (entry.hasExpired()) {
|
||||||
removed.add(entry);
|
if (removed != null) {
|
||||||
|
removed.add(entry);
|
||||||
|
}
|
||||||
work = true;
|
work = true;
|
||||||
it.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,6 @@ package me.lucko.luckperms.common.model;
|
|||||||
|
|
||||||
import com.google.common.collect.ImmutableCollection;
|
import com.google.common.collect.ImmutableCollection;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
import com.google.common.collect.ImmutableSetMultimap;
|
import com.google.common.collect.ImmutableSetMultimap;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
@ -64,7 +63,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -283,18 +281,6 @@ public abstract class PermissionHolder {
|
|||||||
invalidateCache();
|
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() {
|
public List<Node> getOwnNodes() {
|
||||||
List<Node> ret = new ArrayList<>();
|
List<Node> ret = new ArrayList<>();
|
||||||
this.transientNodes.copyTo(ret);
|
this.transientNodes.copyTo(ret);
|
||||||
@ -694,25 +680,25 @@ public abstract class PermissionHolder {
|
|||||||
public boolean auditTemporaryPermissions() {
|
public boolean auditTemporaryPermissions() {
|
||||||
Set<Node> removed = new HashSet<>();
|
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)) {
|
ImmutableCollection<Node> before = getEnduringNodes().values();
|
||||||
invalidateCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (removed.isEmpty()) {
|
if (!this.enduringNodes.auditTemporaryNodes(removed)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImmutableSet<Node> after = ImmutableSet.copyOf(getOwnNodesSet());
|
invalidateCache();
|
||||||
|
ImmutableCollection<Node> after = getEnduringNodes().values();
|
||||||
for (Node r : removed) {
|
for (Node r : removed) {
|
||||||
this.plugin.getEventFactory().handleNodeRemove(r, this, before, after);
|
this.plugin.getEventFactory().handleNodeRemove(r, this, before, after);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
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()) {
|
for (Node n : getData(type).immutable().values()) {
|
||||||
if (n.almostEquals(node)) {
|
if (n.almostEquals(node)) {
|
||||||
return Optional.of(n);
|
return Optional.of(n);
|
||||||
@ -855,12 +841,8 @@ public abstract class PermissionHolder {
|
|||||||
return DataMutateResult.ALREADY_HAS;
|
return DataMutateResult.ALREADY_HAS;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImmutableCollection<Node> before = getTransientNodes().values();
|
|
||||||
this.transientNodes.add(node);
|
this.transientNodes.add(node);
|
||||||
invalidateCache();
|
invalidateCache();
|
||||||
ImmutableCollection<Node> after = getTransientNodes().values();
|
|
||||||
|
|
||||||
this.plugin.getEventFactory().handleNodeAdd(node, this, before, after);
|
|
||||||
return DataMutateResult.SUCCESS;
|
return DataMutateResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -893,12 +875,8 @@ public abstract class PermissionHolder {
|
|||||||
return DataMutateResult.LACKS;
|
return DataMutateResult.LACKS;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImmutableCollection<Node> before = getTransientNodes().values();
|
|
||||||
this.transientNodes.remove(node);
|
this.transientNodes.remove(node);
|
||||||
invalidateCache();
|
invalidateCache();
|
||||||
ImmutableCollection<Node> after = getTransientNodes().values();
|
|
||||||
|
|
||||||
this.plugin.getEventFactory().handleNodeRemove(node, this, before, after);
|
|
||||||
return DataMutateResult.SUCCESS;
|
return DataMutateResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1024,16 +1002,8 @@ public abstract class PermissionHolder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean clearTransientNodes() {
|
public boolean clearTransientNodes() {
|
||||||
ImmutableCollection<Node> before = getTransientNodes().values();
|
|
||||||
this.transientNodes.clear();
|
this.transientNodes.clear();
|
||||||
invalidateCache();
|
invalidateCache();
|
||||||
ImmutableCollection<Node> after = getTransientNodes().values();
|
|
||||||
|
|
||||||
if (before.size() == after.size()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.plugin.getEventFactory().handleNodeClear(this, before, after);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1046,7 +1016,7 @@ public abstract class PermissionHolder {
|
|||||||
|
|
||||||
boolean seen = false;
|
boolean seen = false;
|
||||||
int best = 0;
|
int best = 0;
|
||||||
for (Node n : getEnduringNodes().get(ImmutableContextSet.empty())) {
|
for (Node n : getOwnNodes(ImmutableContextSet.empty())) {
|
||||||
Integer weight = NodeFactory.parseWeightNode(n.getPermission());
|
Integer weight = NodeFactory.parseWeightNode(n.getPermission());
|
||||||
if (weight == null) {
|
if (weight == null) {
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user