From 1e690c8eacb8eaafaac3d8acb8ee89bbf6560294 Mon Sep 17 00:00:00 2001 From: Will FP Date: Sun, 24 Dec 2023 14:37:47 +0100 Subject: [PATCH] Fixed hardcoded enchantments not working --- .../registration/EcoEnchantsCraftEnchantment.kt | 13 ++++++++++--- .../willfp/ecoenchants/enchant/EcoEnchants.kt | 3 ++- .../ecoenchants/enchant/impl/EcoEnchantBase.kt | 8 ++++++++ .../legacy/LegacyDelegatedEnchantment.kt | 16 ++++++++++++++++ 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/registration/EcoEnchantsCraftEnchantment.kt b/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/registration/EcoEnchantsCraftEnchantment.kt index cdc9a813..59ec0071 100644 --- a/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/registration/EcoEnchantsCraftEnchantment.kt +++ b/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/registration/EcoEnchantsCraftEnchantment.kt @@ -22,6 +22,14 @@ class EcoEnchantsCraftEnchantment( enchant.enchantment = this } + override fun onRegister() { + enchant.onRegister() + } + + override fun onRemove() { + enchant.onRemove() + } + override fun canEnchantItem(item: ItemStack): Boolean { return enchant.canEnchantItem(item) } @@ -105,12 +113,11 @@ class EcoEnchantsCraftEnchantment( override fun getActiveSlots() = emptySet() override fun equals(other: Any?): Boolean { - return other is EcoEnchantsCraftEnchantment && - other.key == this.key + return other is EcoEnchant && this.enchantmentKey == other.enchantmentKey } override fun hashCode(): Int { - return Objects.hash(this.key) + return this.enchantmentKey.hashCode() } override fun toString(): String { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/EcoEnchants.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/EcoEnchants.kt index 03dd9c4e..ee4436e4 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/EcoEnchants.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/EcoEnchants.kt @@ -95,7 +95,8 @@ object EcoEnchants : RegistrableCategory("enchant", "enchants") { ) for (enchantment in hardcodedEnchantments) { - if (enchantment.isPresent) { + // Only register if not already registered (so hardcode can be overridden) + if (enchantment.isPresent && registry[enchantment.id] == null) { doRegister(plugin, enchantment) } } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/impl/EcoEnchantBase.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/impl/EcoEnchantBase.kt index 9ced2865..69b42c9a 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/impl/EcoEnchantBase.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/impl/EcoEnchantBase.kt @@ -126,4 +126,12 @@ abstract class EcoEnchantBase( override fun conflictsWithDirectly(other: Enchantment): Boolean { return other.key.key in conflictIds } + + final override fun equals(other: Any?): Boolean { + return other is EcoEnchant && this.enchantmentKey == other.enchantmentKey + } + + final override fun hashCode(): Int { + return this.enchantmentKey.hashCode() + } } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/registration/legacy/LegacyDelegatedEnchantment.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/registration/legacy/LegacyDelegatedEnchantment.kt index ff99aebb..f35734e6 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/registration/legacy/LegacyDelegatedEnchantment.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/registration/legacy/LegacyDelegatedEnchantment.kt @@ -21,6 +21,14 @@ class LegacyDelegatedEnchantment( enchant.enchantment = this } + override fun onRegister() { + enchant.onRegister() + } + + override fun onRemove() { + enchant.onRemove() + } + override fun translationKey(): String { return "ecoenchants:enchantment.$id" } @@ -89,4 +97,12 @@ class LegacyDelegatedEnchantment( replaceWith = ReplaceWith("this.slots") ) override fun getActiveSlots() = emptySet() + + override fun equals(other: Any?): Boolean { + return other is EcoEnchant && this.enchantmentKey == other.enchantmentKey + } + + override fun hashCode(): Int { + return this.enchantmentKey.hashCode() + } }