diff --git a/packs/BP/scripts/commands/DeleteCommand.js b/packs/BP/scripts/commands/DeleteCommand.js new file mode 100644 index 0000000..7799fda --- /dev/null +++ b/packs/BP/scripts/commands/DeleteCommand.js @@ -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(); diff --git a/packs/BP/scripts/main.js b/packs/BP/scripts/main.js index d7c612e..18e60b0 100644 --- a/packs/BP/scripts/main.js +++ b/packs/BP/scripts/main.js @@ -12,6 +12,7 @@ import './classes/MenuItemHandler'; // Commands import './commands/ConstructCommand'; import './commands/NewCommand'; +import './commands/DeleteCommand'; // Other import './classes/BlockInfo'; diff --git a/packs/RP/texts/en_US.lang b/packs/RP/texts/en_US.lang index 02d57ab..aee85a1 100644 --- a/packs/RP/texts/en_US.lang +++ b/packs/RP/texts/en_US.lang @@ -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.duplicateName=§cAn instance named "%1" already exists. 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". diff --git a/packs/RP/texts/zh_CN.lang b/packs/RP/texts/zh_CN.lang index 181b8d8..246b4ed 100644 --- a/packs/RP/texts/zh_CN.lang +++ b/packs/RP/texts/zh_CN.lang @@ -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.duplicateName=§cAn instance named "%1" already exists. 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".