Last active
November 10, 2016 03:09
-
-
Save BasixKOR/152bbb187189b0bd28df to your computer and use it in GitHub Desktop.
Help coding bukkit plugin with kotlin.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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