Package dev.polv.taleapi.permission
Class PermissionNode
java.lang.Object
dev.polv.taleapi.permission.PermissionNode
Represents a single permission node with state, payload, and context.
Unlike traditional permission systems where a permission is just a string mapped to a boolean, a PermissionNode is a rich state object containing:
- Key: The permission path (e.g., "plots.limit")
- State: A
Tristate(ALLOW, DENY, UNDEFINED) - Payload: An arbitrary value (Integer, Double, String, etc.)
- Context: Conditions for when this permission applies
Solving Dynamic Values
// Old way: "plots.limit.5" - requires string parsing at runtime
// New way: key="plots.limit", payload=5
PermissionNode node = PermissionNode.builder("plots.limit")
.allow()
.payload(5)
.context(ContextSet.of(ContextKey.WORLD, "survival"))
.build();
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for creating PermissionNode instances. -
Method Summary
Modifier and TypeMethodDescriptionstatic PermissionNodeCreates a simple ALLOW permission node with no payload.static PermissionNodeCreates an ALLOW permission node with a payload.booleanappliesInContext(ContextSet currentContext) Checks if this node applies in the given context.static PermissionNode.BuilderCreates a builder for a permission node with the given key.static PermissionNodeCreates a simple DENY permission node with no payload.static PermissionNodeCreates a DENY permission node with a payload.booleanReturns the context for this permission.getKey()Returns the permission key (path).Returns the payload value.getState()Returns the permission state.inthashCode()booleanChecks if this node has a payload.toResult()Converts this node to a PermissionResult.toString()withContext(ContextSet newContext) Creates a copy of this node with a different context.withPayload(Object newPayload) Creates a copy of this node with a different payload.Creates a copy of this node with a different state.
-
Method Details
-
builder
Creates a builder for a permission node with the given key.- Parameters:
key- the permission key (e.g., "plots.create")- Returns:
- a new Builder instance
-
allow
Creates a simple ALLOW permission node with no payload.- Parameters:
key- the permission key- Returns:
- an ALLOW permission node
-
deny
Creates a simple DENY permission node with no payload.- Parameters:
key- the permission key- Returns:
- a DENY permission node
-
allow
Creates an ALLOW permission node with a payload.- Parameters:
key- the permission keypayload- the dynamic value- Returns:
- an ALLOW permission node with payload
-
deny
Creates a DENY permission node with a payload.- Parameters:
key- the permission keypayload- the dynamic value- Returns:
- a DENY permission node with payload
-
getKey
Returns the permission key (path).- Returns:
- the permission key
-
getState
Returns the permission state.- Returns:
- the tristate (ALLOW, DENY, or UNDEFINED)
-
getPayload
Returns the payload value.- Returns:
- the payload, or null if none
-
hasPayload
public boolean hasPayload()Checks if this node has a payload.- Returns:
trueif a payload is present
-
getContext
Returns the context for this permission.- Returns:
- the context set (never null, may be empty)
-
appliesInContext
Checks if this node applies in the given context.- Parameters:
currentContext- the current context to check against- Returns:
trueif this node's context matches
-
toResult
Converts this node to a PermissionResult.- Returns:
- a PermissionResult with this node's state and payload
-
withState
Creates a copy of this node with a different state.- Parameters:
newState- the new state- Returns:
- a new PermissionNode with the updated state
-
withPayload
Creates a copy of this node with a different payload.- Parameters:
newPayload- the new payload- Returns:
- a new PermissionNode with the updated payload
-
withContext
Creates a copy of this node with a different context.- Parameters:
newContext- the new context- Returns:
- a new PermissionNode with the updated context
-
equals
-
hashCode
public int hashCode() -
toString
-