You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
LibCommand is the new in-house command framework for EasyLibrary 2.0. Each command is implemented as a class (extending Command or SubCommand), making the design modular and easy to extend. Command metadata (name, description, aliases, permission node, arguments, subcommands, etc.) is defined in the onBuild() method, execution logic goes in onExecute(), and error handling is done in onFailure(). All arguments are strongly typed and validated before execution; constraints (like permissions or context checks) are provided via separate constraint classes (for example, InGameConstraint).
Modular architecture: Each command is a self-contained class. You can add, remove, or extend commands by creating new classes.
Clear separation of concerns:
Definition: In onBuild(), return an array that declares the command’s name, aliases, description, permission, arguments, subcommands, and constraints.
Execution: Implement the command’s behavior in onExecute(). This method only runs if argument parsing and constraints pass.
Failure handling: In onFailure(), handle any validation failures (missing/invalid arguments, failed constraints, execution errors) and provide user feedback.
Typed arguments & constraints: Define input parameters using specific argument classes (e.g. IntegerArgument, PlayerArgument) which can include range or format constraints. Declare permission/context checks in the 'constraints' array of onBuild() (e.g. using new InGameConstraint()).
Important
The onBuild() method must return an associative array with all command properties. This is where you set the command name, aliases, description, permission node, argument definitions, subcommands, and constraint checks.
Tip
When retrieving arguments in onExecute(), you can supply a default value. For example, $result->getArgumentsList()->get('page', 1) fetches the page argument or returns 1 if it was omitted.
Note
The CommandFailure object provides detailed error information. For constraint failures, getData()['failed_constraints'] may list which checks failed. For argument errors, getData()['argument_errors'] contains messages for each invalid argument. Use these details in onFailure() to tailor your error messages.
Examples
The example below demonstrates a top-level command (MyInfoCommand) with an optional integer argument (page) and an in-game constraint, plus a subcommand (PlayerSubCommand) to display player info. Both classes follow the pattern: define properties in onBuild(), implement logic in onExecute(), and handle errors in onFailure().
Use subcommands (like PlayerSubCommand) to extend a main command with additional functionality. Register subcommands by instantiating them in the parent’s 'subcommands' array (e.g. new PlayerSubCommand($this) in the example). These classes follow the same onBuild(), onExecute(), and onFailure() structure as regular commands.
LibCommand
LibCommand is the new in-house command framework for EasyLibrary 2.0. Each command is implemented as a class (extending
CommandorSubCommand), making the design modular and easy to extend. Command metadata (name, description, aliases, permission node, arguments, subcommands, etc.) is defined in theonBuild()method, execution logic goes inonExecute(), and error handling is done inonFailure(). All arguments are strongly typed and validated before execution; constraints (like permissions or context checks) are provided via separate constraint classes (for example,InGameConstraint).Modular architecture: Each command is a self-contained class. You can add, remove, or extend commands by creating new classes.
Clear separation of concerns:
onBuild(), return an array that declares the command’s name, aliases, description, permission, arguments, subcommands, and constraints.onExecute(). This method only runs if argument parsing and constraints pass.onFailure(), handle any validation failures (missing/invalid arguments, failed constraints, execution errors) and provide user feedback.Typed arguments & constraints: Define input parameters using specific argument classes (e.g.
IntegerArgument,PlayerArgument) which can include range or format constraints. Declare permission/context checks in the'constraints'array ofonBuild()(e.g. usingnew InGameConstraint()).Important
The
onBuild()method must return an associative array with all command properties. This is where you set the command name, aliases, description, permission node, argument definitions, subcommands, and constraint checks.Tip
When retrieving arguments in
onExecute(), you can supply a default value. For example,$result->getArgumentsList()->get('page', 1)fetches thepageargument or returns1if it was omitted.Note
The
CommandFailureobject provides detailed error information. For constraint failures,getData()['failed_constraints']may list which checks failed. For argument errors,getData()['argument_errors']contains messages for each invalid argument. Use these details inonFailure()to tailor your error messages.Examples
The example below demonstrates a top-level command (
MyInfoCommand) with an optional integer argument (page) and an in-game constraint, plus a subcommand (PlayerSubCommand) to display player info. Both classes follow the pattern: define properties inonBuild(), implement logic inonExecute(), and handle errors inonFailure().Command Class
SubCommand Class
Tip
Use subcommands (like
PlayerSubCommand) to extend a main command with additional functionality. Register subcommands by instantiating them in the parent’s'subcommands'array (e.g.new PlayerSubCommand($this)in the example). These classes follow the sameonBuild(),onExecute(), andonFailure()structure as regular commands.