KotlinSpigotPluginTemplate
Basic Kotlin Spigot Plugin Template for plugin developers who wants to use Kotlin. You can clone this repo or create a fork. You can change name, version and main from plugin.yml and they will change Gradle configuration.
Install / Use
/learn @LiberaTeMetuMortis/KotlinSpigotPluginTemplateREADME
How can you use this template?
How to clone
git clone https://github.com/MetuMortis-code/KotlinSpigotPluginTemplate.git
How to use
Configure project/src/main/resources/plugin.yml.
Set version, name, main, api-version and do more if you want.
You should run ./gradlew shadowJar to get usable jar.
Why Kotlin?
Which is in Java but better in Kotlin
val array = arrayOf(1, 2, 3, 4, 5)
val sum = array.sum()
val first = array.first()
val last = array.last()
val biggest = array.maxOrNull()
You don't have to create separate getter and setter methods for fields
var name = "John"
get() = field.toUpperCase()
set(value) {
field = value.toLowerCase()
}
You can use any Java library or api written in Java in Kotlin
import java.util.*
fun main(args: Array<String>) {
val scanner = Scanner(System.`in`)
print("Enter your name: ")
val name = scanner.nextLine()
println("Name is: $name")
scanner.close()
}
What does Java doesn't have but Kotlin does have?
val name = "John"
println("Hello, $name")
val nullableName: String? = null
val nameLength: Int = name?.length ?: -1
println(length)
data class Person(val name: String, val age: Int)
val John = Person("John", 30)
val anotherJohn = Person("John", 30)
println(John.equals(anotherJohn))
fun sayHi(name: String = "No one", age: Integer) = println("Hi, $name, you are $age years old")
sayHi(age = 30)
println(5 in 1..10)
for(i in 1..10) {
println(i)
}
data class Point(val x: Int, val y: Int)
operator fun Point.unaryMinus() = Point(-x, -y)
val point = Point(10, 20)
fun main() {
println(-point) // prints "Point(x=-10, y=-20)"
}
infix fun Int.powerOf(n: Int): Int {
return this.pow(n)
}
println(2 powerOf 3)
fun MutableList<Int>.swap(index1: Int, index2: Int) {
val tmp = this[index1] // 'this' corresponds to the list
this[index1] = this[index2]
this[index2] = tmp
}
val list = mutableListOf(1, 2, 3)
list.swap(0, 2) // 'this' inside 'swap()' will hold the value of 'list'
Kotlin has objects that don’t have any nontrivial supertypes.
val person = object {
val name = "John"
val age = 30
}
println(person.name)
data class Person(val name: String, val age: Int)
val (name, age) = Person("John", 30)
data class Person(var name: String, var age: Int = 0, var city: String = "")
val adam = Person("Adam").apply {
age = 32
city = "London"
}
println(adam) // Person(name=Adam, age=32, city=London)
fun getStringLength(obj: Any): Int? {
if (obj is String) {
return obj.length
}
return null
}
Why Gradle?
I used Gradle because scripting with Gradle using Kotlin is a lot easier than Maven
Related Skills
node-connect
333.7kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
82.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
333.7kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
82.0kCommit, push, and open a PR


