feat(cli): add construct:new command

This commit is contained in:
ForestOfLight
2026-05-19 21:26:34 -07:00
Unverified
parent 4d07e2e1ae
commit 50ed8c3e02
4 changed files with 59 additions and 0 deletions
+46
View File
@@ -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();
+1
View File
@@ -11,6 +11,7 @@ import './classes/MenuItemHandler';
// Commands // Commands
import './commands/ConstructCommand'; import './commands/ConstructCommand';
import './commands/NewCommand';
// Other // Other
import './classes/BlockInfo'; import './classes/BlockInfo';
+6
View File
@@ -110,3 +110,9 @@ construct.option.materialgrabber.grabbed.many=§aGrabbed %s items. ## Insert str
## CLI shared errors ## CLI shared errors
construct.commands.error.instanceNotFound=§cInstance "%1" not found. construct.commands.error.instanceNotFound=§cInstance "%1" not found.
construct.commands.error.notAPlayer=§cThis command can only be used by players. 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.
+6
View File
@@ -110,3 +110,9 @@ construct.option.materialgrabber.grabbed.many=§a已收集 %s 个物品 ## 插
## CLI shared errors ## CLI shared errors
construct.commands.error.instanceNotFound=§cInstance "%1" not found. construct.commands.error.instanceNotFound=§cInstance "%1" not found.
construct.commands.error.notAPlayer=§cThis command can only be used by players. 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.