From 72c4622091639edd84d2c0fae14a736ba17fb759 Mon Sep 17 00:00:00 2001 From: jay Date: Tue, 23 Mar 2021 15:14:13 +0500 Subject: [PATCH] feat(informer): :sparkles: 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. --- lib/plugins/command.js | 2 +- lib/plugins/informer.js | 31 +++++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/lib/plugins/command.js b/lib/plugins/command.js index 47cd4a1..bd4b3a0 100644 --- a/lib/plugins/command.js +++ b/lib/plugins/command.js @@ -331,7 +331,7 @@ function command(username, message) { } break case "info": - cfg.plugins.informer.command(message_parts.splice(1)) + cfg.plugins.informer.command(message_parts.splice(1), player) break // case "use": // bot.useOn(bot.nearestEntity()) diff --git a/lib/plugins/informer.js b/lib/plugins/informer.js index 905a46d..3e36a1e 100644 --- a/lib/plugins/informer.js +++ b/lib/plugins/informer.js @@ -1,6 +1,7 @@ let cfg let bot let mcData +// import v from 'vec3' const v = require('vec3') function block(pos) { @@ -51,34 +52,47 @@ function item( } function entity(name) { - const entity = bot.nearestEntity((entity) => { + const entity = typeof name === "string" ? bot.nearestEntity((entity) => { const ename = entity.name || entity.username return name && ename ? ename == name : true - }) + }) : entity console.log(entity) if (!entity) { cfg.quiet || bot.chat("no 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) 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) { case 0: - // TODO most recent command? - block() + if (cfg.info.recentCommand) { + 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; case 1: switch (message_parts[0]) { + case "i": case "item": item() break + case "e": case "entity": entity() break + case "b": case "block": default: block() @@ -89,9 +103,11 @@ function command(message_parts) { case 2: switch (message_parts[0]) { + case "i": case "item": item(message_parts[1]) break + case "e": case "entity": default: entity(message_parts[1]) @@ -101,6 +117,7 @@ function command(message_parts) { case 4: switch (message_parts[0]) { + case "b": case "block": default: block(message_parts.slice(1)) @@ -110,6 +127,7 @@ function command(message_parts) { break; default: + cfg.quiet || bot.chat("info: unknown command") break; } } @@ -119,6 +137,7 @@ const load = (config) => { bot = cfg.bot cfg.info = { quiet: cfg.quiet, + recentCommand: null, } mcData = bot.mcData || (bot.mcData = require('minecraft-data')(bot.version)) }