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, and you show any of them with player.send_form(form). Each form takes callbacks that run when the player responds.
Message form
A title, a body, and two buttons. on_submit receives the index of the button the player picked - 0 for the first, 1 for the second:
from endstone.form import MessageForm
def on_command(self, sender, command, args):
form = MessageForm(
title="Confirm",
content="Teleport to spawn?",
button1="Yes",
button2="No",
on_submit=lambda player, selection: player.perform_command("spawn") if selection == 0 else None,
)
sender.send_form(form)
return TrueAction form
A title, a body, and a vertical list of buttons. Give each button its own on_click, or read the chosen index in on_submit:
from endstone.form import ActionForm
form = ActionForm(title="Warps", content="Pick a destination")
form.add_button("Spawn", on_click=lambda player: player.perform_command("spawn"))
form.add_button(
"Home",
icon="textures/items/ender_pearl",
on_click=lambda player: player.perform_command("home"),
)
player.send_form(form)A button can carry an icon (a texture path or URL). Use add_label, add_header, and add_divider to structure the list.
Modal form
A form of input controls - text fields, toggles, sliders, dropdowns. on_submit receives a JSON string holding each control's value, in order:
import json
from endstone.form import ModalForm, TextInput, Toggle, Slider
form = ModalForm(
title="Settings",
controls=[
TextInput(label="Nickname", placeholder="Enter a name"),
Toggle(label="Enable flight", default_value=False),
Slider(label="View distance", min=4, max=32, step=1, default_value=12),
],
on_submit=lambda player, data: player.send_message(str(json.loads(data))),
)
player.send_form(form)Available controls are TextInput, Toggle, Slider, StepSlider, and Dropdown, plus Label, Header, and Divider for layout.
Handle closing
Every form takes an optional on_close callback, run when the player dismisses it without submitting:
form.on_close = lambda player: player.send_message("Maybe next time.")