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
35 lines (35 loc) · 1.05 KB
/
index.js
File metadata and controls
35 lines (35 loc) · 1.05 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
// Script example for ScriptAPI
// Author: Smell of curry <https://github.com/smell-of-curry>
// Project: https://github.com/JaylyDev/ScriptAPI
import { world } from "@minecraft/server";
/**
* The prefix that is added before a rank tag
* @example `/tag @s add "RANK_PREFIX"member`
*/
const RANK_PREFIX = "rank:";
/**
* The default Rank that the player has in chat with no ranks
*/
const DEFAULT_RANK = "§bMember";
/**
* Gets chat ranks from a player
* @param player
* @returns ranks player has
*/
function getRanks(player) {
const ranks = player
.getTags()
.map((v) => {
if (!v.startsWith(RANK_PREFIX))
return null;
return v.substring(RANK_PREFIX.length);
})
.filter((x) => x);
return ranks.length == 0 ? [DEFAULT_RANK] : ranks;
}
world.beforeEvents.chatSend.subscribe((data) => {
const ranks = getRanks(data.sender).join("§r§l§8][§r");
const message = data.message;
world.sendMessage(`§r§l§8[§r${ranks}§r§l§8]§r§7 ${data.sender.name}:§r ${message}`);
data.cancel = true;
});