feat(cli): add construct:stats command
This commit is contained in:
@@ -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();
|
||||
@@ -24,6 +24,7 @@ import './commands/PrevLayerCommand';
|
||||
import './commands/VerifierCommand';
|
||||
import './commands/OptionCommand';
|
||||
import './commands/InfoCommand';
|
||||
import './commands/StatsCommand';
|
||||
|
||||
// Other
|
||||
import './classes/BlockInfo';
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user