Class AsyncLoginEvent
java.lang.Object
me.internalizable.numdrassl.api.event.connection.AsyncLoginEvent
- All Implemented Interfaces:
ResultedEvent<AsyncLoginEvent.AsyncLoginResult>
public class AsyncLoginEvent
extends Object
implements ResultedEvent<AsyncLoginEvent.AsyncLoginResult>
Event fired during the authentication phase, specifically designed for asynchronous operations.
This event is triggered before the player is fully admitted to the server (before LoginEvent).
It provides a mechanism for plugins to load blocking data (e.g., SQL databases, Redis, Web APIs)
without freezing the main proxy thread.
Example Usage
@Subscribe
public void onAsyncLogin(AsyncLoginEvent event) {
// 1. Create a future running on a separate thread (IO)
CompletableFuture<Void> dbTask = CompletableFuture.runAsync(() -> {
User user = database.load(event.getPlayer().getUniqueId());
if (user.isBanned()) {
event.setResult(AsyncLoginEvent.AsyncLoginResult.denied("You are banned"));
}
});
// 2. Register the task so the proxy waits for completion
event.registerTask(dbTask);
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classRepresents the result of the asynchronous pre-login attempt.Nested classes/interfaces inherited from interface ResultedEvent
ResultedEvent.GenericResult, ResultedEvent.Result -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionRetrieves all registered synchronization tasks.Get the current result.voidregisterTask(CompletableFuture<?> task) Registers a synchronization task.voidSet the result.
-
Constructor Details
-
AsyncLoginEvent
-
-
Method Details
-
registerTask
Registers a synchronization task.The proxy will defer the finalization of the login process until the provided
CompletableFutureis completed. If the future completes exceptionally, the login may be aborted.- Parameters:
task- A future representing the asynchronous work (e.g., database loading).
-
getLoginTasks
Retrieves all registered synchronization tasks.- Returns:
- A list of futures that must complete before login proceeds.
-
getPlayer
-
getResult
Description copied from interface:ResultedEventGet the current result.- Specified by:
getResultin interfaceResultedEvent<AsyncLoginEvent.AsyncLoginResult>- Returns:
- the result
-
setResult
Description copied from interface:ResultedEventSet the result.- Specified by:
setResultin interfaceResultedEvent<AsyncLoginEvent.AsyncLoginResult>- Parameters:
result- the new result
-