diff --git a/build.gradle.kts b/build.gradle.kts index 0accb33d..6ebfc767 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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") } diff --git a/eco-core/core-plugin/build.gradle.kts b/eco-core/core-plugin/build.gradle.kts index 5bf40c5b..924a69b4 100644 --- a/eco-core/core-plugin/build.gradle.kts +++ b/eco-core/core-plugin/build.gradle.kts @@ -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") diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt index bc028e2b..55bf8b36 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt @@ -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()) }, diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/price/PriceFactoryPlayerPoints.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/price/PriceFactoryPlayerPoints.kt new file mode 100644 index 00000000..613f673d --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/price/PriceFactoryPlayerPoints.kt @@ -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): 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() + + 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 + } + + } +} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/resources/paper-plugin.yml b/eco-core/core-plugin/src/main/resources/paper-plugin.yml index a0eab4d0..836da03e 100644 --- a/eco-core/core-plugin/src/main/resources/paper-plugin.yml +++ b/eco-core/core-plugin/src/main/resources/paper-plugin.yml @@ -189,6 +189,10 @@ dependencies: required: false bootstrap: false + - name: PlayerPoints + required: false + bootstrap: false + - name: Denizen required: false bootstrap: false \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index dfeb658e..79a82bd6 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -52,4 +52,5 @@ softdepend: - PvPManager - DeluxeMenus - UltraEconomy + - PlayerPoints - Denizen