forked from JaylyDev/ScriptAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageForm.js
More file actions
47 lines (47 loc) · 1.09 KB
/
MessageForm.js
File metadata and controls
47 lines (47 loc) · 1.09 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
import { MessageFormData } from "@minecraft/server-ui";
export class MessageFormButton {
constructor(text) {
this.text = text;
}
;
}
;
/**
* Builds a simple player form with buttons that let the player
* take action.
*/
export class MessageFormBuilder {
constructor() {
this.buttons = [];
}
body(bodyText) {
this.bodyText = bodyText;
return this;
}
button1(text) {
this.buttons[0] = new MessageFormButton(text);
return this;
}
button2(text) {
this.buttons[1] = new MessageFormButton(text);
return this;
}
show(player) {
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) {
this.titleText = titleText;
return this;
}
}
;