From 993ffcedddce718bda3f9c57ee199cd577c1ac16 Mon Sep 17 00:00:00 2001 From: ForestOfLight Date: Wed, 20 May 2026 03:03:40 -0700 Subject: [PATCH] feat(cli): add construct:stats command --- packs/BP/scripts/commands/StatsCommand.js | 38 +++++++++++++++++++++++ packs/BP/scripts/main.js | 1 + packs/RP/texts/en_US.lang | 4 +++ packs/RP/texts/zh_CN.lang | 4 +++ 4 files changed, 47 insertions(+) create mode 100644 packs/BP/scripts/commands/StatsCommand.js diff --git a/packs/BP/scripts/commands/StatsCommand.js b/packs/BP/scripts/commands/StatsCommand.js new file mode 100644 index 0000000..c68de26 --- /dev/null +++ b/packs/BP/scripts/commands/StatsCommand.js @@ -0,0 +1,38 @@ +import { CustomCommandParamType, CustomCommandStatus, system } from '@minecraft/server'; +import { Command } from '../classes/Commands/Command'; +import { findInstance } from '../classes/Commands/lib/findInstance'; +import { commandError } from '../classes/Commands/lib/commandError'; +import { InstanceFormBuilder } from '../classes/Instance/InstanceFormBuilder'; + +export class StatsCommand extends Command { + constructor() { + super({ + name: 'stats', + description: 'construct.commands.stats', + mandatoryParameters: [ + { name: 'instanceName', type: CustomCommandParamType.String } + ], + callback: (source, instanceName) => this.run(source, instanceName) + }); + } + + run(source, instanceName) { + try { + const instance = findInstance(source, instanceName); + if (!instance) return { status: CustomCommandStatus.Failure }; + system.run(async () => { + try { + const { stats } = await InstanceFormBuilder.buildStatistics(instance); + source.sendMessage(stats); + } catch (err) { + source.sendMessage({ translate: 'construct.commands.stats.alreadyRunning' }); + } + }); + return { status: CustomCommandStatus.Success }; + } catch (err) { + return commandError(source, err); + } + } +} + +export const statsCommand = new StatsCommand(); diff --git a/packs/BP/scripts/main.js b/packs/BP/scripts/main.js index 3c97ef5..cee0a1e 100644 --- a/packs/BP/scripts/main.js +++ b/packs/BP/scripts/main.js @@ -24,6 +24,7 @@ import './commands/PrevLayerCommand'; import './commands/VerifierCommand'; import './commands/OptionCommand'; import './commands/InfoCommand'; +import './commands/StatsCommand'; // Other import './classes/BlockInfo'; diff --git a/packs/RP/texts/en_US.lang b/packs/RP/texts/en_US.lang index 44f8892..3db5aa0 100644 --- a/packs/RP/texts/en_US.lang +++ b/packs/RP/texts/en_US.lang @@ -178,3 +178,7 @@ construct.commands.info.noLocation=§7Location:§r (none) construct.commands.info.layer=§7Layer:§r %1 / %2 construct.commands.info.verifier=§7Verifier:§r %1 construct.commands.info.bounds=§7Bounds:§r (%1, %2, %3) -> (%4, %5, %6) + +## construct:stats +construct.commands.stats=Run the structure verifier and print statistics. +construct.commands.stats.alreadyRunning=§cA verification is already in progress. diff --git a/packs/RP/texts/zh_CN.lang b/packs/RP/texts/zh_CN.lang index b752943..4af099d 100644 --- a/packs/RP/texts/zh_CN.lang +++ b/packs/RP/texts/zh_CN.lang @@ -178,3 +178,7 @@ construct.commands.info.noLocation=§7Location:§r (none) construct.commands.info.layer=§7Layer:§r %1 / %2 construct.commands.info.verifier=§7Verifier:§r %1 construct.commands.info.bounds=§7Bounds:§r (%1, %2, %3) -> (%4, %5, %6) + +## construct:stats +construct.commands.stats=Run the structure verifier and print statistics. +construct.commands.stats.alreadyRunning=§cA verification is already in progress.