Include whether a node is normal/transient in InheritanceOriginMetadata

This commit is contained in:
Luck 2022-01-01 19:33:48 +00:00
parent 6781c1fb51
commit 4de7448394
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
5 changed files with 28 additions and 7 deletions

View File

@ -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.
*

View File

@ -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;
}
}

View File

@ -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

View File

@ -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

View File

@ -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);
});