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 { CustomCommandParamType, CustomCommandStatus, CommandPermissionLevel, 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 DeleteCommand extends Command {
|
||||
constructor() {
|
||||
@@ -12,24 +10,18 @@ export class DeleteCommand extends Command {
|
||||
mandatoryParameters: [
|
||||
{ name: 'instanceName', type: CustomCommandParamType.String }
|
||||
],
|
||||
permissionLevel: CommandPermissionLevel.Any,
|
||||
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);
|
||||
}
|
||||
const instance = structureCollection.get(instanceName);
|
||||
system.run(() => {
|
||||
structureCollection.delete(instanceName);
|
||||
source.sendMessage({ translate: 'construct.commands.delete.success', with: [instanceName] });
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user