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 "") 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 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/ConfigOptions.kt b/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt index a35901c..b620fd4 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,42 @@ 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 != null) 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.${type.key.key.lowercase()}", DEFAULT_ENCHANT_COUNT_LIMIT) + .takeIf { it in ENCHANT_COUNT_LIMIT_RANGE } + } + /** + * 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 87e4bae..bee9bda 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,9 @@ object EnchantmentUtil { val bypassFuse = player.hasPermission(CustomAnvil.bypassFusePermission) val bypassLevel = player.hasPermission(CustomAnvil.bypassLevelPermission) + 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 @@ -45,6 +49,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) } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 0bad067..a0f0876 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_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: