Class PermissionSetupEvent
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 Summary
ConstructorsConstructorDescriptionPermissionSetupEvent(PermissionSubject subject, PermissionProvider defaultProvider) Creates a new permission setup event. -
Method Summary
Modifier and TypeMethodDescriptionCreates the permission function using the current provider and subject.Gets the combined async task that must complete before proceeding.Gets the current permission provider that will be used.Gets the permission subject whose permissions are being set up.voidRegisters an async task that must complete before the login proceeds.voidsetProvider(PermissionProvider provider) Sets the permission provider to use for this subject.
-
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 updefaultProvider- the default permission provider
-
-
Method Details
-
getSubject
Gets the permission subject whose permissions are being set up.This can be a
Playeror the console command source.- Returns:
- the permission subject
-
getProvider
Gets the current permission provider that will be used.- Returns:
- the permission provider
-
setProvider
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
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
Gets the combined async task that must complete before proceeding.- Returns:
- the async task, never null (completes immediately if no async work)
-
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
-