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
43 lines (40 loc) · 1.36 KB
/
index.js
File metadata and controls
43 lines (40 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
// Script example for ScriptAPI
// Author: Smell of Curry <https://github.com/smell-of-curry>
// Project: https://github.com/JaylyDev/ScriptAPI
import { Player, world } from "@minecraft/server";
//Prefix for all custom commands
const COMMAND_PREFIX = "!";
/**
* The function that will handle all custom command inputs and outputs
* @param {string} command
* @param {string[]} args
* @param {string} msg
* @param {Player} player
*/
function customCommand(command, args, msg, player) {
switch (command) {
case "spawn":
player.runCommandAsync(`execute "${player.nameTag}" ~~~ tp @s 0 100 0`);
break;
case "test":
player.runCommandAsync(`execute "${player.nameTag}" ~~~ say test`);
break;
case "gmc":
player.runCommandAsync(`gamemode 1 "${player.nameTag}"`);
break;
case "gms":
player.runCommandAsync(`gamemode 0 "${player.nameTag}"`);
break;
default:
player.runCommandAsync(`say error! ${command} is not a valid command!`);
}
}
//Checks if a command was run (checks for the prefix)
world.beforeEvents.chatSend.subscribe((msg) => {
if (!msg.message.startsWith(COMMAND_PREFIX)) return;
const args = msg.message.slice(COMMAND_PREFIX.length).trim().split(/\s+/);
msg.cancel = true;
const player = msg.sender;
const command = args.shift();
customCommand(command, args, args.join(" "), player);
});