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.

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.

      Parameters:
      callback - the callback to register
      Returns:
      the UUID identifier for this callback
    • 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()