Interface PermissionContext

All Superinterfaces:
PermissionContextOwner
All Known Subinterfaces:
MutablePermissionContext

public interface PermissionContext extends PermissionContextOwner
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.

  • Field Details

    • NAME

      static final PermissionContext.Key<String> 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

      static final PermissionContext.Key<net.minecraft.world.phys.Vec3> POSITION
      Represents position current position in which permission check is applied.
    • BLOCK_POSITION

      static final PermissionContext.Key<net.minecraft.core.BlockPos> BLOCK_POSITION
      Represents position current block position in which permission check is applied.
    • ENTITY

      static final PermissionContext.Key<net.minecraft.world.entity.Entity> ENTITY
      Represents entity for which permission check is applied.
    • COMMAND_SOURCE_STACK

      static final PermissionContext.Key<net.minecraft.commands.CommandSourceStack> COMMAND_SOURCE_STACK
      Represents command source stack for which permission check is applied.
    • LEVEL

      static final PermissionContext.Key<net.minecraft.world.level.Level> LEVEL
      Represents level for which permission check is applied.
    • SERVER

      static final PermissionContext.Key<net.minecraft.server.MinecraftServer> 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 context
      type - type of the context
      permissionLevel - 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 uuid
      server - 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 uuid
      server - the currently running server instance
      Returns:
      mutable permission context
    • key

      static <T> PermissionContext.Key<T> key(net.minecraft.resources.Identifier identifier)
      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

      The type of the context.
    • get

      <T> @Nullable T get(PermissionContext.Key<T> key)
      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

      default <T> T orElse(PermissionContext.Key<T> key, T defaultValue)
      Returns optional value attached to this context, with a fallback.
      Type Parameters:
      T - type of value
      Parameters:
      key - unique key
      defaultValue - fallback value, if it's not present or null
      Returns:
      stored value if it's present, otherwise defaultValue
    • mutable

      default MutablePermissionContext 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

      Provides a set of defined permission context keys.
      Returns:
      unmodifiable set of permission keys.
    • getPermissionContext

      default PermissionContext getPermissionContext()
      Description copied from interface: PermissionContextOwner
      Provides the permission context. In case of entities, this context will be dynamic.
      Specified by:
      getPermissionContext in interface PermissionContextOwner
      Returns:
      PermissionContext attached to this object