Class ChatCallbackManager

java.lang.Object
com.ultikits.ultitools.manager.ChatCallbackManager

@Internal public class ChatCallbackManager extends Object
Manager for chat-based callback commands.

Enables clickable chat messages that execute callbacks when clicked. Registers a hidden command /ultitools_callback that executes registered callbacks by their UUID.

聊天回调命令管理器。 支持可点击的聊天消息,点击时执行回调。 注册一个隐藏命令 /ultitools_callback,通过 UUID 执行已注册的回调。

Usage Example / 使用示例:


 VoidFunc0 callback = () -> player.sendMessage("Clicked!");
 UUID callbackId = ChatCallbackManager.registerCallback(callback);
 
 // Create clickable text that runs: /ultitools_callback <callbackId>
 Component text = Component.text("[Click Me]")
     .clickEvent(ClickEvent.runCommand("/ultitools_callback " + callbackId));
 
Since:
6.0.0
Author:
wisdomme
See Also:
  • Field Details

    • callbacks

      private static final Map<UUID,Runnable> callbacks
      Thread-safe storage for pending callbacks / 待处理回调的线程安全存储
    • initialized

      private static boolean initialized
      Initialization flag to prevent multiple command registrations / 防止多次命令注册的初始化标志
  • Constructor Details

    • ChatCallbackManager

      public ChatCallbackManager()
  • Method Details

    • registerCallback

      public static UUID registerCallback(Runnable callback)
      Registers a callback and returns its unique identifier.

      The callback will be executed once when a player runs the command /ultitools_callback <uuid>. After execution, the callback is removed.

      注册一个回调并返回其唯一标识符。 当玩家运行命令 /ultitools_callback <uuid> 时,回调将被执行一次,执行后移除。

      Parameters:
      callback - the callback to register / 要注册的回调
      Returns:
      the UUID identifier for this callback / 此回调的 UUID 标识符
    • getCommandMap

      private static org.bukkit.command.CommandMap getCommandMap()
      Get the CommandMap from Bukkit's PluginManager. Returns null if the PluginManager is not a SimplePluginManager (e.g., in test environments).
    • initialize

      private static void initialize()