mirror of
https://github.com/Auxilor/EcoBits.git
synced 2026-01-04 15:41:39 +00:00
@@ -33,6 +33,7 @@ allprojects {
|
||||
maven { url 'https://repo.codemc.org/repository/nms/' }
|
||||
maven { url 'https://repo.codemc.io/repository/maven-public/' }
|
||||
maven { url 'https://repo.dmulloy2.net/repository/public/' }
|
||||
maven { url 'https://repo.extendedclip.com/content/repositories/placeholderapi/' }
|
||||
}
|
||||
|
||||
jar {
|
||||
@@ -44,11 +45,15 @@ allprojects {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'com.willfp:eco:6.47.0'
|
||||
compileOnly 'com.willfp:eco:6.50.1'
|
||||
|
||||
compileOnly 'org.jetbrains:annotations:23.0.0'
|
||||
|
||||
compileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.7.10'
|
||||
|
||||
compileOnly 'me.clip:placeholderapi:2.11.2'
|
||||
|
||||
implementation 'com.github.ben-manes.caffeine:caffeine:3.1.0'
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.willfp.ecobits.commands
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.command.impl.Subcommand
|
||||
import com.willfp.eco.core.data.PlayerProfile
|
||||
import com.willfp.eco.util.StringUtils
|
||||
import com.willfp.eco.util.savedDisplayName
|
||||
import com.willfp.eco.util.toNiceString
|
||||
|
||||
@@ -2,14 +2,19 @@
|
||||
|
||||
package com.willfp.ecobits.currencies
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache
|
||||
import com.github.benmanes.caffeine.cache.Caffeine
|
||||
import com.willfp.eco.core.config.interfaces.Config
|
||||
import com.willfp.eco.core.data.keys.PersistentDataKey
|
||||
import com.willfp.eco.core.data.keys.PersistentDataKeyType
|
||||
import com.willfp.eco.core.data.profile
|
||||
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager
|
||||
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.PlayerlessPlaceholder
|
||||
import com.willfp.eco.core.price.Prices
|
||||
import com.willfp.eco.util.savedDisplayName
|
||||
import com.willfp.eco.util.toNiceString
|
||||
import com.willfp.ecobits.EcoBitsPlugin
|
||||
import com.willfp.ecobits.integrations.IntegrationVault
|
||||
@@ -18,6 +23,8 @@ import org.bukkit.Bukkit
|
||||
import org.bukkit.OfflinePlayer
|
||||
import org.bukkit.plugin.ServicePriority
|
||||
import java.text.DecimalFormat
|
||||
import java.time.Duration
|
||||
import java.util.regex.Pattern
|
||||
import kotlin.math.floor
|
||||
import kotlin.math.log10
|
||||
import kotlin.math.pow
|
||||
@@ -27,6 +34,10 @@ class Currency(
|
||||
val plugin: EcoBitsPlugin,
|
||||
val config: Config
|
||||
) {
|
||||
val leaderBoardCache: Cache<Int, LeaderboardCacheEntry?> = Caffeine.newBuilder()
|
||||
.expireAfterWrite(Duration.ofSeconds(plugin.configYml.getInt("cache-expire-after").toLong()))
|
||||
.build()
|
||||
|
||||
val default = config.getDouble("default")
|
||||
|
||||
val name = config.getFormattedString("name")
|
||||
@@ -46,7 +57,40 @@ class Currency(
|
||||
default
|
||||
)
|
||||
|
||||
fun getTop(place: Int): LeaderboardCacheEntry? {
|
||||
return leaderBoardCache.get(place) {
|
||||
val top = Bukkit.getOfflinePlayers()
|
||||
.sortedByDescending { it.getBalance(this) }.getOrNull(place - 1)
|
||||
|
||||
if (top == null) {
|
||||
null
|
||||
} else LeaderboardCacheEntry(top, top.getBalance(this))
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
PlaceholderManager.registerPlaceholder(
|
||||
DynamicPlaceholder(
|
||||
plugin,
|
||||
Pattern.compile("top_${id}_[0-9]+_[a-z]+"),
|
||||
) {
|
||||
value ->
|
||||
val place = value.split("_").getOrNull(2)
|
||||
?.toIntOrNull() ?: return@DynamicPlaceholder "Invalid place"
|
||||
val type = value.split("_").getOrNull(3)
|
||||
?: return@DynamicPlaceholder "Type required"
|
||||
return@DynamicPlaceholder when(type) {
|
||||
"name" -> this.getTop(place)?.player?.savedDisplayName
|
||||
?: plugin.langYml.getFormattedString("top.name-empty")
|
||||
|
||||
"amount" -> this.getTop(place)?.amount?.formatWithExtension()
|
||||
?: plugin.langYml.getFormattedString("top.amount-empty")
|
||||
|
||||
else -> "Invalid type"
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
PlaceholderManager.registerPlaceholder(
|
||||
PlayerPlaceholder(
|
||||
plugin,
|
||||
@@ -96,6 +140,8 @@ class Currency(
|
||||
}
|
||||
}
|
||||
|
||||
data class LeaderboardCacheEntry(val player: OfflinePlayer, val amount: Double)
|
||||
|
||||
fun Double.formatWithExtension(): String {
|
||||
val suffix = charArrayOf(' ', 'k', 'M', 'B', 'T', 'P', 'E')
|
||||
val numValue = this.toLong()
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
server-id: "main" # Server ID for local currencies over MySQL/MongoDB.
|
||||
|
||||
cache-expire-after: 300 # Leaderboard cache expire time in seconds.
|
||||
|
||||
currencies:
|
||||
- id: crystals # The ID of the currency.
|
||||
name: "&bCrystals ❖" # The name of the currency.
|
||||
|
||||
@@ -17,3 +17,6 @@ messages:
|
||||
cannot-afford: "&cYou can't afford to do this!"
|
||||
paid-player: "&fYou paid %player%&r &a%amount%&r &f%currency%&f!"
|
||||
too-much: "&fYou can't pay %player%&r this many &f%currency%&f as they already have too many!"
|
||||
top:
|
||||
name-empty: "&cEmpty"
|
||||
amount-empty: "&cEmpty"
|
||||
|
||||
@@ -10,6 +10,7 @@ depend:
|
||||
- ProtocolLib
|
||||
softdepend:
|
||||
- Vault
|
||||
- PlaceholderAPI
|
||||
commands:
|
||||
ecobits:
|
||||
description: Base Command
|
||||
|
||||
Reference in New Issue
Block a user