Annotation Interface AsyncCommand
Warning: Async commands should not directly access Bukkit APIs that must run on main thread.
Inject Scheduler and use
scheduler.global().run(...) for global work or scheduler.entity(player).run(...)
for player-owned work. Command bodies themselves use the framework-owned async scheduler.
At server stop all executors share approximately ten seconds of command waiting, including completion hooks; core commands are drained before framework services shut down. Only actual command waiting consumes the allowance, and repeated shutdown starts do not replenish it. A separate module unload shares a fresh ten-second allowance across that module's executors. This allowance is independent of UI shutdown waiting (up to about twenty seconds combined). Bodies are never interrupted. Do not block awaiting a tick-thread handoff during that wait: the unload thread owns the tick thread, and scheduling is rejected once the relevant owner retires.
Example:
@CmdMapping(format = "backup")
@AsyncCommand
public void backupWorld(@CmdSender Player player) {
// This runs async - safe for I/O operations
performBackup();
// Sync back to main thread for Bukkit operations
scheduler.entity(player).run(() -> {
player.sendMessage("Backup completed!");
});
}
- Since:
- 6.2.0
- Author:
- wisdomme
- See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionCustom message key in"<namespace>:<path>"form, for example"my-module:busy".booleanWhether to show "Processing..." message to sender while executing.intThe number of seconds the framework waits for the command body before reporting a timeout to the sender.
-
Element Details
-
showProcessing
boolean showProcessingWhether to show "Processing..." message to sender while executing.- Returns:
- true to show processing message
- Default:
true
-
processingMessageKey
String processingMessageKeyCustom message key in"<namespace>:<path>"form, for example"my-module:busy". The module catalogue supplies its colors. Invalid syntax logs one warning per executor and value and uses the framework's default processing message.- Returns:
- the namespaced message key, or empty for the default message
- Default:
""
-
timeout
int timeoutThe number of seconds the framework waits for the command body before reporting a timeout to the sender.This is a deadline on how long the framework waits, not a cancellation of the command body. (D-13, matching
Transactional.timeout()'s register for the structurally identical case, D-10.) When the configured duration elapses with the body still running, the framework stops waiting and sends the sender a timeout message -- exactly once. The command body is never interrupted or cancelled: the framework's async scheduler runs on a shared thread pool, and interrupting a pooled thread is unsafe, since it can affect unrelated tasks sharing that pool. The body keeps running to completion on its own; whatever it does after the deadline -- return, throw, send further messages of its own -- happens exactly as if no timeout had fired, and none of it is surfaced through the timeout report.Defaults to 30 seconds. A value of 0 disables the watcher entirely: the framework then waits indefinitely and never reports a timeout, regardless of how long the body runs.
- Returns:
- timeout in seconds
- Default:
30
-