From 00adf05d2b747903e8bb7baedc0d241b1b6f9bda Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 16 Jul 2025 18:08:49 +0200 Subject: [PATCH 1/7] use eco enchant enchant limit --- src/main/kotlin/io/delilaheve/CustomAnvil.kt | 6 +++--- src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt | 8 ++++++++ .../cuanvil/dependency/plugins/EcoEnchantDependency.kt | 6 ++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/io/delilaheve/CustomAnvil.kt b/src/main/kotlin/io/delilaheve/CustomAnvil.kt index 442af0a..f629c2f 100644 --- a/src/main/kotlin/io/delilaheve/CustomAnvil.kt +++ b/src/main/kotlin/io/delilaheve/CustomAnvil.kt @@ -52,8 +52,8 @@ open class CustomAnvil : JavaPlugin() { // Command Name to reload the config const val commandReloadName = "anvilconfigreload" - // Test command name - const val commandTestName = "customanvilconfig" + // Config command name + const val commandConfigName = "customanvilconfig" // Current plugin instance lateinit var instance: CustomAnvil @@ -208,7 +208,7 @@ open class CustomAnvil : JavaPlugin() { var command = getCommand(commandReloadName) command?.setExecutor(ReloadExecutor()) - command = getCommand(commandTestName) + command = getCommand(commandConfigName) command?.setExecutor(EditConfigExecutor()) } diff --git a/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt b/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt index 87e4bae..dcf59df 100644 --- a/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt +++ b/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt @@ -4,6 +4,7 @@ import io.delilaheve.CustomAnvil import org.bukkit.entity.HumanEntity import org.bukkit.inventory.ItemStack import xyz.alexcrea.cuanvil.config.ConfigHolder +import xyz.alexcrea.cuanvil.dependency.DependencyManager import xyz.alexcrea.cuanvil.enchant.CAEnchantment import xyz.alexcrea.cuanvil.group.ConflictType import kotlin.math.max @@ -33,6 +34,10 @@ object EnchantmentUtil { val bypassFuse = player.hasPermission(CustomAnvil.bypassFusePermission) val bypassLevel = player.hasPermission(CustomAnvil.bypassLevelPermission) + // TODO add custom anvil maximum enchant count per item and globally too + var maxEnchantCount = DependencyManager.ecoEnchantCompatibility?.getEcoLevelLimit() + if(maxEnchantCount == null || maxEnchantCount < 0) maxEnchantCount = Int.MAX_VALUE; + other.forEach { (enchantment, level) -> if(!enchantment.isAllowed(player)) return@forEach @@ -45,6 +50,9 @@ object EnchantmentUtil { // Enchantment not yet in result list if (!containsKey(enchantment)) { + // Do not allow new enchantment if above maximum + if(this.size <= maxEnchantCount) return@forEach + // Add the enchantment if it doesn't have conflicts, or if player is allowed to bypass enchantment restrictions this[enchantment] = cappedLevel if(bypassFuse){ diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/EcoEnchantDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/EcoEnchantDependency.kt index 22fce5e..079d570 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/EcoEnchantDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/EcoEnchantDependency.kt @@ -1,7 +1,9 @@ package xyz.alexcrea.cuanvil.dependency.plugins +import com.willfp.eco.core.EcoPlugin import com.willfp.ecoenchants.enchant.EcoEnchant import com.willfp.ecoenchants.enchant.EcoEnchants +import com.willfp.ecoenchants.mechanics.infiniteIfNegative import io.delilaheve.CustomAnvil import org.bukkit.event.inventory.PrepareAnvilEvent import org.bukkit.plugin.Plugin @@ -32,6 +34,10 @@ class EcoEnchantDependency(private val ecoEnchantPlugin: Plugin) { } + public fun getEcoLevelLimit(): Int { + return (ecoEnchantPlugin as EcoPlugin).configYml.getInt("anvil.enchant-limit").infiniteIfNegative() + } + fun disableAnvilListener() { PrepareAnvilEvent.getHandlerList().unregister(this.ecoEnchantPlugin) } From a8177c9aba991e136fff5b7be58b23fb9096f835 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 16 Jul 2025 23:11:38 +0200 Subject: [PATCH 2/7] why am I this stupid --- src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt b/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt index dcf59df..24b6fa3 100644 --- a/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt +++ b/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt @@ -51,7 +51,7 @@ object EnchantmentUtil { // Enchantment not yet in result list if (!containsKey(enchantment)) { // Do not allow new enchantment if above maximum - if(this.size <= maxEnchantCount) return@forEach + if(this.size >= maxEnchantCount) return@forEach // Add the enchantment if it doesn't have conflicts, or if player is allowed to bypass enchantment restrictions this[enchantment] = cappedLevel From b095cd531618291e8514b6bdda58473bb2a46bde Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 23 Jul 2025 12:05:39 +0200 Subject: [PATCH 3/7] add config value for per item enchantment limit --- src/main/resources/config.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 0bad067..08aa964 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -270,6 +270,15 @@ disable-merge-over: # If uncommented. 2 unbreaking II book would not give an unbreaking III book. but unbreaking III book can still be applied #minecraft:unbreaking: 2 +# The maximum number of enchantment an item can get. -1 for infinity +# Use eco enchant enchant_limit if present by default unless "default" is not equal to -1 +enchantment_limit: + default: -1 + # Limit for specific items. example bellow is an example with stick + # Per item enchantment limit override eco enchant enchant_limit and default limit + items: + stick: -1 + # Settings for lore modification lore_edit: book_and_quil: From 65d6af7672a1884fef7fa8d3bc8a03eef9f6d2e9 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 23 Jul 2025 12:44:39 +0200 Subject: [PATCH 4/7] add per item enchant count limit --- .../io/delilaheve/util/ConfigOptions.kt | 51 +++++++++++++++++++ .../io/delilaheve/util/EnchantmentUtil.kt | 5 +- src/main/resources/config.yml | 2 +- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt b/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt index a35901c..95bd694 100644 --- a/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt +++ b/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt @@ -2,10 +2,12 @@ package io.delilaheve.util import io.delilaheve.CustomAnvil import io.delilaheve.util.EnchantmentUtil.enchantmentName +import org.bukkit.Material import org.bukkit.NamespacedKey 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.enchant.CAEnchantment import xyz.alexcrea.cuanvil.util.AnvilUseType import java.util.* @@ -46,6 +48,11 @@ object ConfigOptions { const val EXCLUSIVE_WORK_PENALTY_INCREASE = "exclusive_increase" const val EXCLUSIVE_WORK_PENALTY_ADDITIVE = "exclusive_additive" + // Enchant limit config + const val ENCHANT_COUNT_LIMIT_ROOT = "enchantment_count_limit" + const val ENCHANT_COUNT_LIMIT_DEFAULT = "$ENCHANT_COUNT_LIMIT_ROOT.default" + const val ENCHANT_COUNT_LIMIT_ITEMS = "$ENCHANT_COUNT_LIMIT_ROOT.items" + const val DEFAULT_LIMIT_PATH = "default_limit" const val ENCHANT_LIMIT_ROOT = "enchant_limits" @@ -55,6 +62,7 @@ object ConfigOptions { const val IMMUTABLE_ENCHANTMENT_LIST = "immutable_enchantments" + // Keys for specific enchantment values private const val KEY_BOOK = "book" private const val KEY_ITEM = "item" @@ -81,6 +89,8 @@ object ConfigOptions { const val DEFAULT_SACRIFICE_ILLEGAL_COST = 1 const val DEFAULT_ADD_BOOK_ENCHANTMENT_AS_STORED_ENCHANTMENT = false; + const val DEFAULT_ENCHANT_COUNT_LIMIT = -1 + // Color related config const val DEFAULT_ALLOW_COLOR_CODE = false const val DEFAULT_ALLOW_HEXADECIMAL_COLOR = false @@ -121,6 +131,10 @@ object ConfigOptions { @JvmField val ENCHANT_LIMIT_RANGE = 1..255 + // Valid range for an enchantment count limit + @JvmField + val ENCHANT_COUNT_LIMIT_RANGE = -1..255 + // -------------- // Other defaults // -------------- @@ -329,6 +343,43 @@ object ConfigOptions { .getInt(DEFAULT_LIMIT_PATH, DEFAULT_ENCHANT_LIMIT) } + /** + * Get material enchantment count limit + * + * @return the current enchantment limit. -1 if none + */ + fun getEnchantCountLimit(type: Material): Int? { + val limit = materialEnchantCountLimit(type) + + if(limit >= 0) return limit + if(defaultEnchantCountLimit >= 0) return defaultEnchantCountLimit + + return DependencyManager.ecoEnchantCompatibility?.getEcoLevelLimit() + } + + /** + * Get the material enchantment count limit. + * + * @return The current enchantment limit. -1 if none + */ + private fun materialEnchantCountLimit(type: Material): Int { + return ConfigHolder.DEFAULT_CONFIG.config + .getInt(ENCHANT_COUNT_LIMIT_ITEMS, DEFAULT_ENCHANT_COUNT_LIMIT) + .takeIf { it in ENCHANT_COUNT_LIMIT_RANGE } + ?: DEFAULT_ENCHANT_COUNT_LIMIT + } + /** + * User configured default enchantment count limit + */ + val defaultEnchantCountLimit: Int + get() { + return ConfigHolder.DEFAULT_CONFIG + .config + .getInt(ENCHANT_COUNT_LIMIT_DEFAULT, DEFAULT_ENCHANT_COUNT_LIMIT) + .takeIf { it in ENCHANT_COUNT_LIMIT_RANGE } + ?: DEFAULT_ENCHANT_COUNT_LIMIT + } + /** * Whether to show debug logging */ diff --git a/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt b/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt index 24b6fa3..bee9bda 100644 --- a/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt +++ b/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt @@ -34,9 +34,8 @@ object EnchantmentUtil { val bypassFuse = player.hasPermission(CustomAnvil.bypassFusePermission) val bypassLevel = player.hasPermission(CustomAnvil.bypassLevelPermission) - // TODO add custom anvil maximum enchant count per item and globally too - var maxEnchantCount = DependencyManager.ecoEnchantCompatibility?.getEcoLevelLimit() - if(maxEnchantCount == null || maxEnchantCount < 0) maxEnchantCount = Int.MAX_VALUE; + var maxEnchantCount = ConfigOptions.getEnchantCountLimit(item.type) + if(maxEnchantCount == null || maxEnchantCount < 0) maxEnchantCount = Int.MAX_VALUE other.forEach { (enchantment, level) -> if(!enchantment.isAllowed(player)) return@forEach diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 08aa964..a0f0876 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -272,7 +272,7 @@ disable-merge-over: # The maximum number of enchantment an item can get. -1 for infinity # Use eco enchant enchant_limit if present by default unless "default" is not equal to -1 -enchantment_limit: +enchantment_count_limit: default: -1 # Limit for specific items. example bellow is an example with stick # Per item enchantment limit override eco enchant enchant_limit and default limit From d03d2a0444020980d95959c0f072a0771982730c Mon Sep 17 00:00:00 2001 From: alexcrea Date: Thu, 24 Jul 2025 04:30:52 +0200 Subject: [PATCH 5/7] fix small issue --- src/main/kotlin/io/delilaheve/util/ConfigOptions.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt b/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt index 95bd694..b620fd4 100644 --- a/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt +++ b/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt @@ -351,7 +351,7 @@ object ConfigOptions { fun getEnchantCountLimit(type: Material): Int? { val limit = materialEnchantCountLimit(type) - if(limit >= 0) return limit + if(limit != null) return limit if(defaultEnchantCountLimit >= 0) return defaultEnchantCountLimit return DependencyManager.ecoEnchantCompatibility?.getEcoLevelLimit() @@ -362,11 +362,10 @@ object ConfigOptions { * * @return The current enchantment limit. -1 if none */ - private fun materialEnchantCountLimit(type: Material): Int { + private fun materialEnchantCountLimit(type: Material): Int? { return ConfigHolder.DEFAULT_CONFIG.config - .getInt(ENCHANT_COUNT_LIMIT_ITEMS, DEFAULT_ENCHANT_COUNT_LIMIT) + .getInt("$ENCHANT_COUNT_LIMIT_ITEMS.${type.key.key.lowercase()}", DEFAULT_ENCHANT_COUNT_LIMIT) .takeIf { it in ENCHANT_COUNT_LIMIT_RANGE } - ?: DEFAULT_ENCHANT_COUNT_LIMIT } /** * User configured default enchantment count limit From 3b8a8fa590e095a81ae37463b93cd5cb5b0834cc Mon Sep 17 00:00:00 2001 From: alexcrea Date: Thu, 24 Jul 2025 04:33:55 +0200 Subject: [PATCH 6/7] update default config --- defaultconfigs/1.18/config.yml | 14 ++++++++++++-- defaultconfigs/1.21/config.yml | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/defaultconfigs/1.18/config.yml b/defaultconfigs/1.18/config.yml index 9c1ad67..fbe43f7 100644 --- a/defaultconfigs/1.18/config.yml +++ b/defaultconfigs/1.18/config.yml @@ -270,6 +270,15 @@ disable-merge-over: # If uncommented. 2 unbreaking II book would not give an unbreaking III book. but unbreaking III book can still be applied #minecraft:unbreaking: 2 +# The maximum number of enchantment an item can get. -1 for infinity +# Use eco enchant enchant_limit if present by default unless "default" is not equal to -1 +enchantment_count_limit: + default: -1 + # Limit for specific items. example bellow is an example with stick + # Per item enchantment limit override eco enchant enchant_limit and default limit + items: + stick: -1 + # Settings for lore modification lore_edit: book_and_quil: @@ -318,7 +327,7 @@ lore_edit: # Permission is ca.lore_edit.paper use_permission: true # what order should the lines should get added/removed (start/end, if invalid or not present will be end) - order: "end" + order: end append_line: # If adding lore line using paper is enabled @@ -338,6 +347,7 @@ lore_edit: allow_color_code: true allow_hexadecimal_color: true color_use_cost: 0 + use_cost: 0 remove_line: # If removing lore line using paper is enabled @@ -367,4 +377,4 @@ debug_log_verbose: false # ProtocoLib may also be used if the server is in an "unsupported" version even if this option is disabled. force_protocolib: false -configVersion: 1.8.0 +configVersion: 1.11.0 diff --git a/defaultconfigs/1.21/config.yml b/defaultconfigs/1.21/config.yml index 9c1ad67..d6e76bf 100644 --- a/defaultconfigs/1.21/config.yml +++ b/defaultconfigs/1.21/config.yml @@ -267,8 +267,17 @@ enchant_values: disable-merge-over: # Sharpness is set to -1. it equivalent to it not being set to anything (and work as vanilla) minecraft:sharpness: -1 - # If uncommented. 2 unbreaking II book would not give an unbreaking III book. but unbreaking III book can still be applied - #minecraft:unbreaking: 2 +# If uncommented. 2 unbreaking II book would not give an unbreaking III book. but unbreaking III book can still be applied +# minecraft:unbreaking: 2 + +# The maximum number of enchantment an item can get. -1 for infinity +# Use eco enchant enchant_limit if present by default unless "default" is not equal to -1 +enchantment_count_limit: + default: -1 + # Limit for specific items. example bellow is an example with stick + # Per item enchantment limit override eco enchant enchant_limit and default limit + items: + stick: -1 # Settings for lore modification lore_edit: @@ -318,7 +327,7 @@ lore_edit: # Permission is ca.lore_edit.paper use_permission: true # what order should the lines should get added/removed (start/end, if invalid or not present will be end) - order: "end" + order: end append_line: # If adding lore line using paper is enabled @@ -338,6 +347,7 @@ lore_edit: allow_color_code: true allow_hexadecimal_color: true color_use_cost: 0 + use_cost: 0 remove_line: # If removing lore line using paper is enabled @@ -367,4 +377,4 @@ debug_log_verbose: false # ProtocoLib may also be used if the server is in an "unsupported" version even if this option is disabled. force_protocolib: false -configVersion: 1.8.0 +configVersion: 1.11.0 \ No newline at end of file From 6e0279845971a018cafecf913470e755ab3f2796 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Thu, 24 Jul 2025 04:34:17 +0200 Subject: [PATCH 7/7] version up --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index e4b866d..3a04751 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,7 +18,7 @@ plugins { } group = "xyz.alexcrea" -version = "1.13.1" +version = "1.14.0" val effectiveVersion = "$version" + (if (System.getenv("SMALL_COMMIT_HASH") != null) "-dev-${System.getenv("SMALL_COMMIT_HASH")!!}" else "")