Skip to content

Commit 146ad61

Browse files
committed
Fixed crash in issue #116
1 parent 0daf730 commit 146ad61

11 files changed

Lines changed: 115 additions & 166 deletions

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Plugin Settings
22
plugin_name=LiteEco
3-
plugin_version=1.6.6-SNAPSHOT
3+
plugin_version=1.6.7-SNAPSHOT
44
plugin_description=LiteEco is an economy plugin using VaultAPI
55

66
#Server Dependency

src/main/kotlin/com/github/encryptsl/lite/eco/api/economy/SuspendLiteEcoEconomyWrapper.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import com.github.encryptsl.lite.eco.LiteEco
44
import com.github.encryptsl.lite.eco.api.PlayerAccount
55
import com.github.encryptsl.lite.eco.common.database.entity.User
66
import com.github.encryptsl.lite.eco.common.extensions.io
7-
import com.github.encryptsl.lite.eco.common.extensions.mainThread
87
import org.bukkit.Bukkit
98
import java.math.BigDecimal
109
import java.util.*
@@ -13,9 +12,7 @@ class SuspendLiteEcoEconomyWrapper : ModernLiteEcoEconomyImpl() {
1312

1413
override suspend fun getUserByUUID(uuid: UUID, currency: String): Optional<User> = io {
1514
if (PlayerAccount.isPlayerOnline(uuid) || PlayerAccount.isAccountCached(uuid, currency)) {
16-
val name = mainThread(LiteEco.instance) {
17-
Bukkit.getPlayer(uuid)?.name.toString()
18-
}
15+
val name = Bukkit.getPlayer(uuid)?.name.toString()
1916
Optional.of(User(name, uuid, PlayerAccount.getBalance(uuid, currency)))
2017
} else {
2118
Optional.ofNullable(LiteEco.instance.databaseEcoModel.getUserByUUID(uuid, currency))
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
package com.github.encryptsl.lite.eco.common.extensions
22

3-
import com.github.encryptsl.lite.eco.LiteEco
43
import kotlinx.coroutines.CoroutineScope
54
import kotlinx.coroutines.Dispatchers
65
import kotlinx.coroutines.withContext
76

87
suspend fun <T> io(block: suspend CoroutineScope.() -> T): T =
9-
withContext(Dispatchers.IO, block)
10-
11-
suspend fun <T> mainThread(liteEco: LiteEco, block: suspend CoroutineScope.() -> T): T =
12-
withContext(liteEco.bukkitDispatchers.main, block)
8+
withContext(Dispatchers.IO, block)

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

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.github.encryptsl.lite.eco.common.hook.vault.unlocked
33
import com.github.encryptsl.lite.eco.LiteEco
44
import com.github.encryptsl.lite.eco.api.enums.TypeLogger
55
import com.github.encryptsl.lite.eco.common.extensions.isApproachingZero
6-
import com.github.encryptsl.lite.eco.common.extensions.mainThread
76
import kotlinx.coroutines.launch
87
import kotlinx.coroutines.runBlocking
98
import net.milkbowl.vault2.economy.EconomyResponse
@@ -141,9 +140,7 @@ class AdaptiveEconomyVaultUnlockedAPI(private val liteEco: LiteEco) : UnusedVaul
141140
return if (has(pluginName, accountID, amount)) {
142141
liteEco.debugger.debug(AdaptiveEconomyVaultUnlockedAPI::class.java, "$pluginName successfully withdraw ${accountID} from his balance ${balance(pluginName, accountID)} amount $amount")
143142
liteEco.pluginScope.launch {
144-
val username = mainThread(liteEco) {
145-
Bukkit.getOfflinePlayer(accountID).name.toString()
146-
}
143+
val username = Bukkit.getOfflinePlayer(accountID).name.toString()
147144
val currentBalance = liteEco.api.getBalance(accountID, liteEco.currencyImpl.defaultCurrency())
148145
liteEco.loggerModel.logging(TypeLogger.WITHDRAW, pluginName, username, liteEco.currencyImpl.defaultCurrency(), currentBalance, currentBalance - amount)
149146
liteEco.api.withdraw(accountID, liteEco.currencyImpl.defaultCurrency(), amount)
@@ -169,9 +166,7 @@ class AdaptiveEconomyVaultUnlockedAPI(private val liteEco: LiteEco) : UnusedVaul
169166
return if (has(pluginName, accountID, worldName, currency, amount)) {
170167
liteEco.debugger.debug(AdaptiveEconomyVaultUnlockedAPI::class.java, "$pluginName successfully withdraw ${accountID} from his balance ${balance(pluginName, accountID)} amount $amount")
171168
liteEco.pluginScope.launch {
172-
val username = mainThread(liteEco) {
173-
Bukkit.getOfflinePlayer(accountID).name.toString()
174-
}
169+
val username = Bukkit.getOfflinePlayer(accountID).name.toString()
175170
val currentBalance = liteEco.api.getBalance(accountID, currency)
176171
liteEco.loggerModel.logging(TypeLogger.WITHDRAW, pluginName, username, currency, currentBalance, currentBalance - amount)
177172
liteEco.api.withdraw(accountID, currency, amount)
@@ -194,9 +189,7 @@ class AdaptiveEconomyVaultUnlockedAPI(private val liteEco: LiteEco) : UnusedVaul
194189
return if (has(pluginName, accountID, amount)) {
195190
liteEco.debugger.debug(AdaptiveEconomyVaultUnlockedAPI::class.java, "$pluginName successfully deposit $accountID to his balance ${balance(pluginName, accountID)} amount $amount")
196191
liteEco.pluginScope.launch {
197-
val username = mainThread(liteEco) {
198-
Bukkit.getOfflinePlayer(accountID).name.toString()
199-
}
192+
val username = Bukkit.getOfflinePlayer(accountID).name.toString()
200193
val currencyName = liteEco.currencyImpl.defaultCurrency()
201194
val currentBalance = liteEco.api.getBalance(accountID, currencyName)
202195
if (liteEco.currencyImpl.getCheckBalanceLimit(currentBalance, currencyName, amount)) {
@@ -232,9 +225,7 @@ class AdaptiveEconomyVaultUnlockedAPI(private val liteEco: LiteEco) : UnusedVaul
232225
return if (has(pluginName, accountID, worldName, currency, amount)) {
233226
liteEco.debugger.debug(AdaptiveEconomyVaultUnlockedAPI::class.java, "$pluginName successfully deposit $accountID to his balance ${balance(pluginName, accountID)} amount $amount")
234227
liteEco.pluginScope.launch {
235-
val username = mainThread(liteEco) {
236-
Bukkit.getOfflinePlayer(accountID).name.toString()
237-
}
228+
val username = Bukkit.getOfflinePlayer(accountID).name.toString()
238229
val currentBalance = liteEco.api.getBalance(accountID, currency)
239230
if (liteEco.currencyImpl.getCheckBalanceLimit(currentBalance, currency, amount)) {
240231
EconomyResponse(amount, balance(pluginName, accountID), EconomyResponse.ResponseType.FAILURE, FAIL_REACHED_BALANCE_LIMIT)
@@ -255,9 +246,7 @@ class AdaptiveEconomyVaultUnlockedAPI(private val liteEco: LiteEco) : UnusedVaul
255246
return if (hasAccount(accountID)) {
256247
liteEco.debugger.debug(AdaptiveEconomyVaultUnlockedAPI::class.java, "$pluginName successfully $accountID set his balance ${balance(pluginName, accountID)} to amount $amount")
257248
liteEco.pluginScope.launch {
258-
val username = mainThread(liteEco) {
259-
Bukkit.getOfflinePlayer(accountID).name.toString()
260-
}
249+
val username = Bukkit.getOfflinePlayer(accountID).name.toString()
261250
val currencyName = liteEco.currencyImpl.defaultCurrency()
262251
val currentBalance = liteEco.api.getBalance(accountID, currencyName)
263252

@@ -290,9 +279,7 @@ class AdaptiveEconomyVaultUnlockedAPI(private val liteEco: LiteEco) : UnusedVaul
290279
return if (hasAccount(accountID)) {
291280
liteEco.debugger.debug(AdaptiveEconomyVaultUnlockedAPI::class.java, "$pluginName successfully $accountID set his balance ${balance(pluginName, accountID)} to amount $amount")
292281
liteEco.pluginScope.launch {
293-
val username = mainThread(liteEco) {
294-
Bukkit.getOfflinePlayer(accountID).name.toString()
295-
}
282+
val username = Bukkit.getOfflinePlayer(accountID).name.toString()
296283
val currentBalance = liteEco.api.getBalance(accountID, currency)
297284

298285
if (liteEco.currencyImpl.getCheckBalanceLimit(amount, currency)) {

src/main/kotlin/com/github/encryptsl/lite/eco/common/manager/economy/PlayerEconomyPayHandler.kt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.github.encryptsl.lite.eco.common.manager.economy
22

33
import com.github.encryptsl.lite.eco.LiteEco
44
import com.github.encryptsl.lite.eco.api.enums.TypeLogger
5-
import com.github.encryptsl.lite.eco.common.extensions.mainThread
65
import kotlinx.coroutines.launch
76
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder
87
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver
@@ -31,16 +30,14 @@ class PlayerEconomyPayHandler(
3130
return@launch
3231
}
3332

34-
mainThread(liteEco) {
35-
if (!liteEco.api.has(sender.uniqueId, currency, money))
36-
return@mainThread sender.sendMessage(liteEco.locale.translation("messages.error.insufficient_funds"))
33+
if (!liteEco.api.has(sender.uniqueId, currency, money))
34+
return@launch sender.sendMessage(liteEco.locale.translation("messages.error.insufficient_funds"))
3735

38-
if (liteEco.currencyImpl.getCheckBalanceLimit(user.money, currency, money)) {
39-
sender.sendMessage(liteEco.locale.translation("messages.error.balance_above_limit",
40-
Placeholder.parsed("account", target.name.toString())
41-
))
42-
return@mainThread
43-
}
36+
if (liteEco.currencyImpl.getCheckBalanceLimit(user.money, currency, money)) {
37+
sender.sendMessage(liteEco.locale.translation("messages.error.balance_above_limit",
38+
Placeholder.parsed("account", target.name.toString())
39+
))
40+
return@launch
4441
}
4542

4643
liteEco.loggerModel.logging(TypeLogger.TRANSFER,

src/main/kotlin/com/github/encryptsl/lite/eco/common/manager/economy/admin/EconomyGlobalDepositHandler.kt

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.github.encryptsl.lite.eco.common.manager.economy.admin
22

33
import com.github.encryptsl.lite.eco.LiteEco
44
import com.github.encryptsl.lite.eco.api.enums.TypeLogger
5-
import com.github.encryptsl.lite.eco.common.extensions.mainThread
65
import kotlinx.coroutines.launch
76
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder
87
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver
@@ -53,20 +52,18 @@ class EconomyGlobalDepositHandler(
5352
}
5453
liteEco.increaseTransactions(players.size)
5554

56-
mainThread(liteEco) {
57-
sender.sendMessage(liteEco.locale.translation("messages.global.add_money",
58-
TagResolver.resolver(
59-
Placeholder.parsed("money", liteEco.currencyImpl.fullFormatting(money)),
60-
Placeholder.parsed("currency", liteEco.currencyImpl.currencyModularNameConvert(currency, money))
61-
))
62-
)
63-
if (liteEco.config.getBoolean("messages.global.notify_add")) {
64-
Bukkit.broadcast(liteEco.locale.translation("messages.broadcast.add_money", TagResolver.resolver(
65-
Placeholder.parsed("sender", sender.name),
66-
Placeholder.parsed("money", liteEco.currencyImpl.fullFormatting(money, currency)),
67-
Placeholder.parsed("currency", liteEco.currencyImpl.currencyModularNameConvert(currency, money))
68-
)))
69-
}
55+
sender.sendMessage(liteEco.locale.translation("messages.global.add_money",
56+
TagResolver.resolver(
57+
Placeholder.parsed("money", liteEco.currencyImpl.fullFormatting(money)),
58+
Placeholder.parsed("currency", liteEco.currencyImpl.currencyModularNameConvert(currency, money))
59+
))
60+
)
61+
if (liteEco.config.getBoolean("messages.global.notify_add")) {
62+
Bukkit.broadcast(liteEco.locale.translation("messages.broadcast.add_money", TagResolver.resolver(
63+
Placeholder.parsed("sender", sender.name),
64+
Placeholder.parsed("money", liteEco.currencyImpl.fullFormatting(money, currency)),
65+
Placeholder.parsed("currency", liteEco.currencyImpl.currencyModularNameConvert(currency, money))
66+
)))
7067
}
7168
}
7269
}

src/main/kotlin/com/github/encryptsl/lite/eco/common/manager/economy/admin/EconomyGlobalSetHandler.kt

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.github.encryptsl.lite.eco.common.manager.economy.admin
22

33
import com.github.encryptsl.lite.eco.LiteEco
44
import com.github.encryptsl.lite.eco.api.enums.TypeLogger
5-
import com.github.encryptsl.lite.eco.common.extensions.mainThread
65
import kotlinx.coroutines.launch
76
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder
87
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver
@@ -54,19 +53,16 @@ class EconomyGlobalSetHandler(
5453

5554
liteEco.increaseTransactions(players.size)
5655

57-
mainThread(liteEco) {
58-
sender.sendMessage(liteEco.locale.translation("messages.global.set_money", TagResolver.resolver(
59-
Placeholder.parsed("money", liteEco.currencyImpl.fullFormatting(money, currency)),
56+
sender.sendMessage(liteEco.locale.translation("messages.global.set_money", TagResolver.resolver(
57+
Placeholder.parsed("money", liteEco.currencyImpl.fullFormatting(money, currency)),
58+
Placeholder.parsed("currency", liteEco.currencyImpl.currencyModularNameConvert(currency, money))
59+
)))
60+
if (liteEco.config.getBoolean("messages.global.notify_set")) {
61+
Bukkit.broadcast(liteEco.locale.translation("messages.broadcast.set_money", TagResolver.resolver(
62+
Placeholder.parsed("sender", sender.name),
63+
Placeholder.parsed("money", liteEco.currencyImpl.fullFormatting(money)),
6064
Placeholder.parsed("currency", liteEco.currencyImpl.currencyModularNameConvert(currency, money))
6165
)))
62-
63-
if (liteEco.config.getBoolean("messages.global.notify_set")) {
64-
Bukkit.broadcast(liteEco.locale.translation("messages.broadcast.set_money", TagResolver.resolver(
65-
Placeholder.parsed("sender", sender.name),
66-
Placeholder.parsed("money", liteEco.currencyImpl.fullFormatting(money)),
67-
Placeholder.parsed("currency", liteEco.currencyImpl.currencyModularNameConvert(currency, money))
68-
)))
69-
}
7066
}
7167
}
7268
}

src/main/kotlin/com/github/encryptsl/lite/eco/common/manager/economy/admin/EconomyGlobalWithdrawHandler.kt

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.github.encryptsl.lite.eco.common.manager.economy.admin
22

33
import com.github.encryptsl.lite.eco.LiteEco
44
import com.github.encryptsl.lite.eco.api.enums.TypeLogger
5-
import com.github.encryptsl.lite.eco.common.extensions.mainThread
65
import kotlinx.coroutines.launch
76
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder
87
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver
@@ -47,20 +46,18 @@ class EconomyGlobalWithdrawHandler(
4746

4847
liteEco.increaseTransactions(players.size)
4948

50-
mainThread(liteEco) {
51-
sender.sendMessage(liteEco.locale.translation("messages.global.withdraw_money",
52-
TagResolver.resolver(
53-
Placeholder.parsed("money", liteEco.currencyImpl.fullFormatting(money)),
54-
Placeholder.parsed("currency", liteEco.currencyImpl.currencyModularNameConvert(currency, money))
55-
)
56-
))
57-
if (liteEco.config.getBoolean("messages.global.notify_withdraw")) {
58-
Bukkit.broadcast(liteEco.locale.translation("messages.broadcast.withdraw_money", TagResolver.resolver(
59-
Placeholder.parsed("sender", sender.name),
60-
Placeholder.parsed("money", liteEco.currencyImpl.fullFormatting(money, currency)),
61-
Placeholder.parsed("currency", liteEco.currencyImpl.currencyModularNameConvert(currency, money))
62-
)))
63-
}
49+
sender.sendMessage(liteEco.locale.translation("messages.global.withdraw_money",
50+
TagResolver.resolver(
51+
Placeholder.parsed("money", liteEco.currencyImpl.fullFormatting(money)),
52+
Placeholder.parsed("currency", liteEco.currencyImpl.currencyModularNameConvert(currency, money))
53+
)
54+
))
55+
if (liteEco.config.getBoolean("messages.global.notify_withdraw")) {
56+
Bukkit.broadcast(liteEco.locale.translation("messages.broadcast.withdraw_money", TagResolver.resolver(
57+
Placeholder.parsed("sender", sender.name),
58+
Placeholder.parsed("money", liteEco.currencyImpl.fullFormatting(money, currency)),
59+
Placeholder.parsed("currency", liteEco.currencyImpl.currencyModularNameConvert(currency, money))
60+
)))
6461
}
6562
}
6663
}

0 commit comments

Comments
 (0)