constmessageForm = newMessageFormData() .title("Message Form Example") .body("This shows a simple example using §o§7MessageFormData§r.") .button1("Button 1") .button2("Button 2");
messageForm .show(players[0]) .then((formData: MessageFormResponse) => { // player canceled the form, or another dialog was up and open. if (formData.canceled || formData.selection === undefined) { return; }
messageForm .show(players[0]) .then((formData: MessageFormResponse) => { // player canceled the form, or another dialog was up and open. if (formData.canceled || formData.selection === undefined) { return; }
import { world } from"@minecraft/server"; import { MessageFormData } from"@minecraft/server-ui"; // Find player with admin tag letplayer = world.getPlayers({ tags: ["admin"] })[0]; letform = newMessageFormData(); 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"); } });
Builds a simple two-button modal dialog.
Example: showBasicMessageForm.ts
Example: showTranslatedMessageForm.ts
Example: HigherRandomTickWarningPrompt.js