refactor(mover): 🚚 move commands inside mover plugin itself

This reduces the code inside the command plugin.
Most of the logic was only relevant to moving anyway.
Command aliases like `come` and `follow` still remain in command plugin.
This commit is contained in:
jay 2021-01-17 23:59:39 +05:00
parent 7050a1621b
commit cc18ac5c2e
2 changed files with 97 additions and 95 deletions

View File

@ -219,100 +219,7 @@ function command(username, message) {
break; break;
case "move": case "move":
case "go": case "go":
// TODO move most of the subcommands into mover.js? cfg.plugins.mover.command(message_parts.slice(1), player)
const message_parts2 = message_parts.slice(2)
switch (message_parts[1]) {
case "init":
cfg.plugins.mover.initMoves()
break
case "near":
// message_parts2 = message_parts.slice(2)
switch (message_parts2.length) {
case 0:
cfg.plugins.mover.moveNear(bot.nearestEntity().position)
break
case 1:
switch (message_parts2[0]) {
case "me":
if (player) {
cfg.plugins.mover.moveNear(player.position)
} else {
cfg.quiet || bot.chat("can't see you")
}
break;
default:
const aPlayer = bot.players[message_parts[2]] ? bot.players[message_parts[2]].entity : null
if (aPlayer) {
cfg.plugins.mover.moveNear(aPlayer.position)
} else {
cfg.quiet || bot.chat(`can't see ${message_parts[2]}`)
}
break;
}
break
case 2:
//TODO this isn't near
cfg.plugins.mover.moveXZ(message_parts2)
break
case 3:
//TODO more checks
cfg.plugins.mover.moveNear(message_parts2)
break
default:
break
}
break
case "follow":
// message_parts2 = message_parts.slice(2)
switch (message_parts2.length) {
case 0:
cfg.plugins.mover.follow(bot.nearestEntity())
break
case 1:
let dist = 3
switch (message_parts2[0]) {
case "close":
dist = 1
case "me":
case "once":
if (player) {
cfg.plugins.mover.follow(player, message_parts2[0] === "me", dist)
} else {
cfg.quiet || bot.chat("can't see you")
}
break;
default:
const aPlayer = bot.players[message_parts[2]] ? bot.players[message_parts[2]].entity : null
if (aPlayer) {
cfg.plugins.mover.follow(aPlayer)
} else {
cfg.quiet || bot.chat(`can't see ${message_parts[2]}`)
}
break;
}
break
// case 2:
// bot.lookAt({}) goalxz?
// break
// case 3:
//TODO more checks
// cfg.plugins.mover.moveNear(message_parts2)
// break
default:
todo()
break
}
break
case "stop":
cfg.plugins.mover.stop()
break
default:
return todo()
break;
}
break; break;
case "attack": case "attack":

View File

@ -108,6 +108,101 @@ function stop() {
bot.stopDigging() bot.stopDigging()
} }
function command(message_parts, player) {
const message_parts2 = message_parts.slice(1)
switch (message_parts[0]) {
case "init":
initMoves()
break
case "near":
switch (message_parts2.length) {
case 0:
moveNear(bot.nearestEntity().position)
break
case 1:
switch (message_parts2[0]) {
case "me":
if (player) {
moveNear(player.position)
} else {
cfg.quiet || bot.chat("can't see you")
}
break;
default:
const aPlayer = bot.players[message_parts2[0]] ? bot.players[message_parts2[0]].entity : null
if (aPlayer) {
moveNear(aPlayer.position)
} else {
cfg.quiet || bot.chat(`can't see ${message_parts2[0]}`)
}
break;
}
break
case 2:
//TODO this isn't near
moveXZ(message_parts2)
break
case 3:
//TODO more checks
moveNear(message_parts2)
break
default:
break
}
break
case "follow":
// message_parts2 = message_parts.slice(2)
switch (message_parts2.length) {
case 0:
follow(bot.nearestEntity())
break
case 1:
let dist = 3
switch (message_parts2[0]) {
case "close":
dist = 1
case "me":
case "once":
if (player) {
follow(player, message_parts2[0] === "me", dist)
} else {
cfg.quiet || bot.chat("can't see you")
}
break;
default:
const aPlayer = bot.players[message_parts2[0]] ? bot.players[message_parts2[0]].entity : null
if (aPlayer) {
follow(aPlayer)
} else {
cfg.quiet || bot.chat(`can't see ${message_parts2[0]}`)
}
break;
}
break
// case 2:
// bot.lookAt({}) goalxz?
// break
// case 3:
//TODO more checks
// moveNear(message_parts2)
// break
default:
cfg.quiet || bot.chat("unknown or bad command")
break
}
break
case "stop":
stop()
break
default:
return cfg.quiet || bot.chat(`unknown command ${message_parts[0]}`)
break;
}
}
const load = (config) => { const load = (config) => {
cfg = config cfg = config
bot = cfg.bot bot = cfg.bot
@ -133,4 +228,4 @@ const unload = () => {
bot.off('goal_reached', goalReached) bot.off('goal_reached', goalReached)
} }
module.exports = { load, unload, stop, initMoves, moveNear, moveXZ, moveY, follow } module.exports = { load, unload, command, stop, initMoves, moveNear, moveXZ, moveY, follow }