forked from JaylyDev/ScriptAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageForm.ts
More file actions
49 lines (45 loc) · 1.36 KB
/
MessageForm.ts
File metadata and controls
49 lines (45 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { RawMessage, Player } from "@minecraft/server";
import { MessageFormData, MessageFormResponse } from "@minecraft/server-ui";
export class MessageFormButton {
text: string | RawMessage;
constructor (text: string | RawMessage) {
this.text = text;
};
};
/**
* Builds a simple player form with buttons that let the player
* take action.
*/
export class MessageFormBuilder implements MessageFormData {
/**
* Title of the the modal dialog.
*/
titleText?: string | RawMessage;
bodyText?: string | RawMessage;
buttons: MessageFormButton[] = [];
body(bodyText: string | RawMessage): this {
this.bodyText = bodyText;
return this;
}
button1(text: string | RawMessage): this {
this.buttons[0] = new MessageFormButton(text);
return this;
}
button2(text: string | RawMessage): this {
this.buttons[1] = new MessageFormButton(text);
return this;
}
show(player: Player): Promise<MessageFormResponse> {
const [ button1, button2 ] = this.buttons;
const form = new MessageFormData();
if (!!this.titleText) form.title(this.titleText);
if (!!this.bodyText) form.body(this.bodyText);
if (!!button1) form.button1(button1.text);
if (!!button2) form.button2(button2.text);
return form.show(player);
}
title(titleText: string | RawMessage): this {
this.titleText = titleText;
return this;
}
};