feat: rework commands and fix bugs
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
import { CustomCommandParamType, CustomCommandStatus, system } from '@minecraft/server';
|
||||
import { CommandPermissionLevel, CustomCommandParamType, CustomCommandStatus, system } from '@minecraft/server';
|
||||
import { Command } from '../classes/Commands/Command';
|
||||
import { PlayerCommandOrigin } from '../classes/Commands/PlayerCommandOrigin';
|
||||
import { BuilderOptions } from '../classes/Builder/BuilderOptions';
|
||||
import { requirePlayer } from '../classes/Commands/lib/requirePlayer';
|
||||
import { commandError } from '../classes/Commands/lib/commandError';
|
||||
|
||||
export class OptionCommand extends Command {
|
||||
constructor() {
|
||||
@@ -18,29 +16,22 @@ export class OptionCommand extends Command {
|
||||
enums: [
|
||||
{ name: 'optionId', values: ['easyPlace', 'fastEasyPlace', 'materialGrabber'] }
|
||||
],
|
||||
permissionLevel: CommandPermissionLevel.Any,
|
||||
callback: (source, optionId, state) => this.run(source, optionId, state)
|
||||
});
|
||||
}
|
||||
|
||||
run(source, optionId, state) {
|
||||
try {
|
||||
const player = requirePlayer(source);
|
||||
if (!BuilderOptions.get(optionId)) {
|
||||
system.run(() => source.sendMessage({
|
||||
rawtext: [{ translate: 'construct.commands.option.unknownOption', with: [optionId] }]
|
||||
}));
|
||||
return { status: CustomCommandStatus.Failure };
|
||||
}
|
||||
system.run(() => {
|
||||
BuilderOptions.setValue(optionId, player.id, state);
|
||||
source.sendMessage({
|
||||
rawtext: [{ translate: 'construct.commands.option.success', with: [optionId, String(state)] }]
|
||||
});
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
} catch (err) {
|
||||
return commandError(source, err);
|
||||
if (!BuilderOptions.get(optionId)) {
|
||||
source.sendMessage({ translate: 'construct.commands.option.unknownOption', with: [optionId] });
|
||||
return void 0;
|
||||
}
|
||||
system.run(() => {
|
||||
const player = source.getSource();
|
||||
BuilderOptions.setValue(optionId, player.id, state);
|
||||
source.sendMessage({ translate: 'construct.commands.option.success', with: [optionId, String(state)] });
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user