feat: rework commands and fix bugs
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user