Added UltraEconomy support to Price Lookup
This commit is contained in:
@@ -77,6 +77,8 @@ allprojects {
|
||||
|
||||
// LibsDisguises
|
||||
maven("https://repo.md-5.net/content/groups/public/")
|
||||
|
||||
maven("https://repo.techscode.com/repository/maven-releases/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -71,7 +71,7 @@ public interface Eco {
|
||||
/**
|
||||
* Create an event manager.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
* @param plugin The plugin.F
|
||||
* @return The event manager.
|
||||
*/
|
||||
@NotNull
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.willfp.eco.core.integrations.price;
|
||||
|
||||
import com.willfp.eco.core.price.PriceFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Class to handle afk integrations.
|
||||
*/
|
||||
public final class PriceManager {
|
||||
/**
|
||||
* A set of all registered integrations.
|
||||
*/
|
||||
private static final Set<PriceFactory> REGISTERED = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Register a new integration.
|
||||
*
|
||||
* @param integration The integration to register.
|
||||
*/
|
||||
public static void register(@NotNull final PriceFactory integration) {
|
||||
REGISTERED.removeIf(it -> new HashSet<>(integration.getNames()).containsAll(it.getNames()));
|
||||
REGISTERED.add(integration);
|
||||
}
|
||||
|
||||
private PriceManager() {
|
||||
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,7 @@ dependencies {
|
||||
compileOnly 'com.github.Gypopo:EconomyShopGUI-API:1.1.0'
|
||||
compileOnly 'com.github.N0RSKA:ScytherAPI:55a'
|
||||
compileOnly 'com.ticxo.modelengine:api:R3.0.1'
|
||||
compileOnly 'me.TechsCode:UltraEconomyAPI:1.0.0'
|
||||
|
||||
// MythicMobs
|
||||
compileOnly 'io.lumine:Mythic:5.0.1'
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.willfp.eco.core.integrations.economy.EconomyManager
|
||||
import com.willfp.eco.core.integrations.hologram.HologramManager
|
||||
import com.willfp.eco.core.integrations.mcmmo.McmmoManager
|
||||
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager
|
||||
import com.willfp.eco.core.integrations.price.PriceManager
|
||||
import com.willfp.eco.core.integrations.shop.ShopManager
|
||||
import com.willfp.eco.core.items.Items
|
||||
import com.willfp.eco.core.particle.Particles
|
||||
@@ -114,6 +115,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.PriceUltraEconomy
|
||||
import com.willfp.eco.internal.spigot.integrations.shop.ShopDeluxeSellwands
|
||||
import com.willfp.eco.internal.spigot.integrations.shop.ShopEconomyShopGUI
|
||||
import com.willfp.eco.internal.spigot.integrations.shop.ShopShopGuiPlus
|
||||
@@ -125,6 +127,7 @@ import com.willfp.eco.internal.spigot.recipes.listeners.ComplexInComplex
|
||||
import com.willfp.eco.internal.spigot.recipes.listeners.ComplexInVanilla
|
||||
import com.willfp.eco.internal.spigot.recipes.stackhandlers.ShapedCraftingRecipeStackHandler
|
||||
import com.willfp.eco.internal.spigot.recipes.stackhandlers.ShapelessCraftingRecipeStackHandler
|
||||
import me.TechsCode.UltraEconomy.UltraEconomy
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences
|
||||
import net.milkbowl.vault.economy.Economy
|
||||
import org.bukkit.Bukkit
|
||||
@@ -331,6 +334,13 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
|
||||
}
|
||||
},
|
||||
|
||||
// Price
|
||||
IntegrationLoader("UltraEconomy") {
|
||||
UltraEconomy.getAPI().currencies.forEach {
|
||||
PriceManager.register(PriceUltraEconomy(it))
|
||||
}
|
||||
},
|
||||
|
||||
// Placeholder
|
||||
IntegrationLoader("PlaceholderAPI") { PlaceholderManager.addIntegration(PlaceholderIntegrationPAPI()) },
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.willfp.eco.internal.spigot.integrations.price
|
||||
|
||||
import com.willfp.eco.core.math.MathContext
|
||||
import com.willfp.eco.core.price.Price
|
||||
import com.willfp.eco.core.price.PriceFactory
|
||||
import com.willfp.eco.util.toSingletonList
|
||||
import me.TechsCode.UltraEconomy.UltraEconomy
|
||||
import me.TechsCode.UltraEconomy.objects.Currency
|
||||
import org.bukkit.entity.Player
|
||||
import java.util.function.Function
|
||||
|
||||
class PriceUltraEconomy(private val currency: Currency): PriceFactory {
|
||||
|
||||
/**
|
||||
* Get the names (how the price looks in lookup strings).
|
||||
*
|
||||
*
|
||||
* For example, for XP Levels this would be 'l', 'xpl', 'levels', etc.
|
||||
*
|
||||
* @return The allowed names.
|
||||
*/
|
||||
override fun getNames(): MutableList<String> {
|
||||
return "ultraeconomy:${currency.name.lowercase()}".toSingletonList().toMutableList()
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the price.
|
||||
*
|
||||
* @param baseContext The base MathContext.
|
||||
* @param function The function to use. Should use {@link MathContext#copyWithPlayer(MathContext, Player)}
|
||||
* on calls.
|
||||
* @return The price.
|
||||
*/
|
||||
override fun create(baseContext: MathContext, function: Function<MathContext, Double>): Price {
|
||||
return UEPriceObject(currency, function, baseContext)
|
||||
}
|
||||
|
||||
class UEPriceObject(
|
||||
private val currency: Currency, private val function: Function<MathContext, Double>,
|
||||
private val baseContext: MathContext): Price {
|
||||
private val api = UltraEconomy.getAPI()
|
||||
|
||||
/**
|
||||
* Get if the player can afford the price.
|
||||
*
|
||||
* @param player The player.
|
||||
* @return If the player can afford.
|
||||
*/
|
||||
override fun canAfford(player: Player): Boolean {
|
||||
return (api.accounts.firstOrNull { it.uuid == player.uniqueId }
|
||||
?.getBalance(currency)?.onHand?.toDouble()?: 0.0) >= (function.apply(
|
||||
MathContext.copyWithPlayer(baseContext, player)))
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the player pay the price.
|
||||
*
|
||||
*
|
||||
* Only run this if the player can afford the price.
|
||||
*
|
||||
* @param player The player.
|
||||
*/
|
||||
override fun pay(player: Player) {
|
||||
api.accounts.firstOrNull { it.uuid == player.uniqueId }
|
||||
?.getBalance(currency)
|
||||
?.removeHand(function.apply(MathContext.copyWithPlayer(baseContext, player)).toFloat())
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user