Merge pull request #2 from SKBotNL/main

Update example for DiamondBank-OG
This commit was merged in pull request #2.
This commit is contained in:
NotAlexNoyle authored and GitHub committed 2025-06-11 15:47:21 -04:00
commit 78d97d9a0a
3 files changed
+24 -18

No files matched your search

+3 -3
View File
@@ -3,7 +3,7 @@
package plugin
import kotlinx.coroutines.*
import net.trueog.diamondbankog.DiamondBankAPI
import net.trueog.diamondbankog.DiamondBankAPIKotlin
import org.bukkit.Bukkit
import org.bukkit.plugin.java.JavaPlugin
@@ -14,14 +14,14 @@ class KotlinTemplateOG : JavaPlugin() {
val scope = CoroutineScope(Dispatchers.Default + SupervisorJob())
lateinit var plugin: KotlinTemplateOG
lateinit var diamondBankAPI: DiamondBankAPI
lateinit var diamondBankAPI: DiamondBankAPIKotlin
}
override fun onEnable() {
plugin = this
Config.load()
val diamondBankAPIProvider = server.servicesManager.getRegistration(DiamondBankAPI::class.java)
val diamondBankAPIProvider = server.servicesManager.getRegistration(DiamondBankAPIKotlin::class.java)
if (diamondBankAPIProvider == null) {
this.logger.severe("DiamondBank-OG API is null")
Bukkit.getPluginManager().disablePlugin(this)
+20 -14
View File
@@ -1,14 +1,12 @@
package plugin
import kotlinx.coroutines.future.await
import kotlinx.coroutines.launch
import net.trueog.diamondbankog.DiamondBankAPI.DiamondBankException.*
import net.trueog.diamondbankog.DiamondBankException
import net.trueog.diamondbankog.PostgreSQL.ShardType
import net.trueog.utilitiesog.UtilitiesOG
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.block.BlockBreakEvent
import java.util.concurrent.ExecutionException
class Listeners : Listener {
@@ -18,17 +16,25 @@ class Listeners : Listener {
// launch {} is needed in this case since getPlayerShards().await() calls a database which can be slow to run on the main thread
// and .await() is a function for in coroutines in the first place
KotlinTemplateOG.scope.launch {
val playerShards = try {
KotlinTemplateOG.diamondBankAPI.getPlayerShards(event.player.uniqueId, ShardType.ALL).await()
} catch (e: EconomyDisabledException) {
UtilitiesOG.trueogMessage(event.player, "<red>The economy is disabled.")
return@launch
} catch (e: TransactionsLockedException) {
UtilitiesOG.trueogMessage(event.player, "<red>Your transactions are locked.")
return@launch
} catch (e: OtherException) {
UtilitiesOG.trueogMessage(event.player, "<red>Something went wrong.")
return@launch
val playerShardsResult =
KotlinTemplateOG.diamondBankAPI.getPlayerShards(event.player.uniqueId, ShardType.ALL)
val playerShards = playerShardsResult.getOrElse { e ->
when (e) {
DiamondBankException.EconomyDisabledException -> {
UtilitiesOG.trueogMessage(event.player, "<red>The economy is disabled.")
return@launch
}
DiamondBankException.TransactionsLockedException -> {
UtilitiesOG.trueogMessage(event.player, "<red>Your transactions are locked.")
return@launch
}
else -> {
UtilitiesOG.trueogMessage(event.player, "<red>Something went wrong.")
return@launch
}
}
}
val shardsInBank = playerShards.shardsInBank