diff --git a/index.js b/index.js index d3b30a9..cf0b652 100644 --- a/index.js +++ b/index.js @@ -2,9 +2,24 @@ import { createClient } from "minecraft-protocol"; import { default as settings } from './settings.json' with {type: "json"} import { generateUser } from './util/usergen.js' import EventEmitter from 'node:events' +import { readdirSync } from "node:fs"; const bots = []; +const bpl = readdirSync('plugins') +for (const plugin of bpl) { + if (!plugin.endsWith('.js')) { + continue + } + try { + import(`./plugins/${plugin}`).then((pluginItem)=>{ + for(const bot of bots){ + pluginItem.load(bot) + } + }) + } catch (e) { console.log(e) } +} + const createBot = function createBot (host, oldId) { const bot = new EventEmitter() bot._client = createClient({ diff --git a/plugins/helloworld.js b/plugins/helloworld.js new file mode 100644 index 0000000..7287595 --- /dev/null +++ b/plugins/helloworld.js @@ -0,0 +1,4 @@ +const load = (b) => { + console.log(`Test plugin loaded on bot ${b.id}`) +} +export { load } \ No newline at end of file