-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathfunctions.ts
50 lines (45 loc) · 1.46 KB
/
functions.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
import { NetworkIdentifier } from "bdsx/bds/networkidentifier";
import { CANCEL } from "bdsx/common";
import { bedrockServer } from "bdsx/launcher";
import * as fs from "fs";
import { addlog } from "./scr/log";
export function kick(target: NetworkIdentifier, message: string): CANCEL {
bedrockServer.serverInstance.disconnectClient(target, message);
addlog(`${target.getActor()?.getNameTag()} kicked`);
return CANCEL;
}
export function makeFile(filepath: string, value = {}): void {
if (!fs.existsSync(filepath)) {
fs.writeFileSync(filepath, JSON.stringify(value));
console.log("[", "sos9533scr".yellow, "]", `Made '${filepath}'`.gray, " - sos9533".green);
}
}
export function makeDir(dirname: string): void {
if (!fs.existsSync(dirname)) {
fs.mkdirSync(dirname);
console.log("[", "sos9533scr".yellow, "]", `Made '${dirname}'`.gray, " - sos9533".green);
}
}
export function leadZero(num: number, n: number): string {
var leadZero = "";
let num2 = num.toString();
if (num2.length < n) {
for (var i = 0; i < n - num2.length; i++) leadZero += "0";
}
return leadZero + num;
}
export function dateWithZero(): string {
var d = new Date();
return (
d.getFullYear() +
"-" +
leadZero(d.getMonth() + 1, 2) +
"-" +
leadZero(d.getDate(), 2) +
"-" +
leadZero(d.getHours(), 2) +
"-" +
leadZero(d.getMinutes(), 2) +
"-"
);
}