Class PermissionNode

java.lang.Object
dev.polv.taleapi.permission.PermissionNode

public final class PermissionNode extends Object
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:
  • Method Details

    • builder

      public static PermissionNode.Builder builder(String key)
      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

      public static PermissionNode allow(String key)
      Creates a simple ALLOW permission node with no payload.
      Parameters:
      key - the permission key
      Returns:
      an ALLOW permission node
    • deny

      public static PermissionNode deny(String key)
      Creates a simple DENY permission node with no payload.
      Parameters:
      key - the permission key
      Returns:
      a DENY permission node
    • allow

      public static PermissionNode allow(String key, Object payload)
      Creates an ALLOW permission node with a payload.
      Parameters:
      key - the permission key
      payload - the dynamic value
      Returns:
      an ALLOW permission node with payload
    • deny

      public static PermissionNode deny(String key, Object payload)
      Creates a DENY permission node with a payload.
      Parameters:
      key - the permission key
      payload - the dynamic value
      Returns:
      a DENY permission node with payload
    • getKey

      public String getKey()
      Returns the permission key (path).
      Returns:
      the permission key
    • getState

      public Tristate getState()
      Returns the permission state.
      Returns:
      the tristate (ALLOW, DENY, or UNDEFINED)
    • getPayload

      public Object getPayload()
      Returns the payload value.
      Returns:
      the payload, or null if none
    • hasPayload

      public boolean hasPayload()
      Checks if this node has a payload.
      Returns:
      true if a payload is present
    • getContext

      public ContextSet getContext()
      Returns the context for this permission.
      Returns:
      the context set (never null, may be empty)
    • appliesInContext

      public boolean appliesInContext(ContextSet currentContext)
      Checks if this node applies in the given context.
      Parameters:
      currentContext - the current context to check against
      Returns:
      true if this node's context matches
    • toResult

      public PermissionResult toResult()
      Converts this node to a PermissionResult.
      Returns:
      a PermissionResult with this node's state and payload
    • withState

      public PermissionNode withState(Tristate newState)
      Creates a copy of this node with a different state.
      Parameters:
      newState - the new state
      Returns:
      a new PermissionNode with the updated state
    • withPayload

      public PermissionNode withPayload(Object newPayload)
      Creates a copy of this node with a different payload.
      Parameters:
      newPayload - the new payload
      Returns:
      a new PermissionNode with the updated payload
    • withContext

      public PermissionNode withContext(ContextSet newContext)
      Creates a copy of this node with a different context.
      Parameters:
      newContext - the new context
      Returns:
      a new PermissionNode with the updated context
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object