Class PermissionNode<T>
A permission indicates the ability for an actor to perform an action,
in its most general sense. In the permission system, all permissions are encoded as instances of this class,
optionally integrated by a PermissionDynamicContext
.
A node is uniquely identified by its `nodeName`,
which is a dot-separated string providing meaning to the node itself.
The suggested structure of the name is `modid.name`, where `modid` is the ID of the owner of the node.
This API does not require any implicit hierarchy,
so `modid.name` is not considered a parent of `modid.name.sub`. Such decisions are left to the IPermissionHandler
.
Each node also has an associated PermissionType
, detailing its exact type,
along with a PermissionNode.PermissionResolver
that is used to obtain the default value of the permission.
More information can be found on their documentation.
A node can also be bound to additional PermissionDynamicContextKey
s,
which are used when querying the availability of the permission.
There are no restrictions on their amount. It is also not mandatory to provide a value for all dynamics in a permission query.
See the above link for more information.
Each node should be registered via the PermissionGatherEvent.Nodes
and stored statically in a field.
That instance should then be reused every-time a permission check needs to be performed via PermissionAPI.getPermission(ServerPlayer, PermissionNode, PermissionDynamicContext[])
.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Utility Interface used for resolving the default value of PermissionNodes -
Field Summary
Modifier and TypeFieldDescriptionprivate final PermissionNode.PermissionResolver
<T> private @Nullable Component
private final PermissionDynamicContextKey<?>[]
private final String
private @Nullable Component
private final PermissionType
<T> -
Constructor Summary
ModifierConstructorDescriptionPermissionNode
(String modID, String nodeName, PermissionType<T> type, PermissionNode.PermissionResolver<T> defaultResolver, PermissionDynamicContextKey... dynamics) CallsPermissionNode(String, PermissionType, PermissionResolver, PermissionDynamicContextKey[])
with "modid.nodename" as the first parameterprivate
PermissionNode
(String nodeName, PermissionType<T> type, PermissionNode.PermissionResolver<T> defaultResolver, PermissionDynamicContextKey... dynamics) PermissionNode
(ResourceLocation nodeName, PermissionType<T> type, PermissionNode.PermissionResolver<T> defaultResolver, PermissionDynamicContextKey... dynamics) CallsPermissionNode(String, PermissionType, PermissionResolver, PermissionDynamicContextKey[])
with "namespace.path" as the first parameter -
Method Summary
-
Field Details
-
nodeName
-
type
-
defaultResolver
-
dynamics
-
readableName
-
description
-
-
Constructor Details
-
PermissionNode
public PermissionNode(ResourceLocation nodeName, PermissionType<T> type, PermissionNode.PermissionResolver<T> defaultResolver, PermissionDynamicContextKey... dynamics) CallsPermissionNode(String, PermissionType, PermissionResolver, PermissionDynamicContextKey[])
with "namespace.path" as the first parameter -
PermissionNode
public PermissionNode(String modID, String nodeName, PermissionType<T> type, PermissionNode.PermissionResolver<T> defaultResolver, PermissionDynamicContextKey... dynamics) CallsPermissionNode(String, PermissionType, PermissionResolver, PermissionDynamicContextKey[])
with "modid.nodename" as the first parameter -
PermissionNode
private PermissionNode(String nodeName, PermissionType<T> type, PermissionNode.PermissionResolver<T> defaultResolver, PermissionDynamicContextKey... dynamics) - Parameters:
nodeName
- The identifier of a node, recommended identifier structure: "modid.path.for.node"type
- type object for the PermissionNode, only use types inPermissionTypes
defaultResolver
- Default resolver for the permission, can but doesn't have to be used to by PermissionHandlersdynamics
- PermissionDynamicContextKey is a dynamic component for permission nodes, similar to BlockState Properties. They must be passed into the constructor if you want to use them.
-
-
Method Details
-
setInformation
Allows you to set a human-readable name and description for your Permission.Note: Even though not used by Default, PermissionHandlers may display this information in game, or provide it to the user by other means.
You may usetranslatable components
, but you'll need 2 language files. One inside the data directory for the server and one inside assets for the client.- Parameters:
readableName
- an easier to read name for the PermissionNode, when using TranslatableComponent, key should be of format"permission.name.<nodename>"
description
- description for the PermissionNode when using TranslatableComponent, key should be of format"permission.desc.<nodename>"
- Returns:
- itself with the new information set.
-
getNodeName
-
getType
-
getDynamics
-
getDefaultResolver
-
getReadableName
-
getDescription
-
equals
-
hashCode
public int hashCode()
-