Update example for DiamondBank-OG shards

This commit is contained in:
SKBotNL committed 2025-06-10 22:57:48 +02:00
1 parent 7112968d65
commit 7968b30c08
6 files changed
+73 -27

No files matched your search

+1 -1
View File
@@ -1,4 +1,4 @@
#!/usr/bin/bash
# Fetch all submodule content.
git submodule update --force --recursive --init --remote
git submodule update --force --recursive --init
+2
View File
@@ -44,6 +44,8 @@ dependencies {
compileOnly(project(":libs:Utilities-OG"))
compileOnly(project(":libs:GxUI-OG"))
compileOnly(project(":libs:DiamondBank-OG"))
implementation("org.jetbrains.kotlin:kotlin-stdlib")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2")
}
tasks.withType<AbstractArchiveTask>().configureEach { // Ensure reproducible .jars
+1 -14
View File
@@ -11,41 +11,28 @@ object Config {
private lateinit var file: File
fun load() {
file = File(KotlinTemplateOG.plugin.dataFolder, "config.yml")
if (! file.exists()) {
if (!file.exists()) {
KotlinTemplateOG.plugin.saveDefaultConfig()
}
config = YamlConfiguration.loadConfiguration(file)
this.save()
}
private fun save() {
config.save(file)
}
fun getTemplateBool(): Boolean {
return config.get("templateBool") as Boolean
}
fun getTemplateDouble(): Double {
return config.get("templateDouble") as Double
}
fun getTemplateInt(): Int {
return config.get("templateInt") as Int
}
}
+26 -4
View File
@@ -1,22 +1,44 @@
// This is free and unencumbered software released into the public domain.
// Author: Sekalol15
package plugin
import kotlinx.coroutines.*
import net.trueog.diamondbankog.DiamondBankAPI
import org.bukkit.Bukkit
import org.bukkit.plugin.java.JavaPlugin
// Extending this class is standard bukkit boilerplate for any plugin, or else the server software won't load the classes.
class KotlinTemplateOG : JavaPlugin() {
companion object {
val scope = CoroutineScope(Dispatchers.Default + SupervisorJob())
lateinit var plugin: JavaPlugin
lateinit var plugin: KotlinTemplateOG
lateinit var diamondBankAPI: DiamondBankAPI
}
override fun onEnable() {
plugin = this
Config.load()
val diamondBankAPIProvider = server.servicesManager.getRegistration(DiamondBankAPI::class.java)
if (diamondBankAPIProvider == null) {
this.logger.severe("DiamondBank-OG API is null")
Bukkit.getPluginManager().disablePlugin(this)
return
}
diamondBankAPI = diamondBankAPIProvider.getProvider()
this.server.pluginManager.registerEvents(Listeners(), this)
}
override fun onDisable() {
scope.cancel()
runBlocking {
scope.coroutineContext[Job]?.join()
}
}
}
+41 -6
View File
@@ -1,13 +1,48 @@
package nl.skbotnl.apitest
package plugin
import net.trueog.diamondbankog.PostgreSQL
import kotlinx.coroutines.future.await
import kotlinx.coroutines.launch
import net.trueog.diamondbankog.DiamondBankAPI.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.CompletableFuture
import java.util.concurrent.ExecutionException
class Listeners : Listener {
// @EventHandler
// fun onBlockBreak(event: BlockBreakEvent) {
// }
@EventHandler
fun onBlockBreak(event: BlockBreakEvent) {
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 shardsInBank = playerShards.shardsInBank
val shardsInInventory = playerShards.shardsInInventory
val shardsInEnderChest = playerShards.shardsInEnderChest
if (shardsInBank == null || shardsInInventory == null || shardsInEnderChest == null) {
UtilitiesOG.trueogMessage(event.player, "<red>An error has occurred.")
return@launch
}
val totalBalance = shardsInBank + shardsInInventory + shardsInEnderChest
// Send a message to the player with their balance.
UtilitiesOG.trueogMessage(event.player, "&BYour balance is: &e$totalBalance&B Diamonds.")
UtilitiesOG.logToConsole(
"[Template-OG]",
"The player: " + event.player + "'s <aqua>balance</aqua> is: " + totalBalance + "&B Diamonds"
)
}
}
}
+2 -2
View File
@@ -1,7 +1,7 @@
#Template Config Options
templateBool : true
templateInt : 1
templateBool: true
templateInt: 1
templateDouble: 0.5