Update ShopItem.kt

This commit is contained in:
Exanthiax
2023-04-07 16:15:45 +01:00
committed by GitHub
parent ab8f1e1f2d
commit a8ec393d2b

View File

@@ -21,6 +21,7 @@ import com.willfp.ecoshop.shop.gui.BuyMenu
import com.willfp.ecoshop.shop.gui.SellMenu import com.willfp.ecoshop.shop.gui.SellMenu
import com.willfp.ecoshop.shop.gui.ShopItemSlot import com.willfp.ecoshop.shop.gui.ShopItemSlot
import org.bukkit.Bukkit import org.bukkit.Bukkit
import org.bukkit.ChatColor
import org.bukkit.Material import org.bukkit.Material
import org.bukkit.OfflinePlayer import org.bukkit.OfflinePlayer
import org.bukkit.entity.Player import org.bukkit.entity.Player
@@ -43,6 +44,10 @@ class ShopItem(
val commands = config.getStringsOrNull("command") 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 item = if (config.has("item")) Items.lookup(config.getString("item")) else null
val buyAmount = config.getIntOrNull("buy.amount") ?: 1 val buyAmount = config.getIntOrNull("buy.amount") ?: 1
@@ -256,6 +261,7 @@ class ShopItem(
} }
} }
player.profile.write(timesBoughtKey, player.profile.read(timesBoughtKey) + 1) player.profile.write(timesBoughtKey, player.profile.read(timesBoughtKey) + 1)
if (shop?.isBroadcasting == true) { if (shop?.isBroadcasting == true) {
@@ -337,6 +343,25 @@ class ShopItem(
shop?.sellSound?.playTo(player) 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 return amountSold
} }