-
Notifications
You must be signed in to change notification settings - Fork 0
/
eban.js
87 lines (78 loc) · 2.93 KB
/
eban.js
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const path = './plugins/Eban/banlist.json';
if (!file.exists(path)) {
file.writeTo(path, '[]');
}
mc.regPlayerCmd("eban", "client id ban", function(pl, args) {
let ply = mc.getPlayer(args[0]);
if (ply == null) {
pl.tell('[EBan] ' + Format.Red + 'Unable to get player!');
} else if (ply.isOP()) {
pl.tell('[EBan] ' + Format.Red + 'Failed to ban Opetator');
} else {
pl.tell('[EBan] ' + Format.Green + 'Success!');
id = ply.getDevice().clientId;
ply.kick(Format.White + 'U have been banned');
let confParsed = JSON.parse(file.readFrom(path));
confParsed.push({
"Nick": ply.realName,
"ID": id
});
file.writeTo(path, JSON.stringify(confParsed));
}
}, 1);
mc.regConsoleCmd("eban", "ban player", function(args) {
let ply = mc.getPlayer(args[0])
if (ply == null) {
log('[EBan] ' + 'Unable to get player!')
} else {
log('[EBan] ' + 'Success!')
id = ply.getDevice().clientId
ply.kick(Format.White + 'U have been banned')
let confParsed = JSON.parse(file.readFrom(path));
confParsed.push({
"Nick": ply.realName,
"ID": id
});
file.writeTo(path, JSON.stringify(confParsed));
}
});
mc.regPlayerCmd("unban", "unban player", function(pl, args) {
let banlist = JSON.parse(file.readFrom(path));
for (let i = 0; i < banlist.length; i++) {
if (args[0] === banlist[i]['Nick']) {
unbanObj = `{"Nick":"${banlist[i]['Nick']}","ID":"${banlist[i]['ID']}"}`;
banlist = String(JSON.stringify(banlist));
rewrite = banlist.replace(unbanObj, '');
file.writeTo(path, rewrite)
pl.tell('[EBan] ' + Format.Green + 'Success!');
}
}
}, 1);
mc.regConsoleCmd("unban", "unban player", function(args) {
if (args[0] !== undefined) {
let banlist = JSON.parse(file.readFrom(path));
for (let i = 0; i < banlist.length; i++) {
if (args[0] === banlist[i]['Nick']) {
unbanObj = `,{"Nick":"${banlist[i]['Nick']}","ID":"${banlist[i]['ID']}"}`;
banlist = String(JSON.stringify(banlist));
rewrite = banlist.replace(unbanObj, '');
file.writeTo(path, rewrite)
log('[EBan] ' + 'Success!')
}
}
}
});
mc.regConsoleCmd("elist", "check ban players", function(args) {
let banlist = JSON.parse(file.readFrom(path));
for (let i = 0; i < banlist.length; i++) {
log('banned player: ' + banlist[i]['Nick'])
}
});
mc.listen("onJoin", function(pl) {
let banlist = JSON.parse(file.readFrom(path));
for (let i = 0; i < banlist.length; i++) {
if ((pl.getDevice().clientId === banlist[i]['ID'])) {
pl.kick(Format.Red + 'U have been banned');
}
}
});