KotlinBukkitAPI is an API for Bukkit/SpigotAPI using the cool and nifty features Kotlin has to make your life more easier.
KotlinBukkitAPI goes beyond this samples, and you can find all of it in the wiki/documentation.
Event DSL sample
plugin.events {
event<PlayerJoinEvent> {
player.msg("&3Welcome ${player.name}".translateColor())
}
event<PlayerQuitEvent> {
broadcast("&eThe player &c${player.name} &eleft :(".translateColor())
}
}
Simple Command DSL example
plugin.simpleCommand("twitter") {
sender.msg("&eFollow me on Twitter :D &ahttps://twitter.com/DevSrSouza".translateColor())
}
Item meta DSL and other stuff
val gem = item(Material.DIAMOND).apply {
amount = 5
meta<ItemMeta> {
displayName = "&bGem".translateColor()
}
}
val encbook = item(Material.ENCHANTED_BOOK).meta<EnchantmentStorageMeta> {
displayName = "&4&lThe powerful BOOK".translateColor()
addStoredEnchant(Enchantment.DAMAGE_ALL, 10, true) // putting sharpness 10 to the book
}
Another approach:
val gem = item(Material.DIAMOND, amount = 5).displayName("&bGem".translateColor())
val encbook = metadataItem<EnchantmentStorageMeta>(Material.ENCHANTED_BOOK) {
displayName = "&4&lThe powerful BOOK".translateColor()
addStoredEnchant(Enchantment.DAMAGE_ALL, 10, true) // putting sharpness 10 to the book
}
Menu creator DSL
val myMenu = menu(+"&cWarps", 3, true) {
val arenaPvP = item(Material.DIAMOND_SWORD) {
addEnchant(Enchantment.DAMAGE_ALL, 5, true)
displayName = "&4Arena PvP".translateColor()
}
slot(2, 4, arenaPvP) { // Line, Slot
onClick {
player.teleport(Location(player.world, 250, 70, -355))
close() // close the menu
}
}
slot(2, 6, item(Material.GOLD).displayName("&6Shop".translateColor())) {
onClick {
player.teleport(Location(player.world, 2399, 70, -1234))
close() // close the menu
}
}
// when the menu renders to a player, will show the Paper item with their name.
slot(3, 9, item(Material.PAPER).displayName("Hello {player}")) {
onRender {
showingItem?.meta<ItemMeta> {
displayName = displayName.replace("{player}", player.name)
}
}
}
}
// open to player
myMenu.openToPlayer(player)
You can find more examples in the Documentation
Name | Version |
---|---|
Spigot API | 1.8.8+ |
If you shade your plugin or use PDM, this dependencies should not be loaded be your plugin, you should let the KotlinBukkitAPI provide it at runtime to prevent conflicts.
More about how to setup a project with KotlinBukkitAPI here.
Name | Version |
---|---|
Kotlin STD + JDK8 | 1.4.10 |
Kotlin Reflect | 1.4.10 |
Kotlinx-coroutines | 1.3.9 |
Skedule | 1.2.6 |
Kotlinx.serialization | 1.4.0-RC |
KAML | 0.19.0 |
Exposed | 0.25.1 |
HikariCP | 3.3.1 |
Module | Description |
---|---|
Core | The heart of the project containing the important API and extensions |
Plugins | Extensions for others plugins like Vault, PlaceholderAPI and others |
Exposed | Extensions for SQL framework Exposed |
Serialization | Extensions for Kotlinx.serialization |