feat(cli): add construct:delete command
This commit is contained in:
@@ -0,0 +1,36 @@
|
|||||||
|
import { CustomCommandParamType, CustomCommandStatus, system } from '@minecraft/server';
|
||||||
|
import { Command } from '../classes/Commands/Command';
|
||||||
|
import { structureCollection } from '../classes/Structure/StructureCollection';
|
||||||
|
import { findInstance } from '../classes/Commands/lib/findInstance';
|
||||||
|
import { commandError } from '../classes/Commands/lib/commandError';
|
||||||
|
|
||||||
|
export class DeleteCommand extends Command {
|
||||||
|
constructor() {
|
||||||
|
super({
|
||||||
|
name: 'delete',
|
||||||
|
description: 'construct.commands.delete',
|
||||||
|
mandatoryParameters: [
|
||||||
|
{ name: 'instanceName', type: CustomCommandParamType.String }
|
||||||
|
],
|
||||||
|
callback: (source, instanceName) => this.run(source, instanceName)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
run(source, instanceName) {
|
||||||
|
try {
|
||||||
|
const instance = findInstance(source, instanceName);
|
||||||
|
if (!instance) return { status: CustomCommandStatus.Failure };
|
||||||
|
system.run(() => {
|
||||||
|
structureCollection.delete(instanceName);
|
||||||
|
source.sendMessage({
|
||||||
|
rawtext: [{ translate: 'construct.commands.delete.success', with: [instanceName] }]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return { status: CustomCommandStatus.Success };
|
||||||
|
} catch (err) {
|
||||||
|
return commandError(source, err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const deleteCommand = new DeleteCommand();
|
||||||
@@ -12,6 +12,7 @@ import './classes/MenuItemHandler';
|
|||||||
// Commands
|
// Commands
|
||||||
import './commands/ConstructCommand';
|
import './commands/ConstructCommand';
|
||||||
import './commands/NewCommand';
|
import './commands/NewCommand';
|
||||||
|
import './commands/DeleteCommand';
|
||||||
|
|
||||||
// Other
|
// Other
|
||||||
import './classes/BlockInfo';
|
import './classes/BlockInfo';
|
||||||
|
|||||||
@@ -116,3 +116,7 @@ construct.commands.new=Create a new instance bound to a structure.
|
|||||||
construct.commands.new.success=§aCreated instance "%1" bound to structure "%2".
|
construct.commands.new.success=§aCreated instance "%1" bound to structure "%2".
|
||||||
construct.commands.new.duplicateName=§cAn instance named "%1" already exists.
|
construct.commands.new.duplicateName=§cAn instance named "%1" already exists.
|
||||||
construct.commands.new.unknownStructure=§cNo structure with id "%1" found in the world.
|
construct.commands.new.unknownStructure=§cNo structure with id "%1" found in the world.
|
||||||
|
|
||||||
|
## construct:delete
|
||||||
|
construct.commands.delete=Permanently delete an instance.
|
||||||
|
construct.commands.delete.success=§aDeleted instance "%1".
|
||||||
|
|||||||
@@ -116,3 +116,7 @@ construct.commands.new=Create a new instance bound to a structure.
|
|||||||
construct.commands.new.success=§aCreated instance "%1" bound to structure "%2".
|
construct.commands.new.success=§aCreated instance "%1" bound to structure "%2".
|
||||||
construct.commands.new.duplicateName=§cAn instance named "%1" already exists.
|
construct.commands.new.duplicateName=§cAn instance named "%1" already exists.
|
||||||
construct.commands.new.unknownStructure=§cNo structure with id "%1" found in the world.
|
construct.commands.new.unknownStructure=§cNo structure with id "%1" found in the world.
|
||||||
|
|
||||||
|
## construct:delete
|
||||||
|
construct.commands.delete=Permanently delete an instance.
|
||||||
|
construct.commands.delete.success=§aDeleted instance "%1".
|
||||||
|
|||||||
Reference in New Issue
Block a user