Builds a simple two-button modal dialog.

Example

HigherRandomTickWarningPrompt.js

import { world } from "@minecraft/server";
import { MessageFormData } from "@minecraft/server-ui";
// Find player with admin tag
let player = world.getPlayers({ tags: ["admin"] })[0];
let form = new MessageFormData();
form.title("Higher Random Tick Warning");
form.body(
"Are you sure you want to run this command:\n/gamerule randomtickspeed 1000\nThis can cause lag to the world"
);
form.button1("Yes, do it!");
form.button2("No, leave it as default!");
form.show(player).then((response) => {
if (response.selection == 0) {
player.runCommand("/gamerule randomtickspeed 1000");
}
});

Hierarchy

  • MessageFormData

Constructors

Methods

Constructors

Methods

  • Parameters

    Returns MessageFormData

    Remarks

    Method that sets the body text for the modal form.

    This function can't be called in read-only mode.

  • Parameters

    Returns MessageFormData

    Remarks

    Method that sets the text for the first button of the dialog.

    This function can't be called in read-only mode.

  • Parameters

    Returns MessageFormData

    Remarks

    This method sets the text for the second button on the dialog.

    This function can't be called in read-only mode.

  • Parameters

    • player: Player

      Player to show this dialog to.

    Returns Promise<MessageFormResponse>

    Remarks

    Creates and shows this modal popup form. Returns asynchronously when the player confirms or cancels the dialog.

    This function can't be called in read-only mode.

    Throws

    This function can throw errors.

  • Parameters

    Returns MessageFormData

    Remarks

    This builder method sets the title for the modal dialog.

    This function can't be called in read-only mode.