Add PlayerPoints to prices system
This commit is contained in:
@@ -83,6 +83,9 @@ allprojects {
|
||||
// UltraEconomy
|
||||
maven("https://repo.techscode.com/repository/maven-releases/")
|
||||
|
||||
// PlayerPoints
|
||||
maven("https://repo.rosewooddev.io/repository/public/")
|
||||
|
||||
// Denizen
|
||||
maven("https://maven.citizensnpcs.co/repo")
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ dependencies {
|
||||
compileOnly("com.github.N0RSKA:ScytherAPI:55a")
|
||||
compileOnly("com.ticxo.modelengine:api:R3.0.1")
|
||||
compileOnly("me.TechsCode:UltraEconomyAPI:1.0.0")
|
||||
compileOnly("org.black_ixx:playerpoints:3.2.5")
|
||||
compileOnly("com.github.Ssomar-Developement:SCore:3.4.7")
|
||||
compileOnly("io.lumine:Mythic:5.2.1")
|
||||
compileOnly("io.lumine:LumineUtils:1.19-SNAPSHOT")
|
||||
|
||||
@@ -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()) },
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -189,6 +189,10 @@ dependencies:
|
||||
required: false
|
||||
bootstrap: false
|
||||
|
||||
- name: PlayerPoints
|
||||
required: false
|
||||
bootstrap: false
|
||||
|
||||
- name: Denizen
|
||||
required: false
|
||||
bootstrap: false
|
||||
@@ -52,4 +52,5 @@ softdepend:
|
||||
- PvPManager
|
||||
- DeluxeMenus
|
||||
- UltraEconomy
|
||||
- PlayerPoints
|
||||
- Denizen
|
||||
|
||||
Reference in New Issue
Block a user