From 544b5c5d95e29b4accfa6b5032594ef03098a761 Mon Sep 17 00:00:00 2001 From: ForestOfLight Date: Tue, 19 May 2026 21:51:11 -0700 Subject: [PATCH] feat(cli): add construct:active command --- packs/BP/scripts/commands/ActiveCommand.js | 44 ++++++++++++++++++++++ packs/BP/scripts/main.js | 1 + packs/RP/texts/en_US.lang | 5 +++ packs/RP/texts/zh_CN.lang | 5 +++ 4 files changed, 55 insertions(+) create mode 100644 packs/BP/scripts/commands/ActiveCommand.js diff --git a/packs/BP/scripts/commands/ActiveCommand.js b/packs/BP/scripts/commands/ActiveCommand.js new file mode 100644 index 0000000..b8a9dbb --- /dev/null +++ b/packs/BP/scripts/commands/ActiveCommand.js @@ -0,0 +1,44 @@ +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 ActiveCommand extends Command { + constructor() { + super({ + name: 'active', + description: 'construct.commands.active', + mandatoryParameters: [ + { name: 'instanceName', type: CustomCommandParamType.String }, + { name: 'state', type: CustomCommandParamType.Boolean } + ], + callback: (source, instanceName, state) => this.run(source, instanceName, state) + }); + } + + run(source, instanceName, state) { + try { + const instance = findInstance(source, instanceName); + if (!instance) return { status: CustomCommandStatus.Failure }; + if (state && !instance.hasLocation()) { + system.run(() => source.sendMessage({ + rawtext: [{ translate: 'construct.commands.error.noLocation', with: [instanceName] }] + })); + return { status: CustomCommandStatus.Failure }; + } + system.run(() => { + if (state) instance.enable(); + else instance.disable(); + source.sendMessage({ + rawtext: [{ translate: 'construct.commands.active.success', + with: [instanceName, String(state)] }] + }); + }); + return { status: CustomCommandStatus.Success }; + } catch (err) { + return commandError(source, err); + } + } +} + +export const activeCommand = new ActiveCommand(); diff --git a/packs/BP/scripts/main.js b/packs/BP/scripts/main.js index 59c4141..1b1ee76 100644 --- a/packs/BP/scripts/main.js +++ b/packs/BP/scripts/main.js @@ -17,6 +17,7 @@ import './commands/RenameCommand'; import './commands/ListCommand'; import './commands/PlaceCommand'; import './commands/MoveCommand'; +import './commands/ActiveCommand'; // Other import './classes/BlockInfo'; diff --git a/packs/RP/texts/en_US.lang b/packs/RP/texts/en_US.lang index a9b344c..baa4427 100644 --- a/packs/RP/texts/en_US.lang +++ b/packs/RP/texts/en_US.lang @@ -140,3 +140,8 @@ construct.commands.place.success=§aPlaced instance "%1" at %2 %3 %4 in %5. construct.commands.move=Reposition an instance without toggling its enabled state. construct.commands.move.success=§aMoved instance "%1" to %2 %3 %4 in %5. construct.commands.move.posRequired=§cMust provide coordinates when not running as a player. + +## construct:active +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. diff --git a/packs/RP/texts/zh_CN.lang b/packs/RP/texts/zh_CN.lang index a49666d..1513d74 100644 --- a/packs/RP/texts/zh_CN.lang +++ b/packs/RP/texts/zh_CN.lang @@ -140,3 +140,8 @@ construct.commands.place.success=§aPlaced instance "%1" at %2 %3 %4 in %5. construct.commands.move=Reposition an instance without toggling its enabled state. construct.commands.move.success=§aMoved instance "%1" to %2 %3 %4 in %5. construct.commands.move.posRequired=§cMust provide coordinates when not running as a player. + +## construct:active +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.