mirror of
https://github.com/Auxilor/EcoBits.git
synced 2025-12-19 15:09:19 +00:00
Updated to use PlaceholderContext
This commit is contained in:
@@ -40,7 +40,7 @@ allprojects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("com.willfp:eco:6.53.0")
|
compileOnly("com.willfp:eco:6.56.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")
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.willfp.ecobits.currencies
|
package com.willfp.ecobits.currencies
|
||||||
|
|
||||||
import com.willfp.eco.core.math.MathContext
|
import com.willfp.eco.core.math.MathContext
|
||||||
|
import com.willfp.eco.core.placeholder.context.PlaceholderContext
|
||||||
|
import com.willfp.eco.core.placeholder.context.PlaceholderContextSupplier
|
||||||
import com.willfp.eco.core.price.Price
|
import com.willfp.eco.core.price.Price
|
||||||
import com.willfp.eco.core.price.PriceFactory
|
import com.willfp.eco.core.price.PriceFactory
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
@@ -14,14 +16,14 @@ class PriceFactoryCurrency(
|
|||||||
currency.id
|
currency.id
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun create(baseContext: MathContext, function: Function<MathContext, Double>): Price {
|
override fun create(baseContext: PlaceholderContext, function: PlaceholderContextSupplier<Double>): Price {
|
||||||
return PriceCurrency(currency, baseContext) { function.apply(it) }
|
return PriceCurrency(currency, baseContext) { function.get(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PriceCurrency(
|
private class PriceCurrency(
|
||||||
private val currency: Currency,
|
private val currency: Currency,
|
||||||
private val baseContext: MathContext,
|
private val baseContext: PlaceholderContext,
|
||||||
private val xp: (MathContext) -> Double
|
private val xp: (PlaceholderContext) -> Double
|
||||||
) : Price {
|
) : Price {
|
||||||
private val multipliers = mutableMapOf<UUID, Double>()
|
private val multipliers = mutableMapOf<UUID, Double>()
|
||||||
|
|
||||||
@@ -35,7 +37,7 @@ class PriceFactoryCurrency(
|
|||||||
player.adjustBalance(currency, getValue(player, multiplier))
|
player.adjustBalance(currency, getValue(player, multiplier))
|
||||||
|
|
||||||
override fun getValue(player: Player, multiplier: Double) =
|
override fun getValue(player: Player, multiplier: Double) =
|
||||||
xp(MathContext.copyWithPlayer(baseContext, player)) * getMultiplier(player) * multiplier
|
xp(baseContext.copyWithPlayer(player)) * getMultiplier(player) * multiplier
|
||||||
|
|
||||||
override fun getMultiplier(player: Player): Double {
|
override fun getMultiplier(player: Player): Double {
|
||||||
return multipliers[player.uniqueId] ?: 1.0
|
return multipliers[player.uniqueId] ?: 1.0
|
||||||
|
|||||||
Reference in New Issue
Block a user