8000 Add Kotlin DSL support for delegations by DerEchtePilz · Pull Request #482 · CommandAPI/CommandAPI · GitHub
[go: up one dir, main page]

Skip to content

Add Kotlin DSL support for delegations #482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ This is the current roadmap for the CommandAPI (as of 11th May 2023):
<ul>
<li>https://github.com/JorelAli/CommandAPI/issues/487 Added support for disabling integer centering for location arguments</li>
<li>https://github.com/JorelAli/CommandAPI/issues/488 Fixed calling CommandAPI commands with <code>Bukkit.createCommandSender()</code> not working on paper</li>
<li>https://github.com/JorelAli/CommandAPI/pull/482 Adds Kotlin DSL support for delegations</li>
</ul>
</td>
</tr>
Expand Down
8000
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package dev.jorel.commandapi.examples.kotlin

import de.tr7zw.changeme.nbtapi.NBTContainer
import dev.jorel.commandapi.*
import dev.jorel.commandapi.arguments.*
import dev.jorel.commandapi.arguments.LiteralArgument.of
import dev.jorel.commandapi.executors.*
import dev.jorel.commandapi.kotlindsl.*
import dev.jorel.commandapi.wrappers.*
import dev.jorel.commandapi.wrappers.Rotation
Expand Down Expand Up @@ -1011,6 +1008,18 @@ commandAPICommand("commandRequirement") {
/* ANCHOR_END: kotlindsl6 */

/* ANCHOR: kotlindsl7 */
commandAPICommand("mycommand") {
stringArgument("string")
playerArgument("target")
playerExecutor { player, args ->
val string: String by args
val target: Player by args
// Implementation...
}
}
/* ANCHOR_END: kotlindsl7 */

/* ANCHOR: kotlindsl8 */
commandTree("optionalArgument") {
literalArgument("give") {
itemStackArgument("item") {
Expand All @@ -1028,9 +1037,9 @@ commandTree("optionalArgument") {
}
}
}
/* ANCHOR_END: kotlindsl7 */
/* ANCHOR_END: kotlindsl8 */

/* ANCHOR: kotlindsl8 */
/* ANCHOR: kotlindsl9 */
commandAPICommand("optionalArgument") {
literalArgument("give")
itemStackArgument("item")
Expand All @@ -1045,9 +1054,9 @@ commandAPICommand("optionalArgument") {
player.inventory.addItem(itemStack)
}
}
/* ANCHOR_END: kotlindsl8 */
/* ANCHOR_END: kotlindsl9 */

/* ANCHOR: kotlindsl9 */
/* ANCHOR: kotlindsl10 */
commandTree("replaceSuggestions") {
stringArgument("strings") {
replaceSuggestions(ArgumentSuggestions.strings("one", "two", "three")) // Replaces the suggestions for the "strings" StringArgument
Expand All @@ -1056,9 +1065,9 @@ commandTree("replaceSuggestions") {
}
}
}
/* ANCHOR_END: kotlindsl9 */
/* ANCHOR_END: kotlindsl10 */

/* ANCHOR: kotlindsl10 */
/* ANCHOR: kotlindsl11 */
commandAPICommand("replaceSuggestions") {
stringArgument("strings") {
replaceSuggestions(ArgumentSuggestions.strings("one", "two", "three")) // Replaces the suggestions for the "strings" StringArgument
Expand All @@ -1067,7 +1076,7 @@ commandAPICommand("replaceSuggestions") {
player.sendMessage("You chose option ${args["strings"] as String}!")
}
}
/* ANCHOR_END: kotlindsl10 */
/* ANCHOR_END: kotlindsl11 */
}

fun native() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<parent>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-bukkit</artifactId>
<artifactId>commandapi-kotlin</artifactId>
<version>9.2.0-SNAPSHOT</version>
</parent>

Expand Down Expand Up @@ -89,5 +89,10 @@
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-core-kotlin</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
76 changes: 76 additions & 0 deletions commandapi-kotlin/commandapi-core-kotlin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-kotlin</artifactId>
<version>9.2.0-SNAPSHOT</version>
</parent>

<artifactId>commandapi-core-kotlin</artifactId>

<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</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>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>empty-javadoc-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>javadoc</classifier>
<classesDirectory>${basedir}/javadoc</classesDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-core</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dev.jorel.commandapi.kotlindsl

import dev.jorel.commandapi.executors.CommandArguments
import kotlin.reflect.KProperty

// CommandArguments DSL
inline operator fun <reified T> CommandArguments.getValue(nothing: Nothing?, property: KProperty<*>) = this[property.name] as T
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@

<parent>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-velocity</artifactId>
<artifactId>commandapi-kotlin</artifactId>
<version>9.2.0-SNAPSHOT</version>
</parent>

<artifactId>commandapi-velocity-kotlin</artifactId>
<packaging>jar</packaging>

<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>
Expand Down Expand Up @@ -59,13 +58,18 @@
<scope>provided</scope>
</dependency>

<!--- CommandAPI velocity core dependency -->
<!--- CommandAPI dependencies -->
<dependency>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-velocity-core</artifactId>
<version>9.2.0-SNAPSHOT</version>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-core-kotlin</artifactId>
<version>${project.version}</version>
</dependency>

<!--- Kotlin dependencies -->
<dependency>
Expand All @@ -74,11 +78,5 @@
<version>${kotlin.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
15 changes: 15 additions & 0 deletions commandapi-kotlin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>dev.jorel</groupId>
<artifactId>commandapi</artifactId>
<version>9.2.0-SNAPSHOT</version>
</parent>

<artifactId>commandapi-kotlin</artifactId>
<packaging>pom</packaging>

</project>

This file was deleted.

Loading
0