Skip to content

Command Completions

Alexander Trost edited this page Feb 2, 2022 · 5 revisions

Command Completions

What are Completion Handlers

When a user inputs a command into a system that supports tab completion (All of our supported platforms do), when you type a partial command, ACF can programmatically build suggestions into what the user is wanting to complete to.

This may be sub commands, or input into your defined command such as online players, enum values, etc.

When using your own custom context objects, you can define a matching completion handler to provide completion values.

Completion Configs

Special Completion Handlers are prefixed @ like @foo, you may tack on additional config data by then using : followed by a comma separated list of key/value configs, like so:

@foo:foo=bar,baz=qux

The context handler can then do c.getConfig("foo") to get bar, and c.getConfig("baz") to get qux.

Registering Command Completion Handlers

To register your own custom ones, one would do

manager.getCommandCompletions().registerCompletion("foo", c -> {
   return ImmutableList.of("some", "custom", "completion");
});

Command Replacements / I18N

All Command Replacements can be used in Command Completions using %replacementid syntax for replacements. See Locales / I18N for documentation on using I18N keys.

Asynchronous Command Completions

A completion handler can declare that it is safe to run asynchronous to the applications main thread, by using registerAsyncCompletion instead of registerCompletion.

If the target platform supports Asynchronous Tab Completions, then these handlers will be executed asynchronously.

The only platform at this time that supports Asynchronous Tab Completion is Paper Minecraft Servers, Version 1.12.2+ on builds 1280~ or higher.

If the platform does not support Asynchronous completion, then the handler will be ran synchronous to the standard thread the platform expects it to run on (main).

If a CommandContext accesses Completion data such as through @Values("@completionid"), then that handler will also be executed synchronously.

If knowing you are currently synchronous vs asynchronous matters, you may use CommandManager.getCurrentCommandOperationContext().isAsync();

Default Completion Values

  • @nothing - returns nothing
  • @range - takes a completion, pass range like so @range:0-20 or @range:20 (assumed 0 start)

Minecraft Specific Completion Values

  • @mobs - list of EntityType enum values (Bukkit)
  • @chatcolors - lists of all the chat colors supported by your platform (Bukkit, Bungee)
  • @worlds - lists all world names (Bukkit)
  • @players - lists all online players that you can see (depending on platform API/vanish) (Bukkit, Bungee(no vanish))