feat(cli): add construct:layer command
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
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 LayerCommand extends Command {
|
||||
constructor() {
|
||||
super({
|
||||
name: 'layer',
|
||||
description: 'construct.commands.layer',
|
||||
mandatoryParameters: [
|
||||
{ name: 'instanceName', type: CustomCommandParamType.String },
|
||||
{ name: 'layer', type: CustomCommandParamType.Integer }
|
||||
],
|
||||
callback: (source, instanceName, layer) => this.run(source, instanceName, layer)
|
||||
});
|
||||
}
|
||||
|
||||
run(source, instanceName, layer) {
|
||||
try {
|
||||
const instance = findInstance(source, instanceName);
|
||||
if (!instance) return { status: CustomCommandStatus.Failure };
|
||||
const max = instance.getMaxLayer();
|
||||
if (layer < 0 || layer > max) {
|
||||
system.run(() => source.sendMessage({
|
||||
rawtext: [{ translate: 'construct.commands.layer.outOfBounds',
|
||||
with: [String(layer), instanceName, String(max)] }]
|
||||
}));
|
||||
return { status: CustomCommandStatus.Failure };
|
||||
}
|
||||
system.run(() => {
|
||||
instance.setLayer(layer);
|
||||
source.sendMessage({
|
||||
rawtext: [{ translate: 'construct.commands.layer.success',
|
||||
with: [instanceName, String(layer)] }]
|
||||
});
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
} catch (err) {
|
||||
return commandError(source, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const layerCommand = new LayerCommand();
|
||||
@@ -18,6 +18,7 @@ import './commands/ListCommand';
|
||||
import './commands/PlaceCommand';
|
||||
import './commands/MoveCommand';
|
||||
import './commands/ActiveCommand';
|
||||
import './commands/LayerCommand';
|
||||
|
||||
// Other
|
||||
import './classes/BlockInfo';
|
||||
|
||||
@@ -145,3 +145,8 @@ construct.commands.move.posRequired=§cMust provide coordinates when not running
|
||||
construct.commands.active=Enable or disable an instance.
|
||||
construct.commands.active.success=§aSet instance "%1" active=%2.
|
||||
construct.commands.error.noLocation=§cInstance "%1" has no saved location.
|
||||
|
||||
## construct:layer
|
||||
construct.commands.layer=Set the active layer of an instance (0 = whole structure).
|
||||
construct.commands.layer.success=§aSet instance "%1" layer to %2.
|
||||
construct.commands.layer.outOfBounds=§cLayer %1 is out of bounds for instance "%2" (max %3).
|
||||
|
||||
@@ -145,3 +145,8 @@ construct.commands.move.posRequired=§cMust provide coordinates when not running
|
||||
construct.commands.active=Enable or disable an instance.
|
||||
construct.commands.active.success=§aSet instance "%1" active=%2.
|
||||
construct.commands.error.noLocation=§cInstance "%1" has no saved location.
|
||||
|
||||
## construct:layer
|
||||
construct.commands.layer=Set the active layer of an instance (0 = whole structure).
|
||||
construct.commands.layer.success=§aSet instance "%1" layer to %2.
|
||||
construct.commands.layer.outOfBounds=§cLayer %1 is out of bounds for instance "%2" (max %3).
|
||||
|
||||
Reference in New Issue
Block a user