feat: rework commands and fix bugs

This commit is contained in:
ForestOfLight
2026-05-20 17:08:03 -07:00
Unverified
parent b1370b5d28
commit 7ea64d1e6a
38 changed files with 527 additions and 525 deletions
+9 -21
View File
@@ -1,8 +1,6 @@
import { CustomCommandParamType, CustomCommandStatus, system } from '@minecraft/server';
import { Command } from '../classes/Commands/Command';
import { CommandPermissionLevel, CustomCommandParamType, CustomCommandStatus, system } from '@minecraft/server';
import { structureCollection } from '../classes/Structure/StructureCollection';
import { findInstance } from '../classes/Commands/lib/findInstance';
import { commandError } from '../classes/Commands/lib/commandError';
export class RenameCommand extends Command {
constructor() {
@@ -13,30 +11,20 @@ export class RenameCommand extends Command {
{ name: 'instanceName', type: CustomCommandParamType.String },
{ name: 'newName', type: CustomCommandParamType.String }
],
permissionLevel: CommandPermissionLevel.Any,
callback: (source, instanceName, newName) => this.run(source, instanceName, newName)
});
}
run(source, instanceName, newName) {
try {
const instance = findInstance(source, instanceName);
if (!instance) return { status: CustomCommandStatus.Failure };
if (structureCollection.has(newName)) {
system.run(() => source.sendMessage({
rawtext: [{ translate: 'construct.commands.rename.duplicateName', with: [newName] }]
}));
return { status: CustomCommandStatus.Failure };
}
system.run(() => {
structureCollection.rename(instanceName, newName);
source.sendMessage({
rawtext: [{ translate: 'construct.commands.rename.success', with: [instanceName, newName] }]
});
});
return { status: CustomCommandStatus.Success };
} catch (err) {
return commandError(source, err);
const instance = structureCollection.get(instanceName);
if (structureCollection.has(newName)) {
source.sendMessage({ translate: 'construct.error.instanceExists', with: [newName] });
return void 0;
}
structureCollection.rename(instanceName, newName);
source.sendMessage({ translate: 'construct.commands.rename.success', with: [instanceName, newName] });
return { status: CustomCommandStatus.Success };
}
}