mirror of
https://github.com/Auxilor/EcoBits.git
synced 2025-12-20 15:39:29 +00:00
Cleaned up PR
This commit is contained in:
@@ -46,14 +46,11 @@ allprojects {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly 'com.willfp:eco:6.50.1'
|
compileOnly 'com.willfp:eco:6.50.1'
|
||||||
|
|
||||||
compileOnly 'org.jetbrains:annotations:23.0.0'
|
compileOnly 'org.jetbrains:annotations:23.0.0'
|
||||||
|
|
||||||
compileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.7.10'
|
compileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.7.10'
|
||||||
|
|
||||||
compileOnly 'me.clip:placeholderapi:2.11.2'
|
compileOnly 'me.clip:placeholderapi:2.11.2'
|
||||||
|
compileOnly 'com.github.ben-manes.caffeine:caffeine:3.1.0'
|
||||||
implementation 'com.github.ben-manes.caffeine:caffeine:3.1.0'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType(JavaCompile) {
|
tasks.withType(JavaCompile) {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
package com.willfp.ecobits.currencies
|
package com.willfp.ecobits.currencies
|
||||||
|
|
||||||
import com.github.benmanes.caffeine.cache.Cache
|
|
||||||
import com.github.benmanes.caffeine.cache.Caffeine
|
import com.github.benmanes.caffeine.cache.Caffeine
|
||||||
import com.willfp.eco.core.config.interfaces.Config
|
import com.willfp.eco.core.config.interfaces.Config
|
||||||
import com.willfp.eco.core.data.keys.PersistentDataKey
|
import com.willfp.eco.core.data.keys.PersistentDataKey
|
||||||
@@ -10,7 +9,6 @@ import com.willfp.eco.core.data.keys.PersistentDataKeyType
|
|||||||
import com.willfp.eco.core.data.profile
|
import com.willfp.eco.core.data.profile
|
||||||
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager
|
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager
|
||||||
import com.willfp.eco.core.placeholder.DynamicPlaceholder
|
import com.willfp.eco.core.placeholder.DynamicPlaceholder
|
||||||
import com.willfp.eco.core.placeholder.PlayerDynamicPlaceholder
|
|
||||||
import com.willfp.eco.core.placeholder.PlayerPlaceholder
|
import com.willfp.eco.core.placeholder.PlayerPlaceholder
|
||||||
import com.willfp.eco.core.placeholder.PlayerlessPlaceholder
|
import com.willfp.eco.core.placeholder.PlayerlessPlaceholder
|
||||||
import com.willfp.eco.core.price.Prices
|
import com.willfp.eco.core.price.Prices
|
||||||
@@ -24,6 +22,7 @@ import org.bukkit.OfflinePlayer
|
|||||||
import org.bukkit.plugin.ServicePriority
|
import org.bukkit.plugin.ServicePriority
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
|
import java.util.Optional
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
import kotlin.math.floor
|
import kotlin.math.floor
|
||||||
import kotlin.math.log10
|
import kotlin.math.log10
|
||||||
@@ -34,9 +33,9 @@ class Currency(
|
|||||||
val plugin: EcoBitsPlugin,
|
val plugin: EcoBitsPlugin,
|
||||||
val config: Config
|
val config: Config
|
||||||
) {
|
) {
|
||||||
val leaderBoardCache: Cache<Int, LeaderboardCacheEntry?> = Caffeine.newBuilder()
|
val leaderboardCache = Caffeine.newBuilder()
|
||||||
.expireAfterWrite(Duration.ofSeconds(plugin.configYml.getInt("cache-expire-after").toLong()))
|
.expireAfterWrite(Duration.ofSeconds(plugin.configYml.getInt("cache-expire-after").toLong()))
|
||||||
.build()
|
.build<Int, Optional<LeaderboardPlace>>()
|
||||||
|
|
||||||
val default = config.getDouble("default")
|
val default = config.getDouble("default")
|
||||||
|
|
||||||
@@ -57,15 +56,15 @@ class Currency(
|
|||||||
default
|
default
|
||||||
)
|
)
|
||||||
|
|
||||||
fun getTop(place: Int): LeaderboardCacheEntry? {
|
fun getLeaderboardPlace(place: Int): LeaderboardPlace? {
|
||||||
return leaderBoardCache.get(place) {
|
return leaderboardCache.get(place) {
|
||||||
val top = Bukkit.getOfflinePlayers()
|
val top = Bukkit.getOfflinePlayers()
|
||||||
.sortedByDescending { it.getBalance(this) }.getOrNull(place - 1)
|
.sortedByDescending { it.getBalance(this) }.getOrNull(place - 1)
|
||||||
|
|
||||||
if (top == null) {
|
if (top == null) {
|
||||||
null
|
Optional.empty()
|
||||||
} else LeaderboardCacheEntry(top, top.getBalance(this))
|
} else Optional.of(LeaderboardPlace(top, top.getBalance(this)))
|
||||||
}
|
}.orElse(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@@ -73,20 +72,21 @@ class Currency(
|
|||||||
DynamicPlaceholder(
|
DynamicPlaceholder(
|
||||||
plugin,
|
plugin,
|
||||||
Pattern.compile("top_${id}_[0-9]+_[a-z]+"),
|
Pattern.compile("top_${id}_[0-9]+_[a-z]+"),
|
||||||
) {
|
) { value ->
|
||||||
value ->
|
|
||||||
val place = value.split("_").getOrNull(2)
|
val place = value.split("_").getOrNull(2)
|
||||||
?.toIntOrNull() ?: return@DynamicPlaceholder "Invalid place"
|
?.toIntOrNull() ?: return@DynamicPlaceholder ""
|
||||||
|
|
||||||
val type = value.split("_").getOrNull(3)
|
val type = value.split("_").getOrNull(3)
|
||||||
?: return@DynamicPlaceholder "Type required"
|
?: return@DynamicPlaceholder ""
|
||||||
return@DynamicPlaceholder when(type) {
|
|
||||||
"name" -> this.getTop(place)?.player?.savedDisplayName
|
return@DynamicPlaceholder when (type) {
|
||||||
|
"name" -> this.getLeaderboardPlace(place)?.player?.savedDisplayName
|
||||||
?: plugin.langYml.getFormattedString("top.name-empty")
|
?: plugin.langYml.getFormattedString("top.name-empty")
|
||||||
|
|
||||||
"amount" -> this.getTop(place)?.amount?.formatWithExtension()
|
"amount" -> this.getLeaderboardPlace(place)?.amount?.formatWithExtension()
|
||||||
?: plugin.langYml.getFormattedString("top.amount-empty")
|
?: plugin.langYml.getFormattedString("top.amount-empty")
|
||||||
|
|
||||||
else -> "Invalid type"
|
else -> ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -140,7 +140,10 @@ class Currency(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class LeaderboardCacheEntry(val player: OfflinePlayer, val amount: Double)
|
data class LeaderboardPlace(
|
||||||
|
val player: OfflinePlayer,
|
||||||
|
val amount: Double
|
||||||
|
)
|
||||||
|
|
||||||
fun Double.formatWithExtension(): String {
|
fun Double.formatWithExtension(): String {
|
||||||
val suffix = charArrayOf(' ', 'k', 'M', 'B', 'T', 'P', 'E')
|
val suffix = charArrayOf(' ', 'k', 'M', 'B', 'T', 'P', 'E')
|
||||||
|
|||||||
Reference in New Issue
Block a user