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-bukkit-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.5.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.9.0</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.9.0</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.5.2"
}
dependencies {
    implementation("dev.jorel:commandapi-bukkit-kotlin:9.5.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.9.0"
}
plugins {
    kotlin("jvm") version "1.9.0"
}

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)
}