Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fc42c87

Browse files
committed
adding example project
1 parent dc6a515 commit fc42c87

File tree

5 files changed

+103
-0
lines changed

5 files changed

+103
-0
lines changed

examples/kotlindsl/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# kotlin-dsl
2+
3+
A simple example showcasing creating a command using the Kotlin DSL for the CommandAPI!
4+
5+
Key points:
6+
7+
- You do not need to use the `.register()` method
8+
- You do not need to initialise any arguments.

examples/kotlindsl/pom.xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>dev.jorel</groupId>
4+
<artifactId>kotlin-dsl</artifactId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
7+
<properties>
8+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
9+
</properties>
10+
11+
<repositories>
12+
<!-- This adds the Spigot Maven repository to the build -->
13+
<repository>
14+
<id>spigot-repo</id>
15+
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
16+
</repository>
17+
</repositories>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>dev.jorel</groupId>
22+
<artifactId>commandapi-kotlin</artifactId>
23+
<version>8.6.0-SNAPSHOT</version>
24+
</dependency>
25+
26+
<!--This adds the Spigot API artifact to the build -->
27+
<dependency>
28+
<groupId>org.spigotmc</groupId>
29+
<artifactId>spigot-api</artifactId>
30+
<version>1.19-R0.1-SNAPSHOT</version>
31+
<scope>provided</scope>
32+
</dependency>
33+
</dependencies>
34+
35+
<build>
36+
<defaultGoal>clean package</defaultGoal>
37+
<plugins>
38+
<plugin>
39+
<artifactId>maven-compiler-plugin</artifactId>
40+
<version>3.8.1</version>
41+
<configuration>
42+
<release>16</release>
43+
</configuration>
44+
</plugin>
45+
</plugins>
46+
</build>
47+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.github.jorelali
2+
3+
import dev.jorel.commandapi.CommandAPI
4+
import dev.jorel.commandapi.CommandAPIConfig
5+
import org.bukkit.plugin.java.JavaPlugin
6+
7+
class Main : JavaPlugin() {
8+
9+
override fun onEnable() {
10+
CommandAPI.onLoad(CommandAPIConfig())
11+
CommandAPI.onEnable(this)
12+
SayHelloCommand().register()
13+
}
14+
15+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.github.jorelali
2+
3+
import dev.jorel.commandapi.*
4+
import org.bukkit.entity.Player
5+
6+
class SayHelloCommand {
7+
8+
fun register() {
9+
commandTree("sayhello") {
10+
playerArgument("target") {
11+
playerExecutor { player, args ->
12+
val target: Player = args[0] as Player
13+
target.sendMessage("§6${player.name} says hello to you!")
14+
}
15+
}
16+
}
17+
18+
commandAPICommand("suicide") {
19+
literalArgument("confirm")
20+
playerExecutor { player, args ->
21+
player.health = 0.0
22+
}
23+
}
24+
}
25+
26+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: KotlinDSL
2+
main: io.github.jorelali.Main
3+
version: 0.0.1
4+
author: Skepter
5+
website: https://www.jorel.dev/CommandAPI/
6+
api-version: 1.13
7+
depend: [CommandAPI]

0 commit comments

Comments
 (0)