mc-bot-town/nodejs/controller/guardianFarm.js
2024-10-11 09:46:18 -04:00

54 lines
1.1 KiB
JavaScript

'use strict';
const conf = require('../conf');
const {sleep, nextTick} = require('../utils');
class GuardianFarm{
constructor(args){
this.bot = args.bot;
this.isDangerous = true;
this.isAction = true;
}
async init(){
console.log('GuardianFarm started')
this.onReadyListen = this.bot.on('onReady', async ()=>{
await sleep(3000);
let lastTimeListen = this.bot.bot.time.timeOfDay;
this.onTimeListen = this.bot.bot.on('time', async ()=>{
let isDay = lastTimeListen < this.bot.bot.time.timeOfDay;
lastTimeListen = this.bot.bot.time.timeOfDay;
if(isDay){
await this.onNewDay();
}
});
await this.bot.pluginLoad('Swing');
});
return true;
}
unload(){
this.onReadyListen();
this.onTimeListen();
return true;
}
async onNewDay(){
try{
console.log('GuardianFarm.onNewDay new day!');
await this.bot.pluginUnload('Swing');
await this.bot.pluginLoad('Craft');
await this.bot.pluginUnload('Craft');
await this.bot.pluginLoad('Swing');
}catch(error){
console.error('Error in GuardianFarm.onNewDay:', error);
}
}
}
module.exports = GuardianFarm;