Skip to content

Register custom action

Huynh Tien edited this page Jul 3, 2025 · 1 revision

Register the action

The DialogManager#registerCustomAction can be used to register custom actions so that the manager can listen to incoming events and trigger the actions.

The parameters of the actions include an UUID of the player who triggers the action and a Map<String, String> containing the keys and values of all inputs in the dialog.

String actionId = "test_action_id";
dialogManager.registerCustomAction(actionId, (uuid, map) -> {
    System.out.println("Your name is " + map.get("name"));
});

Use the action

You can now use the id in your dynamicAction

Here is the example for the sample Confirmation Dialog:

dialogManager.createConfirmationDialog()
        .title("Sample Dialog")
        .canCloseWithEscape(true)
        .afterAction(Dialog.AfterAction.CLOSE)
        .body(builder -> builder.text().text("This is a sample dialog. Do you want to proceed?"))
        .input("name", builder -> builder.textInput().label("Enter your name:"))
        .yesAction(builder -> builder.label("Confirm").dynamicCustom(actionId))
        .noAction(builder -> builder.label("Cancel"));

Clone this wiki locally