A Bukkit/Spigot API to use the command UI introduced in Minecraft 1.13
Support and Project Discussion:
Downloads & Documentation:
Announcements:
Compatible Minecraft versions:
The list of what version of the CommandAPI you'll need to run on a specific version of Minecraft is as follows:
- Minecraft 1.13.x: CommandAPI v1.0 to 5.12
- Minecraft 1.14.1, 1.14.2: CommandAPI v2.0 to 5.12
- Minecraft 1.14.3, 1.14.4: CommandAPI v2.1 to 5.12
- Minecraft 1.15.x: CommandAPI v2.3a to 5.12
- Minecraft 1.16.1: CommandAPI v3.0 to 5.12
- Minecraft 1.16.2: CommandAPI v4.0 to 5.12
- Minecraft 1.16.3: CommandAPI v4.2 to 5.12
- Minecraft 1.16.4: CommandAPI v5.2 to 5.12
- Minecraft 1.16.5: CommandAPI v5.7 to 6.0.x
- Minecraft 1.17: CommandAPI 6.0.x
Purpose
This project provides an API to help Bukkit/Spigot developers use the Minecraft 1.13 command UI, which includes:
-
Better commands - Prevent players from running invalid commands, making it easier for developers
-
Better arguments - Easily switch from Location arguments to raw JSON, fully supported with built-in error checking
-
Support for proxied command senders - Run your command as other entities using
/execute as ... run command -
Argument tooltips - Let your users know exactly what their command will do
-
Support for the
/executecommand - Let your command to be executed by the built in/executecommand -
Support for Minecraft's functions - Allow your command to be executed from Minecraft's functions and tags
-
No plugin.yml registration - Commands don't need to be registered in the
plugin.ymlfile anymore -
You don't need Brigadier - You don't need to import Brigadier in your projects to use the CommandAPI
-
No tracking - The CommandAPI don't collect any stats about its plugin; what you see is what you get!
In addition to all of the above:
- Built-in command converter - Convert regular plugin commands into
/execute-compatible ones - no coding experience required! - Optional compile-time annotation-based framework - Don't like writing lots of code with builders? You don't have to if you don't want to!
- Insanely detailed documentation - Trust me, you've never seen a plugin documentation look so good.
Code examples
(I always like to see code examples on GitHub repos, so here's what CommandAPI code looks like):
Simple command registration
new CommandAPICommand("enchantitem")
.withArguments(new EnchantmentArgument("enchantment"))
.withArguments(new IntegerArgument("level", 1, 5))
.executesPlayer((player, args) -> {
Enchantment enchantment = (Enchantment) args[0];
int level = (int) args[1];
//Add the enchantment
player.getInventory().getItemInMainHand().addEnchantment(enchantment, level);
})
.register();Potion removing, suggesting potions that a player has currently
List<Argument> arguments = new ArrayList<>();
arguments.add(new EntitySelectorArgument("target", EntitySelector.ONE_PLAYER));
arguments.add(new PotionEffectArgument("potioneffect").safeOverrideSuggestions(
(sender, prevArgs) -> {
Player target = (Player) prevArgs[0];
//Convert PotionEffect[] into PotionEffectType[]
return target.getActivePotionEffects().stream()
.map(PotionEffect::getType)
.toArray(PotionEffectType[]::new);
})
);
new CommandAPICommand("removeeffect")
.withArguments(arguments)
.executesPlayer((player, args) -> {
EntityType entityType = (EntityType) args[0];
player.getWorld().spawnEntity(player.getLocation(), entityType);
})
.register();Subcommands
new CommandAPICommand("perm")
.withSubcommand(new CommandAPICommand("group")
.withSubcommand(new CommandAPICommand("add")
.withArguments(new StringArgument("permission"))
.withArguments(new StringArgument("groupName"))
.executes((sender, args) -> {
//perm group add code
})
)
.withSubcommand(new CommandAPICommand("remove")
.withArguments(new StringArgument("permission"))
.withArguments(new StringArgument("groupName"))
.executes((sender, args) -> {
//perm group remove code
})
)
)
.withSubcommand(new CommandAPICommand("user")
.withSubcommand(new CommandAPICommand("add")
.withArguments(new StringArgument("permission"))
.withArguments(new StringArgument("userName"))
.executes((sender, args) -> {
//perm user add code
})
)
.withSubcommand(new CommandAPICommand("remove")
.withArguments(new StringArgument("permission"))
.withArguments(new StringArgument("userName"))
.executes((sender, args) -> {
//perm user remove code
})
)
)
.register();Annotation-based commands
@Command("warp")
public class WarpCommand {
// List of warp names and their locations
static Map<String, Location> warps = new HashMap<>();
@Default
public static void warp(CommandSender sender) {
sender.sendMessage("--- Warp help ---");
sender.sendMessage("/warp - Show this help");
sender.sendMessage("/warp <warp> - Teleport to <warp>");
sender.sendMessage("/warp create <warpname> - Creates a warp at your current location");
}
@Default
public static void warp(Player player, @AStringArgument String warpName) {
player.teleport(warps.get(warpName));
}
@Subcommand("create")
@Permission("warps.create")
public static void createWarp(Player player, @AStringArgument String warpName) {
warps.put(warpName, player.getLocation());
}
}Command conversion (no compilation required)
plugins-to-convert:
- Essentials:
- speed <speed>[0..10]
- speed <target>[minecraft:game_profile]
- speed (walk|fly) <speed>[0..10]
- speed (walk|fly) <speed>[0..10] <target>[minecraft:game_profile]Building the CommandAPI
The CommandAPI can be built easily, but requires copies of the Spigot server jars to be present locally on your machine in order to be compatible with any Minecraft version. The CommandAPI is built using the Maven build tool - if you don't have it, you can download it here.
-
Clone the repository using your preferred method, or with the command below:
git clone https://github.com/JorelAli/CommandAPI.git -
Go into the folder named
CommandAPI(Not to be confused with the folder namedCommandAPI, which is what was just cloned). You want the folder which containspom.xml. -
Run
mvn
CommandAPI Project Timeline
This is the current roadmap for the CommandAPI (as of 16th May 2021):
-
CommandAPI 6.1.0: Bug fixes probably?
-
CommandAPI 7.0.0: Annotation improvements
The CommandAPI's annotation system has always been a bit limited and was primarily introduced as a proof-of-concept. In this update, the CommandAPI's annotation system will be improved to be (ideally) as powerful as the non-annotation system and have slightly better type safety.
-
Future:
CustomArgument improvements
The CustomArgument class is fairly flexible, but nowhere near flexible enough. In this update, more attention will be focused on the CustomArgument class to provide it the ability to extend from all other argument types as a base.
Argument conflict detection
The CommandAPI simply uses the Brigadier system under the hood. This system is prone to argument conflicts, which is where certain arguments are given priority over other arguments. (For example "hello" and "123" are both valid string arguments, but if you have a command that has a string argument or an integer argument, Brigadier may ignore the integer argument). In this update, the CommandAPI will try to spot potential conflicts and add a warning in the console. The research required for this is also required in order to implement optional arguments (which is not coming out in this release).
Changelog
| Version | Date | Features / Changes |
|---|---|---|
| 6.0.4 | June 2021 |
|
| 6.0.3 | June 2021 |
|
| 6.0.2 | June 2021 |
|
| 6.0.1 | June 2021 |
|
| 6.0.0 | June 2021 |
Version support changes:
|
| 5.12 | May 2021 |
|
| 5.11 | May 2021 |
|
| 5.10 | May 2021 |
|
| 5.9 | February 2021 |
|
| 5.8 | January 2021 |
|
| 5.7 | January 2021 |
|
| 5.6 | January 2021 |
|
| 5.5 | January 2021 |
|
| 5.4 | December 2020 |
|
| 5.3 | November 2020 |
|
| 5.2 | November 2020 |
|
| 5.1 | October 2020 |
|
| 5.0 | October 2020 |
|
| 4.3c | October 2020 |
|
| 4.3b | September 2020 |
|
| 4.3a | September 2020 |
|
| 4.3 | September 2020 |
|
| 4.2 | September 2020 |
|
| 4.1 | September 2020 |
|
| 4.0 | August 2020 |
|
| 3.4 | July 2020 |
|
| 3.3 | July 2020 |
|
| 3.2 | July 2020 |
|
| 3.1 | July 2020 |
|
| 3.0 | June 2020 |
|
| 2.3a | December 2019 |
|
| 2.3 | August 2019 |
|
| 2.2 | July 2019 |
|
| 2.1 | July 2019 |
|
| 2.0.1 | May 2019 |
|
| 2.0 | May 2019 |
|
| 1.8.2 | January 2019 |
|
| 1.8.1 | December 2018 |
|
| 1.8 | December 2018 |
|
| 1.7.2 | December 2018 |
|
| 1.7.1 | December 2018 |
|
| 1.7 | December 2018 |
|
| 1.6 | November 2018 |
|
| 1.5 | October 2018 |
|
| 1.4 | October 2018 |
|
| 1.3 | October 2018 |
|
| 1.2 | August 2018 |
|
| 1.1 | August 2018 |
|
| 1.0 | August 2018 |
|




