Skip to content

Commit a4f6c87

Browse files
committed
Added debugger.
1 parent e602154 commit a4f6c87

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

src/main/kotlin/com/github/encryptsl/lite/eco/LiteEco.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import com.github.encryptsl.lite.eco.common.database.models.DatabaseMonologModel
1616
import com.github.encryptsl.lite.eco.common.hook.HookManager
1717
import com.github.encryptsl.lite.eco.listeners.*
1818
import com.github.encryptsl.lite.eco.listeners.admin.*
19+
import com.github.encryptsl.lite.eco.utils.Debugger
1920
import com.github.encryptsl.lite.eco.utils.MigrationTool
2021
import com.tchristofferson.configupdater.ConfigUpdater
2122
import org.bstats.bukkit.Metrics
@@ -53,6 +54,7 @@ class LiteEco : JavaPlugin() {
5354
val currencyImpl: Currency by lazy { Currency(this) }
5455
val databaseConnector: DatabaseConnector by lazy { DatabaseConnector(this) }
5556
val accountManager: AccountManager by lazy { AccountManager(this) }
57+
val debugger: Debugger by lazy { Debugger(this) }
5658

5759
private val configAPI: ConfigAPI by lazy { ConfigAPI(this) }
5860
private val hookManager: HookManager by lazy { HookManager(this) }

src/main/kotlin/com/github/encryptsl/lite/eco/common/hook/vault/AdaptiveEconomyVaultAPI.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class AdaptiveEconomyVaultAPI(private val liteEco: LiteEco) : DeprecatedEconomy(
4545
override fun getBalance(player: OfflinePlayer?): Double {
4646
return try {
4747
player?.let { liteEco.api.getBalance(it).toDouble() } ?: 0.0
48-
} catch (e : Exception) {
48+
} catch (_ : Exception) {
4949
return 0.0
5050
}
5151
}
@@ -63,11 +63,13 @@ class AdaptiveEconomyVaultAPI(private val liteEco: LiteEco) : DeprecatedEconomy(
6363
}
6464

6565
override fun withdrawPlayer(player: OfflinePlayer?, amount: Double): EconomyResponse {
66+
liteEco.debugger.debug(AdaptiveEconomyVaultAPI::class.java, "try withdraw from ${player?.name} amount $amount")
6667
if (player == null || amount.toBigDecimal().isApproachingZero()) {
6768
return EconomyResponse(0.0, 0.0, EconomyResponse.ResponseType.FAILURE, null)
6869
}
6970

7071
return if (has(player, amount)) {
72+
liteEco.debugger.debug(AdaptiveEconomyVaultAPI::class.java, "successfully withdraw from ${player.name} amount $amount")
7173
liteEco.api.withDrawMoney(player, liteEco.currencyImpl.defaultCurrency(), amount.toBigDecimal())
7274
EconomyResponse(amount, getBalance(player), EconomyResponse.ResponseType.SUCCESS, null)
7375
} else {
@@ -80,10 +82,12 @@ class AdaptiveEconomyVaultAPI(private val liteEco: LiteEco) : DeprecatedEconomy(
8082
}
8183

8284
override fun depositPlayer(player: OfflinePlayer?, amount: Double): EconomyResponse {
85+
liteEco.debugger.debug(AdaptiveEconomyVaultAPI::class.java, "try deposit to ${player?.name} amount $amount")
8386
if (player == null || !hasAccount(player) || amount.toBigDecimal().isApproachingZero() || liteEco.api.getCheckBalanceLimit(player, getBalance(player).toBigDecimal(), amount = amount.toBigDecimal())) {
8487
return EconomyResponse(0.0, 0.0, EconomyResponse.ResponseType.FAILURE, null)
8588
}
8689

90+
liteEco.debugger.debug(AdaptiveEconomyVaultAPI::class.java, "successfully deposit to ${player.name} amount $amount")
8791
liteEco.api.depositMoney(player, liteEco.currencyImpl.defaultCurrency(), amount.toBigDecimal())
8892

8993
return EconomyResponse(amount, getBalance(player), EconomyResponse.ResponseType.SUCCESS, null)

src/main/kotlin/com/github/encryptsl/lite/eco/common/hook/vault/unlocked/AdaptiveEconomyVaultUnlockedAPI.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,14 @@ class AdaptiveEconomyVaultUnlockedAPI(private val liteEco: LiteEco) : UnusedVaul
142142
}
143143

144144
override fun withdraw(pluginName: String, accountID: UUID, amount: BigDecimal): EconomyResponse {
145+
liteEco.debugger.debug(AdaptiveEconomyVaultUnlockedAPI::class.java, "${pluginName} try withdraw from ${accountID} amount $amount")
146+
145147
if (amount.isApproachingZero()) {
146148
return EconomyResponse(BigDecimal.ZERO, BigDecimal.ZERO, EconomyResponse.ResponseType.FAILURE, AMOUNT_APPROACHING_ZERO)
147149
}
148150

149151
return if (has(pluginName, accountID, amount)) {
152+
liteEco.debugger.debug(AdaptiveEconomyVaultUnlockedAPI::class.java, "$pluginName successfully withdraw from ${accountID} amount $amount")
150153
liteEco.api.withDrawMoney(accountID, liteEco.currencyImpl.defaultCurrency(), amount)
151154
EconomyResponse(amount, balance(pluginName, accountID), EconomyResponse.ResponseType.SUCCESS, SUCCESS_WITHDRAW)
152155
} else {
@@ -161,12 +164,13 @@ class AdaptiveEconomyVaultUnlockedAPI(private val liteEco: LiteEco) : UnusedVaul
161164
currency: String,
162165
amount: BigDecimal
163166
): EconomyResponse {
164-
167+
liteEco.debugger.debug(AdaptiveEconomyVaultUnlockedAPI::class.java, "$pluginName try withdraw from $accountID amount $amount")
165168
if (amount.isApproachingZero()) {
166169
return EconomyResponse(BigDecimal.ZERO, BigDecimal.ZERO, EconomyResponse.ResponseType.FAILURE, AMOUNT_APPROACHING_ZERO)
167170
}
168171

169172
return if (has(pluginName, accountID, amount)) {
173+
liteEco.debugger.debug(AdaptiveEconomyVaultUnlockedAPI::class.java, "$pluginName successfully withdraw from $accountID amount $amount")
170174
liteEco.api.withDrawMoney(accountID, liteEco.currencyImpl.defaultCurrency(), amount)
171175
EconomyResponse(amount, balance(pluginName, accountID), EconomyResponse.ResponseType.SUCCESS, SUCCESS_WITHDRAW)
172176
} else {
@@ -179,10 +183,12 @@ class AdaptiveEconomyVaultUnlockedAPI(private val liteEco: LiteEco) : UnusedVaul
179183
}
180184

181185
override fun deposit(pluginName: String, accountID: UUID, amount: BigDecimal): EconomyResponse {
186+
liteEco.debugger.debug(AdaptiveEconomyVaultUnlockedAPI::class.java, "$pluginName try deposit to $accountID amount $amount")
182187
if (amount.isApproachingZero()) {
183188
return EconomyResponse(amount, balance(pluginName, accountID), EconomyResponse.ResponseType.FAILURE, AMOUNT_APPROACHING_ZERO)
184189
}
185190
return if (has(pluginName, accountID, amount)) {
191+
liteEco.debugger.debug(AdaptiveEconomyVaultUnlockedAPI::class.java, "$pluginName successfully deposit from $accountID amount $amount")
186192
liteEco.api.depositMoney(accountID, liteEco.currencyImpl.defaultCurrency(), amount)
187193
EconomyResponse(amount, balance(pluginName, accountID), EconomyResponse.ResponseType.SUCCESS, SUCCESS_DEPOSIT)
188194
} else {
@@ -201,11 +207,13 @@ class AdaptiveEconomyVaultUnlockedAPI(private val liteEco: LiteEco) : UnusedVaul
201207
currency: String,
202208
amount: BigDecimal
203209
): EconomyResponse {
210+
liteEco.debugger.debug(AdaptiveEconomyVaultUnlockedAPI::class.java, "$pluginName try deposit to $accountID amount $amount")
204211
if (amount.isApproachingZero()) {
205212
return EconomyResponse(amount, balance(pluginName, accountID), EconomyResponse.ResponseType.FAILURE, AMOUNT_APPROACHING_ZERO)
206213
}
207214

208215
return if (has(pluginName, accountID, amount)) {
216+
liteEco.debugger.debug(AdaptiveEconomyVaultUnlockedAPI::class.java, "$pluginName successfully deposit from $accountID amount $amount")
209217
liteEco.api.depositMoney(accountID, currency, amount)
210218
EconomyResponse(amount, balance(pluginName, accountID), EconomyResponse.ResponseType.SUCCESS, SUCCESS_DEPOSIT)
211219
} else {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.github.encryptsl.lite.eco.utils
2+
3+
import com.github.encryptsl.lite.eco.LiteEco
4+
import com.github.encryptsl.lite.eco.api.objects.ModernText
5+
6+
class Debugger(private val liteEco: LiteEco) {
7+
8+
fun <T> debug(provider: Class<T>, message: String) {
9+
if (liteEco.config.getBoolean("plugin.vault-debug")) {
10+
liteEco.componentLogger.info(ModernText.miniModernText("<gold> ${provider.name} $message"))
11+
}
12+
}
13+
14+
}

src/main/resources/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ plugin:
77
prefix: "<dark_gray>[<green>Eco<dark_gray>] <dark_green>»</dark_gray>"
88
# Enable or disable Metrics
99
metrics: true
10+
# Enable or disable Vault Debug
11+
vault-debug: false
1012
# Settings for modifiable players suggestion.
1113
# Enabled: Offline Players Suggestion..
1214
# Disabled: Online Players Suggestion...

0 commit comments

Comments
 (0)