Fixed hardcoded enchantments not working

This commit is contained in:
Will FP 2023-12-24 14:37:47 +01:00
parent 046895fbf6
commit 1e690c8eac
4 changed files with 36 additions and 4 deletions

View File

@ -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<EquipmentSlot>()
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 {

View File

@ -95,7 +95,8 @@ object EcoEnchants : RegistrableCategory<EcoEnchant>("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)
}
}

View File

@ -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()
}
}

View File

@ -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<EquipmentSlot>()
override fun equals(other: Any?): Boolean {
return other is EcoEnchant && this.enchantmentKey == other.enchantmentKey
}
override fun hashCode(): Int {
return this.enchantmentKey.hashCode()
}
}