Pintux Support
  • Welcome
  • BedrockGUI
    • Download & Installation
    • Commands & Permissions
    • Your First Menu
      • Simple
      • Modal
      • Custom
    • API
Powered by GitBook
On this page
  1. BedrockGUI

API

public class ExampleApiUsage {

BedrockGuiAPI api = BedrockGUI.getInstance().getApi();
// ---------- SIMPLE MENU EXAMPLE ----------

public void createAndRegisterSimple(BedrockGuiAPI api) {
    FormMenuBuilder builder = api.createMenuBuilder()
        .setType(FormMenuType.SIMPLE)
        .setTitle("A Simple Title $1")
        .setDescription("Some Description")
        .addButton("Click me", null, "command say Hello $1")
        .addButton("No callback", null, (player, actionValue) -> {
            player.sendMessage("You clicked the second button!");
        });

    FormMenu simpleMenu = builder.build();
    try {
        api.addMenu("my_simple_menu", simpleMenu);
    } catch (javax.management.InstanceAlreadyExistsException e) {
        e.printStackTrace();
    }
}

public void openSimple(BedrockGuiAPI api, FormPlayer player) {
    api.openMenu(player, "my_simple_menu", new String[]{"ExampleArg"});
}

// ---------- MODAL MENU EXAMPLE ----------

public void createAndRegisterModal(BedrockGuiAPI api) {
    FormMenuBuilder builder = api.createMenuBuilder()
        .setType(FormMenuType.MODAL)
        .setTitle("Confirm Action?")
        .setDescription("Are you sure?")
        .addButton("Yes", null, "command say 'Player clicked YES'")
        .addButton("No", null, "command say 'Player clicked NO'");

    FormMenu modalMenu = builder.build();
    try {
        api.addMenu("my_modal", modalMenu);
    } catch (javax.management.InstanceAlreadyExistsException e) {
        e.printStackTrace();
    }
}

public void openModal(BedrockGuiAPI api, FormPlayer player) {
    api.openMenu(player, "my_modal", null);
}

// ---------- CUSTOM MENU EXAMPLE ----------

public void createAndRegisterCustom(BedrockGuiAPI api) {
    Map<String, Object> nameInputProps = new HashMap<>();
    nameInputProps.put("text", "Enter your name");
    nameInputProps.put("placeholder", "Name");
    nameInputProps.put("default", "Steve");
    nameInputProps.put("action", "command say Hello $1");

    Map<String, Object> ageSliderProps = new HashMap<>();
    ageSliderProps.put("text", "Select your age");
    ageSliderProps.put("min", 1);
    ageSliderProps.put("max", 100);
    ageSliderProps.put("step", 1);
    ageSliderProps.put("default", 18);
    ageSliderProps.put("action", "command say You are $1 years old");

    FormMenuBuilder builder = api.createMenuBuilder()
        .setType(FormMenuType.CUSTOM)
        .setTitle("Custom Form Title")
        .setDescription("Fill in details")
        .addComponent("name_input", "input", nameInputProps, null)
        .addComponent("age_slider", "slider", ageSliderProps, null);

    FormAction globalAction = new FormAction(
        "command say Player $name_input is $age_slider years old", 
        (formPlayer, actionValue) -> {
            BiConsumer<FormPlayer, String> cmdCallback = api.getCallbackForAction("command");
            if (cmdCallback != null) {
                cmdCallback.accept(formPlayer, actionValue);
            }
        }
    );
    builder.addGlobalAction(globalAction);

    FormMenu customMenu = builder.build();
    try {
        api.addMenu("my_custom_menu", customMenu);
    } catch (javax.management.InstanceAlreadyExistsException e) {
        e.printStackTrace();
    }
}

public void openCustom(BedrockGuiAPI api, FormPlayer player) {
    api.openMenu(player, "my_custom_menu", new String[]{"ArgValue"});
}

// ---------- EXAMPLES OF CUSTOM CALLBACKS ----------

public void registerCustomCallbacks(BedrockGuiAPI api) {
    try {
        api.registerButtonCallback("myCustomAction", (player, actionValue) -> {
            player.sendMessage("myCustomAction callback triggered with: " + actionValue);
        });
        api.registerButtonCallback("anotherCustomAction", (player, actionValue) -> {
            player.sendMessage("anotherCustomAction fired, value: " + actionValue);
        });
    } catch (InstanceAlreadyExistsException e) {
        e.printStackTrace();
    }
}

}

PreviousCustom

Last updated 5 months ago