feat(informer): various improvements and fixes

Feat:
- Letter aliases for subcommands.
- Most recent command when no input.
- Start player relative info stub.

Fix:
- Player username not shown.
This commit is contained in:
jay 2021-03-23 15:14:13 +05:00
parent 0757776d8b
commit 72c4622091
2 changed files with 26 additions and 7 deletions

View File

@ -331,7 +331,7 @@ function command(username, message) {
} }
break break
case "info": case "info":
cfg.plugins.informer.command(message_parts.splice(1)) cfg.plugins.informer.command(message_parts.splice(1), player)
break break
// case "use": // case "use":
// bot.useOn(bot.nearestEntity()) // bot.useOn(bot.nearestEntity())

View File

@ -1,6 +1,7 @@
let cfg let cfg
let bot let bot
let mcData let mcData
// import v from 'vec3'
const v = require('vec3') const v = require('vec3')
function block(pos) { function block(pos) {
@ -51,34 +52,47 @@ function item(
} }
function entity(name) { function entity(name) {
const entity = bot.nearestEntity((entity) => { const entity = typeof name === "string" ? bot.nearestEntity((entity) => {
const ename = entity.name || entity.username const ename = entity.name || entity.username
return name && ename ? ename == name : true return name && ename ? ename == name : true
}) }) : entity
console.log(entity) console.log(entity)
if (!entity) { if (!entity) {
cfg.quiet || bot.chat("no entity") cfg.quiet || bot.chat("no entity")
return entity return entity
} }
let info = [entity.type, entity.name || entity.username] let info = [entity.type, entity.username || entity.name]
// TODO various info depending on the type of entity; player, villager, etc
if (entity.metadata) info.push("len: " + entity.metadata.length) if (entity.metadata) info.push("len: " + entity.metadata.length)
cfg.quiet || bot.chat(info.join("; ")) cfg.quiet || bot.chat(info.join("; "))
return entity
} }
function command(message_parts) { function command(message_parts, player) {
if (message_parts.length > 0) {
cfg.info.recentCommand = message_parts
}
switch (message_parts.length) { switch (message_parts.length) {
case 0: case 0:
// TODO most recent command? if (cfg.info.recentCommand) {
block() command(cfg.info.recentCommand, player)
} else {
// TODO dispatch on instance of entity, block, etc..
// TODO have the logic inside the function or with a utility function
block(player.position || player?.entity.position || null)
}
break; break;
case 1: case 1:
switch (message_parts[0]) { switch (message_parts[0]) {
case "i":
case "item": case "item":
item() item()
break break
case "e":
case "entity": case "entity":
entity() entity()
break break
case "b":
case "block": case "block":
default: default:
block() block()
@ -89,9 +103,11 @@ function command(message_parts) {
case 2: case 2:
switch (message_parts[0]) { switch (message_parts[0]) {
case "i":
case "item": case "item":
item(message_parts[1]) item(message_parts[1])
break break
case "e":
case "entity": case "entity":
default: default:
entity(message_parts[1]) entity(message_parts[1])
@ -101,6 +117,7 @@ function command(message_parts) {
case 4: case 4:
switch (message_parts[0]) { switch (message_parts[0]) {
case "b":
case "block": case "block":
default: default:
block(message_parts.slice(1)) block(message_parts.slice(1))
@ -110,6 +127,7 @@ function command(message_parts) {
break; break;
default: default:
cfg.quiet || bot.chat("info: unknown command")
break; break;
} }
} }
@ -119,6 +137,7 @@ const load = (config) => {
bot = cfg.bot bot = cfg.bot
cfg.info = { cfg.info = {
quiet: cfg.quiet, quiet: cfg.quiet,
recentCommand: null,
} }
mcData = bot.mcData || (bot.mcData = require('minecraft-data')(bot.version)) mcData = bot.mcData || (bot.mcData = require('minecraft-data')(bot.version))
} }