Skip to content

Instantly share code, notes, and snippets.

@BasixKOR
Last active November 10, 2016 03:09
Show Gist options
  • Save BasixKOR/152bbb187189b0bd28df to your computer and use it in GitHub Desktop.
Save BasixKOR/152bbb187189b0bd28df to your computer and use it in GitHub Desktop.
Help coding bukkit plugin with kotlin.
import org.bukkit.Bukkit
import org.bukkit.OfflinePlayer
import org.bukkit.plugin.java.JavaPlugin
import java.util.*
/**
* Created by Basix on 16. 2. 14.
* Help develop plugin with kotlin.
*
* @author Basix
*/
fun doCommand(f: () -> Unit): Boolean {
/**
* This is lambda function for onCommand method.
* override fun onCommand(sender: CommandSender, cmd: Command, label: String, args: Array<String>) = when (cmd.label){
* "command" -> doCommand{ }
* else -> false
* }
* @param () -> Unit
*/
f()
return true
}
/**
* Works with UUIDFetcher.
*
* @param PlayerName, plugin
*/
fun getOfflinePlayer(PlayerName: String, plugin: JavaPlugin): OfflinePlayer {
val fetcher = UUIDFetcher(Arrays.asList(PlayerName))
var response: Map<String, UUID> = kotlin.collections.emptyMap()
try {
response = fetcher.call()
} catch (e: Exception) {
plugin.logger.warning("Exception while running UUIDFetcher")
e.printStackTrace()
}
return Bukkit.getOfflinePlayer(response.get(PlayerName))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment