diff --git a/packs/BP/scripts/commands/NewCommand.js b/packs/BP/scripts/commands/NewCommand.js new file mode 100644 index 0000000..977f122 --- /dev/null +++ b/packs/BP/scripts/commands/NewCommand.js @@ -0,0 +1,46 @@ +import { CustomCommandParamType, CustomCommandStatus, system } from '@minecraft/server'; +import { Command } from '../classes/Commands/Command'; +import { structureCollection } from '../classes/Structure/StructureCollection'; +import { commandError } from '../classes/Commands/lib/commandError'; + +export class NewCommand extends Command { + constructor() { + super({ + name: 'new', + description: 'construct.commands.new', + mandatoryParameters: [ + { name: 'instanceName', type: CustomCommandParamType.String }, + { name: 'structureId', type: CustomCommandParamType.String } + ], + callback: (source, instanceName, structureId) => this.run(source, instanceName, structureId) + }); + } + + run(source, instanceName, structureId) { + try { + if (structureCollection.has(instanceName)) { + system.run(() => source.sendMessage({ + rawtext: [{ translate: 'construct.commands.new.duplicateName', with: [instanceName] }] + })); + return { status: CustomCommandStatus.Failure }; + } + if (!structureCollection.getWorldStructureIds().includes(structureId)) { + system.run(() => source.sendMessage({ + rawtext: [{ translate: 'construct.commands.new.unknownStructure', with: [structureId] }] + })); + return { status: CustomCommandStatus.Failure }; + } + system.run(() => { + structureCollection.add(instanceName, structureId); + source.sendMessage({ + rawtext: [{ translate: 'construct.commands.new.success', with: [instanceName, structureId] }] + }); + }); + return { status: CustomCommandStatus.Success }; + } catch (err) { + return commandError(source, err); + } + } +} + +export const newCommand = new NewCommand(); diff --git a/packs/BP/scripts/main.js b/packs/BP/scripts/main.js index ba6b6f9..d7c612e 100644 --- a/packs/BP/scripts/main.js +++ b/packs/BP/scripts/main.js @@ -11,6 +11,7 @@ import './classes/MenuItemHandler'; // Commands import './commands/ConstructCommand'; +import './commands/NewCommand'; // Other import './classes/BlockInfo'; diff --git a/packs/RP/texts/en_US.lang b/packs/RP/texts/en_US.lang index dde3495..02d57ab 100644 --- a/packs/RP/texts/en_US.lang +++ b/packs/RP/texts/en_US.lang @@ -110,3 +110,9 @@ construct.option.materialgrabber.grabbed.many=§aGrabbed %s items. ## Insert str ## CLI shared errors construct.commands.error.instanceNotFound=§cInstance "%1" not found. construct.commands.error.notAPlayer=§cThis command can only be used by players. + +## construct:new +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. diff --git a/packs/RP/texts/zh_CN.lang b/packs/RP/texts/zh_CN.lang index d978e39..181b8d8 100644 --- a/packs/RP/texts/zh_CN.lang +++ b/packs/RP/texts/zh_CN.lang @@ -110,3 +110,9 @@ construct.option.materialgrabber.grabbed.many=§a已收集 %s 个物品 ## 插 ## CLI shared errors construct.commands.error.instanceNotFound=§cInstance "%1" not found. construct.commands.error.notAPlayer=§cThis command can only be used by players. + +## construct:new +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.