Skip to content

KotlinBukkitAPI is an API for Bukkit/SpigotAPI using the cool and nifty features Kotlin has to make your life more easier.

License

Notifications You must be signed in to change notification settings

DevSrSouza/KotlinBukkitAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KotlinBukkitAPI

KotlinBukkitAPI

Kotlin version GitHub stars Github Issues GitHub last commit Discord Minecraft Server Running with KotlinBukkitAPI MIT License Build Status

KotlinBukkitAPI is an API for Bukkit/SpigotAPI using the cool and nifty features Kotlin has to make your life more easier.

ANNOUNCEMENT

Developer returns to the project! You can find a lot more information at Discord, join and chat with me!

Contents:

Samples

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

Project

Modules

Module Description
Architecture KotlinPlugin and Lifecycle aware APIs, inspired in Android Lifecycle Components
Extensions Extensions for bunch of Bukkit types like block, player, inventory, text, permissions, etc
Utility Utility types and APIs for Kotlin and Bukkit development, for example, ExpiratioList, OnlinePlayerCollections, Kotlin Duration tick support.
Coroutines Adds Kotlin Coroutines Dispatcher for Bukkit Scheduler API as well as adding Flow APIs and Structured Concurrency (CoroutineScope bounded to Lifecycle of the plugin or Manager class).
Exposed Extensions for SQL framework Exposed
Serialization Extensions for Kotlinx.serialization
Menu DSL to create Menus easy and support for Preview in IntelliJ by using the Plugin
Command Legacy DSL to create Commands and Sub Commands with Parameter type safe, auto registering and support for Coroutines
Scoreboard Legacy DSL to create Scoreboard with support for handling updates easily

Consider donate

Buy Me A Coffee




logo

About

KotlinBukkitAPI is an API for Bukkit/SpigotAPI using the cool and nifty features Kotlin has to make your life more easier.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages