### Install Centurion with bun Source: https://centurion.paradoxum.dev/guides Use this command to install the Centurion framework and its optional UI package using bun. ```bash bun add @rbxts/centurion bun add @rbxts/centurion-ui # Optional if using a custom UI ``` -------------------------------- ### Install Centurion with npm Source: https://centurion.paradoxum.dev/guides Use this command to install the Centurion framework and its optional UI package using npm. ```bash npm install @rbxts/centurion npm install @rbxts/centurion-ui # Optional if using a custom UI ``` -------------------------------- ### Install Centurion with yarn Source: https://centurion.paradoxum.dev/guides Use this command to install the Centurion framework and its optional UI package using yarn. ```bash yarn add @rbxts/centurion yarn add @rbxts/centurion-ui # Optional if using a custom UI ``` -------------------------------- ### Start Centurion Client Source: https://centurion.paradoxum.dev/guides This code snippet initializes Centurion on the client and optionally starts the CenturionUI. Ensure Centurion is started only once. ```typescript import { Centurion } from "@rbxts/centurion"; import { CenturionUI } from "@rbxts/centurion-ui"; Centurion.client() .start() .then(() => CenturionUI.start(Centurion.client(), {})) .catch((err) => warn("Failed to start Centurion:", err)); ``` -------------------------------- ### Start Centurion Server Source: https://centurion.paradoxum.dev/guides This code snippet initializes Centurion on the server. Ensure Centurion is started only once. ```typescript import { Centurion } from "@rbxts/centurion"; Centurion.server().start(); ``` -------------------------------- ### Registering commands and types Source: https://centurion.paradoxum.dev/guides/registration/commands-and-types Initialize the server and load command and type modules from specified containers before starting the server. ```typescript const server = Centurion.server(); // Load command/type modules server.registry.load(script.Parent.commands); server.registry.load(ReplicatedStorage.types); server.start(); ``` -------------------------------- ### Install Centurion with pnpm Source: https://centurion.paradoxum.dev/guides Use this command to install the Centurion framework and its optional UI package using pnpm. ```bash pnpm add @rbxts/centurion pnpm add @rbxts/centurion-ui # Optional if using a custom UI ``` -------------------------------- ### Install Centurion via Package Managers Source: https://centurion.paradoxum.dev/ Commands to install the core Centurion package and the optional UI component using various package managers. ```shell npm install @rbxts/centurion npm install @rbxts/centurion-ui # Optional if using a custom UI ``` ```shell yarn add @rbxts/centurion yarn add @rbxts/centurion-ui # Optional if using a custom UI ``` ```shell pnpm add @rbxts/centurion pnpm add @rbxts/centurion-ui # Optional if using a custom UI ``` ```shell bun add @rbxts/centurion bun add @rbxts/centurion-ui # Optional if using a custom UI ``` -------------------------------- ### Register Commands and Types on Server Source: https://centurion.paradoxum.dev/guides This example demonstrates how to register commands and types on the server using Centurion's registry. Commands and types are loaded from ModuleScripts and ReplicatedStorage respectively. ```typescript const server = Centurion.server(); // Load all child ModuleScripts under each container const commandContainer = script.Parent.commands; server.registry.load(commandContainer); const typeContainer = ReplicatedStorage.types; server.registry.load(typeContainer); // Any loaded commands and types will then be registered once Centurion is started server.start(); ``` -------------------------------- ### Apply Guard to a Command Source: https://centurion.paradoxum.dev/guides/commands/guards This example shows how to apply the `isAdmin` guard to the `kick` command using the `@Guard` decorator. This ensures only users with UserId 1 can execute the kick command. ```typescript @Register() class KickCommand { @Command({ name: "kick", description: "Kick a player", arguments: [ { name: "player", description: "Player to kick", type: CenturionType.Player } ] }) @Guard(isAdmin) kick(ctx: CommandContext, player: Player) { player.Kick("You have been kicked from the server."); ctx.reply(`Successfully kicked ${player.Name}`); } } ``` -------------------------------- ### Type Mismatch Example Source: https://centurion.paradoxum.dev/guides/commands/defining-commands This example demonstrates a type mismatch where the argument is defined as a string but the parameter expects a number. This will not produce a compile-time error but can lead to runtime issues. Ensure argument and parameter types align for type safety. ```typescript @Command({ name: "echo", description: "Displays text", arguments: [ { name: "text", description: "The text to display", type: CenturionType.String, }, ], }) echo(ctx: CommandContext, text: number) {} ``` -------------------------------- ### ServerDispatcher.run Source: https://centurion.paradoxum.dev/reference/dispatcher Executes a command on the server side. ```APIDOC ## ServerDispatcher.run ### Description Executes a command using the provided path, executor, and text. ### Parameters - **path** (string) - Required - The command’s path - **args** (any) - Required - The arguments to pass to the command - **executor** (object) - Required - The command’s executor ### Response - **Promise** (CommandContext) - Resolves when the command has been executed, containing the execution result. ``` -------------------------------- ### ClientDispatcher.run Source: https://centurion.paradoxum.dev/reference/dispatcher Executes a command on the client side or forwards to the server if applicable. ```APIDOC ## ClientDispatcher.run ### Description Executes a command. If the path points to a server command, the command will be executed on the server. ### Parameters - **path** (string) - Required - The command’s path - **args** (any) - Required - The arguments to pass to the command ### Response - **Promise** (HistoryEntry) - Resolves when the command has been executed, containing the command’s response and the execution time. ``` -------------------------------- ### @Command Decorator Source: https://centurion.paradoxum.dev/reference/decorators Defines a command with specified options. ```APIDOC ## @Command(options) ### Description Defines a command. ### Parameters * **options** : `CommandOptions` - The command’s options. ### Usage ```typescript @Register() class ExampleCommand { @Command({ name: "example", description: "An example command", }) example() { // ... } } ``` ``` -------------------------------- ### BaseRegistry Methods Source: https://centurion.paradoxum.dev/reference/registry Methods for loading modules and registering commands, types, and groups within the registry. ```APIDOC ## load(container, descendants) ### Description Loads all ModuleScript instances in the given container. ### Parameters - **container** (Instance) - Required - The container to iterate over. - **descendants** (boolean) - Required - Whether to load descendants of the container. ## registerCommand(options, callback, group, guards) ### Description Registers a command with the given options and callback. ### Parameters - **options** (Object) - Required - The command options. - **callback** (Function) - Required - The command callback. - **group** (Object) - Optional - The group to register the command under. - **guards** (Array) - Optional - The guards to apply to the command. ## registerType(types) ### Description Registers one or more argument types. ### Parameters - **types** (Object|Array) - Required - The types to register. ## registerGroup(groups) ### Description Registers one or more groups. ### Parameters - **groups** (Object|Array) - Required - The groups to register. ``` -------------------------------- ### Implement Info Command Groups Source: https://centurion.paradoxum.dev/guides/examples Demonstrates grouping commands hierarchically and applying guards to an entire class. ```typescript const isAdmin: CommandGuard = (ctx) => { if (ctx.executor.UserId !== 1) { ctx.error("Insufficient permission!"); return false; } return true; }; @Register({ { name: "info", description: "View info about a user or the server", }, { name: "user", description: "View info about a user", parent: ["info"], }, { name: "server", description: "View info about the server", parent: ["info"], }, }) // Assigning a group to the class will // make all commands in the class belong to that group @Group("info") // Similar to the above, this assigns the // provided guard(s) to all commands in the class @Guard(isAdmin) class InfoCommand { // This command will be executable through // "info user view" once registered! @Command({ name: "view", arguments: [ { name: "player", description: "Player to display information about", type: CenturionType.Player, }, ], }) @Group("user") userView(ctx: CommandContext, player: Player) { ctx.reply(``); } // This command can have the same name as the above command, because it // is grouped under "server" instead. // This command will be executable through // "info server view" once registered! @Command({ name: "view", }) @Group("server") serverView(ctx: CommandContext) { ctx.error("Not implemented!"); } } ``` -------------------------------- ### Register Command with Simple Shortcuts Source: https://centurion.paradoxum.dev/guides/commands/shortcuts Register a command with simple key shortcuts. The command will execute when the user presses the specified key. ```typescript @Register() export class EchoCommand { @Command({ name: "echo", description: "Prints a message", shortcuts: [Enum.KeyCode.E, [Enum.KeyCode.LeftAlt, Enum.KeyCode.E]] }) run(ctx: CommandContext) { print("Echo!"); } } ``` -------------------------------- ### Register Command with Shortcuts and Arguments Source: https://centurion.paradoxum.dev/guides/commands/shortcuts Register a command with shortcuts that can also pass arguments. If arguments are provided via the shortcut, they are passed to the command; otherwise, a default behavior occurs. ```typescript @Register() export class EchoCommand { @Command({ name: "echo", description: "Prints a message", shortcuts: [ Enum.KeyCode.E, { keys: [Enum.KeyCode.LeftAlt, Enum.KeyCode.E], args: ["Hello, world!"] }, ] }) run(ctx: CommandContext, text?: string) { if (text !== undefined) { print(text); } else { print("Echo!"); } } } ``` -------------------------------- ### RegistryPath Methods Source: https://centurion.paradoxum.dev/reference/registry Utility methods for manipulating and querying command paths. ```APIDOC ## RegistryPath.fromString() ### Description Creates a new RegistryPath instance from a string. ## parts() ### Description Returns a copy of the path's parts. ### Returns - (Array) - An array of strings. ## parent() ### Description Gets the parent path of the current path. ### Returns - (RegistryPath) - A RegistryPath instance representing the parent. ``` -------------------------------- ### CommandOptions Interface Source: https://centurion.paradoxum.dev/reference/decorators Defines the options available for the @Command decorator. ```APIDOC ## CommandOptions ### Fields * **name** : `string` - The name of the command. * **aliases** : `string[]?` - An array of aliases for the command. * **description** : `string?` - The command’s description. * **arguments** : `ArgumentOptions[]?` - The command’s arguments. ``` -------------------------------- ### Registering and Defining an Echo Command Source: https://centurion.paradoxum.dev/guides/commands/defining-commands Use the @Register decorator for classes containing commands and the @Command decorator to define individual commands with their name, description, and arguments. Ensure argument types match parameter types for type safety. ```typescript @Register() class EchoCommand { @Command({ name: "echo", description: "Displays text", arguments: [ { name: "text", description: "The text to display", type: CenturionType.String, }, ], }) echo(ctx: CommandContext, text: string) { ctx.reply(text); } } ``` -------------------------------- ### ArgumentOptions Interface Source: https://centurion.paradoxum.dev/reference/decorators Defines the options available for command arguments. ```APIDOC ## ArgumentOptions ### Fields * **name** : `string` - The name of the argument. * **description** : `string` - The argument’s description. * **type** : `string` - The argument’s type. Must be the name of a registered type. * **numArgs** : `number | "rest"` - The number of inputs the argument should accept. This will produce an array of values. If set to `rest`, it will accept all remaining arguments, but can only be used on the last argument. * **optional** : `boolean?` - Whether the argument is optional. * **suggestions** : `string[]?` - An array of suggestions for the argument. These will be added to the suggestions returned by the argument’s type. ``` -------------------------------- ### @Register Decorator Source: https://centurion.paradoxum.dev/reference/decorators Marks a class for registration. Commands and groups within the class will be registered. ```APIDOC ## @Register Decorator ### Description Marks a class for registration. You can also register groups from here. The next time register is called, any commands within the class will be registered. Any groups defined in the decorator will be registered before the commands. ### Usage ```typescript @Register({ groups: [ { name: "example", description: "Example group" } ] }) export class MyCommand { // ... } ``` ``` -------------------------------- ### Implement a Kick Command Source: https://centurion.paradoxum.dev/guides/examples Defines a command with a guard to restrict execution to a specific user ID. ```typescript const isAdmin: CommandGuard = (ctx) => { if (ctx.executor.UserId !== 1) { ctx.error("Insufficient permission!"); return false; } return true; }; @Register() class KickCommand { @Command({ name: "kick", description: "Kick a player", arguments: [ { name: "player", description: "Player to kick", type: CenturionType.Player } ] }) @Guard(isAdmin) kick(ctx: CommandContext, player: Player) { player.Kick("You have been kicked from the server."); ctx.reply(`Successfully kicked ${player.Name}`); } } ``` -------------------------------- ### Using CommandContext to Reply Source: https://centurion.paradoxum.dev/guides/commands/defining-commands Commands receive a CommandContext object as their first argument, which is used to send responses back to the executor. The context provides methods like reply() for sending messages. ```typescript @Command({ name: "hello" }) hello(ctx: CommandContext) { ctx.reply(`Hello, ${ctx.executor.Name}!`); } ``` -------------------------------- ### Registering a Kill Command with Player Argument Source: https://centurion.paradoxum.dev/guides/types/usage Define a command that requires a Player argument. Ensure the Player type is correctly specified and handle cases where the player might not have a Humanoid. ```typescript @Register() class KillCommand { @Command({ name: "kill", description: "Kills a player", arguments: [ { name: "player", description: "Player to kill", type: CenturionType.Player, // Specify the name of the type here }, ], }) kill(ctx: CommandContext, player: Player) { const humanoid = player.Character?.FindFirstChildOfClass("Humanoid"); if (humanoid === undefined) { ctx.error(`${player.Name} does not have a Humanoid`); return; } humanoid.Health = 0; ctx.reply(`Successfully killed ${player.Name}`); } } ``` -------------------------------- ### Define Player Type with TypeBuilder Source: https://centurion.paradoxum.dev/guides/types/defining-types This snippet demonstrates how to create a custom 'player' type using TypeBuilder. It includes logic to transform input strings into Player objects, handling '@me' for the executor and searching for players by name. Suggestions are provided by listing all player names. ```typescript import { BaseRegistry, TransformResult, TypeBuilder } from "@rbxts/centurion"; import { t } from "@rbxts/t"; const playerType = TypeBuilder.create("player") .transform((text, executor) => { if (text === "@me") { return TransformResult.ok(executor); } const player = Players.FindFirstChild(text); if (player === undefined || !classIs(player, "Player")) { return TransformResult.err("Player not found"); } return TransformResult.ok(player); }) .suggestions(() => Players.GetPlayers().map((player) => player.Name)) .build(); export = (registry: BaseRegistry) => { registry.registerType(playerType); } ``` -------------------------------- ### TypeBuilder Class Source: https://centurion.paradoxum.dev/reference/types Provides methods for building and customizing ArgumentType objects. ```APIDOC ## TypeBuilder A helper class for building argument types. ### `create(name)` Instantiates a `TypeBuilder` with the given name. **Parameters** : * `name` - The name of the type. **Returns** : A `TypeBuilder` instance. ### `extend(name, argumentType)` Creates a new `TypeBuilder` with the given name, extending from the provided type. **Parameters** : * `name` - The name of the type. * `argumentType` - The type to extend from. **Returns** : A `TypeBuilder` instance. ### `transform(fn, expensive)` Sets the transformation function for the type. If the `expensive` parameter is `true`, it indicates the transformation function is expensive to compute. If the default interface is used, type-checking will be disabled while typing an argument. **Parameters** : * `fn` - The transformation function. * `expensive` - Whether the transformation function is expensive. **Returns** : The `TypeBuilder` instance. ### `suggestions(fn)` Sets the suggestions function for the type. This function provides a list of suggestions for the type. **Parameters** : * `fn` - The suggestions function. **Returns** : The `TypeBuilder` instance. ### `markForRegistration()` Marks the type for registration. **Returns** : The `TypeBuilder` instance. ### `build()` Builds the type, returning an ArgumentType object. If the type has been marked for registration through markForRegistration, it will be added to the list of objects that will be registered when register is called. **Throws** : Will throw an error if the required functions were not defined **Returns** : An ArgumentType object. ``` -------------------------------- ### Group Options Structure Source: https://centurion.paradoxum.dev/reference/registry Defines the structure for group options. ```APIDOC ## `GroupOptions` ### Description Represents the options for a group. ### Fields - **name** (`string`) - Required - The name of the group. - **description** (`string`) - Optional - The group’s description. - **parent** (`string[]`) - Optional - An array of parent groups. ### Request Example ```json { "name": "ParentGroup", "description": "This is a top-level group.", "parent": [] } ``` ### Response Example ```json { "name": "ChildGroup", "description": "A subgroup of ParentGroup.", "parent": ["ParentGroup"] } ``` ``` -------------------------------- ### @Group Decorator Source: https://centurion.paradoxum.dev/reference/decorators Assigns a command to one or more groups. ```APIDOC ## @Group(groups) ### Description Assigns a command to one or more groups. When a class is decorated with this decorator, all commands within the class will be assigned to the group. ### Parameters * **groups** : `...string[]` - The groups to assign to the command. ### Usage ```typescript @Command({ name: "view", description: "Displays info about a player", }) @Group("info", "player") // Command is executable through "info player view" viewPlayer() {} @Command({ name: "view", description: "Displays info about the server", }) @Group("info", "server") // Command is executable through "info server view" viewServer() {} ``` ``` -------------------------------- ### Define a Command with @Command Source: https://centurion.paradoxum.dev/reference/decorators Use the @Command decorator to define a command within a class. It accepts CommandOptions such as name and description. ```typescript @Register() class ExampleCommand { @Command({ name: "example", description: "An example command", }) example() { // ... } } ``` -------------------------------- ### Register Groups with registerGroup Method Source: https://centurion.paradoxum.dev/guides/registration/groups Register multiple groups, including nested ones, using the server.registry.registerGroup method. This is useful for sharing groups between classes. ```typescript const server = Centurion.server(); server.registry.registerGroup( { name: "info", description: "View info about a user or the server", }, { name: "user", description: "View info about a user", parent: ["info"], }, { name: "server", description: "View info about the server", parent: ["info"], } ) server.start(); ``` -------------------------------- ### Disable Client Shortcuts Source: https://centurion.paradoxum.dev/guides/commands/shortcuts Configure the `shortcutsEnabled` option on the client to disable all shortcuts. Shortcuts are enabled by default. ```typescript Centurion.client({ shortcutsEnabled: false, }); ``` -------------------------------- ### Path Manipulation API Source: https://centurion.paradoxum.dev/reference/registry Provides methods to manage path objects. ```APIDOC ## `clear()` ### Description Removes all parts from the path. ### Method (Method not specified, likely an instance method) ### Endpoint (Endpoint not specified, likely an instance method) ### Parameters (No parameters specified) ### Request Example (Not applicable for this method) ### Response (No explicit return value specified, implies void or modification in place) ``` ```APIDOC ## `isEmpty()` ### Description Checks if the path is empty. ### Method (Method not specified, likely an instance method) ### Endpoint (Endpoint not specified, likely an instance method) ### Parameters (No parameters specified) ### Request Example (Not applicable for this method) ### Response #### Success Response (200) - **boolean** (`true` or `false`) - `true` if the path is empty, `false` if not. ### Response Example ```json { "isEmpty": true } ``` ``` -------------------------------- ### Register Group with Decorator Source: https://centurion.paradoxum.dev/guides/registration/groups Register groups for a command class using the @Register decorator. Ensure the 'groups' property is an array of group objects. ```typescript @Register({ groups: [ { name: "example", description: "Example group" } ] }) export class MyCommand { // ... } ``` -------------------------------- ### @Guard Decorator Source: https://centurion.paradoxum.dev/reference/decorators Assigns one or more guards to a command. ```APIDOC ## @Guard(guards) ### Description Assigns one or more guards to a command. When a class is decorated with this decorator, the provided guard(s) will be assigned to all commands within the class. ### Parameters * **guards** : `...CommandGuard[]` - The guards to assign to the command. ### Usage ```typescript @Command({ name: "ban", description: "Bans a player", }) @Guard(isAdmin) ban() {} ``` ``` -------------------------------- ### Accessing Executor and Text from CommandContext Source: https://centurion.paradoxum.dev/guides/commands/defining-commands The CommandContext provides access to the command executor's name and the raw text used to execute the command via ctx.executor.Name and ctx.text respectively. ```typescript @Command({ name: "echo" }) echo(ctx: CommandContext) { print(`${ctx.executor.Name} executed: ${ctx.text}`); } ``` -------------------------------- ### Define a Command Guard Function Source: https://centurion.paradoxum.dev/guides/commands/guards This guard checks if the executor has administrative privileges (UserId 1). It sends an error message and returns false if permissions are insufficient. Use this to restrict access to commands. ```typescript const isAdmin: CommandGuard = (ctx) => { if (ctx.executor.UserId !== 1) { ctx.error("Insufficient permission!"); return false; } return true; }; ``` -------------------------------- ### Assign Commands to Groups with @Group Source: https://centurion.paradoxum.dev/reference/decorators Decorate a command or a class with @Group to assign it to one or more specified groups. This allows for hierarchical command structures. ```typescript @Command({ name: "view", description: "Displays info about a player", }) @Group("info", "player") // Command is executable through "info player view" viewPlayer() {} ``` ```typescript @Command({ name: "view", description: "Displays info about the server", }) @Group("info", "server") // Command is executable through "info server view" viewServer() {} ``` -------------------------------- ### ArgumentType Definition Source: https://centurion.paradoxum.dev/reference/types Defines the structure of an ArgumentType, including its name, transformation, and suggestion functions. ```APIDOC ## ArgumentType * name: `string` - The name of the type. * expensive: `boolean` - Whether the type’s transformation function is expensive. If `true`, type-checking will be disabled in the interface. * transform: `(text, executor) => TransformResult.Object` - A function that transforms a string into the type. * suggestions: `(text, executor) => string[]` - A function that returns suggestions for the type. ``` -------------------------------- ### Assign Commands to a Group (Class-Level) Source: https://centurion.paradoxum.dev/guides/commands/groups Use the @Group decorator at the class level to assign all commands within that class to a specific group. This is recommended when all commands share the same group to avoid repetition. ```typescript @Register() // Assigning a group at the class level assigns the group to all // commands in the class. // You can also do this at the method level, but it's recommended to do it this // way if all commands have the same group to reduce repetition. @Group("profile") class ProfileCommand { @Command({ name: "view", description: "Views a player's profile", arguments: [ { name: "player", description: "The player", type: CenturionType.Player, }, ], }) view(ctx: CommandContext, player: Player) {} @Command({ name: "delete", description: "Deletes a player's profile", arguments: [ { name: "player", description: "The player", type: CenturionType.Player, }, ], }) delete(ctx: CommandContext, player: Player) {} } ``` -------------------------------- ### Apply Guards to Commands with @Guard Source: https://centurion.paradoxum.dev/reference/decorators Use the @Guard decorator to assign one or more guards to a command or class. Guards are executed before the command logic. ```typescript @Command({ name: "ban", description: "Bans a player", }) @Guard(isAdmin) ban() {} ``` -------------------------------- ### Using CommandContext to Send Errors Source: https://centurion.paradoxum.dev/guides/commands/defining-commands The CommandContext can be used to send error messages to the user. The error() method supports rich text formatting. ```typescript @Command({ name: "error" }) errorMessage(ctx: CommandContext) { // The default interface supports rich text, so it can be used here ctx.error("An error occurred."); } ``` -------------------------------- ### Create Nested Groups Source: https://centurion.paradoxum.dev/guides/commands/groups Define nested groups by specifying the parent group using the 'root' key within the @Group decorator. Note that groups with a parent cannot have their own child groups, limiting nesting to two levels. ```typescript @Register() @Group("info") class InfoCommand { @Command({ name: "view", description: "View information about a player", arguments: [{ name: "player", description: "Player to view information for", type: CenturionType.Player }], }) // If info was a global group, you could do @Group("user") here @Group("user") userView(ctx: CommandContext, player: Player) {} @Command({ name: "view", description: "View information about the server", }) @Group("server") serverView(ctx: CommandContext, player: Player) {} } ``` -------------------------------- ### TransformResult Definition Source: https://centurion.paradoxum.dev/reference/types Defines the structure for transformation results, indicating success or failure. ```APIDOC ## TransformResult ### `Object` * `ok` - Whether the transformation was successful. * `value` - The transformed value. If `ok` is false, this will be a `string`, representing the error message. ### `ok(value)` Creates a successful result object, indicating a transformation was successful. **Parameters** : * `value` - The transformed value. **Returns** : TransformResult.Object. ### `err(text)` Creates an error result object, indicating a transformation was not successful. **Parameters** : * `text` - The error message. **Returns** : TransformResult.Object. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.