monetary cost require dialog rename

This commit is contained in:
alexcrea 2026-05-28 20:21:40 +02:00
parent fb27ad2e55
commit 171a8cad6d
Signed by: alexcrea
GPG key ID: E346CD16413450E3
9 changed files with 57 additions and 29 deletions

View file

@ -433,7 +433,10 @@ lore_edit:
# Allow to replace the xp cost by a monetary cost # Allow to replace the xp cost by a monetary cost
# If enabled it will not be bound to the experience level limits # 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: monetary_cost:
enabled: false enabled: false
# If using vault unlocked this allow to specify what currency should be used for anvil usage # If using vault unlocked this allow to specify what currency should be used for anvil usage

View file

@ -453,7 +453,10 @@ lore_edit:
# Allow to replace the xp cost by a monetary cost # Allow to replace the xp cost by a monetary cost
# If enabled it will not be bound to the experience level limits # 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: monetary_cost:
enabled: false enabled: false
# If using vault unlocked this allow to specify what currency should be used for anvil usage # If using vault unlocked this allow to specify what currency should be used for anvil usage

View file

@ -445,7 +445,10 @@ lore_edit:
# Allow to replace the xp cost by a monetary cost # Allow to replace the xp cost by a monetary cost
# If enabled it will not be bound to the experience level limits # 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: monetary_cost:
enabled: false enabled: false
# If using vault unlocked this allow to specify what currency should be used for anvil usage # If using vault unlocked this allow to specify what currency should be used for anvil usage

View file

@ -433,7 +433,10 @@ lore_edit:
# Allow to replace the xp cost by a monetary cost # Allow to replace the xp cost by a monetary cost
# If enabled it will not be bound to the experience level limits # 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: monetary_cost:
enabled: false enabled: false
# If using vault unlocked this allow to specify what currency should be used for anvil usage # If using vault unlocked this allow to specify what currency should be used for anvil usage

View file

@ -6,6 +6,8 @@ import org.bukkit.inventory.InventoryView
object AnvilTitleUtil { object AnvilTitleUtil {
fun rename(view: InventoryView, name: String) { fun rename(view: InventoryView, name: String) {
if(view.title == name) return
view.title = name view.title = name
} }

View file

@ -3,15 +3,16 @@ package io.delilaheve.util
import io.delilaheve.CustomAnvil import io.delilaheve.CustomAnvil
import io.delilaheve.util.EnchantmentUtil.enchantmentName import io.delilaheve.util.EnchantmentUtil.enchantmentName
import org.bukkit.NamespacedKey import org.bukkit.NamespacedKey
import org.bukkit.entity.HumanEntity
import xyz.alexcrea.cuanvil.config.ConfigHolder import xyz.alexcrea.cuanvil.config.ConfigHolder
import xyz.alexcrea.cuanvil.config.WorkPenaltyType import xyz.alexcrea.cuanvil.config.WorkPenaltyType
import xyz.alexcrea.cuanvil.config.WorkPenaltyType.WorkPenaltyPart import xyz.alexcrea.cuanvil.config.WorkPenaltyType.WorkPenaltyPart
import xyz.alexcrea.cuanvil.dependency.DependencyManager import xyz.alexcrea.cuanvil.dependency.DependencyManager
import xyz.alexcrea.cuanvil.dependency.economy.EconomyManager import xyz.alexcrea.cuanvil.dependency.economy.EconomyManager
import xyz.alexcrea.cuanvil.enchant.CAEnchantment import xyz.alexcrea.cuanvil.enchant.CAEnchantment
import xyz.alexcrea.cuanvil.update.UpdateUtils
import xyz.alexcrea.cuanvil.update.Version import xyz.alexcrea.cuanvil.update.Version
import xyz.alexcrea.cuanvil.util.AnvilUseType import xyz.alexcrea.cuanvil.util.AnvilUseType
import xyz.alexcrea.cuanvil.util.dialog.AnvilRenameDialogUtil
import java.math.BigDecimal import java.math.BigDecimal
import java.util.* import java.util.*
@ -90,9 +91,6 @@ object ConfigOptions {
const val DEBUG_LOGGING = "debug_log" const val DEBUG_LOGGING = "debug_log"
const val VERBOSE_DEBUG_LOGGING = "debug_log_verbose" const val VERBOSE_DEBUG_LOGGING = "debug_log_verbose"
// Minimum versions
val MINIMUM_MONETARY_COST_VER = Version(1, 21, 0)
// ---------------------- // ----------------------
// Default config values // Default config values
// ---------------------- // ----------------------
@ -181,6 +179,11 @@ object ConfigOptions {
// Default max before merge disabled (negative mean enabled) // Default max before merge disabled (negative mean enabled)
const val DEFAULT_MAX_BEFORE_MERGE_DISABLED = -1 const val DEFAULT_MAX_BEFORE_MERGE_DISABLED = -1
// -----------
// Permissions
// -----------
private const val RENAME_DIALOG_PERMISSION = "ca.rename.dialog"
// ------------- // -------------
// Get methods // Get methods
// ------------- // -------------
@ -469,6 +472,13 @@ object ConfigOptions {
.getBoolean(DIALOG_RENAME_USE_PERMISSION, DEFAULT_DIALOG_RENAME_USE_PERMISSION) .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 * Do the dialog menu require permission
*/ */
@ -643,12 +653,12 @@ object ConfigOptions {
} }
/* /*
* Monetary configs (only for 1.21+) * Monetary configs (only for 1.21.6+)
* Also require dialog rename
*/ */
val shouldUseMoney: Boolean fun shouldUseMoney(player: HumanEntity): Boolean {
get() {
return EconomyManager.economy?.initialized() == true && return EconomyManager.economy?.initialized() == true &&
UpdateUtils.currentMinecraftVersion().greaterEqual(MINIMUM_MONETARY_COST_VER) && canUseDialogRename(player) &&
ConfigHolder.DEFAULT_CONFIG ConfigHolder.DEFAULT_CONFIG
.config .config
.getBoolean(SHOULD_USE_MONEY, DEFAULT_SHOULD_USE_MONEY) .getBoolean(SHOULD_USE_MONEY, DEFAULT_SHOULD_USE_MONEY)

View file

@ -1,6 +1,7 @@
package xyz.alexcrea.cuanvil.listener package xyz.alexcrea.cuanvil.listener
import com.github.stefvanschie.inventoryframework.util.InventoryViewUtil import com.github.stefvanschie.inventoryframework.util.InventoryViewUtil
import com.jankominek.disenchantment.utils.AnvilCostUtils
import io.delilaheve.CustomAnvil import io.delilaheve.CustomAnvil
import io.delilaheve.util.ConfigOptions import io.delilaheve.util.ConfigOptions
import io.delilaheve.util.EnchantmentUtil.combineWith import io.delilaheve.util.EnchantmentUtil.combineWith
@ -19,6 +20,7 @@ import org.bukkit.event.EventPriority
import org.bukkit.event.Listener import org.bukkit.event.Listener
import org.bukkit.event.inventory.PrepareAnvilEvent import org.bukkit.event.inventory.PrepareAnvilEvent
import org.bukkit.inventory.AnvilInventory import org.bukkit.inventory.AnvilInventory
import org.bukkit.inventory.InventoryView
import org.bukkit.inventory.ItemStack import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.EnchantmentStorageMeta import org.bukkit.inventory.meta.EnchantmentStorageMeta
import org.bukkit.inventory.meta.ItemMeta import org.bukkit.inventory.meta.ItemMeta
@ -45,8 +47,6 @@ class PrepareAnvilListener : Listener {
const val ANVIL_OUTPUT_SLOT = 2 const val ANVIL_OUTPUT_SLOT = 2
var IS_EMPTY_TEST = false 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 // Test for lore edit
if (testLoreEdit(event, inventory, player, first, second)) return if (testLoreEdit(event, inventory, player, first, second)) return
CustomAnvil.log("no anvil fuse type found")
event.result = null event.result = null
} }
private fun setNoResult(event: PrepareAnvilEvent, view: InventoryView) {
event.result = null
AnvilXpUtil.onNoResult(view)
}
private fun tryRenameDialog( private fun tryRenameDialog(
player: HumanEntity, player: HumanEntity,
event: PrepareAnvilEvent event: PrepareAnvilEvent
) { ) {
if(!canUseRenameDialog(player)) return if(!ConfigOptions.canUseDialogRename(player)) return
AnvilRenameDialogUtil.anvilRenameDialog.tryShowDialog(player, event) 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) { private fun processDialogPCD(it: ItemMeta, player: HumanEntity) {
val keepDialog = canUseRenameDialog(player) && ConfigOptions.shouldKeepRenameText val keepDialog = ConfigOptions.canUseDialogRename(player) && ConfigOptions.shouldKeepRenameText
val pdc = it.persistentDataContainer val pdc = it.persistentDataContainer
if(!keepDialog) if(!keepDialog)

View file

@ -6,8 +6,6 @@ import io.delilaheve.util.ConfigOptions.getMonetaryMultiplier as moneyMultiplier
import io.delilaheve.util.EnchantmentUtil.enchantmentName import io.delilaheve.util.EnchantmentUtil.enchantmentName
import io.delilaheve.util.ItemUtil.findEnchantments import io.delilaheve.util.ItemUtil.findEnchantments
import io.delilaheve.util.ItemUtil.isEnchantedBook 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.GameMode
import org.bukkit.NamespacedKey import org.bukkit.NamespacedKey
import org.bukkit.entity.HumanEntity 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.DependencyManager
import xyz.alexcrea.cuanvil.dependency.economy.EconomyManager import xyz.alexcrea.cuanvil.dependency.economy.EconomyManager
import xyz.alexcrea.cuanvil.group.ConflictType import xyz.alexcrea.cuanvil.group.ConflictType
import xyz.alexcrea.cuanvil.util.dialog.AnvilRenameDialogUtil
import java.math.BigDecimal import java.math.BigDecimal
import kotlin.math.min import kotlin.math.min
@ -64,7 +63,7 @@ object AnvilXpUtil {
cost: AnvilCost, cost: AnvilCost,
ignoreRules: Boolean = false ignoreRules: Boolean = false
) { ) {
if (ConfigOptions.shouldUseMoney) if (ConfigOptions.shouldUseMoney(player))
setAnvilPrice(inventory, view, player, cost) setAnvilPrice(inventory, view, player, cost)
else else
setAnvilInvXp(inventory, view, player, cost.sum(), ignoreRules) setAnvilInvXp(inventory, view, player, cost.sum(), ignoreRules)
@ -228,6 +227,11 @@ object AnvilXpUtil {
return resultSum return resultSum
} }
fun onNoResult(player: HumanEntity, view: InventoryView) {
if (ConfigOptions.shouldUseMoney(player))
AnvilTitleUtil.rename(view, "")
}
private fun exclusivePenaltyKey(useType: AnvilUseType): NamespacedKey { private fun exclusivePenaltyKey(useType: AnvilUseType): NamespacedKey {
return NamespacedKey(CustomAnvil.instance, "${EXCLUSIVE_PENALTY_PREFIX}_${useType.typeName}") return NamespacedKey(CustomAnvil.instance, "${EXCLUSIVE_PENALTY_PREFIX}_${useType.typeName}")
} }

View file

@ -435,7 +435,10 @@ lore_edit:
# Allow to replace the xp cost by a monetary cost # Allow to replace the xp cost by a monetary cost
# If enabled it will not be bound to the experience level limits # 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: monetary_cost:
enabled: false enabled: false
# If using vault unlocked this allow to specify what currency should be used for anvil usage # If using vault unlocked this allow to specify what currency should be used for anvil usage