CustomCommandBuilder.ts
import {CommandPermissionLevel, CustomCommand, CustomCommandParameter} from "@minecraft/server";
/**
* @example commandRegistry.registerEnum("test:my_enum,["foo","bar","baz"]);
* const testCommand = new CustomCommandBuilder("test:test","Used for test.","CustomCommandPermissionLevel.Any").setMandatoryParam([
* {type: CustomCommandParamType.Enum,
* name: "test:my_enum"
* }])
*/
export class CustomCommandBuilder implements CustomCommand {
name: string;
description: string;
permissionLevel: CommandPermissionLevel;
/**
*@description コマンドを実行する際に必須のパラメータ。
*@example /namespace:name mandatory_enum1 mandatory_enum2 optional_enum1
*@remarks mandatory_enum1に応じてmandatory_enum2を変えることができません。共通のenumを使用することになります。
*/
mandatoryParameters?: CustomCommandParameter[] | undefined;
/**
* @description コマンドを実行する際の省略可能のパラメータ。
*@example /namespace:name mandatory_enum1 mandatory_enum2 optional_enum1
*@remarks mandatory_enum1に応じてmandatory_enum2を変えることができません。共通のenumを使用することになります。
*/
optionalParameters?: CustomCommandParameter[] | undefined;
cheatsRequired?: boolean | undefined;
constructor(name: string, description: string, permissionLevel?: CommandPermissionLevel) {
this.name = name;
this.description = description;
if (!permissionLevel) {
this.permissionLevel = CommandPermissionLevel.Any;
} else {
this.permissionLevel = permissionLevel;
}
}
setMandatoryParam(mandatoryParameters: CustomCommandParameter[]) {
this.mandatoryParameters = mandatoryParameters;
}
setOptionalParam(optionalParameters: CustomCommandParameter[]) {
this.optionalParameters = optionalParameters;
}
setCheatsRequired(cheatsRequired: boolean) {
this.cheatsRequired = cheatsRequired;
}
}