Skip to content

Commit

Permalink
Push for 1.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
EncryptSL committed Oct 7, 2024
1 parent 34c9924 commit cdf8db7
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 58 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dependencies {
compileOnly("com.github.MilkBowl:VaultAPI:1.7") {
exclude("org.bukkit", "bukkit")
}
compileOnly("com.zaxxer:HikariCP:5.1.0")
compileOnly("com.zaxxer:HikariCP:6.0.0")
compileOnly("me.clip:placeholderapi:2.11.5")
compileOnly("org.jetbrains.exposed:exposed-core:0.54.0")
compileOnly("org.jetbrains.exposed:exposed-jdbc:0.54.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@ import java.util.concurrent.CompletableFuture
class ModernLiteEcoEconomyImpl : DeprecatedLiteEcoEconomyImpl() {

override fun getUserByUUID(uuid: UUID, currency: String): CompletableFuture<User> {
val future = CompletableFuture<User>()

if (PlayerAccount.isPlayerOnline(uuid) || PlayerAccount.isAccountCached(uuid, currency)) {
future.completeAsync { User(Bukkit.getPlayer(uuid)?.name.toString(), uuid, PlayerAccount.getBalance(uuid, currency)) }
return if (PlayerAccount.isPlayerOnline(uuid) || PlayerAccount.isAccountCached(uuid, currency)) {
CompletableFuture.supplyAsync { User(Bukkit.getPlayer(uuid)?.name.toString(), uuid, PlayerAccount.getBalance(uuid, currency)) }
} else {
return LiteEco.instance.databaseEcoModel.getUserByUUID(uuid, currency)
LiteEco.instance.databaseEcoModel.getUserByUUID(uuid, currency)
}

return future
}

override fun deleteAccount(uuid: UUID, currency: String): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class MoneyCMD(private val liteEco: LiteEco) {

if (commandSender is Player) {
val cSender = offlinePlayer ?: commandSender
liteEco.api.getUserByUUID(cSender.uniqueId, c).thenApply { user ->
liteEco.api.getUserByUUID(cSender.uniqueId, c).thenAccept { user ->
val formatMessage = when(offlinePlayer) {
null -> liteEco.locale.translation("messages.balance.format", helper.getComponentBal(user, c))
else -> liteEco.locale.translation("messages.balance.format_target", helper.getComponentBal(user, c))
Expand All @@ -60,18 +60,22 @@ class MoneyCMD(private val liteEco: LiteEco) {
}.exceptionally {
commandSender.sendMessage(liteEco.locale.translation("messages.error.account_not_exist",
Placeholder.parsed("account", cSender.name.toString())))

return@exceptionally null
}
return
}

if (offlinePlayer != null) {
liteEco.api.getUserByUUID(offlinePlayer.uniqueId, c).thenApply { user ->
liteEco.api.getUserByUUID(offlinePlayer.uniqueId, c).thenAccept { user ->
commandSender.sendMessage(
liteEco.locale.translation("messages.balance.format_target", helper.getComponentBal(user, c))
)
}.exceptionally {
commandSender.sendMessage(liteEco.locale.translation("messages.error.account_not_exist",
Placeholder.parsed("account", offlinePlayer.name.toString())))

return@exceptionally null
}
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,17 @@ class DatabaseEcoModel : PlayerSQL {
}

override fun getUserByUUID(uuid: UUID, currency: String): CompletableFuture<User> {
val future = CompletableFuture<User>()
loggedTransaction {
try {
val table = Account(currency)
val row = table.select(table.uuid, table.username, table.money).where(table.uuid eq uuid).singleOrNull()
if (row == null) {
future.completeExceptionally(Exception("User not Found"))
} else {
future.completeAsync { User(row[table.username], row[table.uuid], row[table.money]) }
val future: CompletableFuture<User> = CompletableFuture.supplyAsync {
loggedTransaction {
try {
val table = Account(currency)
val row = table.select(table.uuid, table.username, table.money).where(table.uuid eq uuid).single()
User(row[table.username], row[table.uuid], row[table.money])
} catch (e : ExposedSQLException) {
LiteEco.instance.logger.severe(e.message ?: e.localizedMessage)

throw Exception("Something is wrong with fetching user, ${e.message ?: e.localizedMessage}")
}
} catch (e : ExposedSQLException) {
future.completeExceptionally(Exception("Something is wrong with fetching user, ${e.message ?: e.localizedMessage}"))
LiteEco.instance.logger.severe(e.message ?: e.localizedMessage)
}
}

Expand All @@ -78,14 +76,15 @@ class DatabaseEcoModel : PlayerSQL {
}

override fun getExistPlayerAccount(uuid: UUID, currency: String): CompletableFuture<Boolean> {
val future = CompletableFuture<Boolean>()
loggedTransaction {
try {
val table = Account(currency)
future.completeAsync { !table.select(table.uuid).where(table.uuid eq uuid).empty() }
} catch (e : ExposedSQLException) {
future.completeAsync { false }
LiteEco.instance.logger.severe(e.message ?: e.localizedMessage)
val future: CompletableFuture<Boolean> = CompletableFuture.supplyAsync {
loggedTransaction {
try {
val table = Account(currency)
!table.select(table.uuid).where(table.uuid eq uuid).empty()
} catch (e : ExposedSQLException) {
LiteEco.instance.logger.severe(e.message ?: e.localizedMessage)
false
}
}
}
return future
Expand All @@ -107,14 +106,15 @@ class DatabaseEcoModel : PlayerSQL {
}

override fun getPlayersIds(currency: String): CompletableFuture<MutableCollection<UUID>> {
val future = CompletableFuture<MutableCollection<UUID>>()
loggedTransaction {
try {
val table = Account(currency)
future.completeAsync { table.selectAll().map {it[table.uuid] }.toMutableList() }
} catch (e : ExposedSQLException) {
future.completeAsync { mutableListOf() }
LiteEco.instance.logger.severe(e.message ?: e.localizedMessage)
val future: CompletableFuture<MutableCollection<UUID>> = CompletableFuture.supplyAsync {
loggedTransaction {
try {
val table = Account(currency)
table.selectAll().map {it[table.uuid] }.toMutableList()
} catch (e : ExposedSQLException) {
LiteEco.instance.logger.severe(e.message ?: e.localizedMessage)
mutableListOf()
}
}
}
return future
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ class DatabaseMonologModel(val plugin: Plugin) : AdapterLogger {
}

override fun getLog(): CompletableFuture<List<EconomyLog>> {
val future = CompletableFuture<List<EconomyLog>>()
val log = loggedTransaction {
MonologTable.selectAll().orderBy(MonologTable.timestamp, SortOrder.DESC).mapNotNull {
EconomyLog(it[MonologTable.level], it[MonologTable.log], it[MonologTable.timestamp])
val future: CompletableFuture<List<EconomyLog>> = CompletableFuture.supplyAsync {
loggedTransaction {
MonologTable.selectAll().orderBy(MonologTable.timestamp, SortOrder.DESC).mapNotNull {
EconomyLog(it[MonologTable.level], it[MonologTable.log], it[MonologTable.timestamp])
}
}
}
return future.completeAsync { log }
return future
}

private fun log(level: Level, message: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ class AccountManageListener(private val liteEco: LiteEco) : Listener {
}
OperationType.CACHING_ACCOUNT -> {
for (currency in liteEco.currencyImpl.getCurrenciesKeys()) {
liteEco.databaseEcoModel.getUserByUUID(uuid, currency).thenAccept {
val future = liteEco.databaseEcoModel.getUserByUUID(uuid, currency).thenAccept {
liteEco.api.cacheAccount(uuid, currency, it.money)
}
liteEco.logger.info("Account $uuid was cached into memory !")
future.join()
}
}
OperationType.SYNC_ACCOUNT -> liteEco.api.syncAccount(uuid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class EconomyMoneyDepositListener(private val liteEco: LiteEco) : Listener {
Placeholder.parsed("account", target.name.toString())
))

liteEco.api.getUserByUUID(target.uniqueId, currency).thenApply {
liteEco.api.getUserByUUID(target.uniqueId, currency).thenAccept {
liteEco.increaseTransactions(1)
liteEco.api.depositMoney(target.uniqueId, currency, money)
liteEco.loggerModel.info(liteEco.locale.plainTextTranslation("messages.monolog.admin.normal.deposit", TagResolver.resolver(
Expand All @@ -42,7 +42,8 @@ class EconomyMoneyDepositListener(private val liteEco: LiteEco) : Listener {
Placeholder.parsed("currency", liteEco.currencyImpl.currencyModularNameConvert(currency, money))
)))
}.exceptionally {
return@exceptionally sender.sendMessage(liteEco.locale.translation("messages.error.account_not_exist", Placeholder.parsed("account", target.name.toString())))
sender.sendMessage(liteEco.locale.translation("messages.error.account_not_exist", Placeholder.parsed("account", target.name.toString())))
return@exceptionally null
}

if (sender.name == target.name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class EconomyMoneySetListener(private val liteEco: LiteEco) : Listener {
if (liteEco.api.getCheckBalanceLimit(money) && !sender.hasPermission("lite.eco.admin.bypass.limit"))
return sender.sendMessage(liteEco.locale.translation("messages.error.amount_above_limit"))

liteEco.api.getUserByUUID(target.uniqueId).thenApply {
liteEco.api.getUserByUUID(target.uniqueId).thenAccept {
liteEco.increaseTransactions(1)

liteEco.api.setMoney(target.uniqueId, currency, money)
Expand All @@ -37,6 +37,7 @@ class EconomyMoneySetListener(private val liteEco: LiteEco) : Listener {
)))
}.exceptionally {
sender.sendMessage(liteEco.locale.translation("messages.error.account_not_exist", Placeholder.parsed("account", target.name.toString())))
return@exceptionally null
}

if (sender.name == target.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class EconomyMoneyWithdrawListener(private val liteEco: LiteEco) : Listener {
if (!liteEco.api.has(target.uniqueId, currency, money))
return sender.sendMessage(liteEco.locale.translation("messages.error.insufficient_funds"))

liteEco.api.getUserByUUID(target.uniqueId, currency).thenApply {
liteEco.api.getUserByUUID(target.uniqueId, currency).thenAccept {
liteEco.increaseTransactions(1)
liteEco.api.withDrawMoney(target, currency, money)
liteEco.loggerModel.info(liteEco.locale.plainTextTranslation("messages.monolog.admin.normal.withdraw", TagResolver.resolver(
Expand All @@ -36,8 +36,10 @@ class EconomyMoneyWithdrawListener(private val liteEco: LiteEco) : Listener {
Placeholder.parsed("currency", liteEco.currencyImpl.currencyModularNameConvert(currency, money))
)))
}.exceptionally {
sender.sendMessage(
liteEco.locale.translation("messages.error.account_not_exist", Placeholder.parsed("account", target.name.toString())))
sender.sendMessage(liteEco.locale.translation("messages.error.account_not_exist",
Placeholder.parsed("account", target.name.toString())
))
return@exceptionally null
}

if (sender.name == target.name)
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/paper-libraries.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
libraries:
- com.zaxxer:HikariCP:5.1.0
- com.zaxxer:HikariCP:6.0.0
- org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.20
- org.jetbrains.exposed:exposed-core:0.54.0
- org.jetbrains.exposed:exposed-jdbc:0.54.0
- org.jetbrains.exposed:exposed-kotlin-datetime:0.54.0
- org.jetbrains.exposed:exposed-core:0.55.0
- org.jetbrains.exposed:exposed-jdbc:0.55.0
- org.jetbrains.exposed:exposed-kotlin-datetime:0.55.0
- com.squareup.okhttp3:okhttp:4.12.0
8 changes: 4 additions & 4 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ website: https://encryptsl.github.io
load: STARTUP
softdepend: [PlaceholderAPI, Vault, Treasury, MiniPlaceholders]
libraries:
- com.zaxxer:HikariCP:5.1.0
- com.zaxxer:HikariCP:6.0.0
- org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.20
- org.jetbrains.exposed:exposed-core:0.54.0
- org.jetbrains.exposed:exposed-jdbc:0.54.0
- org.jetbrains.exposed:exposed-kotlin-datetime:0.54.0
- org.jetbrains.exposed:exposed-core:0.55.0
- org.jetbrains.exposed:exposed-jdbc:0.55.0
- org.jetbrains.exposed:exposed-kotlin-datetime:0.55.0
- com.squareup.okhttp3:okhttp:4.12.0

description: ${description}
Expand Down

0 comments on commit cdf8db7

Please sign in to comment.