'use strict'; //enables Javascript's strict mode...enforces stricter error handling for cleaner code const {sleep} = require('../utils'); //require() enables other files to be loaded in. (..) goes up one folder in the filepath const conf = require('../conf'); const {CJbot} = require('../model/minecraft'); const inventoryViewer = require('mineflayer-web-inventory'); const commands = require('./commands'); const {onJoin} = require('./player_list') for(let name in conf.mc.bots){ //navigates to object in mc-bot-town/nodejs/conf/base.js if(CJbot.bots[name]) continue; //Checks if the bot name in mc-bot-town/nodejs/conf/base.js is already present in the CJbot class (located in mc-bot-town-2/nodejs/model/minecraft.js). If it does, it skips over this if statement. let bot = new CJbot({name, host: conf.mc.host, ...conf.mc.bots[name]}); //If not,adds a new bot to the CJbot class, with data from conf.mc.host to provide the bot name, host (server), and other information. //... expands an object into key:value pairs. conf.mc.bots[name] contains information regarding commands, autolog, etc. CJbot.bots[name] = bot; //refers to line 29 in model/minecraft.js. In the CJbot class, an empty object named bots is created. This appends the bot name to this object, and is used to list all available bots. for(let command of conf.mc.bots[name].commands || ['default']){ //Navigates to the commands object in nodejs/conf/base.js and runs lines 19-21 on each command. If no command is found, a list of default commands are used. for(let [name, toAdd] of Object.entries(commands[command])){ //looks at each key:value pair in the commands array. Object.entries returns an array for each keyvalue pair bot.addCommand(name, toAdd) //adss the command to the specified bot in the class CJbot. addCommand is a function defined in model/minecraft.js line 329. } } bot.on('onReady', async function(argument) { // inventoryViewer(bot.bot); onJoin(bot); await sleep(1000); bot.bot.setControlState('jump', true); setTimeout(()=> bot.bot.setControlState('jump', false), 5000) }) // bot.on('message', function(...args){ // console.log('message | ', ...args) // }) } (async ()=>{ try{ for(let name in CJbot.bots){ let bot = CJbot.bots[name]; if(bot.autoConnect){ console.log('Trying to connect', name) console.log('Status for', name, await bot.connect()); await sleep(30000); } } }catch(e){ console.log('!!!!!!!! error:', e) }})() // module.exports = {bot: ez, henry, owen, linda, jimin, nova, ez};