From 76fc3541276f7d8c0a1de3cf1069e5cd2eb50970 Mon Sep 17 00:00:00 2001 From: alexcrea <42614139+alexcrea@users.noreply.github.com> Date: Tue, 23 Apr 2024 02:02:55 +0200 Subject: [PATCH 1/6] Fix swift sneak allowed item on default config. --- src/main/resources/enchant_conflict.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/enchant_conflict.yml b/src/main/resources/enchant_conflict.yml index dfc5261..c3d8867 100644 --- a/src/main/resources/enchant_conflict.yml +++ b/src/main/resources/enchant_conflict.yml @@ -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 ] From 2861238f583917f357fa843f7e44c6308078020d Mon Sep 17 00:00:00 2001 From: alexcrea <42614139+alexcrea@users.noreply.github.com> Date: Tue, 23 Apr 2024 02:24:23 +0200 Subject: [PATCH 2/6] Avoid overriding left item name on custom name. fix #8 Also version up for convenience. --- build.gradle.kts | 2 +- src/main/kotlin/io/delilaheve/AnvilEventListener.kt | 5 ++++- src/main/resources/plugin.yml | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index b2210cc..3e79591 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "xyz.alexcrea" -version = "1.4.1a" +version = "1.4.2a" repositories { mavenCentral() 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/resources/plugin.yml b/src/main/resources/plugin.yml index d06819b..f41a940 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.2a description: Allow to customise anvil mechanics api-version: 1.18 load: POSTWORLD From 46ff34deea9b1408268e1067c3ce3e945cb8528d Mon Sep 17 00:00:00 2001 From: alexcrea <42614139+alexcrea@users.noreply.github.com> Date: Sun, 28 Apr 2024 03:20:32 +0200 Subject: [PATCH 3/6] Hacky fix for 1.20.5. Also: - version up - metric fix (expected as config was changed) - Prepared for long term update system --- build.gradle.kts | 2 +- .../io/delilaheve/util/ConfigOptions.kt | 11 +++++++-- .../cuanvil/group/EnchantConflictManager.kt | 23 +++++++++++++++++-- .../xyz/alexcrea/cuanvil/util/MetricsUtil.kt | 6 ++--- src/main/resources/config.yml | 6 +++++ src/main/resources/enchant_conflict.yml | 4 ++-- src/main/resources/plugin.yml | 2 +- 7 files changed, 43 insertions(+), 11 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 3e79591..7fa9457 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "xyz.alexcrea" -version = "1.4.2a" +version = "1.4.3a" repositories { mavenCentral() diff --git a/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt b/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt index 7d3b6d7..b69ad46 100644 --- a/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt +++ b/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt @@ -217,7 +217,7 @@ object ConfigOptions { * Get the given [enchantment]'s limit */ fun enchantLimit(enchantment: Enchantment): Int { - val path = "${ENCHANT_LIMIT_ROOT}.${enchantment.enchantmentName}" + val path = "${ENCHANT_LIMIT_ROOT}.${getEnchantKey(enchantment)}" return CustomAnvil.instance .config .getInt(path, defaultEnchantLimit) @@ -234,7 +234,7 @@ object ConfigOptions { isFromBook: Boolean ): Int { val typeKey = if (isFromBook) KEY_BOOK else KEY_ITEM - val path = "${ENCHANT_VALUES_ROOT}.${enchantment.enchantmentName}.$typeKey" + val path = "${ENCHANT_VALUES_ROOT}.${getEnchantKey(enchantment)}.$typeKey" return CustomAnvil.instance .config .getInt(path, DEFAULT_ENCHANT_VALUE) @@ -242,6 +242,13 @@ object ConfigOptions { ?: DEFAULT_ENCHANT_VALUE } + fun getEnchantKey(enchantment: Enchantment) : String{ + val enchantKey = enchantment.enchantmentName + if(enchantKey == "sweeping_edge"){ // compatibility with 1.20.5. TODO better update system + return "sweeping" + } + return enchantKey + } /** * Get an array of key of basic config options */ diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt index e4ce6f8..5f7aab1 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? { + + // Teporary 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 c3d8867..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 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index f41a940..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.2a +version: 1.4.3a description: Allow to customise anvil mechanics api-version: 1.18 load: POSTWORLD From 45401edbf495275528c0560055c0fdafa758a632 Mon Sep 17 00:00:00 2001 From: alexcrea <42614139+alexcrea@users.noreply.github.com> Date: Sun, 28 Apr 2024 03:28:58 +0200 Subject: [PATCH 4/6] Update README.md Updated for 1.20.5 --- README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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 + + From 32b535efda448251e52f266f36f8927d1843e045 Mon Sep 17 00:00:00 2001 From: alexcrea <42614139+alexcrea@users.noreply.github.com> Date: Sun, 28 Apr 2024 04:02:03 +0200 Subject: [PATCH 5/6] Better system for handling 1.20.5 sweeping edge. --- .../enchant/EnchantmentProperties.java | 1 + .../io/delilaheve/util/ConfigOptions.kt | 57 +++++++++++++++---- 2 files changed, 48 insertions(+), 10 deletions(-) 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/util/ConfigOptions.kt b/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt index b69ad46..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}.${getEnchantKey(enchantment)}" + 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,22 +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}.${getEnchantKey(enchantment)}.$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 } - fun getEnchantKey(enchantment: Enchantment) : String{ - val enchantKey = enchantment.enchantmentName - if(enchantKey == "sweeping_edge"){ // compatibility with 1.20.5. TODO better update system - return "sweeping" + /** + * 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 enchantKey + return DEFAULT_ENCHANT_VALUE } + /** * Get an array of key of basic config options */ From adaba63d5ef47dbd82f1b854e795cae66e3c67ea Mon Sep 17 00:00:00 2001 From: alexcrea <42614139+alexcrea@users.noreply.github.com> Date: Sun, 28 Apr 2024 04:24:11 +0200 Subject: [PATCH 6/6] Fixed issue about level in fusing. when fusing item with enchant above level limit there was some strange uncapped cases. Also fix a typo. --- .../io/delilaheve/util/EnchantmentUtil.kt | 35 +++++++++---------- .../cuanvil/group/EnchantConflictManager.kt | 2 +- 2 files changed, 18 insertions(+), 19 deletions(-) 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 5f7aab1..f4c9b47 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt @@ -102,7 +102,7 @@ class EnchantConflictManager { private fun getEnchantByName(enchantName: String): Enchantment? { - // Teporary solution for 1.20.5 + // Temporary solution for 1.20.5 when(enchantName){ "sweeping", "sweeping_edge" -> { return SWEEPING_EDGE_ENCHANT