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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
adding example project
  • Loading branch information
DerEchtePilz committed Nov 3, 2022
commit fc42c87bd41bc0e374bc55858d984bbdfc4e2343
8 changes: 8 additions & 0 deletions examples/kotlindsl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# kotlin-dsl

A simple example showcasing creating a command using the Kotlin DSL for the CommandAPI!

Key points:

- You do not need to use the `.register()` method
- You do not need to initialise any arguments.
47 changes: 47 additions & 0 deletions examples/kotlindsl/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>dev.jorel</groupId>
<artifactId>kotlin-dsl</artifactId>
<version>0.0.1-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<repositories>
<!-- This adds the Spigot Maven repository to the build -->
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-kotlin</artifactId>
<version>8.6.0-SNAPSHOT</version>
</dependency>

<!--This adds the Spigot API artifact to the build -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.19-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<defaultGoal>clean package</defaultGoal>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>16</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
15 changes: 15 additions & 0 deletions examples/kotlindsl/src/main/kotlin/io/github/jorelali/Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.github.jorelali

import dev.jorel.commandapi.CommandAPI
import dev.jorel.commandapi.CommandAPIConfig
import org.bukkit.plugin.java.JavaPlugin

class Main : JavaPlugin() {

override fun onEnable() {
CommandAPI.onLoad(CommandAPIConfig())
CommandAPI.onEnable(this)
SayHelloCommand().register()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.github.jorelali

import dev.jorel.commandapi.*
import org.bukkit.entity.Player

class SayHelloCommand {

fun register() {
commandTree("sayhello") {
playerArgument("target") {
playerExecutor { player, args ->
val target: Player = args[0] as Player
target.sendMessage("§6${player.name} says hello to you!")
}
}
}

commandAPICommand("suicide") {
literalArgument("confirm")
playerExecutor { player, args ->
player.health = 0.0
}
}
}

}
7 changes: 7 additions & 0 deletions examples/kotlindsl/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: KotlinDSL
main: io.github.jorelali.Main
version: 0.0.1
author: Skepter
website: https://www.jorel.dev/CommandAPI/
api-version: 1.13
depend: [CommandAPI]