Kotlin-based commands

The CommandAPI also provides an alternative way of making commands when using Kotlin to develop your plugins: A DSL!

This DSL provides many methods to easily add arguments to your command structure. Examples of the DSL can be found here.


Installing the DSL

To install the DSL, you need to add the commandapi-kotlin dependency into your pom.xml or your build.gradle, making sure to specify the server flavor you are developing for:

Adding the dependency with Maven

<dependencies>
    <dependency>
        <groupId>dev.jorel</groupId>
        <artifactId>commandapi-bukkit-kotlin</artifactId>
        <version>9.0.2</version>
    </dependency>
</dependencies>
<dependencies>
    <dependency>
        <groupId>dev.jorel</groupId>
        <artifactId>commandapi-velocity-kotlin</artifactId>
        <version>9.0.2</version>
    </dependency>
</dependencies>

Next, you need to add Kotlin to your project. For this, you first need to add the dependency:

<dependencies>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-stdlib</artifactId>
        <version>1.8.20</version>
    </dependency>
</dependencies>

Finally, you need to add the kotlin-maven-plugin:

<build>
    <plugins>
        <plugin>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-plugin</artifactId>
            <version>1.8.20</version>
            <executions>
                <execution>
                    <id>compile</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
                <execution>
                    <id>test-compile</id>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>test-compile</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <jvmTarget>16</jvmTarget>
            </configuration>
        </plugin>
    </plugins>
</build>

Adding the dependency with Gradle

First, you need to add the repository:

repositories {
    mavenCentral()
}
repositories {
    mavenCentral()
}

Next, you need to add the dependency:

dependencies {
    implementation "dev.jorel:commandapi-bukkit-kotlin:9.0.2"
}
dependencies {
    implementation("dev.jorel:commandapi-bukkit-kotlin:9.0.2")
}
dependencies {
    implementation "dev.jorel:commandapi-velocity-kotlin:9.0.2"
}
dependencies {
    implementation("dev.jorel:commandapi-velocity-kotlin:9.0.2")
}

You also need to add Kotlin to your project. For this, you first need to add the Kotlin plugin:

plugins {
    id "org.jetbrains.kotlin.jvm" version "1.8.20"
}
plugins {
    kotlin("jvm") version "1.8.20"
}

Next, you need to add the dependency (you should already have added the mavenCentral() repository to your project):

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib"
}
dependencies {
    implementation("org.jetbrains.kotlin:kotlin-stdlib")
}

Then, you need to configure the Java version to build against:

kotlin {
    jvmToolchain(16)
}
kotlin {
    jvmToolchain(16)
}