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 05c7cf5..3f5c015 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 @@ -22,7 +22,10 @@ import com.willfp.ecoshop.event.EcoShopSellEvent import com.willfp.ecoshop.shop.gui.BuyMenu import com.willfp.ecoshop.shop.gui.SellMenu import com.willfp.ecoshop.shop.gui.ShopItemSlot +import com.willfp.libreforge.BlankHolder.conditions +import com.willfp.libreforge.EmptyProvidedHolder import com.willfp.libreforge.ViolationContext +import com.willfp.libreforge.conditions.Conditions import com.willfp.libreforge.effects.Effects import com.willfp.libreforge.toDispatcher import com.willfp.libreforge.triggers.TriggerData @@ -47,13 +50,15 @@ class ShopItem( ) : KRegistrable { override val id = config.getString("id") + private val context = ViolationContext(plugin, "shop item $id") + val commands = config.getStrings("command") + config.getStrings("commands") val item = if (config.has("item")) Items.lookup(config.getString("item")) else null val effects = Effects.compileChain( config.getSubsections("effects"), - ViolationContext(plugin, "shop item $id") + context.with("effects") ) val buyAmount = config.getIntOrNull("buy.amount") ?: 1 @@ -96,6 +101,21 @@ class ShopItem( val sellPrice = ConfiguredPrice.create(config.getSubsection("sell")) + val buyConditions = Conditions.compile( + config.getSubsections("buy.conditions"), + context.with("buy conditions") + ) + + val altBuyConditions = Conditions.compile( + config.getSubsections("alt-buy.conditions"), + context.with("alt buy conditions") + ) + + val sellConditions = Conditions.compile( + config.getSubsections("sell.conditions"), + context.with("sell conditions") + ) + val slot = ShopItemSlot(this, plugin) val isShowingQuickBuySell = config.getBoolOrNull("gui.show-quick-buy-sell") ?: true @@ -243,6 +263,20 @@ class ShopItem( } } + val conditions = if (buyType == BuyType.ALT) altBuyConditions else buyConditions + if (!conditions.areMet(player.toDispatcher(), EmptyProvidedHolder)) { + // Only run not met effects if player can afford to buy + if (getBuyPrice(buyType)!!.canAfford(player, amount.toDouble())) { + conditions.areMetAndTrigger( + TriggerData( + player = player + ).dispatch(player.toDispatcher() + )) + } + + return BuyStatus.MISSING_REQUIREMENTS + } + if (!getBuyPrice(buyType)!!.canAfford(player, amount.toDouble())) { return BuyStatus.CANNOT_AFFORD } @@ -339,6 +373,10 @@ class ShopItem( } } + if (!sellConditions.areMet(player.toDispatcher(), EmptyProvidedHolder)) { + return SellStatus.MISSING_REQUIREMENTS + } + return SellStatus.ALLOW } diff --git a/eco-core/core-plugin/src/main/resources/categories/_example.yml b/eco-core/core-plugin/src/main/resources/categories/_example.yml index 4e92af6..b728c42 100644 --- a/eco-core/core-plugin/src/main/resources/categories/_example.yml +++ b/eco-core/core-plugin/src/main/resources/categories/_example.yml @@ -87,6 +87,10 @@ items: require: "%player_rank% > 1" # (Optional) This expression must hold true to be allowed to sell this item. + # The conditions that must be met in order to sell this item. + # Read here: https://plugins.auxilor.io/effects/configuring-a-condition + conditions: [ ] + sell-command: # (Optional) Enter commands that should be executed when a player sells items. You can use %player% and %amount% placeholders - "give %player% stone %amount%" sell-message: # (Optional) Enter messages to send to the player when the player sells this specific items. It will still send the 'sold-item/sold-multiple' from lang.yml @@ -132,6 +136,10 @@ items: type: crystals display: "&b%value% Crystals ❖" + # The conditions that must be met in order to buy this item. + # Read here: https://plugins.auxilor.io/effects/configuring-a-condition + conditions: [ ] + gui: display: item: nether_star @@ -150,8 +158,6 @@ items: type: coins display: "&a$%value%" - require: "%actions_allow_bosses_is_met%" # You can use actions to use conditions here! (https://plugins.auxilor.io/actions/placeholderapi) - max-at-once: 1 # If you want to skip the amount selection GUI, set max at once to 1 so clicking will instant-buy. # Instead of having the item be buyable and sellable, you can have @@ -162,6 +168,10 @@ items: type: crystals display: "&b%value%❖" + # The conditions that must be met in order to buy this item. + # Read here: https://plugins.auxilor.io/effects/configuring-a-condition + conditions: [ ] + gui: display: lore: # You can inherit the item and just add your own extra lore to show additional information.