Simple, but powerful annotation-based multiplatform command API inspired by many of the available APIs.
Those which are not marked are planned, but not ready.
- Annotation-based commands
- Automated argument parsing
- Automated tab-completion
- Custom argument parsers
- BungeeCord support
- SpigotMC support
- PaperMC support
- Velocity support
- Automated help messages
- Automated debug messages
This API works as library - it does not require to install any file to the server.
First, you need to set up the dependency on the ForestCommandAPI. Replace VERSION with the version of the release. Replace PLATFORM with the name of the supported platforms (currently "paper" and "velocity", in the future "spigot" and "bungeecord" will follow).
Maven
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.ForestTechMC.ForestCommandAPI</groupId>
<artifactId>PLATFORM</artifactId>
<version>VERSION</version>
</dependency>
</dependencies>Gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.ForestTechMC.ForestCommandAPI:PLATFORM:VERSION'
}Setting up is platform specific, especially for Velocity due to its unique approach.
PaperMC
Just create a new CommandAPI instance and you're good to go.
@OverridepublicvoidonEnable() {
/* ... your other stuff ... */CommandAPIcommandAPI = newCommandAPI(this);
/* ... your other stuff ... */
}Velocity
This is a bit tricky as internal API structure requires ProxyServer to be accessible from within.
// You need to implement ProxyServerProvider to allow CommandAPI to access the// ProxyServer instance@Plugin(/* your stuff here*/)
publicclassVelocityPluginimplementsProxyServerProvider {
privatefinalProxyServerproxyServer;
@InjectpublicVelocityPlugin(ProxyServerproxyServer/* ... and your other stuff...*/) {
this.proxyServer = proxyServer;
/* ... your other stuff... */
}
@SubscribepublicvoidonProxyInitialization(ProxyInitializeEventevent) {
/* ... your other stuff ... */CommandAPIcommandAPI = newCommandAPI(this);
/* ... your other stuff ... */
}
// Implementing #getProxyServer to provide ProxyServer instance@OverridepublicvoidgetProxyServer() {
returnproxyServer;
}
}Making command class
// Use onEnable or similar method based on the platform@Command(name = "mycmd")
publicclassMyCommandimplementsCommandProcessor {
@SubCommandpublicvoiddefaultNoArgs(CommandSendercommandSender) {
commandSender.sendMessage("Command with no args!");
} @SubCommand(names = "first")
publicvoidprefixNoArgs(CommandSendercommandSender) {
commandSender.sendMessage("Sub-command with no args!");
}
@SubCommand(names = "second")
publicvoidprefixWithArgs(CommandSendercommandSender, @Arg(name="arg1") Stringarg1, @Arg(name="int-arg", required=false) Integerarg2) {
commandSender.sendMessage("Sub-command with args: " + arg1 + " " + arg2);
}
}Registering the command
CommandAPIcommandAPI = newCommandAPI(pluginMain); // plugin main as the argumentcommandAPI.registerCommand(newMyCommand());ForestCommandAPI is licensed under the permissive MIT license. Please see LICENSE.txt for more information.