diff --git a/README.md b/README.md index a6503ad..30cd067 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Custom Anvil **Custom Anvil** is a plugin that allows server administrators to customise every aspect of the anvil's mechanics. -It is expected to work on 1.18 to 1.20.4 minecraft servers running spigot or paper. +It is expected to work on 1.18 to 1.20.5 minecraft servers running spigot or paper. **Custom Anvil** was previously named **Unsafe Enchants+**. It was renamed because it now affects every anvil aspect and not only unsafe enchants @@ -53,5 +53,13 @@ Default configuration can be found on following links: - [unit_repair_item.yml](https://github.com/alexcrea/CustomAnvil/blob/master/src/main/resources/unit_repair_item.yml) - [custom_recipes.yml](https://github.com/alexcrea/CustomAnvil/blob/master/src/main/resources/custom_recipes.yml) --- -### Know issue: -There is non known issue, if you find one please report the issue. +### Known issue: +- Custom recipe config GUI is not reloaded on reload config command. (this should not impact a lot of admin, Custom recipe config should be edited manually only in rare occasion) + +### Planned: +- Finish the config gui +- Semi manual config update on pluign or minecraft update +- Check unknow registered enchantment & warn +- Warn admin on unsuported minecraft version + + diff --git a/build.gradle.kts b/build.gradle.kts index b2210cc..7fa9457 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "xyz.alexcrea" -version = "1.4.1a" +version = "1.4.3a" repositories { mavenCentral() diff --git a/src/main/java/xyz/alexcrea/cuanvil/enchant/EnchantmentProperties.java b/src/main/java/xyz/alexcrea/cuanvil/enchant/EnchantmentProperties.java index eb217b9..3651e87 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/enchant/EnchantmentProperties.java +++ b/src/main/java/xyz/alexcrea/cuanvil/enchant/EnchantmentProperties.java @@ -39,6 +39,7 @@ public enum EnchantmentProperties { SOUL_SPEED(EnchantmentRarity.VERY_RARE), SWIFT_SNEAK(EnchantmentRarity.VERY_RARE), SWEEPING(EnchantmentRarity.RARE), + SWEEPING_EDGE(EnchantmentRarity.RARE), THORNS(EnchantmentRarity.VERY_RARE), UNBREAKING(EnchantmentRarity.UNCOMMON), VANISHING_CURSE(EnchantmentRarity.VERY_RARE); diff --git a/src/main/kotlin/io/delilaheve/AnvilEventListener.kt b/src/main/kotlin/io/delilaheve/AnvilEventListener.kt index 22decff..4138695 100644 --- a/src/main/kotlin/io/delilaheve/AnvilEventListener.kt +++ b/src/main/kotlin/io/delilaheve/AnvilEventListener.kt @@ -9,6 +9,7 @@ import io.delilaheve.util.ItemUtil.isEnchantedBook import io.delilaheve.util.ItemUtil.repairFrom import io.delilaheve.util.ItemUtil.setEnchantmentsUnsafe import io.delilaheve.util.ItemUtil.unitRepair +import org.bukkit.ChatColor import org.bukkit.GameMode import org.bukkit.Material import org.bukkit.entity.Player @@ -161,7 +162,9 @@ class AnvilEventListener : Listener { private fun handleRename(resultItem: ItemStack, inventory: AnvilInventory): Int { // Rename item and add renaming cost resultItem.itemMeta?.let { - if (!it.displayName.contentEquals(inventory.renameText)) { + val displayName = ChatColor.stripColor(it.displayName) + val inventoryName = ChatColor.stripColor(inventory.renameText) + if (!displayName.contentEquals(inventoryName)) { it.setDisplayName(inventory.renameText) resultItem.itemMeta = it return ConfigOptions.itemRenameCost diff --git a/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt b/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt index 7d3b6d7..b9cfa7a 100644 --- a/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt +++ b/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt @@ -217,12 +217,32 @@ object ConfigOptions { * Get the given [enchantment]'s limit */ fun enchantLimit(enchantment: Enchantment): Int { - val path = "${ENCHANT_LIMIT_ROOT}.${enchantment.enchantmentName}" + return enchantLimit(enchantment.enchantmentName) + } + + /** + * Get the given [enchantmentName]'s limit + */ + private fun enchantLimit(enchantmentName: String): Int { + val default = getDefaultLevel(enchantmentName) + + val path = "${ENCHANT_LIMIT_ROOT}.$enchantmentName" return CustomAnvil.instance .config - .getInt(path, defaultEnchantLimit) + .getInt(path, default) .takeIf { it in ENCHANT_LIMIT_RANGE } - ?: defaultEnchantLimit + ?: default + } + + /** + * Get default value if enchantment do not exist on config + */ + private fun getDefaultLevel(enchantmentName: String, // compatibility with 1.20.5. TODO better update system + ) : Int { + if(enchantmentName == "sweeping_edge"){ + return enchantLimit("sweeping") + } + return defaultEnchantLimit } /** @@ -233,15 +253,39 @@ object ConfigOptions { enchantment: Enchantment, isFromBook: Boolean ): Int { + return enchantmentValue(enchantment.enchantmentName, isFromBook) + } + + /** + * Get the appropriate [enchantmentName]'s value dependent on whether + * it's source [isFromBook] + */ + private fun enchantmentValue( + enchantmentName: String, + isFromBook: Boolean + ): Int { + val default = getDefaultValue(enchantmentName, isFromBook) + val typeKey = if (isFromBook) KEY_BOOK else KEY_ITEM - val path = "${ENCHANT_VALUES_ROOT}.${enchantment.enchantmentName}.$typeKey" + val path = "${ENCHANT_VALUES_ROOT}.${enchantmentName}.$typeKey" return CustomAnvil.instance .config - .getInt(path, DEFAULT_ENCHANT_VALUE) + .getInt(path, default) .takeIf { it >= DEFAULT_ENCHANT_VALUE } ?: DEFAULT_ENCHANT_VALUE } + /** + * Get default value if enchantment do not exist on config + */ + private fun getDefaultValue(enchantmentName: String, // compatibility with 1.20.5. TODO better update system + isFromBook: Boolean) : Int { + if(enchantmentName == "sweeping_edge"){ + return enchantmentValue("sweeping", isFromBook) + } + return DEFAULT_ENCHANT_VALUE + } + /** * Get an array of key of basic config options */ diff --git a/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt b/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt index 069a0ed..0f1639c 100644 --- a/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt +++ b/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt @@ -30,10 +30,17 @@ object EnchantmentUtil { ) = mutableMapOf().apply { putAll(this@combineWith) other.forEach { (enchantment, level) -> + // Get max level or 255 if player can bypass + val maxLevel = if (player.hasPermission(CustomAnvil.bypassLevelPermission)) + { 255 } else + { ConfigOptions.enchantLimit(enchantment) } + + val cappedLevel = min(level, maxLevel) + // Enchantment not yet in result list if (!containsKey(enchantment)) { // Add the enchantment if it doesn't have conflicts, or if player is allowed to bypass enchantment restrictions - this[enchantment] = level + this[enchantment] = cappedLevel val conflictType = ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this.keys, mat, enchantment) if (!player.hasPermission(CustomAnvil.bypassFusePermission) && @@ -46,6 +53,8 @@ object EnchantmentUtil { } // Enchantment already in result list else { + val oldLevel = this[enchantment]!! // should be true, see the comment above + // ... and they are conflicting val conflictType = ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this.keys, mat, enchantment) @@ -57,28 +66,18 @@ object EnchantmentUtil { } // ... and they're not the same level - if (this[enchantment] != other[enchantment]) { - val newLevel = max(this[enchantment] ?: 0, other[enchantment] ?: 0) - // apply the greater of the two if non-zero + if (oldLevel != cappedLevel) { + // apply the greater of the two or left one if right is above max + this[enchantment] = max(oldLevel, cappedLevel) - if (newLevel > 0) { - this[enchantment] = newLevel - } } // ... and they're the same level else { // try to increase the enchantment level by 1 - var newLevel = this[enchantment]!! + 1 - // Get max level or 255 if player can bypass - val maxLevel = if (player.hasPermission(CustomAnvil.bypassLevelPermission)) { - 255 - } else { - ConfigOptions.enchantLimit(enchantment) - } - newLevel = min(newLevel, maxLevel) - if (newLevel > 0) { - this[enchantment] = newLevel - } + var newLevel = oldLevel + 1 + newLevel = max(min(newLevel, maxLevel), oldLevel) + this[enchantment] = newLevel + } } } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt index e4ce6f8..f4c9b47 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt @@ -24,6 +24,12 @@ class EnchantConflictManager { // Default name for a joining group private const val DEFAULT_GROUP_NAME = "joinedGroup" + + // 1.20.5 compatibility TODO better update system + private val SWEEPING_EDGE_ENCHANT = + Enchantment.getByKey(NamespacedKey.minecraft("sweeping_edge")) ?: + Enchantment.SWEEPING_EDGE + } private lateinit var conflictMap: HashMap> @@ -76,8 +82,7 @@ class EnchantConflictManager { // Read and add enchantment to conflict val enchantList = section.getStringList(ENCH_LIST_PATH) for (enchantName in enchantList) { - val enchantKey = NamespacedKey.minecraft(enchantName) - val enchant = Enchantment.getByKey(enchantKey) + val enchant = getEnchantByName(enchantName); if (enchant == null) { if (!futureUse) { CustomAnvil.instance.logger.warning("Enchantment $enchantName do not exist but was asked for conflict $conflictName") @@ -95,6 +100,20 @@ class EnchantConflictManager { return conflict } + private fun getEnchantByName(enchantName: String): Enchantment? { + + // Temporary solution for 1.20.5 + when(enchantName){ + "sweeping", "sweeping_edge" -> { + return SWEEPING_EDGE_ENCHANT + } + } + + val enchantKey = NamespacedKey.minecraft(enchantName) + return Enchantment.getByKey(enchantKey); + } + + private fun createConflictObject( section: ConfigurationSection, itemManager: ItemGroupManager, diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/MetricsUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/MetricsUtil.kt index 6e0e270..46f7cf5 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/MetricsUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/MetricsUtil.kt @@ -8,9 +8,9 @@ import xyz.alexcrea.cuanvil.config.ConfigHolder object MetricsUtil { private const val baseConfigHash = -1592940914 - private const val enchantLimitsConfigHash = -1014133828 - private const val enchantValuesConfigHash = 1072574774 - private const val enchantConflictConfigHash = 1406650190 + private const val enchantLimitsConfigHash = -275034280 + private const val enchantValuesConfigHash = -17048020 + private const val enchantConflictConfigHash = 546475833 private const val itemGroupsConfigHash = 1406650190 private const val unitRepairItemConfigHash = 536871958 private const val customAnvilCraftConfigHash = 0 diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 61f169b..7e2435c 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -72,6 +72,7 @@ enchant_limits: fire_aspect: 2 looting: 3 sweeping: 3 + sweeping_edge: 3 efficiency: 5 unbreaking: 3 fortune: 3 @@ -208,6 +209,9 @@ enchant_values: sweeping: item: 4 book: 2 + sweeping_edge: + item: 4 + book: 2 thorns: item: 8 book: 4 @@ -223,3 +227,5 @@ debug_log: false # Whether to show verbose debug logging debug_log_verbose: false + +configVersion: 1.4.3 diff --git a/src/main/resources/enchant_conflict.yml b/src/main/resources/enchant_conflict.yml index dfc5261..387fc90 100644 --- a/src/main/resources/enchant_conflict.yml +++ b/src/main/resources/enchant_conflict.yml @@ -147,8 +147,8 @@ restriction_soul_speed: enchantments: [ soul_speed ] notAffectedGroups: [ enchanted_book, boots ] -restriction_sweeping: - enchantments: [ sweeping ] +restriction_sweeping_edge: + enchantments: [ sweeping, sweeping_edge ] notAffectedGroups: [ enchanted_book, swords ] # Do not exist in 1.18, that mean useInFuture will be set to true @@ -156,7 +156,7 @@ restriction_sweeping: restriction_swift_sneak: useInFuture: true enchantments: [ swift_sneak ] - notAffectedGroups: [ enchanted_book, boots ] + notAffectedGroups: [ enchanted_book, leggings ] restriction_thorns: enchantments: [ thorns ] diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index d06819b..f7e12fa 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ main: io.delilaheve.CustomAnvil name: CustomAnvil prefix: "Custom Anvil" -version: 1.4.1a +version: 1.4.3a description: Allow to customise anvil mechanics api-version: 1.18 load: POSTWORLD