feat(cli): add construct:active command
This commit is contained in:
@@ -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();
|
||||||
@@ -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';
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|||||||
Reference in New Issue
Block a user