{"id":15641682,"url":"https://github.com/cortexpe/commando","last_synced_at":"2025-04-06T22:12:11.890Z","repository":{"id":42469613,"uuid":"188790568","full_name":"CortexPE/Commando","owner":"CortexPE","description":"A Command Framework virion for PocketMine-MP","archived":false,"fork":false,"pushed_at":"2024-05-09T08:29:25.000Z","size":135,"stargazers_count":71,"open_issues_count":11,"forks_count":53,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-30T21:08:00.280Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CortexPE.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-27T07:11:54.000Z","updated_at":"2025-01-23T20:56:47.000Z","dependencies_parsed_at":"2024-05-09T09:52:30.977Z","dependency_job_id":null,"html_url":"https://github.com/CortexPE/Commando","commit_stats":{"total_commits":60,"total_committers":9,"mean_commits":6.666666666666667,"dds":0.6333333333333333,"last_synced_commit":"ede058439d2b217a0f5de86d7456a7a96d2d296f"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CortexPE%2FCommando","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CortexPE%2FCommando/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CortexPE%2FCommando/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CortexPE%2FCommando/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CortexPE","download_url":"https://codeload.github.com/CortexPE/Commando/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247557770,"owners_count":20958047,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T11:44:34.034Z","updated_at":"2025-04-06T22:12:11.872Z","avatar_url":"https://github.com/CortexPE.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1\u003eCommando\u003cimg src=\"https://raw.githubusercontent.com/CortexPE/Commando/master/commando.png\" height=\"64\" width=\"64\" align=\"left\"\u003e\u003c/img\u003e\u0026nbsp;\u003cimg src=\"https://poggit.pmmp.io/ci.shield/CortexPE/Commando/~\"\u003e\u003c/img\u003e\u003c/h1\u003e\r\n\u003cbr /\u003e\r\n\r\nA PocketMine-MP Virion for easier implementation of dynamic commands, including support for Minecraft: Bedrock Edition argument listing aimed for both the end users and the plugin developers.\r\n\r\n# Usage:\r\nInstallation is easy, you may get a compiled phar [here](https://poggit.pmmp.io/ci/CortexPE/Commando/~), integrate the virion itself into your plugin or you could also use it as a composer library by running the command below:\r\n\r\n`composer require cortexpe/commando`\r\n\r\nThis virion is purely object oriented. So, to use it you'll have to extend the `BaseCommand` object, import the `PacketHooker` object and the optional objects for subcommands and arguments (whenever necessary).\r\n\r\nFor PocketMine-MP API 4, you will need to include [Muqsit/SimplePacketHandler](https://github.com/Muqsit/SimplePacketHandler) in your dependencies.\r\n\r\n# Why is this necessary?\r\nThe virion provides an easy way to verify user input, convert user input, and for making sure that our arguments are the type that we expect it to.\r\n\r\nOn the plus side, it also provides the argument list for the client to recognize making it easy to use the command without remembering the order of arguments.\r\n\r\nBecause not only MC: Bedrock can use the commands, I've also implemented command usage pre-generation for ease of use with the console as well.\r\n\r\nThis also provides an easy to use API for lessening boilerplate code while adding more functionality and verbosity (error codes, and error lists, and sending usage messages).\r\n\r\nIt is structured in a similar way to the legacy PocketMine commands for ease of migration from an older codebase.\r\n\r\n**Upon the time of writing this readme file, This virion will be used on [Hierarchy](https://github.com/CortexPE/Hierarchy) for the command implementation clean-up**\r\n\r\n## Basic Usage:\r\n\r\n***NOTE: Other miscellaneous functions can be indexed within your IDEs or by reading the source code. This is only the basic usage of the virion, it does not show every aspect of it as that'd be too long to document.***\r\n\r\n### Create your command class\r\nIn our command class, we need to extend `BaseCommand` and implement its required methods to use all of Commando's features.\r\n```php\r\n\u003c?php\r\n\r\nuse CortexPE\\Commando\\BaseCommand;\r\nuse pocketmine\\command\\CommandSender;\r\n\r\nclass MyCommand extends BaseCommand {\r\n\tprotected function prepare(): void {\r\n\t\t// This is where we'll register our arguments and subcommands\r\n\t}\r\n\t\r\n\tpublic function onRun(CommandSender $sender, string $aliasUsed, array $args): void {\r\n\t\t// This is where the processing will occur if it's NOT handled by other subcommands\r\n\t}\r\n}\r\n```\r\n\r\n### Register the arguments\r\nIf we register arguments, we need to import and use / extend (if needed) the provided argument objects.\r\n```php\r\nuse CortexPE\\Commando\\args\\RawStringArgument;\r\n\r\n\tprotected function prepare(): void {\r\n\t\t// $this-\u003eregisterArgument(position, argument object (name, isOptional));\r\n\t\t$this-\u003eregisterArgument(0, new RawStringArgument(\"name\", true));\r\n\t}\r\n```\r\n\r\n### Handling our arguments\r\nThe arguments passed on our `onRun` method will be mapped by `name =\u003e value` this makes it easy to understand which argument is which, instead of using numeric indices. It is also guaranteed that the arguments passed will be the declared type that we've set.\r\n```php\r\n\tpublic function onRun(CommandSender $sender, string $aliasUsed, array $args): void {\r\n\t\tif(isset($args[\"name\"])){\r\n\t\t\t$sender-\u003esendMessage(\"Hello, \" . $args[\"name\"] . \"!\");\r\n\t\t} else {\r\n\t\t\t$this-\u003esendUsage();\r\n\t\t}\r\n\t}\r\n```\r\n\r\n### Registering the `PacketHooker` for vanilla command arguments\r\nThe `PacketHooker` listener is required for us to be able to inject data to the `AvailableCommandsPacket` the server sends.\r\n```php\r\nuse CortexPE\\Commando\\PacketHooker;\r\n\r\n// onEnable:\r\n\tif(!PacketHooker::isRegistered()) {\r\n\t\tPacketHooker::register($this);\r\n\t}\r\n```\r\n\r\n### Registering the command from a plugin\r\nOnce we've constructed our command with our arguments and subcommands, we can now register our command to PocketMine's command map, to be available to our users.\r\n```php\r\n// onEnable:\r\n$this-\u003egetServer()-\u003egetCommandMap()-\u003eregister(\"myplugin\", new MyCommand($this, \"greet\", \"Make the server greet you!\"));\r\n```\r\nThe only difference with using this framework is that you don't need to set the usage message, as they are pre-generated after all the arguments have been registered.\r\n\r\n### SubCommands\r\nSubcommands work the same way as regular commands, the only difference is that they're registered on the parent command with `BaseCommand-\u003eregisterSubCommand()` having their own set of arguments and own usage message.\r\n\r\n### Error messages\r\nThe virion provides default error messages for user input errors regarding the arguments given. It also provides a way to register your own error message formats for the sake of customizability.\r\n```php\r\n$cmdCtx-\u003esetErrorFormat($errorCode, $format);\r\n// Arrays can be passed on `BaseCommand-\u003esetErrorFormats()` to bulk-set other error messages\r\n```\r\nThe error messages are sent in bulk to the users to let them know what parts are wrong with their input, not having to do trial-and-error.\r\n*A current limitation is that, you cannot register your own error messages with other error codes.*\r\n\r\n-----\r\n**This framework was made with :heart: by CortexPE, Enjoy!~ :3**\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcortexpe%2Fcommando","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcortexpe%2Fcommando","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcortexpe%2Fcommando/lists"}