forked from JaylyDev/ScriptAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.js
More file actions
62 lines (46 loc) · 1.74 KB
/
tests.js
File metadata and controls
62 lines (46 loc) · 1.74 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
50
51
52
53
54
55
56
57
58
59
60
61
62
// Script example for ScriptAPI
// Author: Jayly#1397 <Jayly Discord>
// Project: https://github.com/JaylyDev/ScriptAPI
import { world, system, Player } from "@minecraft/server";
import { ModalFormData, ActionFormData, MessageFormData } from "@minecraft/server-ui";
import { forceShow } from "force-show/index";
world.beforeEvents.chatSend.subscribe(async (event) => {
event.cancel = true;
const modalForm = new ModalFormData();
modalForm.title('Title');
modalForm.dropdown('Dropdown', ['0','1']);
const response = await forceShow(event.sender, modalForm);
// response should be ModalFormResponse
for (const value of response.formValues) {
console.log(value);
}
});
world.beforeEvents.itemUse.subscribe(async (event) => {
if (!(event.source instanceof Player)) return;
event.cancel = true;
const form = new ActionFormData();
form.button('button');
form.button('button');
form.button('button');
const response = await forceShow(event.source, form);
// response should be ActionFormResponse
world.sendMessage(String(response.selection));
});
system.run(async function () {
for (let player of world.getAllPlayers()) {
const form = new MessageFormData();
form.title('title');
form.button1('button');
form.button2('button');
const response = await forceShow(player, form);
// response should be MessageFormResponse
world.sendMessage(String(response.selection));
};
});
// test timeout feature
world.afterEvents.chatSend.subscribe((event) => {
const { sender, message } = event;
forceShow(sender, new MessageFormData().title('Title').body(message), 10).then((res) => {
console.log('Success');
}).catch(console.error);
});