plugins
This commit is contained in:
60
nodejs/controller/swing.js
Normal file
60
nodejs/controller/swing.js
Normal file
@ -0,0 +1,60 @@
|
||||
'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;
|
Reference in New Issue
Block a user