diff --git a/bot/Bot.ts b/bot/Bot.ts new file mode 100644 index 0000000..e5d38e6 --- /dev/null +++ b/bot/Bot.ts @@ -0,0 +1,48 @@ +import mc from "minecraft-protocol"; +import { EventEmitter } from "events"; +export class Bot { + public listener = new EventEmitter(); + + public chat: any; + + public bots: Array + + public options: any; + + public entityId: any; + + constructor (options: any, config: any) { + const listener = this.listener; + + this.options = { + host: options.host ??= "localhost", + port: options.port ??= 25565, + version: options.version ??= "1.21.8", + username: options.username ??= "FNFBoyfriendBot" + }; + + this.options = options; + + listener.on("init_client", (packet: any) => { + client?.on('packet', (data: any, meta: any) => { + listener.emit("packet", data, meta); + listener.emit("packet." + meta.name, data) + }); + + client.on('login', (packet: any) => { + this.entityId = packet.entityId; + }); + + client?.on("end", (reason: any) => { + listener.emit("end", reason); + }); + }); + + const client = mc.createClient(options); + + listener.emit('init_client', client); + this.bots = options.bots ?? [listener]; + + return this; + } +} \ No newline at end of file diff --git a/bot/index.ts b/bot/index.ts index e69de29..19ea9bc 100644 --- a/bot/index.ts +++ b/bot/index.ts @@ -0,0 +1,10 @@ +import { Bot } from "./Bot"; + +const config = require('../config.js'); + +let bots = []; + +for (const options of config.bots) { + let bot = new Bot(options, config); + bot.bots.push(bot); +} \ No newline at end of file