Interface PermissionNode<T>

Type Parameters:
T - type of the permission

@NonExtendable public interface PermissionNode<T>
This class represents a permission, which consist of identifier as the key and a codec to dictate its type. This class can be instantiated dynamically (just before permission request) or statically on mod initialization.

PermissionNode objects are considered to be equal objects (but not the same instances) as long as they were created with the same key and codec pair.

  • Method Summary

    Modifier and Type
    Method
    Description
    @Nullable T
    cast(@Nullable Object value)
    Validates and cast a value to the type of permission nodes.
    com.mojang.serialization.Codec<T>
    Returns a codec, which defined type of this permission.
    net.minecraft.resources.Identifier
    key()
    Returns a key that represents this permission.
    of(String namespace, String path)
    Creates a permission node of boolean type.
    of(net.minecraft.resources.Identifier key)
    Creates a permission node of boolean type.
    static <T> PermissionNode<T>
    ofCustom(String namespace, String path, com.mojang.serialization.Codec<T> codec, Class<T> checkedClass)
    Creates a permission node of custom, codec defined type.
    static <T> PermissionNode<T>
    ofCustom(String namespace, String path, com.mojang.serialization.Codec<T> codec, Predicate<Object> castValidator)
    Creates a permission node of custom, codec defined type.
    static <T> PermissionNode<T>
    ofCustom(net.minecraft.resources.Identifier key, com.mojang.serialization.Codec<T> codec, Class<T> checkedClass)
    Creates a permission node of custom, codec defined type.
    static <T> PermissionNode<T>
    ofCustom(net.minecraft.resources.Identifier key, com.mojang.serialization.Codec<T> codec, Predicate<Object> castValidator)
    Creates a permission node of custom, codec defined type.
    ofInteger(String namespace, String path)
    Creates a permission node of integer type.
    ofInteger(net.minecraft.resources.Identifier key)
    Creates a permission node of integer type.
    ofString(String namespace, String path)
    Creates a permission node of string type.
    ofString(net.minecraft.resources.Identifier key)
    Creates a permission node of string type.
  • Method Details

    • of

      static PermissionNode<Boolean> of(net.minecraft.resources.Identifier key)
      Creates a permission node of boolean type. Primarily used for simple permission checks (if owner can/can't do something).
      Parameters:
      key - a key identifying this permission
      Returns:
      permission node for boolean type
    • of

      static PermissionNode<Boolean> of(String namespace, String path)
      Creates a permission node of boolean type. Primarily used for simple permission checks (if owner can/can't do something).
      Parameters:
      namespace - namespace of the key identifying this permission node
      path - path of the key identifying this permission node
      Returns:
      permission node for boolean type
    • ofInteger

      static PermissionNode<Integer> ofInteger(net.minecraft.resources.Identifier key)
      Creates a permission node of integer type. Primarily used for limiting permission checks (if player can do/have X of something).
      Parameters:
      key - a key identifying this permission
      Returns:
      permission node for integer type
    • ofInteger

      static PermissionNode<Integer> ofInteger(String namespace, String path)
      Creates a permission node of integer type. Primarily used for limiting permission checks (if player can do/have X of something).
      Parameters:
      namespace - namespace of the key identifying this permission node
      path - path of the key identifying this permission node
      Returns:
      permission node for integer type
    • ofString

      static PermissionNode<String> ofString(net.minecraft.resources.Identifier key)
      Creates a permission node of string type. Primarily used for information/logical checks.
      Parameters:
      key - a key identifying this permission
      Returns:
      permission node for string type
    • ofString

      static PermissionNode<String> ofString(String namespace, String path)
      Creates a permission node of string type. Primarily used for information/logical checks.
      Parameters:
      namespace - namespace of the key identifying this permission node
      path - path of the key identifying this permission node
      Returns:
      permission node for string type
    • ofCustom

      static <T> PermissionNode<T> ofCustom(net.minecraft.resources.Identifier key, com.mojang.serialization.Codec<T> codec, Class<T> checkedClass)
      Creates a permission node of custom, codec defined type.
      Type Parameters:
      T - the type of permission
      Parameters:
      key - a key identifying this permission
      codec - a codec used to read the permission value
      checkedClass - the class representing the custom value, used for cast validation
      Returns:
      permission node for codec-defined type
    • ofCustom

      static <T> PermissionNode<T> ofCustom(String namespace, String path, com.mojang.serialization.Codec<T> codec, Class<T> checkedClass)
      Creates a permission node of custom, codec defined type.
      Type Parameters:
      T - the type of permission
      Parameters:
      namespace - namespace of the key identifying this permission node
      path - path of the key identifying this permission node
      codec - a codec used to read the permission value
      checkedClass - the class representing the custom value, used for cast validation
      Returns:
      permission node for codec-defined type
    • ofCustom

      static <T> PermissionNode<T> ofCustom(net.minecraft.resources.Identifier key, com.mojang.serialization.Codec<T> codec, Predicate<Object> castValidator)
      Creates a permission node of custom, codec defined type.
      Type Parameters:
      T - the type of permission
      Parameters:
      key - a key identifying this permission
      codec - a codec used to read the permission value
      castValidator - a predicate used for validating if provided value can be cast to type of this node
      Returns:
      permission node for codec-defined type
    • ofCustom

      static <T> PermissionNode<T> ofCustom(String namespace, String path, com.mojang.serialization.Codec<T> codec, Predicate<Object> castValidator)
      Creates a permission node of custom, codec defined type.
      Type Parameters:
      T - the type of permission
      Parameters:
      namespace - namespace of the key identifying this permission node
      path - path of the key identifying this permission node
      codec - a codec used to read the permission value
      castValidator - a predicate used for validating if provided value can be cast to type of this node
      Returns:
      permission node for codec-defined type
    • cast

      @Nullable T cast(@Nullable Object value)
      Validates and cast a value to the type of permission nodes. Should be used when not handling permission resolution with the provided codec.
      Parameters:
      value - value to cast, should be compatible with T
      Returns:
      The same value as input
      Throws:
      IllegalArgumentException - if the provided object isn't valid!
    • key

      net.minecraft.resources.Identifier key()
      Returns a key that represents this permission.
      Returns:
      key identifying this permission.
    • codec

      com.mojang.serialization.Codec<T> codec()
      Returns a codec, which defined type of this permission.
      Returns:
      codec representing the type of this permission.