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 63abcce..bab6721 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 @@ -10,6 +10,8 @@ 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.shop.Shops +import com.willfp.ecoshop.shop.gui.SellGUI import org.bukkit.event.Listener import java.io.File import java.util.zip.ZipFile @@ -24,6 +26,13 @@ class EcoShopPlugin : EcoPlugin() { override fun handleEnable() { copyConfigs("categories") copyConfigs("shops") + Shops.update(this) + SellGUI.update(this) + } + + override fun handleReload() { + Shops.update(this) + SellGUI.update(this) } private fun copyConfigs(directory: String) { 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 b779d39..23f9880 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 @@ -41,7 +41,13 @@ class ShopItem( ) { val id = config.getString("id") - val commands = config.getStringsOrNull("command") + val commands = config.getStrings("command") + config.getStrings("commands") + + val sellCommand = config.getStringsOrNull("sell.sell-commands") + + val sellItemMessage = config.getStringsOrNull("sell.sell-message") + + val buyItemMessage = config.getStringsOrNull("buy.buy-message") val item = if (config.has("item")) Items.lookup(config.getString("item")) else null @@ -262,11 +268,18 @@ class ShopItem( queue.push() } - if (commands != null) { - for (command in commands) { - Bukkit.dispatchCommand( - Bukkit.getConsoleSender(), - command.replace("%player%", player.name) + for (command in commands) { + Bukkit.dispatchCommand( + Bukkit.getConsoleSender(), + command.replace("%player%", player.name) + .replace("%amount%", amount.toString()) + ) + } + if (buyItemMessage != null) { + for (message in buyItemMessage) { + player.sendMessage( + message.formatEco() + .replace("%player%", player.name) .replace("%amount%", amount.toString()) ) } @@ -354,8 +367,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) { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/Shops.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/Shops.kt index a51ceb6..e8f8b32 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/Shops.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/Shops.kt @@ -30,7 +30,6 @@ object Shops { return ImmutableList.copyOf(BY_ID.values) } - @ConfigUpdater @JvmStatic fun update(plugin: EcoShopPlugin) { ShopCategories.update(plugin) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/gui/SellGUI.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/gui/SellGUI.kt index 25c23f2..4aa2f50 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/gui/SellGUI.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/gui/SellGUI.kt @@ -18,7 +18,6 @@ object SellGUI { private lateinit var menu: Menu @JvmStatic - @ConfigUpdater fun update(plugin: EcoShopPlugin) { val rows = plugin.configYml.getInt("sell-gui.rows") 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 508029a..098bcd8 100644 --- a/eco-core/core-plugin/src/main/resources/categories/_example.yml +++ b/eco-core/core-plugin/src/main/resources/categories/_example.yml @@ -74,6 +74,9 @@ items: amount: 8 # (Optional) The quick buy / default buy amount. Defaults to 1 if not specified. max-at-once: 16 # (Optional) The maximum amount that can be bought at once. Defaults to infinity if not specified. + buy-message: # (Optional) Enter messages to send to the player when the player buys this specific items. It will still send the 'bought-item/bought-multiple' from lang.yml + - "&6Thanks for buying this specific item" + # Options for selling the item, see here: # https://plugins.auxilor.io/all-plugins/prices sell: @@ -83,6 +86,10 @@ items: require: "%player_rank% > 1" # (Optional) This expression must hold true to be allowed to sell this item. + 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 + - "&6Thanks for selling this specific item" gui: column: 4 # How far left to right (1-9). row: 3 # How far up or down (1-6).