Interface PermissionContextOwner

All Known Subinterfaces:
MutablePermissionContext, PermissionContext
All Known Implementing Classes:
net.minecraft.world.entity.Avatar, net.minecraft.world.entity.Entity, FakePlayer, net.minecraft.world.entity.LivingEntity, net.minecraft.world.entity.player.Player, net.minecraft.server.level.ServerPlayer

public interface PermissionContextOwner
Utility interface allowing quick access for permission checking methods. Implemented by default on Entity, CommandSourceStack and PermissionContext. Other mods are allowed to implement this on their own classes as well.

See PermissionContext for creation and modification of permission contexts.

Example usage:

Identifier claimBypassPermission = Identifier.fromNamespaceAndPath("potatoclaims", "bypass_protection");
ServerPlayer player = ...;

AttackEntityCallback.EVENT.register((playerEntity, _, _, entity, _) -> {
    if (ModChecks.isProtected(entity) && !player.checkPermission(claimBypassPermission, PermissionLevel.GAMEMASTERS)) {
        return InteractionResult.FAIL;
    }
    return InteractionResult.PASS;
});
  • Method Summary

    Modifier and Type
    Method
    Description
    default <T> @Nullable T
    A dynamic, typed permission check.
    default <T> @Nullable T
    checkPermission(PermissionNode<T> permission, @Nullable T defaultValue)
    A dynamic, typed permission check.
    default TriState
    checkPermission(net.minecraft.resources.Identifier permission)
    Simple permission check.
    default boolean
    checkPermission(net.minecraft.resources.Identifier permission, boolean defaultValue)
    Simple permission check.
    default boolean
    checkPermission(net.minecraft.resources.Identifier permission, net.minecraft.server.permissions.PermissionLevel defaultPermissionLevel)
    Simple permission check.
    Provides the permission context.
  • Method Details

    • getPermissionContext

      default PermissionContext getPermissionContext()
      Provides the permission context. In case of entities, this context will be dynamic.
      Returns:
      PermissionContext attached to this object
    • checkPermission

      default TriState checkPermission(net.minecraft.resources.Identifier permission)
      Simple permission check. Should be used to check if something is allowed.
      Parameters:
      permission - a permission identifier to check against
      Returns:
      TriState returning value of the permission (DEFAULT if not changed)
    • checkPermission

      default boolean checkPermission(net.minecraft.resources.Identifier permission, boolean defaultValue)
      Simple permission check. Should be used to check if something is allowed. Will default to if permission value is not provided.
      Parameters:
      permission - a permission identifier to check against
      defaultValue - fallback value
      Returns:
      a boolean representing state of the permission, returns defaultValue if not modified by other mods
    • checkPermission

      default boolean checkPermission(net.minecraft.resources.Identifier permission, net.minecraft.server.permissions.PermissionLevel defaultPermissionLevel)
      Simple permission check. Should be used to check if something is allowed. Will check for vanilla permission level, if permission value is not provided.
      Parameters:
      permission - a permission identifier to check against
      defaultPermissionLevel - a fallback permission level to check against
      Returns:
      a boolean representing state of the permission
    • checkPermission

      default <T> @Nullable T checkPermission(PermissionNode<T> permission)
      A dynamic, typed permission check. Should be used to check for more complex permission values, like allowed amount and alike.
      Type Parameters:
      T - type of the permission
      Parameters:
      permission - a permission node to check against
      Returns:
      value of the permission or null if not provided
    • checkPermission

      @Contract("_, null -> _; _, !null -> !null") default <T> @Nullable T checkPermission(PermissionNode<T> permission, @Nullable T defaultValue)
      A dynamic, typed permission check. Should be used to check for more complex permission values, like allowed amount and alike.
      Type Parameters:
      T - type of the permission
      Parameters:
      permission - a permission node to check against
      defaultValue - fallback value, if not provided
      Returns:
      value of the permission or if not provided