forked from JaylyDev/ScriptAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (28 loc) · 1.06 KB
/
index.js
File metadata and controls
28 lines (28 loc) · 1.06 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
// Script example for ScriptAPI
// Author: Jayly <https://github.com/JaylyDev>
// Worldwidebrine#9037 <Bedrock Add-Ons>
// Project: https://github.com/JaylyDev/ScriptAPI
import { system } from "@minecraft/server";
import { FormCancelationReason } from "@minecraft/server-ui";
/**
* @remarks
* Creates and force the API to show a popup form to player.
* Returns asynchronously when the player confirms or cancels the dialog.
* @param player Player to show this dialog to.
* @param form Dialog to show the player to.
* @param timeout Amount of time, in ticks, before the request times out and is abandoned.
* @throws This function can throw errors.
*/
export async function forceShow(player, form, timeout = Infinity) {
const startTick = system.currentTick;
while ((system.currentTick - startTick) < timeout) {
const response = await form.show(player);
if (response.cancelationReason !== FormCancelationReason.UserBusy) {
return response;
}
;
}
;
throw new Error(`Timed out after ${timeout} ticks`);
}
;