feat(cli): add construct:active command

This commit is contained in:
ForestOfLight
2026-05-19 21:51:11 -07:00
Unverified
parent 38a1c3ccbc
commit 544b5c5d95
4 changed files with 55 additions and 0 deletions
@@ -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();
+1
View File
@@ -17,6 +17,7 @@ import './commands/RenameCommand';
import './commands/ListCommand'; import './commands/ListCommand';
import './commands/PlaceCommand'; import './commands/PlaceCommand';
import './commands/MoveCommand'; import './commands/MoveCommand';
import './commands/ActiveCommand';
// Other // Other
import './classes/BlockInfo'; import './classes/BlockInfo';
+5
View File
@@ -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=Reposition an instance without toggling its enabled state.
construct.commands.move.success=§aMoved instance "%1" to %2 %3 %4 in %5. 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.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.
+5
View File
@@ -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=Reposition an instance without toggling its enabled state.
construct.commands.move.success=§aMoved instance "%1" to %2 %3 %4 in %5. 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.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.