Skip to content

Commit

Permalink
Fix when save config
Browse files Browse the repository at this point in the history
  • Loading branch information
sefirosweb committed Apr 1, 2024
1 parent c70288a commit 056fe16
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
27 changes: 16 additions & 11 deletions core/src/modules/botConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion core/src/modules/botWebsocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<BotFriends> = []
Expand Down

0 comments on commit 056fe16

Please sign in to comment.