-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters