diff --git a/packages/world/src/commands/admin/ability.ts b/packages/world/src/commands/admin/ability.ts new file mode 100644 index 00000000..a75f3c9f --- /dev/null +++ b/packages/world/src/commands/admin/ability.ts @@ -0,0 +1,46 @@ +import { type AbilitySet, CommandPermissionLevel } from "@serenityjs/protocol"; + +import { AbilityEnum, BoolEnum, TargetEnum } from "../enums"; + +import type { World } from "../../world"; + +const register = (world: World) => { + // Register the setblock command + world.commands.register( + "ability", + "Sets the ability of a player", + (_, parameters) => { + // Iterate over the entities + for (const entity of parameters.target.result) { + // Check if the entity is a player + if (!entity.isPlayer()) continue; + + // Get the ability from the parameters + const ability = parameters.ability.result as AbilitySet; + + // Get the ability component + const component = entity.getComponent(ability); + + // Get the enabled value from the parameters + const enabled = parameters.enabled.result === "true"; + + // Set the ability value + component.setCurrentValue(enabled); + } + + return { + message: "Successfully set the ability of the targeted players." + }; + }, + { + target: TargetEnum, + ability: AbilityEnum, + enabled: BoolEnum + }, + { + permission: CommandPermissionLevel.Operator + } + ); +}; + +export default register; diff --git a/packages/world/src/commands/admin/index.ts b/packages/world/src/commands/admin/index.ts index 84e2adb0..66e954c1 100644 --- a/packages/world/src/commands/admin/index.ts +++ b/packages/world/src/commands/admin/index.ts @@ -5,8 +5,18 @@ import FILL from "./fill"; import SUMMON from "./summon"; import KICK from "./kick"; import CLEAR from "./clear"; +import ABILITY from "./ability"; // Define all admin commands -const ADMIN_COMMANDS = [GAMEMODE, SETBLOCK, GIVE, FILL, SUMMON, KICK, CLEAR]; +const ADMIN_COMMANDS = [ + GAMEMODE, + SETBLOCK, + GIVE, + FILL, + SUMMON, + KICK, + CLEAR, + ABILITY +]; export { ADMIN_COMMANDS }; diff --git a/packages/world/src/commands/enums/ability.ts b/packages/world/src/commands/enums/ability.ts new file mode 100644 index 00000000..4ab67e92 --- /dev/null +++ b/packages/world/src/commands/enums/ability.ts @@ -0,0 +1,11 @@ +import { CustomEnum } from "@serenityjs/command"; +import { AbilitySet } from "@serenityjs/protocol"; + +const identifiers = Object.values(AbilitySet); + +class AbilityEnum extends CustomEnum { + public static readonly name = "ability"; + public static readonly options = identifiers; +} + +export { AbilityEnum }; diff --git a/packages/world/src/commands/enums/bool.ts b/packages/world/src/commands/enums/bool.ts new file mode 100644 index 00000000..c8991778 --- /dev/null +++ b/packages/world/src/commands/enums/bool.ts @@ -0,0 +1,8 @@ +import { CustomEnum } from "@serenityjs/command"; + +class BoolEnum extends CustomEnum { + public static readonly name = "bool"; + public static readonly options = ["true", "false"]; +} + +export { BoolEnum }; diff --git a/packages/world/src/commands/enums/index.ts b/packages/world/src/commands/enums/index.ts index 022f4ecb..cb81b913 100644 --- a/packages/world/src/commands/enums/index.ts +++ b/packages/world/src/commands/enums/index.ts @@ -3,3 +3,5 @@ export * from "./gamemode"; export * from "./block"; export * from "./item"; export * from "./entity"; +export * from "./bool"; +export * from "./ability";