Fix issue with Bukkit attachment permissions never being removed (#991)
This commit is contained in:
parent
5d34661a15
commit
a0be1c7c48
@ -25,6 +25,8 @@
|
||||
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@ -36,6 +38,18 @@ import javax.annotation.concurrent.Immutable;
|
||||
@Immutable
|
||||
public interface LocalizedNode extends Node {
|
||||
|
||||
/**
|
||||
* Returns a predicate which unwraps the localised node parameter before delegating
|
||||
* the handling to the provided predicate.
|
||||
*
|
||||
* @param delegate the delegate predicate.
|
||||
* @return the composed predicate
|
||||
* @since 4.3
|
||||
*/
|
||||
static Predicate<? super LocalizedNode> composedPredicate(Predicate<Node> delegate) {
|
||||
return localizedNode -> delegate.test(localizedNode.getNode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the delegate node
|
||||
*
|
||||
|
@ -27,6 +27,7 @@ package me.lucko.luckperms.bukkit.model.permissible;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import me.lucko.luckperms.api.LocalizedNode;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.bukkit.model.dummy.DummyPlugin;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
@ -188,13 +189,14 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
||||
|
||||
// remove transient permissions from the holder which were added by this attachment & equal the permission
|
||||
User user = this.permissible.getUser();
|
||||
user.removeIfTransient(n -> n instanceof ImmutableTransientNode && ((ImmutableTransientNode) n).getOwner() == this && n.getPermission().equals(name));
|
||||
|
||||
user.removeIfTransient(LocalizedNode.composedPredicate(n -> n instanceof ImmutableTransientNode && ((ImmutableTransientNode) n).getOwner() == this && n.getPermission().equals(name)));
|
||||
}
|
||||
|
||||
private void clearInternal() {
|
||||
// remove all transient permissions added by this attachment
|
||||
User user = this.permissible.getUser();
|
||||
user.removeIfTransient(n -> n instanceof ImmutableTransientNode && ((ImmutableTransientNode) n).getOwner() == this);
|
||||
user.removeIfTransient(LocalizedNode.composedPredicate(n -> n instanceof ImmutableTransientNode && ((ImmutableTransientNode) n).getOwner() == this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -227,13 +227,13 @@ public final class NodeMap {
|
||||
setContent(multimap.values());
|
||||
}
|
||||
|
||||
boolean removeIf(Predicate<? super Node> predicate) {
|
||||
boolean removeIf(Predicate<? super LocalizedNode> predicate) {
|
||||
boolean ret = this.map.values().removeIf(predicate);
|
||||
this.inheritanceMap.values().removeIf(predicate);
|
||||
return ret;
|
||||
}
|
||||
|
||||
boolean removeIf(ContextSet contextSet, Predicate<? super Node> predicate) {
|
||||
boolean removeIf(ContextSet contextSet, Predicate<? super LocalizedNode> predicate) {
|
||||
ImmutableContextSet context = contextSet.makeImmutable();
|
||||
SortedSet<LocalizedNode> nodes = this.map.get(context);
|
||||
boolean ret = nodes.removeIf(predicate);
|
||||
@ -241,12 +241,12 @@ public final class NodeMap {
|
||||
return ret;
|
||||
}
|
||||
|
||||
boolean auditTemporaryNodes(@Nullable Set<Node> removed) {
|
||||
boolean auditTemporaryNodes(@Nullable Set<? super LocalizedNode> removed) {
|
||||
boolean work = false;
|
||||
|
||||
Iterator<? extends Node> it = this.map.values().iterator();
|
||||
Iterator<? extends LocalizedNode> it = this.map.values().iterator();
|
||||
while (it.hasNext()) {
|
||||
Node entry = it.next();
|
||||
LocalizedNode entry = it.next();
|
||||
if (entry.hasExpired()) {
|
||||
if (removed != null) {
|
||||
removed.add(entry);
|
||||
|
@ -261,11 +261,11 @@ public abstract class PermissionHolder {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean removeIf(Predicate<? super Node> predicate) {
|
||||
public boolean removeIf(Predicate<? super LocalizedNode> predicate) {
|
||||
return removeIf(predicate, null);
|
||||
}
|
||||
|
||||
public boolean removeIf(Predicate<? super Node> predicate, Runnable taskIfSuccess) {
|
||||
public boolean removeIf(Predicate<? super LocalizedNode> predicate, Runnable taskIfSuccess) {
|
||||
ImmutableCollection<? extends Node> before = enduringData().immutable().values();
|
||||
if (!this.enduringNodes.removeIf(predicate)) {
|
||||
return false;
|
||||
@ -280,11 +280,11 @@ public abstract class PermissionHolder {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean removeIf(ContextSet contextSet, Predicate<? super Node> predicate) {
|
||||
public boolean removeIf(ContextSet contextSet, Predicate<? super LocalizedNode> predicate) {
|
||||
return removeIf(contextSet, predicate, null);
|
||||
}
|
||||
|
||||
public boolean removeIf(ContextSet contextSet, Predicate<? super Node> predicate, Runnable taskIfSuccess) {
|
||||
public boolean removeIf(ContextSet contextSet, Predicate<? super LocalizedNode> predicate, Runnable taskIfSuccess) {
|
||||
ImmutableCollection<? extends Node> before = enduringData().immutable().values();
|
||||
if (!this.enduringNodes.removeIf(contextSet, predicate)) {
|
||||
return false;
|
||||
@ -299,7 +299,7 @@ public abstract class PermissionHolder {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean removeIfTransient(Predicate<? super Node> predicate) {
|
||||
public boolean removeIfTransient(Predicate<? super LocalizedNode> predicate) {
|
||||
boolean result = this.transientNodes.removeIf(predicate);
|
||||
if (result) {
|
||||
invalidateCache();
|
||||
@ -455,7 +455,7 @@ public abstract class PermissionHolder {
|
||||
// we don't call events for transient nodes
|
||||
boolean transientWork = this.transientNodes.auditTemporaryNodes(null);
|
||||
|
||||
ImmutableCollection<? extends Node> before = enduringData().immutable().values();
|
||||
ImmutableCollection<? extends LocalizedNode> before = enduringData().immutable().values();
|
||||
Set<Node> removed = new HashSet<>();
|
||||
|
||||
boolean enduringWork = this.enduringNodes.auditTemporaryNodes(removed);
|
||||
|
@ -40,11 +40,6 @@ public final class ImmutableLocalizedNode extends ForwardingNode implements Loca
|
||||
Objects.requireNonNull(node, "node");
|
||||
Objects.requireNonNull(location, "location");
|
||||
|
||||
// unwrap
|
||||
while (node instanceof LocalizedNode) {
|
||||
node = ((LocalizedNode) node).getNode();
|
||||
}
|
||||
|
||||
return new ImmutableLocalizedNode(node, location);
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ package me.lucko.luckperms.nukkit.model.permissible;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import me.lucko.luckperms.api.LocalizedNode;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
@ -189,13 +190,13 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
||||
|
||||
// remove transient permissions from the holder which were added by this attachment & equal the permission
|
||||
User user = this.permissible.getUser();
|
||||
user.removeIfTransient(n -> n instanceof ImmutableTransientNode && ((ImmutableTransientNode) n).getOwner() == this && n.getPermission().equals(name));
|
||||
user.removeIfTransient(LocalizedNode.composedPredicate(n -> n instanceof ImmutableTransientNode && ((ImmutableTransientNode) n).getOwner() == this && n.getPermission().equals(name)));
|
||||
}
|
||||
|
||||
private void clearInternal() {
|
||||
// remove all transient permissions added by this attachment
|
||||
User user = this.permissible.getUser();
|
||||
user.removeIfTransient(n -> n instanceof ImmutableTransientNode && ((ImmutableTransientNode) n).getOwner() == this);
|
||||
user.removeIfTransient(LocalizedNode.composedPredicate(n -> n instanceof ImmutableTransientNode && ((ImmutableTransientNode) n).getOwner() == this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user