{"id":29080853,"url":"https://github.com/imperazim/libcommand","last_synced_at":"2025-06-27T18:38:17.096Z","repository":{"id":301212828,"uuid":"1007042394","full_name":"ImperaZim/LibCommand","owner":"ImperaZim","description":"Command library for PocketMine plugins","archived":false,"fork":false,"pushed_at":"2025-06-25T17:33:25.000Z","size":30,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"stable","last_synced_at":"2025-06-25T18:37:52.075Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ImperaZim.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2025-06-23T11:26:21.000Z","updated_at":"2025-06-25T13:43:56.000Z","dependencies_parsed_at":"2025-06-25T18:38:55.917Z","dependency_job_id":"b7de1c86-127d-4661-b671-e25fdff350f4","html_url":"https://github.com/ImperaZim/LibCommand","commit_stats":null,"previous_names":["imperazim/libcommand"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ImperaZim/LibCommand","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ImperaZim%2FLibCommand","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ImperaZim%2FLibCommand/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ImperaZim%2FLibCommand/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ImperaZim%2FLibCommand/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ImperaZim","download_url":"https://codeload.github.com/ImperaZim/LibCommand/tar.gz/refs/heads/stable","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ImperaZim%2FLibCommand/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262313853,"owners_count":23292216,"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":"2025-06-27T18:38:14.746Z","updated_at":"2025-06-27T18:38:17.078Z","avatar_url":"https://github.com/ImperaZim.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LibCommand\nLibCommand is a small PocketMine-MP command library meant to simplify the process of creating commands while also enhancing the user experience. It provides an API for defining commands (and sub-commands) with rich argument types, permissions, and constraints, handling execution and failure cases automatically. LibCommand works with PocketMine servers and leverages network packet manipulation (via the **LibPacket** dependency) to, for example, enable client-side command suggestions and rendering. In practice, you integrate LibCommand into your plugin and use classes like `Command` and `SubCommand` to define command behavior in code, rather than writing separate entries in `plugin.yml`.\n\n## Installation Instructions\n\n* **Option 1 (Source / Development):** Download the LibCommand ZIP from GitHub and include its source code in your plugin’s project (for example, by putting the library files alongside your plugin code). You can use PocketMine’s *folder plugin* format (with DevTools) to load source folders directly. In that case, ensure the LibCommand files (with namespace `imperazim\\command`) are in your plugin’s `src` folder. Then, in your plugin’s `onEnable()`, register LibCommand by calling:\n\n  ```php\n  \\imperazim\\command\\LibCommand::getInstance()-\u003eregisterInterceptor($this);\n  ```\n\n  This sets up LibCommand’s hooks for your plugin.\n\n* **Option 2 (PHAR):** Download the `LibCommand.phar` file from the GitHub *Releases* page and place it in your server’s `plugins/` directory. The PHAR packaging bundles the entire library into one file. According to the PocketMine documentation, you simply drop the `.phar` into `plugins/` and restart the server to install it. After placing the PHAR, be sure to still register LibCommand in your plugin’s `onEnable()` (as shown above) so your plugin can intercept commands.\n\n## Requirements\nLibCommand depends on the **LibPacket** library. Make sure LibPacket is installed or available on your server (for example, by including it via EasyLibrary or its own PHAR). LibPacket handles the low-level packet work (such as sending command data to clients), so LibCommand will not function properly without it.\n\u003cp\u003e\n    \u003ca href=\"https://github.com/ImperaZim/LibPacket\" \u003e\u003cimg align=\"center\" src=\"https://github-readme-stats.vercel.app/api/pin/?username=imperazim\u0026repo=LibPacket\u0026show_icons=true\u0026theme=radical\u0026hide_border=true\u0026include_all_commits=true\u0026count_private=true\" \u003e\n\u003c/a\u003e\n\u003c/p\u003e\n\n## Usage Examples\n\n#### AdminCommand\n\nThis example defines a root command `/admin` with one sub-command (`user`). In the `onBuild()` method you return metadata (name, description, subcommands). Here’s a simplified snippet (the actual code may include more in `onExecute` and failure handling):\n\n```php\npublic function onBuild(): array {\n    return [\n        'name' =\u003e 'admin',\n        'description' =\u003e 'Root administrative command',\n        'subcommands' =\u003e [\n            new UserSubCommand($this)\n        ]\n    ];\n}\n```\n\nThis creates a command `/admin`. The `UserSubCommand` (below) handles the `/admin user ...` cases. In `onExecute()`, you might show usage or list available sub-commands:\n\n```php\npublic function onExecute(CommandResult $result): void {\n    $sender = $result-\u003egetSender();\n    $available = implode(', ', array_map(fn($cmd) =\u003e $cmd-\u003egetName(), $this-\u003egetSubCommands()));\n    $sender-\u003esendMessage(\"Usage: /admin \u003c{$available}\u003e\");\n}\n```\n\n#### AdvancedTestCommand\n\nThis example demonstrates a command with various argument types and aliases. In `onBuild()` you specify name, aliases, description, permission, and a list of arguments:\n\n```php\npublic function onBuild(): array {\n    return [\n        'name'        =\u003e 'advancedtest',\n        'aliases'     =\u003e ['at', 'fulltest'],\n        'description' =\u003e 'Demo command with all argument types',\n        'permission'  =\u003e DefaultPermissions::ROOT_OPERATOR,\n        'arguments'   =\u003e [\n            new PlayerArgument('player', false),\n            new ItemArgument('item', false),\n            new IntegerArgument('quantity', false, min: 1, max: 64),\n            new WorldArgument('world', true),\n            new FloatArgument('damage', true, min: 0.0, max: 100.0),\n            new StringArgument('message', true),\n            new BooleanArgument('visible', true),\n            new EnumArgument('color', true, ['red', 'blue', 'green']),\n        ],\n        'constraints' =\u003e [\n            new InGameConstraint()\n        ]\n    ];\n}\n```\n\nHere, `/advancedtest` (alias `/at`) accepts a player name, an item, an integer (1–64), optional world, optional float, optional string, optional boolean, and optional enum. In `onExecute()`, you would retrieve these arguments from `$result-\u003egetArgumentsList()` and perform your logic (the example sends a formatted message back to the sender).\n\n#### PromoteSubCommand\n\nThis is a sub-command example under `/admin user`. It promotes a player to operator. In `onBuild()`, you give it a name, description, and arguments:\n\n```php\npublic function onBuild(): array {\n    return [\n        'name'        =\u003e 'promote',\n        'description' =\u003e 'Promote a player to operator',\n        'arguments'   =\u003e [\n            new PlayerArgument('player', false)\n        ]\n    ];\n}\npublic function onExecute(CommandResult $result): void {\n    $target = $result-\u003egetArgumentsList()-\u003eget('player');\n    $result-\u003egetSender()-\u003esendMessage(\"Promoting player {$target-\u003egetName()} to operator.\");\n}\n```\n\nIf the player argument is missing or invalid, LibCommand automatically triggers `onFailure()`, where you can send a usage message. For example:\n\n```php\npublic function onFailure(CommandFailure $failure): void {\n    $failure-\u003egetSender()-\u003esendMessage(\"Usage: /admin user promote \u003cplayer\u003e\");\n}\n```\n\n#### UserSubCommand\n\nThis sub-command groups user-related commands. Its `onBuild()` sets the name and adds `PromoteSubCommand` as a child:\n\n```php\npublic function onBuild(): array {\n    return [\n        'name'        =\u003e 'user',\n        'description' =\u003e 'Manage users',\n        'subcommands' =\u003e [\n            new PromoteSubCommand($this)\n        ]\n    ];\n}\npublic function onExecute(CommandResult $result): void {\n    // No subcommand given: show usage\n    $result-\u003egetSender()-\u003esendMessage(\"Usage: /admin user \u003cpromote\u003e\");\n}\n```\n\nWhen the player types `/admin user promote \u003cname\u003e`, LibCommand will automatically dispatch to the `PromoteSubCommand`. If the player types `/admin user` without arguments or an unknown subcommand, `onExecute()` provides the usage string as shown.\n\n## Getting Started\n\nTo use LibCommand in your plugin, first call its registration method in your main class (usually in `onEnable()`). For example:\n\n```php\npublic function onEnable(): void {\n    \\imperazim\\command\\LibCommand::getInstance()-\u003eregisterInterceptor($this);\n    // Then register your commands with PocketMine:\n    $this-\u003egetServer()-\u003egetCommandMap()-\u003eregister($this-\u003egetName(), new AdminCommand());\n}\n```\n\nThe pattern is similar to other command libraries: you register the LibCommand interceptor for your plugin, then use `$server-\u003egetCommandMap()-\u003eregister()` to register each command instance. After doing this, LibCommand will intercept those commands and handle argument parsing, sub-commands, and execution based on your `onBuild()`/`onExecute()` definitions.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimperazim%2Flibcommand","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimperazim%2Flibcommand","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimperazim%2Flibcommand/lists"}