mirror of
https://github.com/aikar/commands.git
synced 2026-06-23 07:00:37 +00:00
Updated Using ACF (markdown)
+14
-17
@@ -8,9 +8,18 @@ Or manual: https://repo.aikar.co/nexus/content/groups/aikar/co/aikar/
|
||||
## Getting a Command Manager
|
||||
This part is platform specific. Use the command manager that represents your platform.
|
||||
|
||||
Bukkit:
|
||||
```java
|
||||
BukkitCommandManager manager = new BukkitCommandManager(yourBukkitPlugin);
|
||||
```
|
||||
Bungee:
|
||||
```java
|
||||
BungeeCommandManager manager = new BungeeCommandManager(yourBungeePlugin);
|
||||
```
|
||||
Sponge:
|
||||
```java
|
||||
SpongeCommandManager manager = new SpongeCommandManager(yourSpongePlugin);
|
||||
```
|
||||
|
||||
## Registering a command
|
||||
First you need to create a class that extends `BaseCommand`, then register that command with the manager
|
||||
@@ -18,26 +27,14 @@ First you need to create a class that extends `BaseCommand`, then register that
|
||||
manager.registerCommand(new MyCommand());
|
||||
```
|
||||
|
||||
If you need your plugin instance, pass it to your commands constructor like so
|
||||
If you need your plugin instance, pass it to your commands constructor like so (this is called dependency injection if you are not aware)
|
||||
|
||||
```java
|
||||
manager.registerCommand(new MyCommand(myPlugin));
|
||||
```
|
||||
|
||||
## Registering Command Context Handlers
|
||||
[Command Context](Command-Contexts) Handlers are able to resolve input to custom Java objects.
|
||||
See [Wiki Home](./) for links to the other guides, but here is some important ones:
|
||||
|
||||
To register your own custom ones, one would do
|
||||
```java
|
||||
manager.getCommandContexts().registerContext(Foo.class, c -> {
|
||||
return /* stuff */;
|
||||
});
|
||||
```
|
||||
See [CommandExecutionContext](https://github.com/aikar/commands/blob/master/core/src/main/java/co/aikar/commands/CommandExecutionContext.java) for information on what methods are available for (c)
|
||||
See [CommandContexts](https://github.com/aikar/commands/blob/master/core/src/main/java/co/aikar/commands/CommandContexts.java) and [BukkitCommandContexts](https://github.com/aikar/commands/blob/master/bukkit/src/main/java/co/aikar/commands/BukkitCommandContexts.java) 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`
|
||||
* [Command Contexts](Contexts)
|
||||
* [Command Completions](Completions)
|
||||
* [Locales / I18N](Locales)
|
||||
Reference in New Issue
Block a user