-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
57 lines (50 loc) · 1.82 KB
/
index.ts
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
import { events } from "bdsx/event";
import config = require("./config.json");
import { serverProperties } from "bdsx/serverproperties";
import { bedrockServer } from "bdsx/launcher";
export const logPrefix = ``.reset + `[${config.pluginName.yellow}] `
export enum LogInfo {
default,
info,
warn,
error
}
export function rawtext(msg: string, type: LogInfo = LogInfo.default) {
switch (type) {
case LogInfo.info:
return `{"rawtext":[{"text":"§a§l> §r${msg}"}]}`;
case LogInfo.error:
return `{"rawtext":[{"text":"§4§lERROR> §r§c${msg}"}]}`;
case LogInfo.warn:
return `{"rawtext":[{"text":"§6§lWARN> §r§e${msg}"}]}`;
case LogInfo.default:
default:
return `{"rawtext":[{"text":"${msg}"}]}`;
}
}
let rainbowOffset = 0;
const rainbow = ["§c", "§6", "§e", "§a", "§9", "§b", "§d", "§g", "§5", "§2"];
let motdInterval: NodeJS.Timeout;
console.log(logPrefix + "Allocated");
// before BDS launching
events.serverOpen.on(() => {
console.log(logPrefix + "Launched");
if (serverProperties["level-name"] === "UG") require("./ug");
if (serverProperties["level-name"] === "lobby") require("./lobby");
if (serverProperties["level-name"] === "WSMP") require("./wsmp");
if (serverProperties["level-name"] === "CSMP") require("./csmp");
motdInterval = setInterval(() => {
let i = rainbowOffset;
rainbowOffset = (rainbowOffset + 1) & rainbow.length;
const coloredName = config.name.replace(/./g, v => rainbow[i++ % rainbow.length] + v);
try {
bedrockServer.serverInstance.setMotd(coloredName);
} catch (err) {
console.log(err);
}
}, 5000);
});
events.serverClose.on(() => {
clearInterval(motdInterval);
console.log(logPrefix + "Closed");
});