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 9e72dda3..dc6b08eb 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 @@ -112,6 +112,7 @@ 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.PriceFactoryRoyaleEconomy 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 @@ -127,6 +128,7 @@ import com.willfp.eco.internal.spigot.recipes.stackhandlers.ShapedCraftingRecipe import com.willfp.eco.internal.spigot.recipes.stackhandlers.ShapelessCraftingRecipeStackHandler import com.willfp.eco.util.ClassUtils import me.TechsCode.UltraEconomy.UltraEconomy +import me.qKing12.RoyaleEconomy.MultiCurrency.MultiCurrencyHandler import net.kyori.adventure.platform.bukkit.BukkitAudiences import net.milkbowl.vault.economy.Economy import org.bukkit.Bukkit @@ -358,6 +360,11 @@ abstract class EcoSpigotPlugin : EcoPlugin() { } }, IntegrationLoader("PlayerPoints") { Prices.registerPriceFactory(PriceFactoryPlayerPoints()) }, + IntegrationLoader("RoyaleEconomy") { + for (currency in MultiCurrencyHandler.getCurrencies()) { + Prices.registerPriceFactory(PriceFactoryRoyaleEconomy(currency)) + } + }, // Placeholder IntegrationLoader("PlaceholderAPI") { PlaceholderManager.addIntegration(PlaceholderIntegrationPAPI()) }, diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/price/PriceFactoryRoyaleEconomy.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/price/PriceFactoryRoyaleEconomy.kt new file mode 100644 index 00000000..ac2eb753 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/price/PriceFactoryRoyaleEconomy.kt @@ -0,0 +1,58 @@ +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 com.willfp.eco.util.toSingletonList +import me.qKing12.RoyaleEconomy.MultiCurrency.Currency +import me.qKing12.RoyaleEconomy.MultiCurrency.MultiCurrencyHandler +import org.bukkit.entity.Player +import java.util.* + +class PriceFactoryRoyaleEconomy(private val currency: Currency) : PriceFactory { + + override fun getNames(): List { + return currency.currencyName.lowercase().toSingletonList(); + } + + override fun create(baseContext: PlaceholderContext, function: PlaceholderContextSupplier): Price { + return PriceRoyaleEconomy(currency, baseContext) { function.get(it) } + } + + private class PriceRoyaleEconomy( + private val currency: Currency, + private val baseContext: PlaceholderContext, + private val function: (PlaceholderContext) -> Double + ) : Price { + private val multipliers = mutableMapOf() + + override fun canAfford(player: Player, multiplier: Double): Boolean { + return MultiCurrencyHandler + .findCurrencyById(currency.currencyId).getAmount(player.uniqueId.toString()) >= getValue(player, multiplier) + } + + override fun pay(player: Player, multiplier: Double) { + MultiCurrencyHandler.findCurrencyById(currency.currencyId).removeAmount(player.uniqueId.toString(), + getValue(player, multiplier)) + } + + override fun giveTo(player: Player, multiplier: Double) { + MultiCurrencyHandler.findCurrencyById(currency.currencyId).addAmount(player.uniqueId.toString(), + getValue(player, multiplier)) + } + + 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 836da03e..cd6a3206 100644 --- a/eco-core/core-plugin/src/main/resources/paper-plugin.yml +++ b/eco-core/core-plugin/src/main/resources/paper-plugin.yml @@ -194,5 +194,9 @@ dependencies: bootstrap: false - name: Denizen + required: false + bootstrap: false + + - name: RoyaleEconomy required: false bootstrap: false \ No newline at end of file diff --git a/lib/RoyaleEconomyAPI.jar b/lib/RoyaleEconomyAPI.jar new file mode 100644 index 00000000..648c4fb0 Binary files /dev/null and b/lib/RoyaleEconomyAPI.jar differ