From b80578976eaf11de3c7c64f9c2b60801bf315fb6 Mon Sep 17 00:00:00 2001 From: _OfTeN_ Date: Mon, 27 Mar 2023 12:50:45 +0300 Subject: [PATCH 01/10] Moved from ConfigUpdater for performance --- .../src/main/kotlin/com/willfp/ecoshop/EcoShopPlugin.kt | 9 +++++++++ .../src/main/kotlin/com/willfp/ecoshop/shop/Shops.kt | 1 - .../main/kotlin/com/willfp/ecoshop/shop/gui/SellGUI.kt | 1 - 3 files changed, 9 insertions(+), 2 deletions(-) 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/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") From d14fac247427397e145680d87335aa212de76dcd Mon Sep 17 00:00:00 2001 From: _OfTeN_ Date: Mon, 27 Mar 2023 12:53:06 +0300 Subject: [PATCH 02/10] Made ShopItem configs accept "commands", keeping backwards compatibility for "command" --- .../kotlin/com/willfp/ecoshop/shop/ShopItem.kt | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) 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..cb1709c 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,7 @@ class ShopItem( ) { val id = config.getString("id") - val commands = config.getStringsOrNull("command") + val commands = config.getStrings("command") + config.getStrings("commands") val item = if (config.has("item")) Items.lookup(config.getString("item")) else null @@ -246,14 +246,12 @@ class ShopItem( queue.push() } - if (commands != null) { - for (command in commands) { - Bukkit.dispatchCommand( - Bukkit.getConsoleSender(), - command.replace("%player%", player.name) - .replace("%amount%", amount.toString()) - ) - } + for (command in commands) { + Bukkit.dispatchCommand( + Bukkit.getConsoleSender(), + command.replace("%player%", player.name) + .replace("%amount%", amount.toString()) + ) } player.profile.write(timesBoughtKey, player.profile.read(timesBoughtKey) + 1) From ee2f02460669a2746a6e978eaf59a2ad878493c6 Mon Sep 17 00:00:00 2001 From: kforbro Date: Mon, 3 Apr 2023 19:41:54 +0300 Subject: [PATCH 03/10] fix duplicate `global-bottom-lore` --- .../main/kotlin/com/willfp/ecoshop/shop/gui/ShopItemSlot.kt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/gui/ShopItemSlot.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/gui/ShopItemSlot.kt index a89f7a9..c4b6639 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/gui/ShopItemSlot.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/gui/ShopItemSlot.kt @@ -91,10 +91,6 @@ class ShopItemSlot( addLoreLines( plugin.langYml.getStrings("quick-sell") ) - - addLoreLines( - plugin.configYml.getStrings("shop-items.global-bottom-lore.sell").formatEco(player) - ) } } From a9aa6ceb34a6d5edfd7e830d06ce5e2a3bc21bea Mon Sep 17 00:00:00 2001 From: kforbro Date: Mon, 3 Apr 2023 19:50:30 +0300 Subject: [PATCH 04/10] pretty lore with `global-bottom-lore` --- .../willfp/ecoshop/shop/gui/ShopItemSlot.kt | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/gui/ShopItemSlot.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/gui/ShopItemSlot.kt index c4b6639..88ddb39 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/gui/ShopItemSlot.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/gui/ShopItemSlot.kt @@ -66,6 +66,14 @@ class ShopItemSlot( ) } + addLoreLines( + item.bottomLore.formatEco(player) + ) + + if (item.isBuyable) { + addLoreLines(plugin.configYml.getStrings("shop-items.global-bottom-lore.buy").formatEco(player)) + } + if (item.isShowingQuickBuySell) { if (item.isBuyable && item.getMaxBuysAtOnce(player) > item.buyAmount) { if (item.hasAltBuy) { @@ -86,7 +94,13 @@ class ShopItemSlot( ) } } + } + if (item.isSellable) { + addLoreLines(plugin.configYml.getStrings("shop-items.global-bottom-lore.sell").formatEco(player)) + } + + if (item.isShowingQuickBuySell) { if (item.isSellable) { addLoreLines( plugin.langYml.getStrings("quick-sell") @@ -94,18 +108,6 @@ class ShopItemSlot( } } - addLoreLines( - item.bottomLore.formatEco(player) - ) - - if (item.isBuyable) { - addLoreLines(plugin.configYml.getStrings("shop-items.global-bottom-lore.buy").formatEco(player)) - } - - if (item.isSellable) { - addLoreLines(plugin.configYml.getStrings("shop-items.global-bottom-lore.sell").formatEco(player)) - } - addLoreLines(plugin.configYml.getStrings("shop-items.global-bottom-lore.always").formatEco(player)) } }) { 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 05/10] 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) { From 93bb33ba28b910b517b67c37a96f15cba9a079d2 Mon Sep 17 00:00:00 2001 From: Exanthiax <107284021+Exanthiax@users.noreply.github.com> Date: Fri, 7 Apr 2023 16:16:42 +0100 Subject: [PATCH 06/10] Update _example.yml --- .../core-plugin/src/main/resources/categories/_example.yml | 4 ++++ 1 file changed, 4 insertions(+) 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..d52c938 100644 --- a/eco-core/core-plugin/src/main/resources/categories/_example.yml +++ b/eco-core/core-plugin/src/main/resources/categories/_example.yml @@ -83,6 +83,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 + - "&" gui: column: 4 # How far left to right (1-9). row: 3 # How far up or down (1-6). From 3d28c7280e9fbc9037d68309c9f26ec839d3d791 Mon Sep 17 00:00:00 2001 From: Exanthiax <107284021+Exanthiax@users.noreply.github.com> Date: Fri, 7 Apr 2023 16:17:12 +0100 Subject: [PATCH 07/10] Update _example.yml --- eco-core/core-plugin/src/main/resources/categories/_example.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d52c938..ec57e9d 100644 --- a/eco-core/core-plugin/src/main/resources/categories/_example.yml +++ b/eco-core/core-plugin/src/main/resources/categories/_example.yml @@ -86,7 +86,7 @@ items: 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 - - "&" + - "&7Thanks for selling the item!" gui: column: 4 # How far left to right (1-9). row: 3 # How far up or down (1-6). From c3ec73ff3b7e0ee4700272f1b43bedb1e2e937cb Mon Sep 17 00:00:00 2001 From: Exanthiax <107284021+Exanthiax@users.noreply.github.com> Date: Fri, 7 Apr 2023 16:30:54 +0100 Subject: [PATCH 08/10] Update _example.yml --- .../core-plugin/src/main/resources/categories/_example.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 ec57e9d..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: @@ -86,7 +89,7 @@ items: 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 - - "&7Thanks for selling the item!" + - "&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). From 1535bb4f609f7039b0a21dad677229ded0fcb587 Mon Sep 17 00:00:00 2001 From: Exanthiax <107284021+Exanthiax@users.noreply.github.com> Date: Fri, 7 Apr 2023 16:33:57 +0100 Subject: [PATCH 09/10] Update ShopItem.kt --- .../main/kotlin/com/willfp/ecoshop/shop/ShopItem.kt | 12 +++++++++++- 1 file changed, 11 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 03b1e2f..7a0e7b2 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 @@ -48,6 +48,8 @@ class ShopItem( 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 val buyAmount = config.getIntOrNull("buy.amount") ?: 1 @@ -260,7 +262,15 @@ class ShopItem( ) } } - + if (buyItemMessage != null) { + for (message in buyItemMessage) { + player.sendMessage( + message.formatEco() + .replace("%player%", player.name) + .replace("%amount%", amount.toString()) + ) + } + } player.profile.write(timesBoughtKey, player.profile.read(timesBoughtKey) + 1) From a30905113c64830badd4292aea5a62ca07ba91a3 Mon Sep 17 00:00:00 2001 From: Exanthiax <107284021+Exanthiax@users.noreply.github.com> Date: Fri, 7 Apr 2023 16:44:26 +0100 Subject: [PATCH 10/10] Update ShopItem.kt --- .../src/main/kotlin/com/willfp/ecoshop/shop/ShopItem.kt | 1 - 1 file changed, 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 7a0e7b2..ad05d84 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,7 +21,6 @@ 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