Add PlayerPoints to prices system

This commit is contained in:
BuildTools
2023-04-29 10:20:53 +07:00
parent 45e8a57880
commit 430117f342
6 changed files with 67 additions and 0 deletions

View File

@@ -111,6 +111,7 @@ import com.willfp.eco.internal.spigot.integrations.hologram.HologramHolographicD
import com.willfp.eco.internal.spigot.integrations.mcmmo.McmmoIntegrationImpl
import com.willfp.eco.internal.spigot.integrations.multiverseinventories.MultiverseInventoriesIntegration
import com.willfp.eco.internal.spigot.integrations.placeholder.PlaceholderIntegrationPAPI
import com.willfp.eco.internal.spigot.integrations.price.PriceFactoryPlayerPoints
import com.willfp.eco.internal.spigot.integrations.price.PriceFactoryUltraEconomy
import com.willfp.eco.internal.spigot.integrations.shop.ShopDeluxeSellwands
import com.willfp.eco.internal.spigot.integrations.shop.ShopEconomyShopGUI
@@ -357,6 +358,9 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
Prices.registerPriceFactory(PriceFactoryUltraEconomy(currency))
}
},
IntegrationLoader("PlayerPoints") {
Prices.registerPriceFactory(PriceFactoryPlayerPoints())
},
// Placeholder
IntegrationLoader("PlaceholderAPI") { PlaceholderManager.addIntegration(PlaceholderIntegrationPAPI()) },

View File

@@ -0,0 +1,54 @@
package com.willfp.eco.internal.spigot.integrations.price
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.PriceFactory
import org.black_ixx.playerpoints.PlayerPoints
import org.bukkit.entity.Player
import java.util.*
import kotlin.math.roundToInt
class PriceFactoryPlayerPoints : PriceFactory {
override fun getNames() = listOf(
"player_points",
"p_points"
)
override fun create(baseContext: PlaceholderContext, function: PlaceholderContextSupplier<Double>): Price {
return PricePlayerPoints(baseContext) { function.get(it).roundToInt() }
}
private class PricePlayerPoints(
private val baseContext: PlaceholderContext,
private val function: (PlaceholderContext) -> Int
) : Price {
private val api = PlayerPoints.getInstance().api
private val multipliers = mutableMapOf<UUID, Double>()
override fun canAfford(player: Player, multiplier: Double): Boolean {
return api.look(player.uniqueId) >= getValue(player, multiplier)
}
override fun pay(player: Player, multiplier: Double) {
api.take(player.uniqueId, getValue(player, multiplier).roundToInt())
}
override fun giveTo(player: Player, multiplier: Double) {
api.give(player.uniqueId, getValue(player, multiplier).roundToInt())
}
override fun getValue(player: Player, multiplier: Double): Double {
return function(baseContext.copyWithPlayer(player)) * getMultiplier(player) * multiplier
}
override fun getMultiplier(player: Player): Double {
return multipliers[player.uniqueId] ?: 1.0
}
override fun setMultiplier(player: Player, multiplier: Double) {
multipliers[player.uniqueId] = multiplier
}
}
}

View File

@@ -189,6 +189,10 @@ dependencies:
required: false
bootstrap: false
- name: PlayerPoints
required: false
bootstrap: false
- name: Denizen
required: false
bootstrap: false

View File

@@ -52,4 +52,5 @@ softdepend:
- PvPManager
- DeluxeMenus
- UltraEconomy
- PlayerPoints
- Denizen