diff --git a/build.gradle b/build.gradle index 0d88fb8..2b147c8 100644 --- a/build.gradle +++ b/build.gradle @@ -41,12 +41,13 @@ allprojects { } dependencies { - compileOnly 'com.willfp:eco:6.48.0' + compileOnly 'com.willfp:eco:6.65.4' implementation 'com.willfp:ecomponent:1.3.0' compileOnly 'com.github.ben-manes.caffeine:caffeine:3.0.6' compileOnly 'org.jetbrains:annotations:23.0.0' compileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.7.10' + compileOnly 'com.willfp:libreforge:4.33.0' } tasks.withType(JavaCompile) { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/EcoShopPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/EcoShopPlugin.kt index bab6721..e53bf59 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/EcoShopPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/EcoShopPlugin.kt @@ -5,11 +5,13 @@ import com.willfp.eco.core.command.impl.PluginCommand import com.willfp.eco.core.config.ConfigType import com.willfp.eco.core.config.interfaces.Config import com.willfp.eco.core.config.readConfig +import com.willfp.eco.core.integrations.IntegrationLoader import com.willfp.eco.core.integrations.shop.ShopManager import com.willfp.ecoshop.commands.CommandEcoShop import com.willfp.ecoshop.commands.CommandSell import com.willfp.ecoshop.config.UsermadeConfig import com.willfp.ecoshop.integration.EcoShopAdapter +import com.willfp.ecoshop.integration.libreforge.LibreforgeIntegration import com.willfp.ecoshop.shop.Shops import com.willfp.ecoshop.shop.gui.SellGUI import org.bukkit.event.Listener @@ -93,6 +95,12 @@ class EcoShopPlugin : EcoPlugin() { ) } + override fun loadIntegrationLoaders(): List { + return listOf( + IntegrationLoader("libreforge") { LibreforgeIntegration.load() } + ) + } + override fun getMinimumEcoVersion(): String { return "6.48.0" } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/event/EcoShopBuyEvent.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/event/EcoShopBuyEvent.kt new file mode 100644 index 0000000..fe31625 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/event/EcoShopBuyEvent.kt @@ -0,0 +1,31 @@ +package com.willfp.ecoshop.event + +import com.willfp.eco.core.price.Price +import com.willfp.ecoshop.shop.BuyType +import com.willfp.ecoshop.shop.ShopItem +import org.bukkit.entity.Player +import org.bukkit.event.HandlerList +import org.bukkit.event.player.PlayerEvent + +class EcoShopBuyEvent( + who: Player, + override val shopItem: ShopItem, + override var price: Price, + val buyType: BuyType +) : PlayerEvent(who), ShopEvent { + + // Below here is bukkit boilerplate + override fun getHandlers(): HandlerList { + return HANDLERS + } + + companion object { + @JvmStatic + private val HANDLERS: HandlerList = HandlerList() + + @JvmStatic + fun getHandlerList(): HandlerList { + return HANDLERS + } + } +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/event/EcoShopSellEvent.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/event/EcoShopSellEvent.kt index f6b479a..6f70a47 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/event/EcoShopSellEvent.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/event/EcoShopSellEvent.kt @@ -9,11 +9,11 @@ import org.bukkit.inventory.ItemStack class EcoShopSellEvent @JvmOverloads constructor( who: Player, - val shopItem: ShopItem, - var price: Price, + override val shopItem: ShopItem, + override var price: Price, val item: ItemStack, var multiplier: Double = 1.0 -) : PlayerEvent(who) { +) : PlayerEvent(who), ShopEvent { // Below here is bukkit boilerplate override fun getHandlers(): HandlerList { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/event/ShopEvent.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/event/ShopEvent.kt new file mode 100644 index 0000000..7f05170 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/event/ShopEvent.kt @@ -0,0 +1,9 @@ +package com.willfp.ecoshop.event + +import com.willfp.eco.core.price.Price +import com.willfp.ecoshop.shop.ShopItem + +interface ShopEvent { + val shopItem: ShopItem + var price: Price +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/libreforge/LibreforgeIntegration.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/libreforge/LibreforgeIntegration.kt new file mode 100644 index 0000000..56144dc --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/libreforge/LibreforgeIntegration.kt @@ -0,0 +1,20 @@ +package com.willfp.ecoshop.integration.libreforge + +import com.willfp.eco.core.integrations.Integration +import com.willfp.ecoshop.integration.libreforge.impl.FilterShopItem +import com.willfp.ecoshop.integration.libreforge.impl.TriggerBuyItem +import com.willfp.ecoshop.integration.libreforge.impl.TriggerSellItem +import com.willfp.libreforge.filters.Filters +import com.willfp.libreforge.triggers.Triggers + +object LibreforgeIntegration: Integration { + fun load() { + Filters.register(FilterShopItem) + Triggers.register(TriggerBuyItem) + Triggers.register(TriggerSellItem) + } + + override fun getPluginName(): String { + return "libreforge" + } +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/libreforge/impl/FilterShopItem.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/libreforge/impl/FilterShopItem.kt new file mode 100644 index 0000000..b53ede9 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/libreforge/impl/FilterShopItem.kt @@ -0,0 +1,21 @@ +package com.willfp.ecoshop.integration.libreforge.impl + +import com.willfp.eco.core.config.interfaces.Config +import com.willfp.ecoshop.event.ShopEvent +import com.willfp.libreforge.NoCompileData +import com.willfp.libreforge.filters.Filter +import com.willfp.libreforge.triggers.TriggerData + +object FilterShopItem : Filter>("shop_item") { + override fun getValue(config: Config, data: TriggerData?, key: String): Collection { + return config.getStrings(key) + } + + override fun isMet(data: TriggerData, value: Collection, compileData: NoCompileData): Boolean { + val event = data.event as? ShopEvent ?: return true + + return value.any { shopItemName -> + shopItemName.equals(event.shopItem.id, ignoreCase = true) + } + } +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/libreforge/impl/TriggerBuyItem.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/libreforge/impl/TriggerBuyItem.kt new file mode 100644 index 0000000..c718e6a --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/libreforge/impl/TriggerBuyItem.kt @@ -0,0 +1,30 @@ +package com.willfp.ecoshop.integration.libreforge.impl + +import com.willfp.ecoshop.event.EcoShopBuyEvent +import com.willfp.libreforge.triggers.Trigger +import com.willfp.libreforge.triggers.TriggerData +import com.willfp.libreforge.triggers.TriggerParameter +import org.bukkit.event.EventHandler + +object TriggerBuyItem : Trigger("buy_item") { + override val parameters = setOf( + TriggerParameter.PLAYER, + TriggerParameter.LOCATION, + TriggerParameter.EVENT + ) + + @EventHandler(ignoreCancelled = true) + fun handle(event: EcoShopBuyEvent) { + val player = event.player + + this.dispatch( + player, + TriggerData( + player = player, + location = player.location, + event = event, + value = event.price.getValue(player) + ) + ) + } +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/libreforge/impl/TriggerSellItem.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/libreforge/impl/TriggerSellItem.kt new file mode 100644 index 0000000..3091fd2 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/libreforge/impl/TriggerSellItem.kt @@ -0,0 +1,30 @@ +package com.willfp.ecoshop.integration.libreforge.impl + +import com.willfp.ecoshop.event.EcoShopSellEvent +import com.willfp.libreforge.triggers.Trigger +import com.willfp.libreforge.triggers.TriggerData +import com.willfp.libreforge.triggers.TriggerParameter +import org.bukkit.event.EventHandler + +object TriggerSellItem : Trigger("sell_item") { + override val parameters = setOf( + TriggerParameter.PLAYER, + TriggerParameter.LOCATION, + TriggerParameter.EVENT + ) + + @EventHandler(ignoreCancelled = true) + fun handle(event: EcoShopSellEvent) { + val player = event.player + + this.dispatch( + player, + TriggerData( + player = player, + location = player.location, + event = event, + value = event.price.getValue(player) + ) + ) + } +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/ShopItem.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/ShopItem.kt index 3572546..a17ee28 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/ShopItem.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/ShopItem.kt @@ -16,6 +16,7 @@ import com.willfp.eco.core.price.CombinedDisplayPrice import com.willfp.eco.core.price.ConfiguredPrice import com.willfp.eco.util.formatEco import com.willfp.ecoshop.EcoShopPlugin +import com.willfp.ecoshop.event.EcoShopBuyEvent import com.willfp.ecoshop.event.EcoShopSellEvent import com.willfp.ecoshop.shop.gui.BuyMenu import com.willfp.ecoshop.shop.gui.SellMenu @@ -252,10 +253,15 @@ class ShopItem( ) { require(amount in 1..getMaxBuysAtOnce(player)) - when (buyType) { - BuyType.NORMAL -> buyPrice?.pay(player, amount.toDouble()) - BuyType.ALT -> altBuyPrice?.pay(player, amount.toDouble()) - } + val basePrice = when (buyType) { + BuyType.NORMAL -> buyPrice + BuyType.ALT -> altBuyPrice + }!! + + val event = EcoShopBuyEvent(player, this, basePrice.price, buyType) + Bukkit.getPluginManager().callEvent(event) + + event.price.pay(player, amount.toDouble()) if (item != null) { val queue = DropQueue(player) @@ -275,6 +281,7 @@ class ShopItem( .replace("%amount%", amount.toString()) ) } + if (buyItemMessage != null) { for (message in buyItemMessage) { player.sendMessage( @@ -376,6 +383,7 @@ class ShopItem( ) } } + if (sellItemMessage != null) { for (message in sellItemMessage) { player.sendMessage( @@ -387,7 +395,7 @@ class ShopItem( } return amountSold - } + } fun getAmountInPlayerInventory(player: Player): Int { if (item == null) { diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index ab3658e..4232feb 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -13,6 +13,7 @@ softdepend: - StatTrackers - EcoItems - Reforges + - libreforge commands: ecoshop: