Annotation Interface AsyncCommand


@Target(METHOD) @Retention(RUNTIME) @Documented public @interface AsyncCommand
Annotation to mark a command method as async execution. When applied, the command will be executed in an async thread.

Warning: Async commands should not directly access Bukkit APIs that must run on main thread. Use BukkitScheduler.runTask(org.bukkit.plugin.Plugin, Runnable) to sync back to main thread when needed.

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
     Bukkit.getScheduler().runTask(plugin, () -> {
         player.sendMessage("Backup completed!");
     });
 }
 
Since:
6.2.0
Author:
wisdomme
See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Custom processing message key for i18n.
    boolean
    Whether to show "Processing..." message to sender while executing.
    int
    The number of seconds the framework waits for the command body before reporting a timeout to the sender.
  • Element Details

    • showProcessing

      boolean showProcessing
      Whether to show "Processing..." message to sender while executing.
      Returns:
      true to show processing message
      Default:
      true
    • processingMessageKey

      String processingMessageKey
      Custom processing message key for i18n.
      Returns:
      the i18n key, or empty for default message
      Default:
      ""
    • timeout

      int timeout
      The 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: Bukkit'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