-
Notifications
You must be signed in to change notification settings - Fork 0
/
MineflayerAPI.js
59 lines (47 loc) · 1.63 KB
/
MineflayerAPI.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
import { WebSocketServer } from 'ws';
import pkg from 'mineflayer';
const {mineflayer} = pkg;
const wss = new WebSocketServer({ port: 7080 });
wss.on('connection', function connection(ws) {
ws.on('error', console.error);
ws.on('message', function message(data) {
startBot(ws)
});
});
function startBot(ws) {
const bot = pkg.createBot({
host: "play.shotbow.net",
port: 25565,
auth: 'microsoft',
username: process.argv[2],
version: '1.12.2',
hideErrors: true
})
bot.on('spawn', () => {
bot.setQuickBarSlot(0);
bot.activateItem();
})
bot.on('windowOpen', (window) => {
console.log('opened window')
if (window.title === '{"text":"Shotbow"}') {
bot.clickWindow(5,0,0);
bot.clickWindow(5,0,0);
} else if (window.title === '{"text":"Select Server"}') {
let message = '';
for (let i = 0; i < 9; i++) {
try {
let map = window.slots[i].customLore[0]?.slice(2); // Can also be voting
let phase = window.slots[i].customLore[1]?.slice(2);
let playerCount = window.slots[i].customLore[2]?.slice(2);
if (phase.startsWith('Phase 3')) {
phase = 'Phase 3' // Removes '(§bPremium§r join privilege)'
}
message = message + '!' + map + ',' + phase + ',' + playerCount
} catch (error) {
}
}
ws.send(message)
bot.end()
}
})
}