feat(cli): add construct:info command
This commit is contained in:
@@ -0,0 +1,57 @@
|
|||||||
|
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';
|
||||||
|
|
||||||
|
export class InfoCommand extends Command {
|
||||||
|
constructor() {
|
||||||
|
super({
|
||||||
|
name: 'info',
|
||||||
|
description: 'construct.commands.info',
|
||||||
|
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 };
|
||||||
|
const rawtext = [
|
||||||
|
{ translate: 'construct.commands.info.header', with: [instance.getName()] },
|
||||||
|
{ text: '\n' },
|
||||||
|
{ translate: 'construct.commands.info.structure', with: [instance.getStructureId()] },
|
||||||
|
{ text: '\n' },
|
||||||
|
{ translate: 'construct.commands.info.enabled', with: [String(instance.isEnabled())] },
|
||||||
|
{ text: '\n' }
|
||||||
|
];
|
||||||
|
if (instance.hasLocation()) {
|
||||||
|
const { dimensionId, location } = instance.getLocation();
|
||||||
|
rawtext.push({ translate: 'construct.commands.info.location',
|
||||||
|
with: [String(location.x), String(location.y), String(location.z),
|
||||||
|
dimensionId.replace('minecraft:', '')] });
|
||||||
|
} else {
|
||||||
|
rawtext.push({ translate: 'construct.commands.info.noLocation' });
|
||||||
|
}
|
||||||
|
rawtext.push({ text: '\n' });
|
||||||
|
rawtext.push({ translate: 'construct.commands.info.layer',
|
||||||
|
with: [String(instance.getLayer()), String(instance.getMaxLayer())] });
|
||||||
|
rawtext.push({ text: '\n' });
|
||||||
|
rawtext.push({ translate: 'construct.commands.info.verifier',
|
||||||
|
with: [String(instance.options.verifier.isEnabled)] });
|
||||||
|
rawtext.push({ text: '\n' });
|
||||||
|
const bounds = instance.getBounds();
|
||||||
|
rawtext.push({ translate: 'construct.commands.info.bounds',
|
||||||
|
with: [String(bounds.min.x), String(bounds.min.y), String(bounds.min.z),
|
||||||
|
String(bounds.max.x), String(bounds.max.y), String(bounds.max.z)] });
|
||||||
|
system.run(() => source.sendMessage({ rawtext }));
|
||||||
|
return { status: CustomCommandStatus.Success };
|
||||||
|
} catch (err) {
|
||||||
|
return commandError(source, err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const infoCommand = new InfoCommand();
|
||||||
@@ -23,6 +23,7 @@ import './commands/NextLayerCommand';
|
|||||||
import './commands/PrevLayerCommand';
|
import './commands/PrevLayerCommand';
|
||||||
import './commands/VerifierCommand';
|
import './commands/VerifierCommand';
|
||||||
import './commands/OptionCommand';
|
import './commands/OptionCommand';
|
||||||
|
import './commands/InfoCommand';
|
||||||
|
|
||||||
// Other
|
// Other
|
||||||
import './classes/BlockInfo';
|
import './classes/BlockInfo';
|
||||||
|
|||||||
@@ -167,3 +167,14 @@ construct.commands.verifier.success=§aSet instance "%1" verifier=%2.
|
|||||||
construct.commands.option=Toggle a per-player builder option.
|
construct.commands.option=Toggle a per-player builder option.
|
||||||
construct.commands.option.success=§aSet option "%1" = %2.
|
construct.commands.option.success=§aSet option "%1" = %2.
|
||||||
construct.commands.option.unknownOption=§cUnknown option "%1".
|
construct.commands.option.unknownOption=§cUnknown option "%1".
|
||||||
|
|
||||||
|
## construct:info
|
||||||
|
construct.commands.info=Print instance details to chat.
|
||||||
|
construct.commands.info.header=§e=== Instance "%1" ===§r
|
||||||
|
construct.commands.info.structure=§7Structure:§r %1
|
||||||
|
construct.commands.info.enabled=§7Enabled:§r %1
|
||||||
|
construct.commands.info.location=§7Location:§r %1 %2 %3 in %4
|
||||||
|
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)
|
||||||
|
|||||||
@@ -167,3 +167,14 @@ construct.commands.verifier.success=§aSet instance "%1" verifier=%2.
|
|||||||
construct.commands.option=Toggle a per-player builder option.
|
construct.commands.option=Toggle a per-player builder option.
|
||||||
construct.commands.option.success=§aSet option "%1" = %2.
|
construct.commands.option.success=§aSet option "%1" = %2.
|
||||||
construct.commands.option.unknownOption=§cUnknown option "%1".
|
construct.commands.option.unknownOption=§cUnknown option "%1".
|
||||||
|
|
||||||
|
## construct:info
|
||||||
|
construct.commands.info=Print instance details to chat.
|
||||||
|
construct.commands.info.header=§e=== Instance "%1" ===§r
|
||||||
|
construct.commands.info.structure=§7Structure:§r %1
|
||||||
|
construct.commands.info.enabled=§7Enabled:§r %1
|
||||||
|
construct.commands.info.location=§7Location:§r %1 %2 %3 in %4
|
||||||
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user