Class PermissionSetupEvent

java.lang.Object
me.internalizable.numdrassl.api.event.permission.PermissionSetupEvent

public class PermissionSetupEvent extends Object
Event fired when a permission subject's permission function needs to be set up.

This event is fired during the login process for players and when the console is initialized, giving permission plugins the opportunity to provide a custom PermissionFunction or PermissionProvider for the subject.

The subject can be either a Player or the console command source. Permission plugins should handle both cases appropriately.

Async Support

If your permission plugin needs to load data asynchronously (e.g., from a database), use registerAsyncTask(CompletableFuture) to register the task. The proxy will wait for all registered async tasks to complete before proceeding with the login.

Example Usage with LuckPerms

@Subscribe
public void onPermissionSetup(PermissionSetupEvent e) {
    if (!(e.getSubject() instanceof Player player)) {
        return;
    }

    // Register an async task that loads user data
    CompletableFuture<Void> loadTask = CompletableFuture.runAsync(() -> {
        User user = loadUser(player.getUniqueId(), player.getUsername());
        e.setProvider(new MyPermissionProvider(user));
    }, asyncExecutor);

    e.registerAsyncTask(loadTask);
}
See Also:
  • Constructor Details

    • PermissionSetupEvent

      public PermissionSetupEvent(@Nonnull PermissionSubject subject, @Nonnull PermissionProvider defaultProvider)
      Creates a new permission setup event.
      Parameters:
      subject - the permission subject whose permissions are being set up
      defaultProvider - the default permission provider
  • Method Details

    • getSubject

      @Nonnull public PermissionSubject getSubject()
      Gets the permission subject whose permissions are being set up.

      This can be a Player or the console command source.

      Returns:
      the permission subject
    • getProvider

      @Nonnull public PermissionProvider getProvider()
      Gets the current permission provider that will be used.
      Returns:
      the permission provider
    • setProvider

      public void setProvider(@Nonnull PermissionProvider provider)
      Sets the permission provider to use for this subject.

      Permission plugins should call this to install their own permission checking logic. This method is thread-safe and can be called from async tasks.

      Parameters:
      provider - the permission provider
    • registerAsyncTask

      public void registerAsyncTask(@Nonnull CompletableFuture<Void> task)
      Registers an async task that must complete before the login proceeds.

      Use this method when you need to load permission data asynchronously. The proxy will wait for all registered tasks to complete before firing the LoginEvent.

      If multiple tasks are registered, they are combined with CompletableFuture.allOf(CompletableFuture[]).

      Parameters:
      task - the async task to register
    • getAsyncTask

      @Nonnull public CompletableFuture<Void> getAsyncTask()
      Gets the combined async task that must complete before proceeding.
      Returns:
      the async task, never null (completes immediately if no async work)
    • createFunction

      @Nonnull public PermissionFunction createFunction()
      Creates the permission function using the current provider and subject.

      This is a convenience method that calls PermissionProvider.createFunction(PermissionSubject) with this event's subject.

      Returns:
      the created permission function