Use handleError instead of manually setting economyDisabled in onPlayerJoin #38

Merged
SKBotNL merged 3 commits from master into master 2026-04-05 15:00:09 -04:00
8 changed files with 24 additions and 24 deletions

No files matched your search

@@ -48,7 +48,7 @@ internal class Events : Listener {
scope.launch {
val hasEntry =
balanceManager.hasEntry(event.player.uniqueId).getOrElse {
economyDisabled = true
handleError(it)
return@launch
}
if (!hasEntry) {
@@ -41,7 +41,7 @@ object InventorySnapshotUtils {
CommonOperations.shardsToDiamondsFull(
excessShards
)
} <yellow> has been deposited into your bank account"
} <yellow>has been deposited into your bank account"
)
)
}
@@ -77,7 +77,7 @@ object InventorySnapshotUtils {
CommonOperations.shardsToDiamondsFull(
excessShards + excessDiamondsInShards
)
} <yellow> has been deposited into your bank account"
} <yellow>has been deposited into your bank account"
)
)
}
@@ -62,7 +62,7 @@ internal class Deposit(
CommonOperations.diamondsToShards(amount).getOrElse {
sender.sendMessage(
mm.deserialize(
"${config.prefix}<reset>: <red><aqua>Diamonds<red> can only have one decimal digit. Issue /diamondbankhelp for more information."
"${config.prefix}<reset>: <aqua>Diamonds<red> can only have one decimal digit. Issue /diamondbankhelp for more information."
)
)
return true
@@ -78,7 +78,7 @@ internal class Pay(
CommonOperations.diamondsToShards(amount).getOrElse {
sender.sendMessage(
mm.deserialize(
"${config.prefix}<reset>: <red><aqua>Diamonds<red> can only have one decimal digit. Issue /diamondbankhelp for more information."
"${config.prefix}<reset>: <aqua>Diamonds<red> can only have one decimal digit. Issue /diamondbankhelp for more information."
)
)
return true
@@ -148,7 +148,7 @@ internal class Pay(
receiver.uniqueId,
luckPerms,
)
} ${receiver.name}<reset><green>."
}${receiver.name}<reset><green>."
)
)
@@ -161,7 +161,7 @@ internal class Pay(
sender.uniqueId,
luckPerms,
)
} ${sender.name}<reset> <green>has paid you ${
}${sender.name}<reset> <green>has paid you ${
CommonOperations.shardsToDiamondsFull(
shards
)
@@ -65,7 +65,7 @@ internal class Withdraw(
CommonOperations.diamondsToShards(amount).getOrElse {
sender.sendMessage(
mm.deserialize(
"${config.prefix}<reset>: <red><aqua>Diamonds<red> can only have one decimal digit. Issue /diamondbankhelp for more information."
"${config.prefix}<reset>: <aqua>Diamonds<red> can only have one decimal digit. Issue /diamondbankhelp for more information."
)
)
return true
@@ -106,7 +106,7 @@ internal class Withdraw(
CommonOperations.shardsToDiamondsFull(
shardsToWithdraw
)
} <red>because your bank only contains <yellow>${
} <red>because your bank only contains ${
CommonOperations.shardsToDiamondsFull(
bankShards
)
@@ -358,9 +358,9 @@ class DepositTest {
@ParameterizedTest(name = "{0}")
@DisplayName("Deposit with invalid argument should fail")
@CsvSource(
"Not a number, abc, Invalid argument",
"Negative, -1, You cannot deposit a negative or zero amount",
"Zero, 0, You cannot deposit a negative or zero amount",
"Not a number, abc, <red>Invalid argument",
"Negative, -1, <red>You cannot deposit a negative or zero amount",
"Zero, 0, <red>You cannot deposit a negative or zero amount",
"More than one decimal digit, 1.11, <aqua>Diamonds<red> can only have one decimal digit. Issue /diamondbankhelp for more information",
)
fun depositInvalidArg(@Suppress("UNUSED_PARAMETER") name: String, argument: String, errorMessage: String) =
@@ -372,7 +372,7 @@ class DepositTest {
waitForCoroutines(scope)
assertAll(
{ verify { player.sendMessage(Component.text("DiamondBank-OG<reset>: <red>$errorMessage.")) } },
{ verify { player.sendMessage(Component.text("DiamondBank-OG<reset>: $errorMessage.")) } },
{ coVerify(exactly = 0) { balanceManager.addToBankShards(any(), any()) } },
{ assertEquals(5, inventory.countDiamonds(), "Diamond count") },
{ assertFalse(inventory.isLocked(), "Inventory locked") },
@@ -274,7 +274,7 @@ class PayTest {
verify {
player.sendMessage(
Component.text(
"DiamondBank-OG<reset>: <green>Successfully paid <yellow>$successDiamondText <green>to OtherPlayer<reset><green>."
"DiamondBank-OG<reset>: <green>Successfully paid <yellow>$successDiamondText <green>to OtherPlayer<reset><green>."
)
)
}
@@ -283,7 +283,7 @@ class PayTest {
verify {
otherPlayer.sendMessage(
Component.text(
"DiamondBank-OG<reset>: <green> Player<reset> <green>has paid you <yellow>$successDiamondText<green>."
"DiamondBank-OG<reset>: <green>Player<reset> <green>has paid you <yellow>$successDiamondText<green>."
)
)
}
@@ -437,9 +437,9 @@ class PayTest {
@ParameterizedTest(name = "{0}")
@DisplayName("Pay with invalid argument should fail")
@CsvSource(
"Not a number, abc, Invalid argument",
"Negative, -1, You cannot pay a negative or zero amount",
"Zero, 0, You cannot pay a negative or zero amount",
"Not a number, abc, <red>Invalid argument",
"Negative, -1, <red>You cannot pay a negative or zero amount",
"Zero, 0, <red>You cannot pay a negative or zero amount",
"More than one decimal digit, 1.11, <aqua>Diamonds<red> can only have one decimal digit. Issue /diamondbankhelp for more information",
)
fun payInvalidArg(@Suppress("UNUSED_PARAMETER") name: String, argument: String, errorMessage: String) = runTest {
@@ -450,7 +450,7 @@ class PayTest {
waitForCoroutines(scope)
assertAll(
{ verify { player.sendMessage(Component.text("DiamondBank-OG<reset>: <red>$errorMessage.")) } },
{ verify { player.sendMessage(Component.text("DiamondBank-OG<reset>: $errorMessage.")) } },
{ coVerify(exactly = 0) { balanceManager.subtractFromBankShards(any(), any()) } },
{ assertEquals(0, inventory.countTotal(), "Total count") },
{ assertFalse(inventory.isLocked(), "Inventory locked") },
@@ -225,9 +225,9 @@ class WithdrawTest {
@ParameterizedTest(name = "{0}")
@DisplayName("Withdraw with invalid argument should fail")
@CsvSource(
"Not a number, abc, Invalid argument",
"Negative, -1, You cannot withdraw a negative or zero amount",
"Zero, 0, You cannot withdraw a negative or zero amount",
"Not a number, abc, <red>Invalid argument",
"Negative, -1, <red>You cannot withdraw a negative or zero amount",
"Zero, 0, <red>You cannot withdraw a negative or zero amount",
"More than one decimal digit, 1.11, <aqua>Diamonds<red> can only have one decimal digit. Issue /diamondbankhelp for more information",
)
fun withdrawInvalidArg(@Suppress("UNUSED_PARAMETER") name: String, argument: String, errorMessage: String) =
@@ -239,7 +239,7 @@ class WithdrawTest {
waitForCoroutines(scope)
assertAll(
{ verify { player.sendMessage(Component.text("DiamondBank-OG<reset>: <red>$errorMessage.")) } },
{ verify { player.sendMessage(Component.text("DiamondBank-OG<reset>: $errorMessage.")) } },
{ coVerify(exactly = 0) { balanceManager.subtractFromBankShards(any(), any()) } },
{ assertEquals(0, inventory.countTotal(), "Total count") },
{ assertFalse(inventory.isLocked(), "Inventory locked") },
@@ -287,7 +287,7 @@ class WithdrawTest {
verify {
player.sendMessage(
Component.text(
"DiamondBank-OG<reset>: <red>Cannot withdraw <yellow>5.0 <aqua>Diamonds <red>because your bank only contains <yellow><yellow>2.0 <aqua>Diamonds<red>."
"DiamondBank-OG<reset>: <red>Cannot withdraw <yellow>5.0 <aqua>Diamonds <red>because your bank only contains <yellow>2.0 <aqua>Diamonds<red>."
)
)
}