FancyInnovations

Creating Dialogs

Creating custom dialog windows

FancyDialogs allows you to create custom dialog windows that display to players in Minecraft. Dialogs can contain text, buttons, and form inputs.

Dialog structure

A dialog consists of:

  • ID - Unique identifier
  • Title - Dialog window title
  • Body - Content text (multiple lines)
  • Inputs (optional) - Form fields
  • Buttons - Action buttons

Creating a simple dialog

Basic text dialog

import com.fancyinnovations.fancydialogs.api.*;
import com.fancyinnovations.fancydialogs.api.data.*;

// Create dialog data
DialogData dialogData = new DialogData(
    "welcome_dialog",           // ID
    "Welcome!",                  // Title
    true,                        // Can close with ESC
    List.of(
        new DialogBodyData("Welcome to our server!"),
        new DialogBodyData("We hope you enjoy your stay.")
    ),
    null,                        // No inputs
    List.of(
        new DialogButton("OK", null, List.of(), UUID.randomUUID())
    )
);

// Create dialog instance
Dialog dialog = FancyDialogs.get().createDialog(dialogData);

// Register
FancyDialogs.get().getDialogRegistry().register(dialog);

// Show to player
dialog.open(player);

Using DialogBodyData

Dialog body can contain multiple paragraphs:

List<DialogBodyData> body = List.of(
    new DialogBodyData("<gold><bold>Server Rules</bold></gold>"),
    new DialogBodyData(""),
    new DialogBodyData("1. Be respectful to other players"),
    new DialogBodyData("2. No griefing or stealing"),
    new DialogBodyData("3. Keep chat family-friendly"),
    new DialogBodyData(""),
    new DialogBodyData("<gray>Click OK to accept</gray>")
);

Adding buttons

Simple button

DialogButton okButton = new DialogButton(
    "OK",                        // Label
    "Click to continue",         // Tooltip (optional)
    List.of(),                   // Actions
    UUID.randomUUID()            // Unique ID
);

Button with actions

import com.fancyinnovations.fancydialogs.api.data.DialogButton.DialogAction;

DialogButton actionButton = new DialogButton(
    "Teleport to Spawn",
    "Click to teleport",
    List.of(
        new DialogAction("teleport", "spawn"),
        new DialogAction("message", "Teleporting...")
    ),
    UUID.randomUUID()
);

Multiple buttons

List<DialogButton> buttons = List.of(
    new DialogButton("Yes", "Confirm action", List.of(
        new DialogAction("close", null),
        new DialogAction("message", "Confirmed!")
    ), UUID.randomUUID()),

    new DialogButton("No", "Cancel action", List.of(
        new DialogAction("close", null)
    ), UUID.randomUUID())
);

Built-in dialog types

Notice dialog

Quick notification dialogs:

import com.fancyinnovations.fancydialogs.api.builtin.NoticeDialog;

// Simple notice
NoticeDialog.show(player, "Your changes have been saved!");

// With custom title
new NoticeDialog("Success", "Your changes have been saved!").show(player);

Confirmation dialog

Yes/No dialogs with callbacks:

import com.fancyinnovations.fancydialogs.api.builtin.ConfirmationDialog;

new ConfirmationDialog("Are you sure you want to delete this?")
    .withTitle("Confirm Delete")
    .withOnConfirm(() -> {
        // User clicked Yes
        player.sendMessage("Deleted!");
        performDelete();
    })
    .withOnCancel(() -> {
        // User clicked No
        player.sendMessage("Cancelled.");
    })
    .ask(player);

Form inputs

Text field

import com.fancyinnovations.fancydialogs.api.data.inputs.*;

DialogTextField nameField = new DialogTextField(
    "player_name",               // Key
    "Enter your name:",          // Label
    0                            // Order
);

DialogInputs inputs = new DialogInputs(List.of(nameField));

Checkbox

DialogCheckbox agreeBox = new DialogCheckbox(
    "agree_terms",               // Key
    "I agree to the terms",      // Label
    1                            // Order
);

Select dropdown

DialogSelect rankSelect = new DialogSelect(
    "rank_choice",               // Key
    "Choose your rank:",         // Label
    2,                           // Order
    List.of("Member", "VIP", "MVP") // Options
);

Complete form example

public class RegistrationDialog {

    public void show(Player player) {
        // Create form inputs
        DialogTextField username = new DialogTextField(
            "username", "Username:", 0
        );

        DialogTextField email = new DialogTextField(
            "email", "Email:", 1
        );

        DialogCheckbox newsletter = new DialogCheckbox(
            "newsletter", "Subscribe to newsletter", 2
        );

        DialogSelect country = new DialogSelect(
            "country", "Country:", 3,
            List.of("USA", "UK", "Canada", "Other")
        );

        DialogInputs inputs = new DialogInputs(
            List.of(username, email, newsletter, country)
        );

        // Create submit button
        DialogButton submitBtn = new DialogButton(
            "Register",
            "Complete registration",
            List.of(
                new DialogAction("submit_form", "registration")
            ),
            UUID.randomUUID()
        );

        // Create dialog
        DialogData data = new DialogData(
            "registration",
            "Player Registration",
            true,
            List.of(
                new DialogBodyData("<gold><bold>Register Your Account</bold></gold>"),
                new DialogBodyData(""),
                new DialogBodyData("Please fill in your information below:")
            ),
            inputs,
            List.of(submitBtn)
        );

        Dialog dialog = FancyDialogs.get().createDialog(data);
        FancyDialogs.get().getDialogRegistry().register(dialog);
        dialog.open(player);
    }
}

Dialog actions

Register custom actions to handle button clicks:

import com.fancyinnovations.fancydialogs.api.DialogActionRegistry;

public class CustomDialogAction {

    public void register() {
        DialogActionRegistry registry =
            FancyDialogs.get().getDialogActionRegistry();

        registry.registerAction("give_reward", (player, data) -> {
            // Give player a reward
            player.getInventory().addItem(new ItemStack(Material.DIAMOND, 5));
            player.sendMessage("You received 5 diamonds!");
        });
    }
}

// Use in button
new DialogButton("Claim Reward", null, List.of(
    new DialogAction("give_reward", null)
), UUID.randomUUID());

Complete example: Quest dialog

public class QuestDialog {

    public void showQuestStart(Player player) {
        DialogData data = new DialogData(
            "quest_start",
            "New Quest Available!",
            true,
            List.of(
                new DialogBodyData("<gold><bold>The Lost Treasure</bold></gold>"),
                new DialogBodyData(""),
                new DialogBodyData("A mysterious treasure has been discovered in the ancient ruins."),
                new DialogBodyData("Will you help retrieve it?"),
                new DialogBodyData(""),
                new DialogBodyData("<gray>Reward: 1000 coins, Diamond Sword</gray>")
            ),
            null,
            List.of(
                new DialogButton("Accept Quest", "Start the quest", List.of(
                    new DialogAction("accept_quest", "lost_treasure"),
                    new DialogAction("close", null)
                ), UUID.randomUUID()),

                new DialogButton("Decline", "Maybe later", List.of(
                    new DialogAction("close", null)
                ), UUID.randomUUID())
            )
        );

        Dialog dialog = FancyDialogs.get().createDialog(data);
        dialog.open(player);
    }

    public void showQuestComplete(Player player) {
        DialogData data = new DialogData(
            "quest_complete",
            "Quest Complete!",
            true,
            List.of(
                new DialogBodyData("<green><bold>Congratulations!</bold></green>"),
                new DialogBodyData(""),
                new DialogBodyData("You have completed The Lost Treasure quest!"),
                new DialogBodyData(""),
                new DialogBodyData("Rewards:"),
                new DialogBodyData("• 1000 coins"),
                new DialogBodyData("• Diamond Sword")
            ),
            null,
            List.of(
                new DialogButton("Claim Rewards", null, List.of(
                    new DialogAction("give_quest_reward", "lost_treasure"),
                    new DialogAction("close", null)
                ), UUID.randomUUID())
            )
        );

        Dialog dialog = FancyDialogs.get().createDialog(data);
        dialog.open(player);
    }
}

Managing dialogs

Check if dialog is open

Dialog dialog = FancyDialogs.get().getDialogRegistry().get("my_dialog");

if (dialog != null) {
    boolean isOpen = dialog.isOpenedFor(player);

    if (isOpen) {
        // Dialog is currently shown to this player
    }
}

Close dialog

dialog.close(player);

Get dialog viewers

Set<UUID> viewers = dialog.getViewers();

// Check how many players have the dialog open
int viewerCount = viewers.size();

Example: Shop dialog

public class ShopDialog {

    public void show(Player player) {
        DialogSelect itemSelect = new DialogSelect(
            "item",
            "Select item to purchase:",
            0,
            List.of("Diamond Sword - $100", "Diamond Armor - $400", "Enchanted Book - $50")
        );

        DialogTextField quantity = new DialogTextField(
            "quantity",
            "Quantity:",
            1
        );

        DialogInputs inputs = new DialogInputs(List.of(itemSelect, quantity));

        DialogData data = new DialogData(
            "shop",
            "Server Shop",
            true,
            List.of(
                new DialogBodyData("<gold><bold>Welcome to the Shop!</bold></gold>"),
                new DialogBodyData(""),
                new DialogBodyData("Select an item and quantity to purchase:")
            ),
            inputs,
            List.of(
                new DialogButton("Purchase", "Buy selected items", List.of(
                    new DialogAction("process_purchase", null)
                ), UUID.randomUUID()),

                new DialogButton("Cancel", "Close shop", List.of(
                    new DialogAction("close", null)
                ), UUID.randomUUID())
            )
        );

        Dialog dialog = FancyDialogs.get().createDialog(data);
        dialog.open(player);
    }
}

Best practices

1. Use unique IDs

Always use unique IDs for your dialogs to avoid conflicts:

String id = plugin.getName() + "_" + "my_dialog";

2. Register dialogs once

Register dialogs when your plugin enables, not every time you show them:

@Override
public void onEnable() {
    registerDialogs();
}

private void registerDialogs() {
    Dialog welcomeDialog = createWelcomeDialog();
    FancyDialogs.get().getDialogRegistry().register(welcomeDialog);
}

3. Clean up on disable

Unregister dialogs when your plugin disables:

@Override
public void onDisable() {
    DialogRegistry registry = FancyDialogs.get().getDialogRegistry();
    registry.unregister("myplugin_welcome");
}

4. Handle button clicks

Listen to DialogButtonClickedEvent to handle form submissions:

@EventHandler
public void onDialogButton(DialogButtonClickedEvent event) {
    Dialog dialog = event.getDialog();
    Player player = event.getPlayer();
    DialogButton button = event.getButton();

    // Handle the click
    if (dialog.getId().equals("registration")) {
        handleRegistration(player, dialog);
    }
}

On this page