Home›Java›Mods›jCommands
ModsJava

jCommands

Java mod listed for Minecraft 1.7–1.18. Download on the author's site.

⬇ Download on Spigot
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:

Spoiler: Simple arguments
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();
Spoiler: Custom Arguments
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();
 
Spoiler: Executors
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();
Spoiler: subCommands
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();
Quick facts

Install steps are the general flow for this file type — How to install Minecraft Java mods & modpacks walks through it step by step.

jCommands is a free Minecraft Java mod. Compatible with Minecraft 1.7, 1.8, 1.9, 1.10 and newer. Downloaded 130 times (via Spigot). Download it and open it directly in the game.

Explore more