From a8ec393d2b98651b6475f4d65a149fb09fce00b5 Mon Sep 17 00:00:00 2001 From: Exanthiax <107284021+Exanthiax@users.noreply.github.com> Date: Fri, 7 Apr 2023 16:15:45 +0100 Subject: [PATCH] Update ShopItem.kt --- .../com/willfp/ecoshop/shop/ShopItem.kt | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) 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 a3b27dc..03b1e2f 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 @@ -21,6 +21,7 @@ import com.willfp.ecoshop.shop.gui.BuyMenu import com.willfp.ecoshop.shop.gui.SellMenu import com.willfp.ecoshop.shop.gui.ShopItemSlot import org.bukkit.Bukkit +import org.bukkit.ChatColor import org.bukkit.Material import org.bukkit.OfflinePlayer import org.bukkit.entity.Player @@ -43,6 +44,10 @@ class ShopItem( val commands = config.getStringsOrNull("command") + val sellCommand = config.getStringsOrNull("sell.sell-commands") + + val sellItemMessage = config.getStringsOrNull("sell.sell-message") + val item = if (config.has("item")) Items.lookup(config.getString("item")) else null val buyAmount = config.getIntOrNull("buy.amount") ?: 1 @@ -256,6 +261,7 @@ class ShopItem( } } + player.profile.write(timesBoughtKey, player.profile.read(timesBoughtKey) + 1) if (shop?.isBroadcasting == true) { @@ -337,8 +343,27 @@ class ShopItem( shop?.sellSound?.playTo(player) + if (sellCommand != null) { + for (command in sellCommand) { + Bukkit.dispatchCommand( + Bukkit.getConsoleSender(), + command.replace("%player%", player.name) + .replace("%amount%", amountSold.toString()) + ) + } + } + if (sellItemMessage != null) { + for (message in sellItemMessage) { + player.sendMessage( + message.formatEco() + .replace("%player%", player.name) + .replace("%amount%", amountSold.toString()) + ) + } + } + return amountSold - } + } fun getAmountInPlayerInventory(player: Player): Int { if (item == null) {