feat: update sleeper

nogameplay
jay 3 years ago
parent 5ead6b7267
commit 8eb6d790b0
  1. 12
      lib/plugins/sleeper.js

@ -1,6 +1,6 @@
const pathfinder = require('mineflayer-pathfinder').pathfinder let pathfinder
const { Bot } = require('mineflayer') //TODO replace with simple pathfinder motions
const { const {
gameplay, gameplay,
MoveTo, MoveTo,
@ -71,6 +71,7 @@ function sleep(quiet) {
) )
// bot.chat('/afk') // bot.chat('/afk')
} }
bot.pathfinder.movements
} }
function wake() { function wake() {
@ -86,7 +87,7 @@ function wake() {
function autoSleep() { function autoSleep() {
if (!bot.time.isDay && !cfg.sleep.timeoutFn && cfg.sleep.auto && !bot.isSleeping) { if (!bot.time.isDay && !cfg.sleep.timeoutFn && cfg.sleep.auto && !bot.isSleeping) {
sleep() sleep()
cfg.sleep.timeoutFn = setTimeout(() => { cfg.sleep.timeoutFn = null }, cfg.sleep.timeout) // give 2 seconds for multiple events cfg.sleep.timeoutFn = setTimeout(() => { cfg.sleep.timeoutFn = null }, cfg.sleep.timeout)
console.log("sleeping?", bot.isSleeping, bot.time) console.log("sleeping?", bot.isSleeping, bot.time)
} }
} }
@ -98,10 +99,11 @@ const load = (config) => {
auto: true, auto: true,
// timeout: 30 * 1000, // timeout: 30 * 1000,
timeout: 2 * 60 * 1000, timeout: 2 * 60 * 1000,
quiet: false quiet: !!cfg.quiet
} }
bot.loadPlugin(pathfinder) pathfinder = bot.pathfinder || require('mineflayer-pathfinder').pathfinder
// bot.loadPlugin(pathfinder)
bot.loadPlugin(gameplay) bot.loadPlugin(gameplay)
inv = cfg.plugins["inventory"] inv = cfg.plugins["inventory"]
bot.on("time", autoSleep) bot.on("time", autoSleep)

Loading…
Cancel
Save