From d28170cc3f03583edc3d8cbca1427133bdf99445 Mon Sep 17 00:00:00 2001 From: Luck Date: Thu, 20 Sep 2018 11:25:31 +0100 Subject: [PATCH] Operations to add new nodes with differing values should just override existing entries, instead of failing with the ALREADY_HAS result (#1198) --- .../me/lucko/luckperms/common/model/NodeMap.java | 13 ++++++++++--- .../luckperms/common/model/PermissionHolder.java | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/me/lucko/luckperms/common/model/NodeMap.java b/common/src/main/java/me/lucko/luckperms/common/model/NodeMap.java index b8bcecfde..9b7248ff5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/model/NodeMap.java +++ b/common/src/main/java/me/lucko/luckperms/common/model/NodeMap.java @@ -181,9 +181,16 @@ public final class NodeMap { ImmutableContextSet context = node.getFullContexts().makeImmutable(); LocalizedNode n = localise(node); - this.map.put(context, n); - if (node.isGroupNode() && node.getValue()) { - this.inheritanceMap.put(context, n); + SortedSet nodesInContext = this.map.get(context); + nodesInContext.removeIf(e -> e.equals(node, StandardNodeEquality.IGNORE_EXPIRY_TIME_AND_VALUE)); + nodesInContext.add(n); + + if (node.isGroupNode()) { + SortedSet groupNodesInContext = this.inheritanceMap.get(context); + groupNodesInContext.removeIf(e -> e.equals(node, StandardNodeEquality.IGNORE_EXPIRY_TIME_AND_VALUE)); + if (node.getValue()) { + groupNodesInContext.add(n); + } } } diff --git a/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java b/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java index 5439154a5..f2bc2d128 100644 --- a/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java @@ -539,7 +539,7 @@ public abstract class PermissionHolder { } public DataMutateResult setPermission(Node node, boolean callEvent) { - if (hasPermission(NodeMapType.ENDURING, node, StandardNodeEquality.IGNORE_EXPIRY_TIME_AND_VALUE) != Tristate.UNDEFINED) { + if (hasPermission(NodeMapType.ENDURING, node, StandardNodeEquality.IGNORE_EXPIRY_TIME) != Tristate.UNDEFINED) { return DataMutateResult.ALREADY_HAS; } @@ -565,7 +565,7 @@ public abstract class PermissionHolder { } public DataMutateResult setTransientPermission(Node node) { - if (hasPermission(NodeMapType.TRANSIENT, node, StandardNodeEquality.IGNORE_EXPIRY_TIME_AND_VALUE) != Tristate.UNDEFINED) { + if (hasPermission(NodeMapType.TRANSIENT, node, StandardNodeEquality.IGNORE_EXPIRY_TIME) != Tristate.UNDEFINED) { return DataMutateResult.ALREADY_HAS; }