Class: MessageFormData
Builds a simple two-button modal dialog.
Example
import { Player } from '@minecraft/server';
import { MessageFormResponse, MessageFormData } from '@minecraft/server-ui';
function showMessage(player: Player) {
const messageForm = new MessageFormData()
.title({ translate: 'permissions.removeplayer' }) // "Remove player"
.body({ translate: 'accessibility.list.or.two', with: ['Player 1', 'Player 2'] }) // "Player 1 or Player 2"
.button1('Player 1')
.button2('Player 2');
messageForm
.show(player)
.then((formData: MessageFormResponse) => {
// player canceled the form, or another dialog was up and open.
if (formData.canceled || formData.selection === undefined) {
return;
}
player.sendMessage(`You selected ${formData.selection === 0 ? 'Player 1' : 'Player 2'}`);
})
.catch((error: Error) => {
player.sendMessage('Failed to show form: ' + error);
});
}
Constructors
new MessageFormData()
new MessageFormData():
MessageFormData
Returns
Methods
body()
body(
bodyText
):MessageFormData
Parameters
Parameter | Type |
---|---|
bodyText | string | RawMessage |
Returns
Remarks
Method that sets the body text for the modal form.
button1()
button1(
text
):MessageFormData
Parameters
Parameter | Type |
---|---|
text | string | RawMessage |
Returns
Remarks
Method that sets the text for the first button of the dialog.
button2()
button2(
text
):MessageFormData
Parameters
Parameter | Type |
---|---|
text | string | RawMessage |
Returns
Remarks
This method sets the text for the second button on the dialog.
show()
show(
player
):Promise ↗️
<MessageFormResponse
>
Parameters
Parameter | Type | Description |
---|---|---|
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.
title()
title(
titleText
):MessageFormData
Parameters
Parameter | Type |
---|---|
titleText | string | RawMessage |
Returns
Remarks
This builder method sets the title for the modal dialog.