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 TypeMethodDescription@Nullable TValidates and cast a value to the type of permission nodes.com.mojang.serialization.Codec<T> codec()Returns a codec, which defined type of this permission.net.minecraft.resources.Identifierkey()Returns a key that represents this permission.static PermissionNode<Boolean> Creates a permission node of boolean type.static PermissionNode<Boolean> 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.static PermissionNode<Integer> Creates a permission node of integer type.static PermissionNode<Integer> ofInteger(net.minecraft.resources.Identifier key) Creates a permission node of integer type.static PermissionNode<String> Creates a permission node of string type.static PermissionNode<String> ofString(net.minecraft.resources.Identifier key) Creates a permission node of string type.
-
Method Details
-
of
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
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 nodepath- path of the key identifying this permission node- Returns:
- permission node for boolean type
-
ofInteger
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
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 nodepath- path of the key identifying this permission node- Returns:
- permission node for integer type
-
ofString
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
Creates a permission node of string type. Primarily used for information/logical checks.- Parameters:
namespace- namespace of the key identifying this permission nodepath- 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 permissioncodec- a codec used to read the permission valuecheckedClass- 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 nodepath- path of the key identifying this permission nodecodec- a codec used to read the permission valuecheckedClass- 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 permissioncodec- a codec used to read the permission valuecastValidator- 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 nodepath- path of the key identifying this permission nodecodec- a codec used to read the permission valuecastValidator- a predicate used for validating if provided value can be cast to type of this node- Returns:
- permission node for codec-defined type
-
cast
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.
-