Script API - v26.70.26
    Preparing search index...

    Class MessageFormData

    Builds a simple two-button modal dialog.

    import { world, DimensionLocation } from '@minecraft/server';
    import { MessageFormResponse, MessageFormData } from '@minecraft/server-ui';

    function showBasicMessageForm(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) {
    const players = world.getPlayers();

    const messageForm = new MessageFormData()
    .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;
    }

    log(`You selected ${formData.selection === 0 ? 'Button 1' : 'Button 2'}`);
    })
    .catch((error: Error) => {
    log('Failed to show form: ' + error);
    return -1;
    });
    }
    import { world, DimensionLocation } from '@minecraft/server';
    import { MessageFormResponse, MessageFormData } from '@minecraft/server-ui';

    function showTranslatedMessageForm(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) {
    const players = world.getPlayers();

    const messageForm = new MessageFormData()
    .title({ translate: 'permissions.removeplayer' })
    .body({ translate: 'accessibility.list.or.two', with: ['Player 1', 'Player 2'] })
    .button1('Player 1')
    .button2('Player 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;
    }

    log(`You selected ${formData.selection === 0 ? 'Player 1' : 'Player 2'}`);
    })
    .catch((error: Error) => {
    log('Failed to show form: ' + error);
    return -1;
    });
    }
    import { Player, system } from "@minecraft/server";
    import { MessageFormData } from "@minecraft/server-ui";

    // Run `/scriptevent example:randomtickwarning` in chat to show the confirmation prompt.
    system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
    if (id !== "example:randomtickwarning" || !(sourceEntity instanceof Player)) return;
    const player = sourceEntity;

    const form = new MessageFormData()
    .title("Higher Random Tick Warning")
    .body("Run `/gamerule randomtickspeed 1000`? High tick speeds can cause lag.")
    .button1("Yes, do it")
    .button2("No, keep default");

    form.show(player).then((response) => {
    if (response.selection === 0) {
    player.runCommand("gamerule randomtickspeed 1000");
    player.sendMessage("Updated randomtickspeed to 1000.");
    } else if (response.selection === 1) {
    player.sendMessage("Kept the default randomtickspeed.");
    }
    });
    });

    image

    export class MessageFormData {
    body(bodyText: minecraftserver.RawMessage | string): MessageFormData;
    button1(text: minecraftserver.RawMessage | string): MessageFormData;
    button2(text: minecraftserver.RawMessage | string): MessageFormData;
    show(player: minecraftserver.Player): Promise<MessageFormResponse>;
    title(titleText: minecraftserver.RawMessage | string): MessageFormData;
    }
    Index
    • Parameters

      Returns MessageFormData

      Method that sets the body text for the modal form.

      This function can't be called in early-execution mode.

      import { Player, system } from "@minecraft/server";
      import { MessageFormData } from "@minecraft/server-ui";

      // Run `/scriptevent example:teleportrequest` in chat to open the form.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:teleportrequest" || !(sourceEntity instanceof Player)) return;

      const form = new MessageFormData();
      form.title("Teleport Request");
      form.body("Do you want to teleport to the arena?");
      form.button1("Teleport");
      form.button2("Cancel");

      form.show(sourceEntity).then((response) => {
      if (response.canceled || response.selection === undefined) return;
      if (response.selection === 0) {
      sourceEntity.sendMessage("Teleporting to the arena.");
      } else {
      sourceEntity.sendMessage("Teleport canceled.");
      }
      });
      });
    • Parameters

      Returns MessageFormData

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

      This function can't be called in early-execution mode.

      import { Player, system } from "@minecraft/server";
      import { MessageFormData } from "@minecraft/server-ui";

      // Run `/scriptevent example:confirmpurchase` in chat to open the form.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:confirmpurchase" || !(sourceEntity instanceof Player)) return;

      const form = new MessageFormData();
      form.title("Confirm Purchase");
      form.body("Buy 1 diamond sword for 10 emeralds?");
      form.button1("Confirm");
      form.button2("Cancel");

      form.show(sourceEntity).then((response) => {
      if (response.canceled || response.selection === undefined) return;
      if (response.selection === 0) {
      sourceEntity.sendMessage("Purchased a diamond sword.");
      } else {
      sourceEntity.sendMessage("Purchase canceled.");
      }
      });
      });
    • Parameters

      Returns MessageFormData

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

      This function can't be called in early-execution mode.

      import { Player, system } from "@minecraft/server";
      import { MessageFormData } from "@minecraft/server-ui";

      // Run `/scriptevent example:resethighscore` in chat to open the form.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:resethighscore" || !(sourceEntity instanceof Player)) return;

      const form = new MessageFormData();
      form.title("Reset High Score");
      form.body("Are you sure you want to reset your local high score?");
      form.button1("Yes, Reset");
      form.button2("No, Keep Score");

      form.show(sourceEntity).then((response) => {
      if (response.canceled || response.selection === undefined) return;
      if (response.selection === 0) {
      sourceEntity.sendMessage("Reset high score.");
      } else {
      sourceEntity.sendMessage("Kept high score.");
      }
      });
      });
    • Parameters

      • player: Player

        Player to show this dialog to.

      Returns Promise<MessageFormResponse>

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

      This function can't be called in restricted-execution mode.

      This function can't be called in early-execution mode.

      import { Player, system } from "@minecraft/server";
      import { MessageFormData } from "@minecraft/server-ui";

      // Run `/scriptevent example:enablepvp` in chat to open the form.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:enablepvp" || !(sourceEntity instanceof Player)) return;

      const form = new MessageFormData();
      form.title("Enable PvP");
      form.body("Would you like to enable PvP combat in this arena?");
      form.button1("Enable");
      form.button2("Disable");

      form.show(sourceEntity).then((response) => {
      if (response.canceled || response.selection === undefined) {
      sourceEntity.sendMessage("PvP prompt was canceled.");
      return;
      }
      if (response.selection === 0) {
      sourceEntity.sendMessage("PvP enabled.");
      } else {
      sourceEntity.sendMessage("PvP disabled.");
      }
      });
      });
    • Parameters

      Returns MessageFormData

      This builder method sets the title for the modal dialog.

      This function can't be called in early-execution mode.

      import { Player, system } from "@minecraft/server";
      import { MessageFormData } from "@minecraft/server-ui";

      // Run `/scriptevent example:leaveparty` in chat to open the form.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:leaveparty" || !(sourceEntity instanceof Player)) return;

      const form = new MessageFormData();
      form.title("Leave Party");
      form.body("Are you sure you want to leave your active party?");
      form.button1("Leave");
      form.button2("Stay");

      form.show(sourceEntity).then((response) => {
      if (response.canceled || response.selection === undefined) return;
      if (response.selection === 0) {
      sourceEntity.sendMessage("You chose Leave.");
      } else {
      sourceEntity.sendMessage("You chose Stay.");
      }
      });
      });