From 4de7448394e9364c4a70c7e5096a4584da4ed215 Mon Sep 17 00:00:00 2001 From: Luck Date: Sat, 1 Jan 2022 19:33:48 +0000 Subject: [PATCH] Include whether a node is normal/transient in InheritanceOriginMetadata --- .../node/metadata/types/InheritanceOriginMetadata.java | 10 ++++++++++ .../luckperms/common/model/InheritanceOrigin.java | 10 +++++++++- .../lucko/luckperms/common/model/PermissionHolder.java | 4 ++-- .../luckperms/common/model/nodemap/NodeMapMutable.java | 7 +++++-- .../model/calculated/CalculatedSubjectData.java | 4 ++-- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/api/src/main/java/net/luckperms/api/node/metadata/types/InheritanceOriginMetadata.java b/api/src/main/java/net/luckperms/api/node/metadata/types/InheritanceOriginMetadata.java index 68b70f95b..ec318fae5 100644 --- a/api/src/main/java/net/luckperms/api/node/metadata/types/InheritanceOriginMetadata.java +++ b/api/src/main/java/net/luckperms/api/node/metadata/types/InheritanceOriginMetadata.java @@ -26,6 +26,7 @@ package net.luckperms.api.node.metadata.types; import net.luckperms.api.model.PermissionHolder; +import net.luckperms.api.model.data.DataType; import net.luckperms.api.node.Node; import net.luckperms.api.node.metadata.NodeMetadataKey; @@ -56,6 +57,15 @@ public interface InheritanceOriginMetadata { */ PermissionHolder.@NonNull Identifier getOrigin(); + /** + * Gets the {@link DataType type} of the {@link net.luckperms.api.model.data.NodeMap} + * the node was inherited from. + * + * @return the type of the NodeMap the node was inherited from. + * @since 5.4 + */ + @NonNull DataType getDataType(); + /** * Gets whether the associated node was inherited from another holder. * diff --git a/common/src/main/java/me/lucko/luckperms/common/model/InheritanceOrigin.java b/common/src/main/java/me/lucko/luckperms/common/model/InheritanceOrigin.java index d9acea639..5dbd596ca 100644 --- a/common/src/main/java/me/lucko/luckperms/common/model/InheritanceOrigin.java +++ b/common/src/main/java/me/lucko/luckperms/common/model/InheritanceOrigin.java @@ -26,19 +26,27 @@ package me.lucko.luckperms.common.model; import net.luckperms.api.model.PermissionHolder; +import net.luckperms.api.model.data.DataType; import net.luckperms.api.node.metadata.types.InheritanceOriginMetadata; import org.checkerframework.checker.nullness.qual.NonNull; public class InheritanceOrigin implements InheritanceOriginMetadata { private final PermissionHolder.Identifier location; + private final DataType dataType; - public InheritanceOrigin(PermissionHolder.Identifier location) { + public InheritanceOrigin(PermissionHolder.Identifier location, DataType dataType) { this.location = location; + this.dataType = dataType; } @Override public PermissionHolder.@NonNull Identifier getOrigin() { return this.location; } + + @Override + public @NonNull DataType getDataType() { + return this.dataType; + } } 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 948d1b1e7..d5577e7f2 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 @@ -111,7 +111,7 @@ public abstract class PermissionHolder { * * @see #normalData() */ - private final RecordedNodeMap normalNodes = new RecordedNodeMap(new NodeMapMutable(this)); + private final RecordedNodeMap normalNodes = new RecordedNodeMap(new NodeMapMutable(this, DataType.NORMAL)); /** * The holders transient nodes. @@ -123,7 +123,7 @@ public abstract class PermissionHolder { * * @see #transientData() */ - private final NodeMap transientNodes = new NodeMapMutable(this); + private final NodeMap transientNodes = new NodeMapMutable(this, DataType.TRANSIENT); /** * Comparator used to ordering groups when calculating inheritance diff --git a/common/src/main/java/me/lucko/luckperms/common/model/nodemap/NodeMapMutable.java b/common/src/main/java/me/lucko/luckperms/common/model/nodemap/NodeMapMutable.java index 8ec1d828e..7084c3cd5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/model/nodemap/NodeMapMutable.java +++ b/common/src/main/java/me/lucko/luckperms/common/model/nodemap/NodeMapMutable.java @@ -35,6 +35,7 @@ import me.lucko.luckperms.common.node.comparator.NodeComparator; import net.luckperms.api.context.ContextSatisfyMode; import net.luckperms.api.context.ContextSet; import net.luckperms.api.context.ImmutableContextSet; +import net.luckperms.api.model.data.DataType; import net.luckperms.api.node.Node; import net.luckperms.api.node.NodeEqualityPredicate; import net.luckperms.api.node.metadata.types.InheritanceOriginMetadata; @@ -89,9 +90,11 @@ public class NodeMapMutable extends NodeMapBase { private final Lock lock = new ReentrantLock(); protected final PermissionHolder holder; + private final DataType type; - public NodeMapMutable(PermissionHolder holder) { + public NodeMapMutable(PermissionHolder holder, DataType type) { this.holder = holder; + this.type = type; } @Override @@ -115,7 +118,7 @@ public class NodeMapMutable extends NodeMapBase { return node; } - return node.toBuilder().withMetadata(InheritanceOriginMetadata.KEY, new InheritanceOrigin(this.holder.getIdentifier())).build(); + return node.toBuilder().withMetadata(InheritanceOriginMetadata.KEY, new InheritanceOrigin(this.holder.getIdentifier(), this.type)).build(); } @Override diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/calculated/CalculatedSubjectData.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/calculated/CalculatedSubjectData.java index 9637e2160..fe8ff8076 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/calculated/CalculatedSubjectData.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/calculated/CalculatedSubjectData.java @@ -155,7 +155,7 @@ public class CalculatedSubjectData implements LPSubjectData { .permission(key) .value(value) .context(entry.getKey()) - .withMetadata(InheritanceOriginMetadata.KEY, new InheritanceOrigin(this.parentSubject.getIdentifier())) + .withMetadata(InheritanceOriginMetadata.KEY, new InheritanceOrigin(this.parentSubject.getIdentifier(), this.type)) .build(); nodeMap.put(key, node); }); @@ -320,7 +320,7 @@ public class CalculatedSubjectData implements LPSubjectData { .key(key) .value(value) .context(entry.getKey()) - .withMetadata(InheritanceOriginMetadata.KEY, new InheritanceOrigin(this.parentSubject.getIdentifier())) + .withMetadata(InheritanceOriginMetadata.KEY, new InheritanceOrigin(this.parentSubject.getIdentifier(), this.type)) .build(); nodeMap.put(key, node); });