Class PermissionChecker

java.lang.Object
com.github.alex1304.ultimategdbot.api.command.PermissionChecker

public final class PermissionChecker
extends Object
Class used to check permissions for using a command.
  • Constructor Details

  • Method Details

    • register

      public void register​(String name, Function<Context,​reactor.core.publisher.Mono<Boolean>> checker)
      Registers a new permission into this checker.
      Parameters:
      name - a name that uniquely identifies this permission
      checker - a function that takes a Context as input and asynchronously tells whether the permission is granted or not. An empty Mono is considered the same as false. This function is called when using isGranted(String, Context)
      Throws:
      IllegalArgumentException - if a permission with this name already exists, or if the permission name is blank as per String.isBlank()
    • register

      public void register​(PermissionLevel level, Function<Context,​reactor.core.publisher.Mono<Boolean>> checker)
      Registers a new permission into this checker.
      Parameters:
      level - the level the permission should be attached to
      checker - a function that takes a Context as input and asynchronously tells whether the permission is granted or not. An empty Mono is considered the same as false. This function is called when using isGranted(PermissionLevel, Context)
    • registerAll

      public void registerAll​(PermissionChecker source)
      Copies all permissions registered in the specified permission checker into this one.
      Parameters:
      source - the source permission checker
    • isGranted

      public reactor.core.publisher.Mono<Boolean> isGranted​(String name, Context ctx)
      Checks whether the given permission is granted in the specified context. If the permission has not been registered into this checker, false will be emitted. If the given permission name is the empty string "", it will always emit true.
      Parameters:
      name - the name of the permission to check
      ctx - the context that applies for the check
      Returns:
      a Mono that emits true if either the given permission is granted, false otherwise.
    • isGranted

      public reactor.core.publisher.Mono<Boolean> isGranted​(PermissionLevel level, Context ctx)
      Checks whether the given permission level is granted in the specified context. If no permission attached to this level is granted, it will check permissions attached to higher levels. If at least one permission is granted, true is emitted.
      Parameters:
      level - the permission level to check
      ctx - the context that applies for the check
      Returns:
      a Mono that emits true if any permission attached to the specified level or a higher level is granted, false otherwise.
      Throws:
      IllegalArgumentException - if level is negative