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:

IdentifierCommandAPI argument
brigadier:boolBooleanArgument
brigadier:doubleDoubleArgument
brigadier:floatFloatArgument
brigadier:integerIntegerArgument
brigadier:longLongArgument
brigadier:stringStringArgument
TextArgument
GreedyStringArgument
CustomArgument<T>
minecraft:angleAngleArgument
minecraft:block_posLocationArgument
(LocationType.BLOCK_POSITION)
minecraft:block_predicateBlockPredicateArgument
minecraft:block_stateBlockStateArgument
minecraft:colorChatColorArgument
minecraft:column_posLocation2DArgument
(LocationType.BLOCK_POSITION)
minecraft:componentChatComponentArgument
minecraft:dimensionEnvironmentArgument
minecraft:entityEntitySelectorArgument
minecraft:entity_anchor
minecraft:entity_summonEntityTypeArgument
minecraft:float_rangeFloatRangeArgument
minecraft:functionFunctionArgument
minecraft:game_profilePlayerArgument
minecraft:game_profileOfflinePlayerArgument
minecraft:int_rangeIntegerRangeArgument
minecraft:item_enchantmentEnchantmentArgument
minecraft:item_predicateItemStackPredicateArgument
minecraft:item_slot
minecraft:item_stackItemStackArgument
minecraft:messageChatArgument
minecraft:mob_effectPotionEffectArgument
minecraft:nbt
minecraft:nbt_compound_tagNBTCompoundArgument
minecraft:nbt_path
minecraft:nbt_tag
minecraft:objectiveObjectiveArgument
minecraft:objective_criteriaObjectiveCriteriaArgument
minecraft:operationMathOperationArgument
minecraft:particleParticleArgument
minecraft:resource_locationAdvancementArgument
BiomeArgument
CustomArgument<T>
LootTableArgument
RecipeArgument
SoundArgument
minecraft:rotationRotationArgument
minecraft:score_holderScoreHolderArgument
minecraft:scoreboard_slotScoreboardSlotArgument
minecraft:swizzleAxisArgument
minecraft:teamTeamArgument
minecraft:timeTimeArgument
minecraft:uuidUUIDArgument
minecraft:vec2Location2DArgument
(LocationType.PRECISE_POSITION)
minecraft:vec3LocationArgument
(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 and feet. It's incredibly unnecessary for any other purpose and is easier to implement with a MultiLiteralArgument.

  • 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 the NBTCompoundArgument, 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();
    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.