Class PermissionNode<T>

java.lang.Object
net.neoforged.neoforge.server.permission.nodes.PermissionNode<T>

public final class PermissionNode<T> extends Object
Represents the basic unit at the heart of the permission system.

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 PermissionDynamicContextKeys, 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[]).

  • Field Details

    • nodeName

      private final String nodeName
    • type

      private final PermissionType<T> type
    • defaultResolver

      private final PermissionNode.PermissionResolver<T> defaultResolver
    • dynamics

      private final PermissionDynamicContextKey<?>[] dynamics
    • readableName

      @Nullable private @Nullable net.minecraft.network.chat.Component readableName
    • description

      @Nullable private @Nullable net.minecraft.network.chat.Component description
  • Constructor Details

  • Method Details

    • setInformation

      public PermissionNode setInformation(net.minecraft.network.chat.Component readableName, net.minecraft.network.chat.Component description)
      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 use translatable 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

      public String getNodeName()
    • getType

      public PermissionType<T> getType()
    • getDynamics

      public PermissionDynamicContextKey<?>[] getDynamics()
    • getDefaultResolver

      public PermissionNode.PermissionResolver<T> getDefaultResolver()
    • getReadableName

      @Nullable public @Nullable net.minecraft.network.chat.Component getReadableName()
    • getDescription

      @Nullable public @Nullable net.minecraft.network.chat.Component getDescription()
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object