Forms

Show interactive forms to players.

Forms are the pop-up UIs Bedrock shows on a player's screen. Endstone provides three types in endstone/form, built with fluent setters and shown with player->sendForm(form). Each form takes callbacks that run when the player responds. The examples alias the namespace with namespace es = endstone;.

Message form

A title, a body, and two buttons. The submit callback receives the index of the button the player picked - 0 for the first, 1 for the second:

include/my_plugin.h
#include <endstone/endstone.hpp>

namespace es = endstone;

// where you have a Player *player:
es::MessageForm form;
form.setTitle("Confirm")
    .setContent("Teleport to spawn?")
    .setButton1("Yes")
    .setButton2("No")
    .setOnSubmit([](es::Player *player, int selection) {
        if (selection == 0) {
            player->performCommand("spawn");
        }
    });
player->sendForm(form);

Action form

A title, a body, and a vertical list of buttons. Give each button its own click callback, or read the chosen index in the submit callback:

es::ActionForm form;
form.setTitle("Warps")
    .setContent("Pick a destination")
    .addButton("Spawn", std::nullopt, [](es::Player *player) { player->performCommand("spawn"); })
    .addButton("Home", "textures/items/ender_pearl", [](es::Player *player) { player->performCommand("home"); });
player->sendForm(form);

A button can carry an icon (a texture path or URL) as its second argument. Use addLabel, addHeader, and addDivider to structure the list.

A form of input controls - text fields, toggles, sliders, dropdowns. The submit callback receives a JSON string holding each control's value, in order:

es::ModalForm form;
form.setTitle("Settings")
    .setControls({
        es::TextInput("Nickname", "Enter a name"),
        es::Toggle("Enable flight", false),
        es::Slider("View distance", 4, 32, 1),
    })
    .setOnSubmit([](es::Player *player, std::string data) {
        player->sendMessage(data);  // JSON string of the controls' values
    });
player->sendForm(form);

Available controls are TextInput, Toggle, Slider, StepSlider, and Dropdown, plus Label, Header, and Divider for layout.

Handle closing

Every form takes an optional close callback, run when the player dismisses it without submitting:

form.setOnClose([](es::Player *player) {
    player->sendMessage("Maybe next time.");
});

On this page