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.

警告:异步命令不应直接访问必须在主线程运行的 Bukkit API。 需要时使用 BukkitScheduler.runTask() 同步回主线程。

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
    Timeout in seconds.
  • 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. 自定义处理中消息的 i18n 键。
      Returns:
      the i18n key, or empty for default message
      Default:
      ""
    • timeout

      int timeout
      Timeout in seconds. If the async operation takes longer, it will be cancelled. Set to 0 for no timeout.

      超时时间(秒)。如果异步操作超时,将被取消。 设为 0 表示无超时。

      Returns:
      timeout in seconds
      Default:
      30