From 056fe16d9ba07b293c1bf974224466efe70bf0db Mon Sep 17 00:00:00 2001 From: Sefirosweb Date: Mon, 1 Apr 2024 02:15:50 +0200 Subject: [PATCH] Fix when save config --- core/src/modules/botConfig.ts | 27 ++++++++++++++++----------- core/src/modules/botWebsocket.ts | 2 +- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/core/src/modules/botConfig.ts b/core/src/modules/botConfig.ts index 9d6cfd7..445dade 100644 --- a/core/src/modules/botConfig.ts +++ b/core/src/modules/botConfig.ts @@ -7,6 +7,20 @@ import _ from 'lodash' let bot: Bot +export const fixConfigTypes = () => { + if (bot.config.sleepArea) { + bot.config.sleepArea = new Vec3(bot.config.sleepArea.x, bot.config.sleepArea.y, bot.config.sleepArea.z) + } + + // Transform JSON raw data into Object types + bot.config.patrol = bot.config.patrol.map(p => new Vec3(p.x, p.y, p.z)) + bot.config.chests = bot.config.chests.map(c => ({ + ...c, + position: new Vec3(c.position.x, c.position.y, c.position.z) + })) + +} + export default (_bot: Bot, botName: string) => { bot = _bot @@ -28,23 +42,14 @@ export default (_bot: Bot, botName: string) => { bot.config = botConfig - if (bot.config.sleepArea) { - bot.config.sleepArea = new Vec3(bot.config.sleepArea.x, bot.config.sleepArea.y, bot.config.sleepArea.z) - } - - // Transform JSON raw data into Object types - bot.config.patrol = bot.config.patrol.map(p => new Vec3(p.x, p.y, p.z)) - bot.config.chests = bot.config.chests.map(c => ({ - ...c, - position: new Vec3(c.position.x, c.position.y, c.position.z) - })) - if (save) { saveBotConfig(botName) } } export const saveBotConfig = async (botName?: string) => { + fixConfigTypes() + const dir = path.join(__dirname, '..', 'botConfig') try { diff --git a/core/src/modules/botWebsocket.ts b/core/src/modules/botWebsocket.ts index aca5168..6c98a35 100644 --- a/core/src/modules/botWebsocket.ts +++ b/core/src/modules/botWebsocket.ts @@ -8,7 +8,7 @@ import { Entity } from 'prismarine-entity' import { Bot } from 'mineflayer' import { connectBotToServer } from '@/modules/connectSocket' import { webSocketQueue } from './queues' -import { saveBotConfig } from './botConfig' +import { fixConfigTypes, saveBotConfig } from './botConfig' let socket: Socket let friends: Array = []