Internal CommandAPI
The CommandAPI does a lot of stuff "behind the scenes". This internal CommandAPI section will go into detail about what the CommandAPI does, how it's implemented and why it has been implemented like that.
Argument identifiers
The CommandAPI's arguments are representations of the different arguments that the Minecraft Command Data protocol handles. These are outlined in the table below:
Identifier | CommandAPI argument |
---|---|
brigadier:bool | BooleanArgument |
brigadier:double | DoubleArgument |
brigadier:float | FloatArgument |
brigadier:integer | IntegerArgument |
brigadier:long | LongArgument |
brigadier:string | StringArgument TextArgument GreedyStringArgument CustomArgument<T> |
minecraft:angle | AngleArgument |
minecraft:block_pos | LocationArgument ( LocationType.BLOCK_POSITION ) |
minecraft:block_predicate | BlockPredicateArgument |
minecraft:block_state | BlockStateArgument |
minecraft:color | ChatColorArgument |
minecraft:column_pos | Location2DArgument ( LocationType.BLOCK_POSITION ) |
minecraft:component | ChatComponentArgument |
minecraft:dimension | WorldArgument |
minecraft:entity | EntitySelectorArgument |
minecraft:entity_anchor | |
minecraft:entity_summon | EntityTypeArgument |
minecraft:float_range | FloatRangeArgument |
minecraft:function | FunctionArgument |
minecraft:game_profile | PlayerArgument |
minecraft:game_profile | OfflinePlayerArgument |
minecraft:int_range | IntegerRangeArgument |
minecraft:item_enchantment | EnchantmentArgument |
minecraft:item_predicate | ItemStackPredicateArgument |
minecraft:item_slot | |
minecraft:item_stack | ItemStackArgument |
minecraft:message | ChatArgument |
minecraft:mob_effect | PotionEffectArgument |
minecraft:nbt | |
minecraft:nbt_compound_tag | NBTCompoundArgument |
minecraft:nbt_path | |
minecraft:nbt_tag | |
minecraft:objective | ObjectiveArgument |
minecraft:objective_criteria | ObjectiveCriteriaArgument |
minecraft:operation | MathOperationArgument |
minecraft:particle | ParticleArgument |
minecraft:resource_location | AdvancementArgument BiomeArgument CustomArgument<T> LootTableArgument NamespacedKeyArgument RecipeArgument SoundArgument |
minecraft:rotation | RotationArgument |
minecraft:score_holder | ScoreHolderArgument |
minecraft:scoreboard_slot | ScoreboardSlotArgument |
minecraft:swizzle | AxisArgument |
minecraft:team | TeamArgument |
minecraft:time | TimeArgument |
minecraft:uuid | UUIDArgument |
minecraft:vec2 | Location2DArgument ( LocationType.PRECISE_POSITION ) |
minecraft:vec3 | LocationArgument ( LocationType.PRECISE_POSITION ) |
There are a few arguments that aren't implemented. Here's why:
-
minecraft:entity_anchor
- This argument only has two values:eyes
andfeet
. It's incredibly unnecessary for any other purpose and is easier to implement with aMultiLiteralArgument
. -
minecraft:item_slot
- Bukkit's implementation of item slot numbers differs very wildly to Minecraft's implementation of item slot numbers. This difference makes it near-impossible to have a suitable middle-ground for item slot numbers that ensures that invalid numbers cannot be passed to the wrong inventory type. An implementation of this would require a rewrite of the current system to maintain proper inventory slot access safety. -
minecraft:nbt
,minecraft:nbt_path
,minecraft:nbt_tag
- You've got theNBTCompoundArgument
, that's good enough, right? ¯\_(ツ)_/¯
Reloading datapacks
During the initialization of Minecraft 1.16+ servers, the CommandAPI uses a custom datapack reloading sequence as opposed to the normal Vanilla Minecraft datapack reloading method. The CommandAPI's method uses the server's current command dispatcher object as opposed to a new one, which allows datapacks to use commands registered by the CommandAPI. This can be invoked using the following method:
CommandAPI.reloadDatapacks();
Getting a list of registered commands
The CommandAPI doesn't store the CommandAPICommand
objects during the main running of the server because it simply doesn't need to. Instead, it stores a list of RegisteredCommand
objects which are defined as the following, which should be fairly self-explanatory:
public record RegisteredCommand {
String commandName();
List<String> argsAsStr();
Optional<String> shortDescription();
Optional<String> fullDescription();
Optional<String[]> usageDescription();
String[] aliases();
CommandPermission permission();
}
The argsAsStr()
method returns a list of arguments in a string format, of the form argName:SimpleClassName
, where argName
is the name of the argument (the argument's node name) and SimpleClassName
is the name of the argument class that was used to construct it (such as IntegerArgument
).
A List<RegisteredCommand>
can be acquired using the following method:
CommandAPI.getRegisteredCommands();
Note that this list does not update when commands are unregistered, only when commands are registered.