forked from sefirosweb/minecraftLegion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateNewBot.js
61 lines (52 loc) · 1.63 KB
/
createNewBot.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
const fs = require("fs");
const util = require("util");
const copyFile = util.promisify(fs.copyFile);
const accessFile = util.promisify(fs.access);
require("module-alias/register");
const mineflayer = require("mineflayer");
const botWebsocket = require("@modules/botWebsocket");
const createNewBot = (botName, botPassword = "", server, port, customStart) => {
const bot = mineflayer.createBot({
username: botName,
host: server,
port: port,
});
botWebsocket.loadBot(bot);
bot.setMaxListeners(0);
bot.once("inject_allowed", () => {
bot.loadPlugin(require("mineflayer-pathfinder").pathfinder);
});
bot.once("kicked", (reason) => {
const reasonDecoded = JSON.parse(reason);
console.log(reasonDecoded);
process.exit();
});
bot.once("error", (error) => {
botWebsocket.log("Error bot detected " + JSON.stringify(error));
console.log(error);
process.exit();
});
bot.once("spawn", async () => {
console.log(bot.version);
botWebsocket.connect();
botWebsocket.log("Ready!");
if (customStart) {
const customFilePath = "./custom_start/custom.js";
accessFile(customFilePath)
.catch((err) => {
const exampleFile = "./custom_start/custom_example.js";
return copyFile(exampleFile, customFilePath);
})
.then(() => {
const customStart = require(customFilePath)(bot);
return customStart.start();
})
.then(() => {
require("@NestedStateModules/startStateMachine")(bot);
});
} else {
require("@NestedStateModules/startStateMachine")(bot);
}
});
}
module.exports = createNewBot