Add RoyaleEconomy to prices system
This commit is contained in:
@@ -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()) },
|
||||
|
||||
@@ -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<String> {
|
||||
return currency.currencyName.lowercase().toSingletonList();
|
||||
}
|
||||
|
||||
override fun create(baseContext: PlaceholderContext, function: PlaceholderContextSupplier<Double>): 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<UUID, Double>()
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -194,5 +194,9 @@ dependencies:
|
||||
bootstrap: false
|
||||
|
||||
- name: Denizen
|
||||
required: false
|
||||
bootstrap: false
|
||||
|
||||
- name: RoyaleEconomy
|
||||
required: false
|
||||
bootstrap: false
|
||||
BIN
lib/RoyaleEconomyAPI.jar
Normal file
BIN
lib/RoyaleEconomyAPI.jar
Normal file
Binary file not shown.
Reference in New Issue
Block a user