{"id":16579738,"url":"https://github.com/tbluef/bluecommands","last_synced_at":"2026-03-04T13:32:05.545Z","repository":{"id":192389838,"uuid":"686615270","full_name":"TBlueF/BlueCommands","owner":"TBlueF","description":"Generic but powerful annotation based CommandAPI","archived":false,"fork":false,"pushed_at":"2025-02-26T13:48:43.000Z","size":172,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-29T01:48:59.658Z","etag":null,"topics":["annotations","commands"],"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/TBlueF.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,"zenodo":null}},"created_at":"2023-09-03T11:47:59.000Z","updated_at":"2025-02-26T13:48:34.000Z","dependencies_parsed_at":"2024-04-04T01:40:02.867Z","dependency_job_id":"5a67a251-56f3-499c-8772-9480e3eebc46","html_url":"https://github.com/TBlueF/BlueCommands","commit_stats":null,"previous_names":["tbluef/bluecommands"],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/TBlueF/BlueCommands","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TBlueF%2FBlueCommands","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TBlueF%2FBlueCommands/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TBlueF%2FBlueCommands/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TBlueF%2FBlueCommands/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TBlueF","download_url":"https://codeload.github.com/TBlueF/BlueCommands/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TBlueF%2FBlueCommands/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30081426,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T13:22:36.021Z","status":"ssl_error","status_checked_at":"2026-03-04T13:20:45.750Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["annotations","commands"],"created_at":"2024-10-11T22:19:10.094Z","updated_at":"2026-03-04T13:32:05.510Z","avatar_url":"https://github.com/TBlueF.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Usage\n\n### Adding to project\n```kotlin\nrepositories {\n    maven ( \"https://repo.bluecolored.de/releases\" )\n}\n\ndependencies {\n    implementation(\"de.bluecolored:bluecommands-core:1.2.0\")\n    implementation(\"de.bluecolored:bluecommands-brigadier:1.2.0\") // Optional\n}\n```\n\n### Creating and executing Commands\n```java\nclass MyCommands {\n    \n    private Command\u003cCommandSender, Object\u003e commands;\n    \n    public MyCommands() {\n        BlueCommands\u003cCommandSender\u003e commandFactory = new BlueCommands\u003c\u003e();\n        this.commands = commandFactory.createCommand(this);\n    }\n    \n    public void runCommand(CommandSender sender, String input) {\n        \n        // parse the command\n        ParseResult\u003cCommandSender, Object\u003e parseResult = this.commands.parse(sender, new InputReader(input));\n        \n        // get the match with the highest priority\n        ParseMatch\u003cCommandSender, Object\u003e match = parseResult.getMatches().stream()\n                .max(Comparator.comparing(ParseMatch::getPriority))\n                .orElse(null);\n        \n        if (match == null) {\n            // handle no command found\n            return;\n        }\n\n        // execute the command (the result is whatever the command-method returns)\n        Object executionResult = match.execute();\n        \n    }\n    \n    @Command(\"foo \u003carg1\u003e [optionalArg2]\")\n    public void fooCommand(\n          CommandSender sender,\n          @Argument(\"arg1\") String stringArgument,\n          @Argument(\"optionalArg2\") Double optionalDoubleArgument\n    ) {\n        // do something\n    }\n  \n}\n```\n\n### Creating custom argument-parsers\nExample here for creating an argument parser which accepts online Bukkit-Players: \n```java\npublic class PlayerArgument\u003cS\u003e extends SimpleArgumentParser\u003cS, Player\u003e {\n\n    public PlayerArgument() {\n        super(false, false);\n    }\n\n    @Override\n    public Player parse(S context, String name) throws CommandParseException {\n        Player player = Bukkit.getPlayerExact(name);\n        if (player == null) {\n            throw new CommandParseException(\"'\" + name + \"' is not an online player!\");\n        }\n        return player;\n    }\n\n    @Override\n    public List\u003cSuggestion\u003e suggest(S context, InputReader input) {\n        return Bukkit.getOnlinePlayers().stream()\n                .map(player -\u003e (Suggestion) new SimpleSuggestion(player.getName()))\n                .toList();\n    }\n\n}\n```\nThen register the new Parser before creating your commands:\n```java\nBlueCommands\u003cCommandSender\u003e commandFactory = new BlueCommands\u003c\u003e();\n\n// register the custom argument-parser\ncommandFactory.setArgumentParserForArgumentType(Player.class, new PlayerArgument\u003c\u003e());\n\nthis.commands = commandFactory.createCommand(this);\n```\n\n### Context-Resolver\nWith context-resolvers you can add other parameters to your command-method that should be resolved from the context.\n```java\nBlueCommands\u003cCommandSender\u003e commandFactory = new BlueCommands\u003c\u003e();\ncommandFactory.setContextResolverForType(Server.class, CommandSender::getServer);\n```\nThen in a command you can add a `Server` parameter which will be filled based on the current command-context:\n```java\n@Command(\"foo \u003carg1\u003e [optionalArg2]\")\npublic void fooCommand(\n      Server server,\n      @Argument(\"arg1\") String stringArgument,\n      @Argument(\"optionalArg2\") Double optionalDoubleArgument\n) {\n    // ...\n}\n```\n\n### Context-Predicates (e.g. Permissions)\nHere an example to create a Permission annotation and use it to validate commands for a context.\n\nCreate the new Annotation:\n```java \n@Target(ElementType.METHOD)\n@Retention(RetentionPolicy.RUNTIME)\npublic @interface Permission {\n    String value();\n}\n```\nLabel your commands with this new annotation:\n```java\n@Command(\"foo \u003carg1\u003e [optionalArg2]\")\n@Permission(\"foo.bar.bazz\")\npublic void fooCommand(\n      CommandSender sender,\n      @Argument(\"arg1\") String stringArgument,\n      @Argument(\"optionalArg2\") Double optionalDoubleArgument\n) {\n    // ...\n}\n```\nRegister a context-predicate for this Annotation:\n```java\nBlueCommands\u003cCommandSender\u003e commandFactory = new BlueCommands\u003c\u003e();\ncommandFactory.setAnnotationContextPredicate(Permission.class, (permission, commandSender) -\u003e {\n    return commandSender.hasPermission(permission.value());\n});\n```\nWhen the annotation is present, the command will now only be available if the registered predicate returns `true`.\n\n### Merging commands\nYou can merge multiple commands into one. E.g. if you have multiple objects that hold command-methods:\n```java\nBlueCommands\u003cCommandSender\u003e commandFactory = new BlueCommands\u003c\u003e();\nCommand\u003cCommandSender, Object\u003e root = new Command\u003c\u003e();\nroot.tryMerge(commandFactory.createCommand(object1));\nroot.tryMerge(commandFactory.createCommand(object2));\nroot.tryMerge(commandFactory.createCommand(object3));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftbluef%2Fbluecommands","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftbluef%2Fbluecommands","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftbluef%2Fbluecommands/lists"}