Interface Node
-
- All Known Subinterfaces:
ChatMetaNode<N,B>,DisplayNameNode,InheritanceNode,MetaNode,PermissionNode,PrefixNode,RegexPermissionNode,ScopedNode<N,B>,SuffixNode,WeightNode
@NonExtendable public interface Node
Represents a LuckPerms "node".The
Nodeclass encapsulates more than just permission assignments. Nodes are used to store data about inherited groups, as well as assigned prefixes, suffixes and meta values.Combining these various states into one object (a "node") means that a holder only has to have one type of data set (a set of nodes) in order to take on various properties.
It is recommended that users of the API make use of
Streams to manipulate data and obtain the required information.This interface provides a number of methods to read the attributes of the node, as well as methods to query and extract additional state and properties from these settings.
Nodes have the following 4 key attributes:
key- the key of the nodevalue- the value of the node (false for negated)context- the contexts required for this node to applyexpiry- the time when this node should expire
These are the key attributes which are considered when evaluating node
equality.Nodes can also optionally have
metadataattached to them, added during construction usingNodeBuilder.withMetadata(NodeMetadataKey, Object), and queried usingmetadata(NodeMetadataKey)andgetMetadata(NodeMetadataKey). Such metadata is never considered when evaluatingequals(Object)orequals(Node, NodeEqualityPredicate)(any form of equality check).There are a number of node types, all of which extend from this class:
PermissionNode- represents an assigned permissionRegexPermissionNode- represents an assigned regex permissionInheritanceNode- an "inheritance node" marks that the holder should inherit data from another groupPrefixNode- represents an assigned prefixSuffixNode- represents an assigned suffixMetaNode- represents an assigned meta optionWeightNode- marks the weight of the object holding this nodeDisplayNameNode- marks the display name of the object holding this node
The core node state must be immutable in all implementations.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static @NonNull NodeBuilder<?,?>builder(@NonNull String key)Gets aNodeBuilderfor the given nodekey.booleanequals(@NonNull Node other, @NonNull NodeEqualityPredicate equalityPredicate)Gets if this Node is equal to another node as defined by the givenNodeEqualityPredicate.booleanequals(Object obj)Gets if this Node is equal to another node.@NonNull ImmutableContextSetgetContexts()Gets the contexts required for this node to apply.@Nullable InstantgetExpiry()Gets the time when this node will expire.@Nullable DurationgetExpiryDuration()Gets the time until this node will expire.@NonNull StringgetKey()Gets the key (String) of the node.<T> Optional<T>getMetadata(NodeMetadataKey<T> key)Gets the metadata corresponding to the givenkey, if present.@NonNull NodeType<?>getType()Gets the type of the node.booleangetValue()Gets the value of the node.booleanhasExpired()Gets if the node has expired.booleanhasExpiry()Gets if this node is assigned temporarily.default booleanisNegated()Gets if the node is negated.default <T> Tmetadata(NodeMetadataKey<T> key)Gets the metadata corresponding to the givenkey, throwing an exception if no data is present.@NonNull @Unmodifiable Collection<String>resolveShorthand()Resolves any shorthand parts of this node and returns the full list of resolved nodes.@NonNull NodeBuilder<?,?>toBuilder()Gets aNodeBuilder, with the attributes of this node already applied.
-
-
-
Method Detail
-
builder
static @NonNull NodeBuilder<?,?> builder(@NonNull String key)
Gets aNodeBuilderfor the given nodekey.- Parameters:
key- the key- Returns:
- the node builder
-
getValue
boolean getValue()
Gets the value of the node.A negated setting would result in a value of
false.- Returns:
- the nodes value
-
isNegated
default boolean isNegated()
Gets if the node is negated.This is the inverse of the
value.- Returns:
- true if the node is negated
-
resolveShorthand
@NonNull @Unmodifiable Collection<String> resolveShorthand()
Resolves any shorthand parts of this node and returns the full list of resolved nodes.The list will not contain the exact permission itself.
- Returns:
- a list of full nodes
-
hasExpiry
boolean hasExpiry()
Gets if this node is assigned temporarily.- Returns:
- true if this node will expire in the future
-
getExpiry
@Nullable Instant getExpiry()
Gets the time when this node will expire.- Returns:
- the
Instantwhen this node will expire, ornullif it doesn't have an expiry time
-
hasExpired
boolean hasExpired()
Gets if the node has expired.This returns false if the node is not temporary.
- Returns:
- true if this node has expired
-
getExpiryDuration
@Nullable Duration getExpiryDuration()
Gets the time until this node will expire.Returns
nullif the node doesn't have an expiry time, and anegativeduration if it has already expired.- Returns:
- the duration until the nodes expiry
- Since:
- 5.1
-
getContexts
@NonNull ImmutableContextSet getContexts()
Gets the contexts required for this node to apply.- Returns:
- the contexts required for this node to apply
-
getMetadata
<T> Optional<T> getMetadata(NodeMetadataKey<T> key)
Gets the metadata corresponding to the givenkey, if present.- Type Parameters:
T- the metadata type- Parameters:
key- the key- Returns:
- the data, if present
-
metadata
default <T> T metadata(NodeMetadataKey<T> key) throws IllegalStateException
Gets the metadata corresponding to the givenkey, throwing an exception if no data is present.- Type Parameters:
T- the metadata type- Parameters:
key- the key- Returns:
- the data
- Throws:
IllegalStateException- if data isn't present
-
equals
boolean equals(Object obj)
Gets if this Node is equal to another node.- Overrides:
equalsin classObject- Parameters:
obj- the other node- Returns:
- true if this node is equal to the other provided
- See Also:
NodeEqualityPredicate.EXACT
-
equals
boolean equals(@NonNull Node other, @NonNull NodeEqualityPredicate equalityPredicate)
Gets if this Node is equal to another node as defined by the givenNodeEqualityPredicate.- Parameters:
other- the other nodeequalityPredicate- the predicate- Returns:
- true if this node is considered equal
-
toBuilder
@NonNull NodeBuilder<?,?> toBuilder()
Gets aNodeBuilder, with the attributes of this node already applied.- Returns:
- an editable, builder form of this node
-
-