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
30 lines (27 loc) · 1.1 KB
/
index.js
File metadata and controls
30 lines (27 loc) · 1.1 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
// Script example for ScriptAPI
// Author: Jayly#1397 <Jayly Discord>
// Project: https://github.com/JaylyDev/ScriptAPI
import { MinecraftDimensionTypes, system, world } from "@minecraft/server";
/**
* @param {string} taskName
* @param {string[]} commands
* @param {boolean} loop
*/
export function task (taskName, commands, loop = false) {
if (typeof taskName !== 'string' || typeof loop !== 'boolean') throw new TypeError('Native type conversion failed.');
if (commands.filter((value) => typeof value !== 'string').length > 0) throw new TypeError('Native variant type conversion failed.');
let id = system.runInterval(function runCommands () {
let line = 0;
system.clearRun(id);
try {
for (const command of commands) {
line++;
world.getDimension(MinecraftDimensionTypes.overworld).runCommand(command);
};
if (loop) id = system.runInterval(runCommands);
} catch (reason) {
console.warn(`Task ${taskName} failed to load correctly with error(s):`);
console.warn(`Error on line ${line}: command failed to parse with error '${reason}'`);
};
});
};