mirror of
https://github.com/Auxilor/EcoBits.git
synced 2025-12-19 15:09:19 +00:00
Converted to BigDecimal
This commit is contained in:
@@ -40,7 +40,7 @@ allprojects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("com.willfp:eco:6.56.0")
|
compileOnly("com.willfp:eco:6.60.0")
|
||||||
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")
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ class EcoBitsPlugin : EcoPlugin() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getMinimumEcoVersion(): String {
|
||||||
|
return "6.60.0"
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
lateinit var instance: EcoBitsPlugin
|
lateinit var instance: EcoBitsPlugin
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import net.milkbowl.vault.economy.Economy
|
|||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.OfflinePlayer
|
import org.bukkit.OfflinePlayer
|
||||||
import org.bukkit.plugin.ServicePriority
|
import org.bukkit.plugin.ServicePriority
|
||||||
|
import java.math.BigDecimal
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import java.util.Optional
|
import java.util.Optional
|
||||||
@@ -38,11 +39,11 @@ class Currency(
|
|||||||
.expireAfterWrite(Duration.ofSeconds(plugin.configYml.getInt("cache-expire-after").toLong()))
|
.expireAfterWrite(Duration.ofSeconds(plugin.configYml.getInt("cache-expire-after").toLong()))
|
||||||
.build<Int, Optional<LeaderboardPlace>>()
|
.build<Int, Optional<LeaderboardPlace>>()
|
||||||
|
|
||||||
val default = config.getDouble("default")
|
val default = BigDecimal(config.getDouble("default"))
|
||||||
|
|
||||||
val name = config.getFormattedString("name")
|
val name = config.getFormattedString("name")
|
||||||
|
|
||||||
val max = config.getDouble("max").let { if (it < 0) Double.MAX_VALUE else it }
|
val max = BigDecimal(config.getDouble("max").let { if (it < 0) Double.POSITIVE_INFINITY else it })
|
||||||
|
|
||||||
val isPayable = config.getBool("payable")
|
val isPayable = config.getBool("payable")
|
||||||
|
|
||||||
@@ -56,7 +57,7 @@ class Currency(
|
|||||||
|
|
||||||
val key = PersistentDataKey(
|
val key = PersistentDataKey(
|
||||||
plugin.createNamespacedKey(if (isLocal) "${plugin.serverID}_${id}" else id),
|
plugin.createNamespacedKey(if (isLocal) "${plugin.serverID}_${id}" else id),
|
||||||
PersistentDataKeyType.DOUBLE,
|
PersistentDataKeyType.BIG_DECIMAL,
|
||||||
default
|
default
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -162,10 +163,10 @@ class Currency(
|
|||||||
|
|
||||||
data class LeaderboardPlace(
|
data class LeaderboardPlace(
|
||||||
val player: OfflinePlayer,
|
val player: OfflinePlayer,
|
||||||
val amount: Double
|
val amount: BigDecimal
|
||||||
)
|
)
|
||||||
|
|
||||||
fun Double.formatWithExtension(): String {
|
fun BigDecimal.formatWithExtension(): String {
|
||||||
val suffix = charArrayOf(' ', 'k', 'M', 'B', 'T', 'P', 'E')
|
val suffix = charArrayOf(' ', 'k', 'M', 'B', 'T', 'P', 'E')
|
||||||
val numValue = this.toLong()
|
val numValue = this.toLong()
|
||||||
val value = floor(log10(numValue.toDouble())).toInt()
|
val value = floor(log10(numValue.toDouble())).toInt()
|
||||||
@@ -179,17 +180,17 @@ fun Double.formatWithExtension(): String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun OfflinePlayer.getBalance(currency: Currency): Double {
|
fun OfflinePlayer.getBalance(currency: Currency): BigDecimal {
|
||||||
return this.profile.read(currency.key)
|
return this.profile.read(currency.key)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun OfflinePlayer.setBalance(currency: Currency, value: Double) {
|
fun OfflinePlayer.setBalance(currency: Currency, value: BigDecimal) {
|
||||||
this.profile.write(
|
this.profile.write(
|
||||||
currency.key,
|
currency.key,
|
||||||
value.coerceIn(0.0..currency.max)
|
value.coerceIn(BigDecimal(0.0)..currency.max)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun OfflinePlayer.adjustBalance(currency: Currency, by: Double) {
|
fun OfflinePlayer.adjustBalance(currency: Currency, by: BigDecimal) {
|
||||||
this.setBalance(currency, this.getBalance(currency) + by)
|
this.setBalance(currency, this.getBalance(currency) + by)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,13 +26,13 @@ class PriceFactoryCurrency(
|
|||||||
private val multipliers = mutableMapOf<UUID, Double>()
|
private val multipliers = mutableMapOf<UUID, Double>()
|
||||||
|
|
||||||
override fun canAfford(player: Player, multiplier: Double) =
|
override fun canAfford(player: Player, multiplier: Double) =
|
||||||
player.getBalance(currency) >= getValue(player, multiplier)
|
player.getBalance(currency).toDouble() >= getValue(player, multiplier)
|
||||||
|
|
||||||
override fun pay(player: Player, multiplier: Double) =
|
override fun pay(player: Player, multiplier: Double) =
|
||||||
player.adjustBalance(currency, -getValue(player, multiplier))
|
player.adjustBalance(currency, -getValue(player, multiplier).toBigDecimal())
|
||||||
|
|
||||||
override fun giveTo(player: Player, multiplier: Double) =
|
override fun giveTo(player: Player, multiplier: Double) =
|
||||||
player.adjustBalance(currency, getValue(player, multiplier))
|
player.adjustBalance(currency, getValue(player, multiplier).toBigDecimal())
|
||||||
|
|
||||||
override fun getValue(player: Player, multiplier: Double) =
|
override fun getValue(player: Player, multiplier: Double) =
|
||||||
xp(baseContext.copyWithPlayer(player)) * getMultiplier(player) * multiplier
|
xp(baseContext.copyWithPlayer(player)) * getMultiplier(player) * multiplier
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class IntegrationVault(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun format(amount: Double): String {
|
override fun format(amount: Double): String {
|
||||||
return amount.formatWithExtension()
|
return amount.toBigDecimal().formatWithExtension()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun currencyNamePlural(): String {
|
override fun currencyNamePlural(): String {
|
||||||
@@ -70,7 +70,7 @@ class IntegrationVault(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getBalance(player: OfflinePlayer): Double {
|
override fun getBalance(player: OfflinePlayer): Double {
|
||||||
return player.getBalance(currency)
|
return player.getBalance(currency).toDouble()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("Deprecated in Java", ReplaceWith("getBalance(playerName)"))
|
@Deprecated("Deprecated in Java", ReplaceWith("getBalance(playerName)"))
|
||||||
@@ -91,7 +91,7 @@ class IntegrationVault(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun has(player: OfflinePlayer, amount: Double): Boolean {
|
override fun has(player: OfflinePlayer, amount: Double): Boolean {
|
||||||
return player.getBalance(currency) >= amount
|
return player.getBalance(currency).toDouble() >= amount
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("Deprecated in Java", ReplaceWith("has(playerName, amount)"))
|
@Deprecated("Deprecated in Java", ReplaceWith("has(playerName, amount)"))
|
||||||
@@ -120,7 +120,7 @@ class IntegrationVault(
|
|||||||
return EconomyResponse(0.0, 0.0, EconomyResponse.ResponseType.FAILURE, "Can't withdraw below 0.")
|
return EconomyResponse(0.0, 0.0, EconomyResponse.ResponseType.FAILURE, "Can't withdraw below 0.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.getBalance(currency) - amount < 0) {
|
if (player.getBalance(currency).toDouble() - amount < 0) {
|
||||||
return EconomyResponse(
|
return EconomyResponse(
|
||||||
0.0,
|
0.0,
|
||||||
0.0,
|
0.0,
|
||||||
@@ -129,11 +129,11 @@ class IntegrationVault(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
player.adjustBalance(currency, -amount)
|
player.adjustBalance(currency, -amount.toBigDecimal())
|
||||||
|
|
||||||
return EconomyResponse(
|
return EconomyResponse(
|
||||||
amount,
|
amount,
|
||||||
player.getBalance(currency),
|
player.getBalance(currency).toDouble(),
|
||||||
EconomyResponse.ResponseType.SUCCESS,
|
EconomyResponse.ResponseType.SUCCESS,
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
@@ -165,7 +165,7 @@ class IntegrationVault(
|
|||||||
return EconomyResponse(0.0, 0.0, EconomyResponse.ResponseType.FAILURE, "Can't deposit below 0.")
|
return EconomyResponse(0.0, 0.0, EconomyResponse.ResponseType.FAILURE, "Can't deposit below 0.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.getBalance(currency) + amount > currency.max) {
|
if (player.getBalance(currency).toDouble() + amount > currency.max.toDouble()) {
|
||||||
return EconomyResponse(
|
return EconomyResponse(
|
||||||
0.0,
|
0.0,
|
||||||
0.0,
|
0.0,
|
||||||
@@ -174,10 +174,10 @@ class IntegrationVault(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
player.adjustBalance(currency, amount)
|
player.adjustBalance(currency, amount.toBigDecimal())
|
||||||
return EconomyResponse(
|
return EconomyResponse(
|
||||||
amount,
|
amount,
|
||||||
player.getBalance(currency),
|
player.getBalance(currency).toDouble(),
|
||||||
EconomyResponse.ResponseType.SUCCESS,
|
EconomyResponse.ResponseType.SUCCESS,
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user