Skip to content
Daniel Ennis edited this page Jun 22, 2017 · 18 revisions

Using ACF - Annotation Command Framework

Build Tool Setup

See Maven, Gradle, or you can find artifacts here:

https://repo.aikar.co/content/groups/aikar/co/aikar/commands/

Getting a Command Manager

BukkitCommandManager manager = new BukkitCommandManager(yourBukkitPlugin);

Registering a command

First you need to create a class that extends BaseCommand, then register that command with the manager

manager.registerCommand(new MyCommand());

If you need your plugin instance, pass it to your commands constructor like so

manager.registerCommand(new MyCommand(myPlugin));

Registering Command Completion Handlers

Special Completion Handlers are prefixed @ like @foo

To register your own custom ones, one would do

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

Registering Command Context Handlers

Command Context Handlers are able to resolve input to custom Java objects.

To register your own custom ones, one would do

manager.getCommandContexts().registerContext(Foo.class, c -> {
   return /* stuff */;
});

See CommandExecutionContext for information on what methods are available for (c) See CommandContexts and BukkitCommandContexts for examples.

You may also use registerIssuerAwareContext instead to tell ACF that this resolver is able to resolve without consuming input, by understanding the context of the issuer of the command (such as World, Location, Etc)

A non issuer aware resolver must consume input. Issuer Aware may optionally consume input if supplied, and fallback to context if not.

If you want an Issuer Only resolver, one that always resolves based on Issuer and never consumes input, you may use registerIssuerOnlyContext