jCommands icon

jCommands -----

Api to easily create commands on the go.



Light weight and simple library to create spigot commands in the go.

I made this api in a couple of days to use in my plugins as I find the spigot / bukkit api to be out of date and leads to a lot of boilerplate code.

Usage

First, to use the api, you need to register your plugin

Code (Text):
    @Override
    public void onEnable() {
        JCommands.register(this);
    }

jCommands provides a very simple command creation abstraction. Here is an example:

Code (Text):
    JCommand.create("example")
        .assertPermission("example.permission.node")
        .assertUsage("/example <player>")
        .withArguments(new PlayerArgument("target"))
        .executes((commandSender, args) -> {
            args.get("target").getAsPlayer().sendMessage("This is an example");
        })
        .register();
As you can see, it comes with various methods to assert the functions of the command and
some predefined arguments that will tabComplete automatically for you, in this case,
PlayerArgument returns all the online players in the server, although it can be override.

More examples of the api usage:

Code (Text):
JCommand.create("simpleArguments")
        .assertRequirements((commandSender) -> commandSender.isOp())   // The command will only be executed if certain conditions are met
        .withArguments(new IntegerArgument("int"), new BooleanArgument("boolean"))  // The arguments are parsed in order
        .executes((commandSender, args) -> {
            int number = args.get("int").getAsInt();    // You can get the argument by name
            boolean bool = args.get(1).getAsBoolean();  // Or by position
         })
        .register();
Code (Text):

JCommand.create("Custom argument")
        .withArguments(new StringArgument("actions")
                .overrideSuggestions(() -> Arrays.asList("sell", "buy", "sellAll"))        // You can set your own custom autocomplete arguments
        )
        .register();
 
Code (Text):
JCommand.create("executorExample")
        .executesPlayer((player, args) -> {    // Will only be executed if the command is called by a player
             // Do something
        })
        .executesConsole((console, args) -> {  // Will only be executed if the command is called from console
             // Do something
         })
        .executes((console, args) -> {         // Executes no matter who called the command
             // Do something
         })
        .register();
Code (Text):
JCommand.create("essentials")
        .withSubcommands(JCommand.create("warp")
                 .withArguments(new StringArgument("permission"))
                 .withArguments(new StringArgument("groupName"))
                 .executes((sender, args) -> {
                     //perm group add code
                 })
                )
         .withSubcommands(JCommand.create("setWarp")
                  .withArguments(new StringArgument("permission"))
                  .withArguments(new StringArgument("userName"))
                  .executes((sender, args) -> {
                      //perm user add code
                  })
                )
          .withSubcommands(JCommand.create("spawn")
                  .withArguments(new StringArgument("permission"))
                  .withArguments(new StringArgument("userName"))
                  .executes((sender, args) -> {
                      //perm user remove code
                  })
           )
          .register();
Resource Information
Author:
----------
Total Downloads: 106
First Release: Dec 26, 2021
Last Update: Feb 2, 2022
Category: ---------------
All-Time Rating:
1 ratings
Version -----
Released: --------------------
Downloads: ------
Version Rating:
----------------------
-- ratings