From 171a8cad6dc6296902dea40767aaa391ab83a445 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Thu, 28 May 2026 20:21:40 +0200 Subject: [PATCH] monetary cost require dialog rename --- defaultconfigs/1.18/config.yml | 5 +++- defaultconfigs/1.21.11/config.yml | 5 +++- defaultconfigs/1.21.9/config.yml | 5 +++- defaultconfigs/1.21/config.yml | 5 +++- .../alexcrea/cuanvil/util/AnvilTitleUtil.kt | 2 ++ .../io/delilaheve/util/ConfigOptions.kt | 28 +++++++++++++------ .../cuanvil/listener/PrepareAnvilListener.kt | 21 ++++++-------- .../xyz/alexcrea/cuanvil/util/AnvilXpUtil.kt | 10 +++++-- src/main/resources/config.yml | 5 +++- 9 files changed, 57 insertions(+), 29 deletions(-) rename nms/{v1_21R1 => nms-paper}/src/main/kotlin/xyz/alexcrea/cuanvil/util/AnvilTitleUtil.kt (86%) diff --git a/defaultconfigs/1.18/config.yml b/defaultconfigs/1.18/config.yml index 1a1663a..fb70505 100644 --- a/defaultconfigs/1.18/config.yml +++ b/defaultconfigs/1.18/config.yml @@ -433,7 +433,10 @@ lore_edit: # Allow to replace the xp cost by a monetary cost # If enabled it will not be bound to the experience level limits # -# This feature can only be enabled starting with 1.21 +# It also requires to enable dialog rename (set "enable_dialog_rename: false" a bit higher) +# If dialog rename permission is enabled and player do not have the permission merge will fall back to vanilla xp cost +# +# As this feature require dialog rename, it can only be enabled starting with paper 1.21.6 monetary_cost: enabled: false # If using vault unlocked this allow to specify what currency should be used for anvil usage diff --git a/defaultconfigs/1.21.11/config.yml b/defaultconfigs/1.21.11/config.yml index 2daa373..b70798c 100644 --- a/defaultconfigs/1.21.11/config.yml +++ b/defaultconfigs/1.21.11/config.yml @@ -453,7 +453,10 @@ lore_edit: # Allow to replace the xp cost by a monetary cost # If enabled it will not be bound to the experience level limits # -# This feature can only be enabled starting with 1.21 +# It also requires to enable dialog rename (set "enable_dialog_rename: false" a bit higher) +# If dialog rename permission is enabled and player do not have the permission merge will fall back to vanilla xp cost +# +# As this feature require dialog rename, it can only be enabled starting with paper 1.21.6 monetary_cost: enabled: false # If using vault unlocked this allow to specify what currency should be used for anvil usage diff --git a/defaultconfigs/1.21.9/config.yml b/defaultconfigs/1.21.9/config.yml index 8532881..31bdb1f 100644 --- a/defaultconfigs/1.21.9/config.yml +++ b/defaultconfigs/1.21.9/config.yml @@ -445,7 +445,10 @@ lore_edit: # Allow to replace the xp cost by a monetary cost # If enabled it will not be bound to the experience level limits # -# This feature can only be enabled starting with 1.21 +# It also requires to enable dialog rename (set "enable_dialog_rename: false" a bit higher) +# If dialog rename permission is enabled and player do not have the permission merge will fall back to vanilla xp cost +# +# As this feature require dialog rename, it can only be enabled starting with paper 1.21.6 monetary_cost: enabled: false # If using vault unlocked this allow to specify what currency should be used for anvil usage diff --git a/defaultconfigs/1.21/config.yml b/defaultconfigs/1.21/config.yml index 25e47dc..1dafa54 100644 --- a/defaultconfigs/1.21/config.yml +++ b/defaultconfigs/1.21/config.yml @@ -433,7 +433,10 @@ lore_edit: # Allow to replace the xp cost by a monetary cost # If enabled it will not be bound to the experience level limits # -# This feature can only be enabled starting with 1.21 +# It also requires to enable dialog rename (set "enable_dialog_rename: false" a bit higher) +# If dialog rename permission is enabled and player do not have the permission merge will fall back to vanilla xp cost +# +# As this feature require dialog rename, it can only be enabled starting with paper 1.21.6 monetary_cost: enabled: false # If using vault unlocked this allow to specify what currency should be used for anvil usage diff --git a/nms/v1_21R1/src/main/kotlin/xyz/alexcrea/cuanvil/util/AnvilTitleUtil.kt b/nms/nms-paper/src/main/kotlin/xyz/alexcrea/cuanvil/util/AnvilTitleUtil.kt similarity index 86% rename from nms/v1_21R1/src/main/kotlin/xyz/alexcrea/cuanvil/util/AnvilTitleUtil.kt rename to nms/nms-paper/src/main/kotlin/xyz/alexcrea/cuanvil/util/AnvilTitleUtil.kt index 805b150..cc92b78 100644 --- a/nms/v1_21R1/src/main/kotlin/xyz/alexcrea/cuanvil/util/AnvilTitleUtil.kt +++ b/nms/nms-paper/src/main/kotlin/xyz/alexcrea/cuanvil/util/AnvilTitleUtil.kt @@ -6,6 +6,8 @@ import org.bukkit.inventory.InventoryView object AnvilTitleUtil { fun rename(view: InventoryView, name: String) { + if(view.title == name) return + view.title = name } diff --git a/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt b/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt index 9ee7317..b163de8 100644 --- a/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt +++ b/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt @@ -3,15 +3,16 @@ package io.delilaheve.util import io.delilaheve.CustomAnvil import io.delilaheve.util.EnchantmentUtil.enchantmentName import org.bukkit.NamespacedKey +import org.bukkit.entity.HumanEntity import xyz.alexcrea.cuanvil.config.ConfigHolder import xyz.alexcrea.cuanvil.config.WorkPenaltyType import xyz.alexcrea.cuanvil.config.WorkPenaltyType.WorkPenaltyPart import xyz.alexcrea.cuanvil.dependency.DependencyManager import xyz.alexcrea.cuanvil.dependency.economy.EconomyManager import xyz.alexcrea.cuanvil.enchant.CAEnchantment -import xyz.alexcrea.cuanvil.update.UpdateUtils import xyz.alexcrea.cuanvil.update.Version import xyz.alexcrea.cuanvil.util.AnvilUseType +import xyz.alexcrea.cuanvil.util.dialog.AnvilRenameDialogUtil import java.math.BigDecimal import java.util.* @@ -90,9 +91,6 @@ object ConfigOptions { const val DEBUG_LOGGING = "debug_log" const val VERBOSE_DEBUG_LOGGING = "debug_log_verbose" - // Minimum versions - val MINIMUM_MONETARY_COST_VER = Version(1, 21, 0) - // ---------------------- // Default config values // ---------------------- @@ -181,6 +179,11 @@ object ConfigOptions { // Default max before merge disabled (negative mean enabled) const val DEFAULT_MAX_BEFORE_MERGE_DISABLED = -1 + // ----------- + // Permissions + // ----------- + private const val RENAME_DIALOG_PERMISSION = "ca.rename.dialog" + // ------------- // Get methods // ------------- @@ -469,6 +472,13 @@ object ConfigOptions { .getBoolean(DIALOG_RENAME_USE_PERMISSION, DEFAULT_DIALOG_RENAME_USE_PERMISSION) } + fun canUseDialogRename(player: HumanEntity): Boolean { + if(!doRenameDialog || !AnvilRenameDialogUtil.anvilRenameDialog.canSendDialog()) return false + if(doRenameDialogUsePermission && !player.hasPermission(RENAME_DIALOG_PERMISSION)) return false + + return true + } + /** * Do the dialog menu require permission */ @@ -643,16 +653,16 @@ object ConfigOptions { } /* - * Monetary configs (only for 1.21+) + * Monetary configs (only for 1.21.6+) + * Also require dialog rename */ - val shouldUseMoney: Boolean - get() { + fun shouldUseMoney(player: HumanEntity): Boolean { return EconomyManager.economy?.initialized() == true && - UpdateUtils.currentMinecraftVersion().greaterEqual(MINIMUM_MONETARY_COST_VER) && + canUseDialogRename(player) && ConfigHolder.DEFAULT_CONFIG .config .getBoolean(SHOULD_USE_MONEY, DEFAULT_SHOULD_USE_MONEY) - } + } val usedCurrency: String get() { diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt index c71e82e..fc04dcf 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt @@ -1,6 +1,7 @@ package xyz.alexcrea.cuanvil.listener import com.github.stefvanschie.inventoryframework.util.InventoryViewUtil +import com.jankominek.disenchantment.utils.AnvilCostUtils import io.delilaheve.CustomAnvil import io.delilaheve.util.ConfigOptions import io.delilaheve.util.EnchantmentUtil.combineWith @@ -19,6 +20,7 @@ import org.bukkit.event.EventPriority import org.bukkit.event.Listener import org.bukkit.event.inventory.PrepareAnvilEvent import org.bukkit.inventory.AnvilInventory +import org.bukkit.inventory.InventoryView import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.EnchantmentStorageMeta import org.bukkit.inventory.meta.ItemMeta @@ -45,8 +47,6 @@ class PrepareAnvilListener : Listener { const val ANVIL_OUTPUT_SLOT = 2 var IS_EMPTY_TEST = false - - private const val RENAME_DIALOG_PERMISSION = "ca.rename.dialog" } /** @@ -121,29 +121,26 @@ class PrepareAnvilListener : Listener { // Test for lore edit if (testLoreEdit(event, inventory, player, first, second)) return - CustomAnvil.log("no anvil fuse type found") event.result = null } + private fun setNoResult(event: PrepareAnvilEvent, view: InventoryView) { + event.result = null + AnvilXpUtil.onNoResult(view) + } + private fun tryRenameDialog( player: HumanEntity, event: PrepareAnvilEvent ) { - if(!canUseRenameDialog(player)) return + if(!ConfigOptions.canUseDialogRename(player)) return AnvilRenameDialogUtil.anvilRenameDialog.tryShowDialog(player, event) } - private fun canUseRenameDialog(player: HumanEntity): Boolean { - if(!ConfigOptions.doRenameDialog || !AnvilRenameDialogUtil.anvilRenameDialog.canSendDialog()) return false - if(ConfigOptions.doRenameDialogUsePermission && !player.hasPermission(RENAME_DIALOG_PERMISSION)) return false - - return true - } - private fun processDialogPCD(it: ItemMeta, player: HumanEntity) { - val keepDialog = canUseRenameDialog(player) && ConfigOptions.shouldKeepRenameText + val keepDialog = ConfigOptions.canUseDialogRename(player) && ConfigOptions.shouldKeepRenameText val pdc = it.persistentDataContainer if(!keepDialog) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/AnvilXpUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/AnvilXpUtil.kt index 07f3d23..c8829f3 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/AnvilXpUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/AnvilXpUtil.kt @@ -6,8 +6,6 @@ import io.delilaheve.util.ConfigOptions.getMonetaryMultiplier as moneyMultiplier import io.delilaheve.util.EnchantmentUtil.enchantmentName import io.delilaheve.util.ItemUtil.findEnchantments import io.delilaheve.util.ItemUtil.isEnchantedBook -import net.kyori.adventure.text.Component -import net.kyori.adventure.text.format.TextColor import org.bukkit.GameMode import org.bukkit.NamespacedKey import org.bukkit.entity.HumanEntity @@ -21,6 +19,7 @@ import xyz.alexcrea.cuanvil.config.ConfigHolder import xyz.alexcrea.cuanvil.dependency.DependencyManager import xyz.alexcrea.cuanvil.dependency.economy.EconomyManager import xyz.alexcrea.cuanvil.group.ConflictType +import xyz.alexcrea.cuanvil.util.dialog.AnvilRenameDialogUtil import java.math.BigDecimal import kotlin.math.min @@ -64,7 +63,7 @@ object AnvilXpUtil { cost: AnvilCost, ignoreRules: Boolean = false ) { - if (ConfigOptions.shouldUseMoney) + if (ConfigOptions.shouldUseMoney(player)) setAnvilPrice(inventory, view, player, cost) else setAnvilInvXp(inventory, view, player, cost.sum(), ignoreRules) @@ -228,6 +227,11 @@ object AnvilXpUtil { return resultSum } + fun onNoResult(player: HumanEntity, view: InventoryView) { + if (ConfigOptions.shouldUseMoney(player)) + AnvilTitleUtil.rename(view, "") + } + private fun exclusivePenaltyKey(useType: AnvilUseType): NamespacedKey { return NamespacedKey(CustomAnvil.instance, "${EXCLUSIVE_PENALTY_PREFIX}_${useType.typeName}") } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 5ba61ec..27c0248 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -435,7 +435,10 @@ lore_edit: # Allow to replace the xp cost by a monetary cost # If enabled it will not be bound to the experience level limits # -# This feature can only be enabled starting with 1.21 +# It also requires to enable dialog rename (set "enable_dialog_rename: false" a bit higher) +# If dialog rename permission is enabled and player do not have the permission merge will fall back to vanilla xp cost +# +# As this feature require dialog rename, it can only be enabled starting with paper 1.21.6 monetary_cost: enabled: false # If using vault unlocked this allow to specify what currency should be used for anvil usage