Interface PermissionContext
- All Superinterfaces:
PermissionContextOwner
- All Known Subinterfaces:
MutablePermissionContext
Interface representing context object used for permission checks, providing both required
and additional values.
Permission checks should be applied by calling methods defined in PermissionContextOwner
For command checks, you can use PermissionPredicates.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceKey used to represent additional permission context.static enumIdentifies the owner type of the permission context. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PermissionContext.Key<net.minecraft.core.BlockPos> Represents position current block position in which permission check is applied.static final PermissionContext.Key<net.minecraft.commands.CommandSourceStack> Represents command source stack for which permission check is applied.static final PermissionContext.Key<net.minecraft.world.entity.Entity> Represents entity for which permission check is applied.static final PermissionContext.Key<net.minecraft.world.level.Level> Represents level for which permission check is applied.static final PermissionContext.Key<String> Represents name attached to the permission context.static final PermissionContext.Key<net.minecraft.world.phys.Vec3> Represents position current position in which permission check is applied.static final PermissionContext.Key<net.minecraft.server.MinecraftServer> Represents the server to which this context is attached to. -
Method Summary
Modifier and TypeMethodDescriptionstatic MutablePermissionContextcreate(UUID uuid, PermissionContext.Type type, net.minecraft.server.permissions.PermissionLevel permissionLevel) Creates a custom context, without any optional values.<T> @Nullable Tget(PermissionContext.Key<T> key) Returns optional value attached to this context.default PermissionContextProvides the permission context.static <T> PermissionContext.Key<T> key(net.minecraft.resources.Identifier identifier) Creates a unique key, intended for attaching additional context data.keys()Provides a set of defined permission context keys.default MutablePermissionContextmutable()Creates a mutable copy of this context.offlinePlayer(UUID uuid, net.minecraft.server.MinecraftServer server) Creates a context of offline player.offlinePlayer(net.minecraft.server.players.NameAndId nameAndId, net.minecraft.server.MinecraftServer server) Creates a context of offline player.default <T> TorElse(PermissionContext.Key<T> key, T defaultValue) Returns optional value attached to this context, with a fallback.net.minecraft.server.permissions.PermissionLevelProvides the vanilla permission level of the context.type()The type of the context.uuid()UUID connected to this context.Methods inherited from interface PermissionContextOwner
checkPermission, checkPermission, checkPermission, checkPermission, checkPermission
-
Field Details
-
NAME
Represents name attached to the permission context. There is no requirement for it to be unique, as it might be changed by external factors. Mainly used to help with identifying system-type contexts or context with shared/nil uuid. For entities, it defaults to the plain name, based on either custom name or entity type name. -
POSITION
Represents position current position in which permission check is applied. -
BLOCK_POSITION
Represents position current block position in which permission check is applied. -
ENTITY
Represents entity for which permission check is applied. -
COMMAND_SOURCE_STACK
Represents command source stack for which permission check is applied. -
LEVEL
Represents level for which permission check is applied. -
SERVER
Represents the server to which this context is attached to.
-
-
Method Details
-
create
static MutablePermissionContext create(UUID uuid, PermissionContext.Type type, net.minecraft.server.permissions.PermissionLevel permissionLevel) Creates a custom context, without any optional values.- Parameters:
uuid- the uuid connected to this contexttype- type of the contextpermissionLevel- base permission level- Returns:
- mutable permission context
-
offlinePlayer
static CompletableFuture<MutablePermissionContext> offlinePlayer(UUID uuid, net.minecraft.server.MinecraftServer server) Creates a context of offline player. Do note that depending on the backing implementation, the check for offline players might be noticeably slower, so using async check methods or checking them on non-main threads is encouraged.- Parameters:
uuid- player's uuidserver- the currently running server instance- Returns:
- mutable permission context
-
offlinePlayer
static CompletableFuture<MutablePermissionContext> offlinePlayer(net.minecraft.server.players.NameAndId nameAndId, net.minecraft.server.MinecraftServer server) Creates a context of offline player. Do note that depending on the backing implementation, the check for offline players might be noticeably slower, so using async check methods or checking them on non-main threads is encouraged.- Parameters:
nameAndId- player's name and uuidserver- the currently running server instance- Returns:
- mutable permission context
-
key
Creates a unique key, intended for attaching additional context data. This key/value can't be serialized.- Type Parameters:
T- type of attached- Parameters:
identifier- unique identifier- Returns:
- unique key
-
uuid
UUID uuid()UUID connected to this context. -
type
PermissionContext.Type type()The type of the context. -
get
Returns optional value attached to this context.- Type Parameters:
T- type of value- Parameters:
key- unique key- Returns:
- stored value if it's present, null otherwise
-
orElse
Returns optional value attached to this context, with a fallback.- Type Parameters:
T- type of value- Parameters:
key- unique keydefaultValue- fallback value, if it's not present or null- Returns:
- stored value if it's present, otherwise defaultValue
-
mutable
Creates a mutable copy of this context.- Returns:
- a new mutable permission context.
-
permissionLevel
net.minecraft.server.permissions.PermissionLevel permissionLevel()Provides the vanilla permission level of the context.- Returns:
- permission level of the context.
-
keys
Set<PermissionContext.Key<?>> keys()Provides a set of defined permission context keys.- Returns:
- unmodifiable set of permission keys.
-
getPermissionContext
Description copied from interface:PermissionContextOwnerProvides the permission context. In case of entities, this context will be dynamic.- Specified by:
getPermissionContextin interfacePermissionContextOwner- Returns:
- PermissionContext attached to this object
-