Add toggle debug command for cache monitoring #34

Merged
SKBotNL merged 3 commits from master into master 2026-04-04 09:53:03 -04:00
4 changed files with 58 additions and 3 deletions

No files matched your search

@@ -79,10 +79,16 @@ internal class CachingBalanceManager : BalanceManager {
override suspend fun getShardTypeShards(uuid: UUID, type: ShardType): Result<Long> {
if ((beingModified[uuid to type]?.get() ?: 0) > 0) {
if (DiamondBankOG.debug) {
DiamondBankOG.plugin.logger.info("Cache miss (being modified) for $uuid!")
}
return postgreSQL.getShardTypeShards(uuid, type)
}
val cacheBalance = cache.getBalance(uuid, type)
if (cacheBalance == -1L) {
if (DiamondBankOG.debug) {
DiamondBankOG.plugin.logger.info("Cache miss for $uuid!")
}
increment(uuid, type)
val dbBalance =
postgreSQL.getShardTypeShards(uuid, type).getOrElse {
@@ -91,6 +97,8 @@ internal class CachingBalanceManager : BalanceManager {
cache.setBalance(uuid, dbBalance, type)
decrement(uuid, type)
return Result.success(dbBalance)
} else if (DiamondBankOG.debug) {
DiamondBankOG.plugin.logger.info("Cache hit for $uuid!")
}
return Result.success(cacheBalance)
}
@@ -98,10 +106,16 @@ internal class CachingBalanceManager : BalanceManager {
override suspend fun getTotalShards(uuid: UUID): Result<Long> {
val anyBeingModified = beingModified.any { it.key.first == uuid && it.value.get() > 0 }
if (anyBeingModified) {
if (DiamondBankOG.debug) {
DiamondBankOG.plugin.logger.info("Cache miss (being modified) for $uuid!")
}
return postgreSQL.getTotalShards(uuid)
}
val cacheBalance = cache.getBalance(uuid, ShardType.TOTAL)
if (cacheBalance == -1L) {
if (DiamondBankOG.debug) {
DiamondBankOG.plugin.logger.info("Cache miss for $uuid!")
}
increment(uuid, ShardType.TOTAL)
val dbBalance =
postgreSQL.getTotalShards(uuid).getOrElse {
@@ -110,6 +124,8 @@ internal class CachingBalanceManager : BalanceManager {
cache.setBalance(uuid, dbBalance, ShardType.TOTAL)
decrement(uuid, ShardType.TOTAL)
return Result.success(dbBalance)
} else if (DiamondBankOG.debug) {
DiamondBankOG.plugin.logger.info("Cache hit for $uuid!")
}
return Result.success(cacheBalance)
}
@@ -117,12 +133,18 @@ internal class CachingBalanceManager : BalanceManager {
override suspend fun getAllShards(uuid: UUID): Result<PlayerShards> {
val anyBeingModified = beingModified.any { it.key.first == uuid && it.value.get() > 0 }
if (anyBeingModified) {
if (DiamondBankOG.debug) {
DiamondBankOG.plugin.logger.info("Cache miss (being modified) for $uuid!")
}
return postgreSQL.getAllShards(uuid)
}
val cacheBankBalance = cache.getBalance(uuid, ShardType.BANK)
val cacheInventoryBalance = cache.getBalance(uuid, ShardType.INVENTORY)
val cacheEnderChestBalance = cache.getBalance(uuid, ShardType.ENDER_CHEST)
if (cacheBankBalance == -1L || cacheInventoryBalance == -1L || cacheEnderChestBalance == -1L) {
if (DiamondBankOG.debug) {
DiamondBankOG.plugin.logger.info("Cache miss for $uuid!")
}
increment(uuid, ShardType.TOTAL)
val dbPlayerShards =
postgreSQL.getAllShards(uuid).getOrElse {
@@ -133,6 +155,8 @@ internal class CachingBalanceManager : BalanceManager {
cache.setBalance(uuid, dbPlayerShards.enderChest, ShardType.ENDER_CHEST)
decrement(uuid, ShardType.TOTAL)
return Result.success(dbPlayerShards)
} else if (DiamondBankOG.debug) {
DiamondBankOG.plugin.logger.info("Cache hit for $uuid!")
}
return Result.success(PlayerShards(cacheBankBalance, cacheInventoryBalance, cacheEnderChestBalance))
}
@@ -25,6 +25,8 @@ internal open class DiamondBankOG : JavaPlugin() {
lateinit var redis: Redis
lateinit var luckPerms: LuckPerms
var debug: Boolean = false
fun isRedisInitialized() = ::redis.isInitialized
fun isBalanceManagerInitialized() = ::balanceManager.isInitialized
@@ -102,6 +104,8 @@ internal open class DiamondBankOG : JavaPlugin() {
this.getCommand("enableeconomy")?.setExecutor(EnableEconomy())
this.getCommand("disableeconomy")?.setExecutor(DisableEconomy())
this.getCommand("dbogtoggledebug")?.setExecutor(ToggleDebug())
Shard.createCraftingRecipes()
val diamondBankAPIJava = DiamondBankAPIJava()
@@ -0,0 +1,27 @@
package net.trueog.diamondbankog.commands
import net.trueog.diamondbankog.DiamondBankOG
import net.trueog.diamondbankog.DiamondBankOG.Companion.config
import net.trueog.diamondbankog.DiamondBankOG.Companion.mm
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
class ToggleDebug : CommandExecutor {
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>?): Boolean {
if (!sender.hasPermission("diamondbank-og.debug")) {
sender.sendMessage(
mm.deserialize("${config.prefix}<reset>: <red>You do not have permission to use this command.")
)
return true
}
DiamondBankOG.debug = !DiamondBankOG.debug
sender.sendMessage(
mm.deserialize(
"${config.prefix}<reset>: Debug mode is now turned ${if (DiamondBankOG.debug) "<green>on" else "<red>off"}<reset>."
)
)
return true
}
}
+3 -3
View File
@@ -51,9 +51,9 @@ commands:
autodeposit:
description: Toggles auto-deposit, automatically deposits picked up Diamond currency items, mutually exclusive with auto-compress
usage: /autodeposit
dbogtests:
description: Run the DiamondBank-OG tests, only available in dev builds
usage: /dbogtests
dbogtoggledebug:
description: Toggles debug mode
usage: /dbtoggledebug
# So we can overwrite Essentials' commands
softdepend: [ Essentials-OG ]