{"id":13407772,"url":"https://github.com/lucko/commodore","last_synced_at":"2025-04-07T13:06:30.506Z","repository":{"id":33044604,"uuid":"141506866","full_name":"lucko/commodore","owner":"lucko","description":" Utility for using Minecraft's 1.13 'brigadier' library in Bukkit plugins.","archived":false,"fork":false,"pushed_at":"2022-08-03T21:01:13.000Z","size":125,"stargazers_count":174,"open_issues_count":11,"forks_count":16,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-07-31T20:28:20.771Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lucko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-19T01:08:12.000Z","updated_at":"2024-07-27T15:47:07.000Z","dependencies_parsed_at":"2022-07-31T10:38:08.881Z","dependency_job_id":null,"html_url":"https://github.com/lucko/commodore","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucko%2Fcommodore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucko%2Fcommodore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucko%2Fcommodore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucko%2Fcommodore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucko","download_url":"https://codeload.github.com/lucko/commodore/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247657277,"owners_count":20974344,"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-07-30T20:00:48.555Z","updated_at":"2025-04-07T13:06:30.487Z","avatar_url":"https://github.com/lucko.png","language":"Java","funding_links":[],"categories":["Commands"],"sub_categories":[],"readme":"# commodore  [![Javadocs](https://javadoc.io/badge/me.lucko/commodore.svg)](https://javadoc.io/doc/me.lucko/commodore) [![Maven Central](https://img.shields.io/maven-metadata/v/https/repo1.maven.org/maven2/me/lucko/commodore/maven-metadata.xml.svg?label=maven%20central\u0026colorB=brightgreen)](https://search.maven.org/artifact/me.lucko/commodore)\n\ncommodore is a utility for using Minecraft's 1.13 [brigadier](https://github.com/Mojang/brigadier) library in Bukkit plugins. It allows you to easily register command completion data for your plugin's commands.\n\nIf you have questions, feel free to ask in [Discord](https://discord.gg/AEqagwA).\n\n#### Example\n![](https://i.imgur.com/4VElTNG.png)\n![](https://i.imgur.com/o3AcyVY.png)\n\n___\n\n### Approaches to registering completion data\n\ncommodore supports:\n* Registering completions using brigadier's `LiteralCommandNode` builder API\n* Registering completions using commodore's `.commodore` file format\n\nFor example, implementing completions for [Minecraft's `/time` command](https://minecraft.gamepedia.com/Commands/time):\n\n#### Using brigadier's `LiteralCommandNode` builder API\n```java\nLiteralCommandNode\u003c?\u003e timeCommand = LiteralArgumentBuilder.literal(\"time\")\n        .then(LiteralArgumentBuilder.literal(\"set\")\n                .then(LiteralArgumentBuilder.literal(\"day\"))\n                .then(LiteralArgumentBuilder.literal(\"noon\"))\n                .then(LiteralArgumentBuilder.literal(\"night\"))\n                .then(LiteralArgumentBuilder.literal(\"midnight\"))\n                .then(RequiredArgumentBuilder.argument(\"time\", IntegerArgumentType.integer())))\n        .then(LiteralArgumentBuilder.literal(\"add\")\n                .then(RequiredArgumentBuilder.argument(\"time\", IntegerArgumentType.integer())))\n        .then(LiteralArgumentBuilder.literal(\"query\")\n                .then(LiteralArgumentBuilder.literal(\"daytime\"))\n                .then(LiteralArgumentBuilder.literal(\"gametime\"))\n                .then(LiteralArgumentBuilder.literal(\"day\"))\n        ).build();\n\ncommodore.register(bukkitCommand, timeCommand);\n```\n\n#### Using commodore's `.commodore` file format\n```\ntime {\n  set {\n    day;\n    noon;\n    night;\n    midnight;\n    time brigadier:integer;\n  }\n  add {\n    time brigadier:integer;\n  }\n  query {\n    daytime;\n    gametime;\n    day;\n  }\n}\n```\n```java\n// assuming the file above is stored as \"time.commodore\" in the plugin jar\nLiteralCommandNode\u003c?\u003e timeCommand = CommodoreFileFormat.parse(plugin.getResource(\"time.commodore\"));\ncommodore.register(bukkitCommand, timeCommand);\n```\n\nUsing the `.commodore` file format is recommended. In my opinion it is much easier to read/understand/update than the Node Builder API provided by brigadier.\n\nAnother example of a `.commodore` file can be found [here](https://github.com/lucko/LuckPerms/blob/master/bukkit/src/main/resources/luckperms.commodore), for the [LuckPerms](https://luckperms.net/) plugin commands. The corresponding code used to register the completions is [here](https://github.com/lucko/LuckPerms/blob/master/bukkit/src/main/java/me/lucko/luckperms/bukkit/brigadier/LuckPermsBrigadier.java).\n\n\n## Usage\n\nThis guide assumes your plugin is built using Maven or Gradle though.\n\n#### 1) Configure your build script to shade commodore into your plugin jar\n\n\u003cdetails\u003e\n\u003csummary\u003eMaven\u003c/summary\u003e\n\nYou need to add (or merge) the following sections into your `pom.xml` file.\n```xml\n\u003cbuild\u003e\n    \u003cplugins\u003e\n        \u003cplugin\u003e\n            \u003cgroupId\u003eorg.apache.maven.plugins\u003c/groupId\u003e\n            \u003cartifactId\u003emaven-shade-plugin\u003c/artifactId\u003e\n            \u003cversion\u003e3.2.1\u003c/version\u003e\n            \u003cexecutions\u003e\n                \u003cexecution\u003e\n                    \u003cphase\u003epackage\u003c/phase\u003e\n                    \u003cgoals\u003e\n                        \u003cgoal\u003eshade\u003c/goal\u003e\n                    \u003c/goals\u003e\n                    \u003cconfiguration\u003e\n                        \u003cartifactSet\u003e\n                            \u003cincludes\u003e\n                                \u003cinclude\u003eme.lucko:commodore\u003c/include\u003e\n                            \u003c/includes\u003e\n                        \u003c/artifactSet\u003e\n                        \u003crelocations\u003e\n                            \u003crelocation\u003e\n                                \u003cpattern\u003eme.lucko.commodore\u003c/pattern\u003e\n                                \u003c!-- vvv Replace with the package of your plugin vvv --\u003e\n                                \u003cshadedPattern\u003ecom.yourdomain.yourplugin.commodore\u003c/shadedPattern\u003e\n                            \u003c/relocation\u003e\n                        \u003c/relocations\u003e\n                    \u003c/configuration\u003e\n                \u003c/execution\u003e\n            \u003c/executions\u003e\n        \u003c/plugin\u003e\n    \u003c/plugins\u003e\n\u003c/build\u003e\n\n\u003cdependencies\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003eme.lucko\u003c/groupId\u003e\n        \u003cartifactId\u003ecommodore\u003c/artifactId\u003e\n        \u003c!-- vvv Replace with the latest commodore version vvv --\u003e\n        \u003cversion\u003e{version}\u003c/version\u003e\n        \u003cscope\u003ecompile\u003c/scope\u003e\n    \u003c/dependency\u003e\n\u003c/dependencies\u003e\n\n\u003crepositories\u003e\n    \u003crepository\u003e\n        \u003cid\u003eminecraft-repo\u003c/id\u003e\n        \u003curl\u003ehttps://libraries.minecraft.net/\u003c/url\u003e\n    \u003c/repository\u003e\n\u003c/repositories\u003e\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eGradle\u003c/summary\u003e\n\nYou need to add (or merge) the following sections into your `build.gradle` file.\n```gradle\nplugins {\n  id 'com.github.johnrengelman.shadow' version '6.1.0'\n}\n\nrepositories {\n  mavenCentral()\n  maven { url 'https://libraries.minecraft.net/' }\n}\n\ndependencies {\n  /* vvv Replace with the latest commodore version vvv */\n  implementation 'me.lucko:commodore:{version}'\n}\n\nshadowJar {\n  dependencies {\n    exclude(dependency('com.mojang:brigadier'))\n  }\n  \n  /* vvv Replace with the package of your plugin vvv */\n  relocate 'me.lucko.commodore', 'com.yourdomain.yourplugin.commodore'\n}\n```\n\u003c/details\u003e\n\nReplace `{version}` with the latest version: [![latest version](https://img.shields.io/maven-metadata/v/https/repo1.maven.org/maven2/me/lucko/commodore/maven-metadata.xml.svg?label=latest%20version\u0026colorB=brightgreen)](https://search.maven.org/artifact/me.lucko/commodore)\n\n#### 2) Setup commodore in your plugin\n\n```java\npackage me.lucko.example;\n\nimport com.mojang.brigadier.arguments.BoolArgumentType;\nimport com.mojang.brigadier.arguments.StringArgumentType;\nimport com.mojang.brigadier.builder.LiteralArgumentBuilder;\nimport com.mojang.brigadier.builder.RequiredArgumentBuilder;\n\nimport me.lucko.commodore.Commodore;\nimport me.lucko.commodore.CommodoreProvider;\n\nimport org.bukkit.command.PluginCommand;\nimport org.bukkit.plugin.java.JavaPlugin;\n\npublic class TestPlugin extends JavaPlugin {\n\n    @Override\n    public void onEnable() {\n\n        // register your command executor as normal.\n        PluginCommand command = getCommand(\"mycommand\");\n        command.setExecutor(new MyCommandExecutor());\n\n        // check if brigadier is supported\n        if (CommodoreProvider.isSupported()) {\n            \n            // get a commodore instance\n            Commodore commodore = CommodoreProvider.getCommodore(this);\n\n            // register your completions.\n            registerCompletions(commodore, command);\n        }\n    }\n    \n    // You will need to put this method inside another class to prevent classloading\n    // errors when your plugin loads on pre 1.13 versions.\n    private static void registerCompletions(Commodore commodore, PluginCommand command) {\n        commodore.register(command, LiteralArgumentBuilder.literal(\"mycommand\")\n                .then(RequiredArgumentBuilder.argument(\"some-argument\", StringArgumentType.string()))\n                .then(RequiredArgumentBuilder.argument(\"some-other-argument\", BoolArgumentType.bool()))\n        );\n    }\n}\n```\n\nThe `com.mojang.brigadier` packages will be automatically imported into your classpath when you add the commodore dependency, but they should not be shaded into your plugins jar file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucko%2Fcommodore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucko%2Fcommodore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucko%2Fcommodore/lists"}