File tree Expand file tree Collapse file tree 5 files changed +103
-0
lines changed
kotlin/io/github/jorelali Expand file tree Collapse file tree 5 files changed +103
-0
lines changed Original file line number Diff line number Diff line change
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.
Original file line number Diff line number Diff line change
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 >
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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]
You can’t perform that action at this time.
0 commit comments