feat(cli): add construct:option command
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { CustomCommandParamType, CustomCommandStatus, system } from '@minecraft/server';
|
||||
import { Command } from '../classes/Commands/Command';
|
||||
import { PlayerCommandOrigin } from '../classes/Commands/PlayerCommandOrigin';
|
||||
import { BuilderOptions } from '../classes/Builder/BuilderOptions';
|
||||
import { requirePlayer } from '../classes/Commands/lib/requirePlayer';
|
||||
import { commandError } from '../classes/Commands/lib/commandError';
|
||||
|
||||
export class OptionCommand extends Command {
|
||||
constructor() {
|
||||
super({
|
||||
name: 'option',
|
||||
description: 'construct.commands.option',
|
||||
allowedSources: [PlayerCommandOrigin],
|
||||
mandatoryParameters: [
|
||||
{ name: 'optionId', type: CustomCommandParamType.Enum },
|
||||
{ name: 'state', type: CustomCommandParamType.Boolean }
|
||||
],
|
||||
enums: [
|
||||
{ name: 'optionId', values: ['easyPlace', 'fastEasyPlace', 'materialGrabber'] }
|
||||
],
|
||||
callback: (source, optionId, state) => this.run(source, optionId, state)
|
||||
});
|
||||
}
|
||||
|
||||
run(source, optionId, state) {
|
||||
try {
|
||||
const player = requirePlayer(source);
|
||||
if (!BuilderOptions.get(optionId)) {
|
||||
system.run(() => source.sendMessage({
|
||||
rawtext: [{ translate: 'construct.commands.option.unknownOption', with: [optionId] }]
|
||||
}));
|
||||
return { status: CustomCommandStatus.Failure };
|
||||
}
|
||||
system.run(() => {
|
||||
BuilderOptions.setValue(optionId, player.id, state);
|
||||
source.sendMessage({
|
||||
rawtext: [{ translate: 'construct.commands.option.success', with: [optionId, String(state)] }]
|
||||
});
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
} catch (err) {
|
||||
return commandError(source, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const optionCommand = new OptionCommand();
|
||||
@@ -22,6 +22,7 @@ import './commands/LayerCommand';
|
||||
import './commands/NextLayerCommand';
|
||||
import './commands/PrevLayerCommand';
|
||||
import './commands/VerifierCommand';
|
||||
import './commands/OptionCommand';
|
||||
|
||||
// Other
|
||||
import './classes/BlockInfo';
|
||||
|
||||
@@ -162,3 +162,8 @@ construct.commands.prevlayer.success=§aInstance "%1" stepped back to layer %2.
|
||||
## construct:verifier
|
||||
construct.commands.verifier=Toggle block validation overlay for an instance.
|
||||
construct.commands.verifier.success=§aSet instance "%1" verifier=%2.
|
||||
|
||||
## construct:option
|
||||
construct.commands.option=Toggle a per-player builder option.
|
||||
construct.commands.option.success=§aSet option "%1" = %2.
|
||||
construct.commands.option.unknownOption=§cUnknown option "%1".
|
||||
|
||||
@@ -162,3 +162,8 @@ construct.commands.prevlayer.success=§aInstance "%1" stepped back to layer %2.
|
||||
## construct:verifier
|
||||
construct.commands.verifier=Toggle block validation overlay for an instance.
|
||||
construct.commands.verifier.success=§aSet instance "%1" verifier=%2.
|
||||
|
||||
## construct:option
|
||||
construct.commands.option=Toggle a per-player builder option.
|
||||
construct.commands.option.success=§aSet option "%1" = %2.
|
||||
construct.commands.option.unknownOption=§cUnknown option "%1".
|
||||
|
||||
Reference in New Issue
Block a user