2024-10-11 09:46:18 -04:00

61 lines
1.1 KiB
JavaScript

'use strict';
const conf = require('../conf');
const {sleep} = require('../utils');
class Swing{
constructor(args){
this.bot = args.bot;
this.target = args.target;
this.interval = args.interval;
this.intervalStop;
this.isDangerous = true;
this.isAction = true;
}
async init(){
this.onReadyListen = this.bot.on('onReady', async ()=>{
console.log('Swing.init onReady called');
try{
this.block = this.bot.findBlockBySign('guardian\nattack spot');
await this.goToSpot();
await this.swing();
}catch(error){
console.error('Error in Swing.init:', error)
}
});
return true;
}
unload(){
clearInterval(this.intervalStop);
this.intervalStop = null;
this.onReadyListen();
return true;
}
async goToSpot(){
await this.bot.goTo({
where: this.block,
range: 3,
});
}
async swing(){
this.intervalStop = setInterval(async ()=>{
try{
// console.log('attacking');
await this.bot.bot.attack(
this.bot.bot.nearestEntity(
entity => entity.name.toLowerCase() === 'guardian'
)
);
}catch(error){}
}, 1010);
}
}
module.exports = Swing;