From 250607ecb21883b9171817c0b7c10df26981d03c Mon Sep 17 00:00:00 2001 From: Will FP Date: Sat, 9 Dec 2023 14:14:59 +0000 Subject: [PATCH] Registration improvements --- .../proxy/v1_17_R1/EcoCraftEnchantment.kt | 23 ---------------- .../v1_17_R1/EcoCraftEnchantmentManager.kt | 4 ++- .../proxy/v1_18_R1/EcoCraftEnchantment.kt | 23 ---------------- .../v1_18_R1/EcoCraftEnchantmentManager.kt | 4 ++- .../proxy/v1_18_R2/EcoCraftEnchantment.kt | 23 ---------------- .../v1_18_R2/EcoCraftEnchantmentManager.kt | 4 ++- .../proxy/v1_19_R1/EcoCraftEnchantment.kt | 23 ---------------- .../v1_19_R1/EcoCraftEnchantmentManager.kt | 4 ++- .../proxy/v1_19_R2/EcoCraftEnchantment.kt | 23 ---------------- .../v1_19_R2/EcoCraftEnchantmentManager.kt | 4 ++- .../proxy/v1_19_R3/EcoCraftEnchantment.kt | 23 ---------------- .../v1_19_R3/EcoCraftEnchantmentManager.kt | 4 ++- .../proxy/v1_20_R1/EcoCraftEnchantment.kt | 23 ---------------- .../v1_20_R1/EcoCraftEnchantmentManager.kt | 4 ++- .../proxy/v1_20_R2/EcoCraftEnchantment.kt | 23 ---------------- .../v1_20_R2/EcoCraftEnchantmentManager.kt | 4 ++- .../v1_20_R3/ModernEnchantmentRegisterer.kt | 4 +-- ...ment.kt => EcoEnchantsCraftEnchantment.kt} | 6 ++--- .../ModifiedVanillaCraftEnchantment.kt | 5 ++++ .../legacy/LegacyEnchantmentRegisterer.kt | 26 +++++++++++++++++-- 20 files changed, 58 insertions(+), 199 deletions(-) rename eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/registration/{DelegatedCraftEnchantment.kt => EcoEnchantsCraftEnchantment.kt} (96%) diff --git a/eco-core/core-nms/v1_17_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_17_R1/EcoCraftEnchantment.kt b/eco-core/core-nms/v1_17_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_17_R1/EcoCraftEnchantment.kt index b222837d..ad73b2a7 100644 --- a/eco-core/core-nms/v1_17_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_17_R1/EcoCraftEnchantment.kt +++ b/eco-core/core-nms/v1_17_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_17_R1/EcoCraftEnchantment.kt @@ -20,27 +20,4 @@ class EcoCraftEnchantment( return data.conflicts?.contains(other.key) ?: super.conflictsWith(other) } - - @Suppress("UNCHECKED_CAST") - fun register() { - org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byKey") - .apply { - isAccessible = true - (get(null) as MutableMap).apply { remove(key) } - } - - org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byName") - .apply { - isAccessible = true - (get(null) as MutableMap).apply { remove(name) } - } - - org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("acceptingNew") - .apply { - isAccessible = true - set(null, true) - } - - org.bukkit.enchantments.Enchantment.registerEnchantment(this) - } } diff --git a/eco-core/core-nms/v1_17_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_17_R1/EcoCraftEnchantmentManager.kt b/eco-core/core-nms/v1_17_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_17_R1/EcoCraftEnchantmentManager.kt index 4a40c2d5..8973c22d 100644 --- a/eco-core/core-nms/v1_17_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_17_R1/EcoCraftEnchantmentManager.kt +++ b/eco-core/core-nms/v1_17_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_17_R1/EcoCraftEnchantmentManager.kt @@ -2,6 +2,7 @@ package com.willfp.ecoenchants.proxy.v1_17_R1 import com.willfp.ecoenchants.enchant.EcoCraftEnchantmentManagerProxy import com.willfp.ecoenchants.enchant.VanillaEnchantmentData +import com.willfp.ecoenchants.enchant.registration.legacy.LegacyEnchantmentRegisterer import org.bukkit.enchantments.Enchantment class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy { @@ -16,7 +17,8 @@ class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy { if (key.key != enchantment.key.key) { continue } - EcoCraftEnchantment(enchant, data).register() + + LegacyEnchantmentRegisterer.registerToBukkit(EcoCraftEnchantment(enchant, data)) } } } diff --git a/eco-core/core-nms/v1_18_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_18_R1/EcoCraftEnchantment.kt b/eco-core/core-nms/v1_18_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_18_R1/EcoCraftEnchantment.kt index 1a3ef24a..d0137be6 100644 --- a/eco-core/core-nms/v1_18_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_18_R1/EcoCraftEnchantment.kt +++ b/eco-core/core-nms/v1_18_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_18_R1/EcoCraftEnchantment.kt @@ -20,27 +20,4 @@ class EcoCraftEnchantment( return data.conflicts?.contains(other.key) ?: super.conflictsWith(other) } - - @Suppress("UNCHECKED_CAST") - fun register() { - org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byKey") - .apply { - isAccessible = true - (get(null) as MutableMap).apply { remove(key) } - } - - org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byName") - .apply { - isAccessible = true - (get(null) as MutableMap).apply { remove(name) } - } - - org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("acceptingNew") - .apply { - isAccessible = true - set(null, true) - } - - org.bukkit.enchantments.Enchantment.registerEnchantment(this) - } } diff --git a/eco-core/core-nms/v1_18_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_18_R1/EcoCraftEnchantmentManager.kt b/eco-core/core-nms/v1_18_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_18_R1/EcoCraftEnchantmentManager.kt index 747e8d81..f69cfe3b 100644 --- a/eco-core/core-nms/v1_18_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_18_R1/EcoCraftEnchantmentManager.kt +++ b/eco-core/core-nms/v1_18_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_18_R1/EcoCraftEnchantmentManager.kt @@ -2,6 +2,7 @@ package com.willfp.ecoenchants.proxy.v1_18_R1 import com.willfp.ecoenchants.enchant.EcoCraftEnchantmentManagerProxy import com.willfp.ecoenchants.enchant.VanillaEnchantmentData +import com.willfp.ecoenchants.enchant.registration.legacy.LegacyEnchantmentRegisterer import org.bukkit.enchantments.Enchantment class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy { @@ -16,7 +17,8 @@ class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy { if (key.key != enchantment.key.key) { continue } - EcoCraftEnchantment(enchant, data).register() + + LegacyEnchantmentRegisterer.registerToBukkit(EcoCraftEnchantment(enchant, data)) } } } diff --git a/eco-core/core-nms/v1_18_R2/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_18_R2/EcoCraftEnchantment.kt b/eco-core/core-nms/v1_18_R2/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_18_R2/EcoCraftEnchantment.kt index e73161b7..f6a68ec3 100644 --- a/eco-core/core-nms/v1_18_R2/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_18_R2/EcoCraftEnchantment.kt +++ b/eco-core/core-nms/v1_18_R2/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_18_R2/EcoCraftEnchantment.kt @@ -20,27 +20,4 @@ class EcoCraftEnchantment( return data.conflicts?.contains(other.key) ?: super.conflictsWith(other) } - - @Suppress("UNCHECKED_CAST") - fun register() { - org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byKey") - .apply { - isAccessible = true - (get(null) as MutableMap).apply { remove(key) } - } - - org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byName") - .apply { - isAccessible = true - (get(null) as MutableMap).apply { remove(name) } - } - - org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("acceptingNew") - .apply { - isAccessible = true - set(null, true) - } - - org.bukkit.enchantments.Enchantment.registerEnchantment(this) - } } diff --git a/eco-core/core-nms/v1_18_R2/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_18_R2/EcoCraftEnchantmentManager.kt b/eco-core/core-nms/v1_18_R2/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_18_R2/EcoCraftEnchantmentManager.kt index b3b25144..9720403d 100644 --- a/eco-core/core-nms/v1_18_R2/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_18_R2/EcoCraftEnchantmentManager.kt +++ b/eco-core/core-nms/v1_18_R2/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_18_R2/EcoCraftEnchantmentManager.kt @@ -2,6 +2,7 @@ package com.willfp.ecoenchants.proxy.v1_18_R2 import com.willfp.ecoenchants.enchant.EcoCraftEnchantmentManagerProxy import com.willfp.ecoenchants.enchant.VanillaEnchantmentData +import com.willfp.ecoenchants.enchant.registration.legacy.LegacyEnchantmentRegisterer import org.bukkit.enchantments.Enchantment class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy { @@ -16,7 +17,8 @@ class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy { if (key.key != enchantment.key.key) { continue } - EcoCraftEnchantment(enchant, data).register() + + LegacyEnchantmentRegisterer.registerToBukkit(EcoCraftEnchantment(enchant, data)) } } } diff --git a/eco-core/core-nms/v1_19_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_19_R1/EcoCraftEnchantment.kt b/eco-core/core-nms/v1_19_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_19_R1/EcoCraftEnchantment.kt index 4793ed6c..2fd8d9f5 100644 --- a/eco-core/core-nms/v1_19_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_19_R1/EcoCraftEnchantment.kt +++ b/eco-core/core-nms/v1_19_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_19_R1/EcoCraftEnchantment.kt @@ -20,27 +20,4 @@ class EcoCraftEnchantment( return data.conflicts?.contains(other.key) ?: super.conflictsWith(other) } - - @Suppress("UNCHECKED_CAST") - fun register() { - org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byKey") - .apply { - isAccessible = true - (get(null) as MutableMap).apply { remove(key) } - } - - org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byName") - .apply { - isAccessible = true - (get(null) as MutableMap).apply { remove(name) } - } - - org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("acceptingNew") - .apply { - isAccessible = true - set(null, true) - } - - org.bukkit.enchantments.Enchantment.registerEnchantment(this) - } } diff --git a/eco-core/core-nms/v1_19_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_19_R1/EcoCraftEnchantmentManager.kt b/eco-core/core-nms/v1_19_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_19_R1/EcoCraftEnchantmentManager.kt index e8b7995f..009ec746 100644 --- a/eco-core/core-nms/v1_19_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_19_R1/EcoCraftEnchantmentManager.kt +++ b/eco-core/core-nms/v1_19_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_19_R1/EcoCraftEnchantmentManager.kt @@ -2,6 +2,7 @@ package com.willfp.ecoenchants.proxy.v1_19_R1 import com.willfp.ecoenchants.enchant.EcoCraftEnchantmentManagerProxy import com.willfp.ecoenchants.enchant.VanillaEnchantmentData +import com.willfp.ecoenchants.enchant.registration.legacy.LegacyEnchantmentRegisterer import org.bukkit.enchantments.Enchantment class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy { @@ -16,7 +17,8 @@ class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy { if (key.key != enchantment.key.key) { continue } - EcoCraftEnchantment(enchant, data).register() + + LegacyEnchantmentRegisterer.registerToBukkit(EcoCraftEnchantment(enchant, data)) } } } diff --git a/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_19_R2/EcoCraftEnchantment.kt b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_19_R2/EcoCraftEnchantment.kt index 9470ff5f..ec9bfd5b 100644 --- a/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_19_R2/EcoCraftEnchantment.kt +++ b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_19_R2/EcoCraftEnchantment.kt @@ -20,27 +20,4 @@ class EcoCraftEnchantment( return data.conflicts?.contains(other.key) ?: super.conflictsWith(other) } - - @Suppress("UNCHECKED_CAST") - fun register() { - org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byKey") - .apply { - isAccessible = true - (get(null) as MutableMap).apply { remove(key) } - } - - org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byName") - .apply { - isAccessible = true - (get(null) as MutableMap).apply { remove(name) } - } - - org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("acceptingNew") - .apply { - isAccessible = true - set(null, true) - } - - org.bukkit.enchantments.Enchantment.registerEnchantment(this) - } } diff --git a/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_19_R2/EcoCraftEnchantmentManager.kt b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_19_R2/EcoCraftEnchantmentManager.kt index 8c10ae8b..db55562b 100644 --- a/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_19_R2/EcoCraftEnchantmentManager.kt +++ b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_19_R2/EcoCraftEnchantmentManager.kt @@ -2,6 +2,7 @@ package com.willfp.ecoenchants.proxy.v1_19_R2 import com.willfp.ecoenchants.enchant.EcoCraftEnchantmentManagerProxy import com.willfp.ecoenchants.enchant.VanillaEnchantmentData +import com.willfp.ecoenchants.enchant.registration.legacy.LegacyEnchantmentRegisterer import net.minecraft.core.registries.BuiltInRegistries import org.bukkit.enchantments.Enchantment @@ -17,7 +18,8 @@ class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy { if (key.key != enchantment.key.key) { continue } - EcoCraftEnchantment(enchant, data).register() + + LegacyEnchantmentRegisterer.registerToBukkit(EcoCraftEnchantment(enchant, data)) } } } diff --git a/eco-core/core-nms/v1_19_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_19_R3/EcoCraftEnchantment.kt b/eco-core/core-nms/v1_19_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_19_R3/EcoCraftEnchantment.kt index cb5285f7..6069dfce 100644 --- a/eco-core/core-nms/v1_19_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_19_R3/EcoCraftEnchantment.kt +++ b/eco-core/core-nms/v1_19_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_19_R3/EcoCraftEnchantment.kt @@ -20,27 +20,4 @@ class EcoCraftEnchantment( return data.conflicts?.contains(other.key) ?: super.conflictsWith(other) } - - @Suppress("UNCHECKED_CAST") - fun register() { - org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byKey") - .apply { - isAccessible = true - (get(null) as MutableMap).apply { remove(key) } - } - - org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byName") - .apply { - isAccessible = true - (get(null) as MutableMap).apply { remove(name) } - } - - org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("acceptingNew") - .apply { - isAccessible = true - set(null, true) - } - - org.bukkit.enchantments.Enchantment.registerEnchantment(this) - } } diff --git a/eco-core/core-nms/v1_19_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_19_R3/EcoCraftEnchantmentManager.kt b/eco-core/core-nms/v1_19_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_19_R3/EcoCraftEnchantmentManager.kt index 6bc7823c..de90c83b 100644 --- a/eco-core/core-nms/v1_19_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_19_R3/EcoCraftEnchantmentManager.kt +++ b/eco-core/core-nms/v1_19_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_19_R3/EcoCraftEnchantmentManager.kt @@ -2,6 +2,7 @@ package com.willfp.ecoenchants.proxy.v1_19_R3 import com.willfp.ecoenchants.enchant.EcoCraftEnchantmentManagerProxy import com.willfp.ecoenchants.enchant.VanillaEnchantmentData +import com.willfp.ecoenchants.enchant.registration.legacy.LegacyEnchantmentRegisterer import net.minecraft.core.registries.BuiltInRegistries import org.bukkit.enchantments.Enchantment @@ -17,7 +18,8 @@ class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy { if (key.key != enchantment.key.key) { continue } - EcoCraftEnchantment(enchant, data).register() + + LegacyEnchantmentRegisterer.registerToBukkit(EcoCraftEnchantment(enchant, data)) } } } diff --git a/eco-core/core-nms/v1_20_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R1/EcoCraftEnchantment.kt b/eco-core/core-nms/v1_20_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R1/EcoCraftEnchantment.kt index 94c01b75..230c38d2 100644 --- a/eco-core/core-nms/v1_20_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R1/EcoCraftEnchantment.kt +++ b/eco-core/core-nms/v1_20_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R1/EcoCraftEnchantment.kt @@ -20,27 +20,4 @@ class EcoCraftEnchantment( return data.conflicts?.contains(other.key) ?: super.conflictsWith(other) } - - @Suppress("UNCHECKED_CAST") - fun register() { - org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byKey") - .apply { - isAccessible = true - (get(null) as MutableMap).apply { remove(key) } - } - - org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byName") - .apply { - isAccessible = true - (get(null) as MutableMap).apply { remove(name) } - } - - org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("acceptingNew") - .apply { - isAccessible = true - set(null, true) - } - - org.bukkit.enchantments.Enchantment.registerEnchantment(this) - } } diff --git a/eco-core/core-nms/v1_20_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R1/EcoCraftEnchantmentManager.kt b/eco-core/core-nms/v1_20_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R1/EcoCraftEnchantmentManager.kt index e5701260..8ce8a824 100644 --- a/eco-core/core-nms/v1_20_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R1/EcoCraftEnchantmentManager.kt +++ b/eco-core/core-nms/v1_20_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R1/EcoCraftEnchantmentManager.kt @@ -2,6 +2,7 @@ package com.willfp.ecoenchants.proxy.v1_20_R1 import com.willfp.ecoenchants.enchant.EcoCraftEnchantmentManagerProxy import com.willfp.ecoenchants.enchant.VanillaEnchantmentData +import com.willfp.ecoenchants.enchant.registration.legacy.LegacyEnchantmentRegisterer import net.minecraft.core.registries.BuiltInRegistries import org.bukkit.enchantments.Enchantment @@ -17,7 +18,8 @@ class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy { if (key.key != enchantment.key.key) { continue } - EcoCraftEnchantment(enchant, data).register() + + LegacyEnchantmentRegisterer.registerToBukkit(EcoCraftEnchantment(enchant, data)) } } } diff --git a/eco-core/core-nms/v1_20_R2/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R2/EcoCraftEnchantment.kt b/eco-core/core-nms/v1_20_R2/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R2/EcoCraftEnchantment.kt index dad9a2c3..098967cc 100644 --- a/eco-core/core-nms/v1_20_R2/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R2/EcoCraftEnchantment.kt +++ b/eco-core/core-nms/v1_20_R2/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R2/EcoCraftEnchantment.kt @@ -20,27 +20,4 @@ class EcoCraftEnchantment( return data.conflicts?.contains(other.key) ?: super.conflictsWith(other) } - - @Suppress("UNCHECKED_CAST") - fun register() { - org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byKey") - .apply { - isAccessible = true - (get(null) as MutableMap).apply { remove(key) } - } - - org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byName") - .apply { - isAccessible = true - (get(null) as MutableMap).apply { remove(name) } - } - - org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("acceptingNew") - .apply { - isAccessible = true - set(null, true) - } - - org.bukkit.enchantments.Enchantment.registerEnchantment(this) - } } diff --git a/eco-core/core-nms/v1_20_R2/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R2/EcoCraftEnchantmentManager.kt b/eco-core/core-nms/v1_20_R2/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R2/EcoCraftEnchantmentManager.kt index 20699773..38cd1eaa 100644 --- a/eco-core/core-nms/v1_20_R2/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R2/EcoCraftEnchantmentManager.kt +++ b/eco-core/core-nms/v1_20_R2/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R2/EcoCraftEnchantmentManager.kt @@ -2,6 +2,7 @@ package com.willfp.ecoenchants.proxy.v1_20_R2 import com.willfp.ecoenchants.enchant.EcoCraftEnchantmentManagerProxy import com.willfp.ecoenchants.enchant.VanillaEnchantmentData +import com.willfp.ecoenchants.enchant.registration.legacy.LegacyEnchantmentRegisterer import net.minecraft.core.registries.BuiltInRegistries import org.bukkit.enchantments.Enchantment @@ -17,7 +18,8 @@ class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy { if (key.key != enchantment.key.key) { continue } - EcoCraftEnchantment(enchant, data).register() + + LegacyEnchantmentRegisterer.registerToBukkit(EcoCraftEnchantment(enchant, data)) } } } diff --git a/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/ModernEnchantmentRegisterer.kt b/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/ModernEnchantmentRegisterer.kt index d24408ae..c40e4c49 100644 --- a/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/ModernEnchantmentRegisterer.kt +++ b/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/ModernEnchantmentRegisterer.kt @@ -3,7 +3,7 @@ package com.willfp.ecoenchants.proxy.v1_20_R3 import com.willfp.ecoenchants.enchant.EcoEnchant import com.willfp.ecoenchants.enchant.EcoEnchants import com.willfp.ecoenchants.enchant.registration.modern.ModernEnchantmentRegistererProxy -import com.willfp.ecoenchants.proxy.v1_20_R3.registration.DelegatedCraftEnchantment +import com.willfp.ecoenchants.proxy.v1_20_R3.registration.EcoEnchantsCraftEnchantment import com.willfp.ecoenchants.proxy.v1_20_R3.registration.ModifiedVanillaCraftEnchantment import com.willfp.ecoenchants.proxy.v1_20_R3.registration.VanillaEcoEnchantsEnchantment import net.minecraft.core.MappedRegistry @@ -71,7 +71,7 @@ class ModernEnchantmentRegisterer : ModernEnchantmentRegistererProxy { Registry.register(BuiltInRegistries.ENCHANTMENT, enchant.id, nms) - return DelegatedCraftEnchantment(enchant, nms) + return EcoEnchantsCraftEnchantment(enchant, nms) } override fun unregister(enchant: EcoEnchant) { diff --git a/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/registration/DelegatedCraftEnchantment.kt b/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/registration/EcoEnchantsCraftEnchantment.kt similarity index 96% rename from eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/registration/DelegatedCraftEnchantment.kt rename to eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/registration/EcoEnchantsCraftEnchantment.kt index 6439f7ba..9f73394f 100644 --- a/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/registration/DelegatedCraftEnchantment.kt +++ b/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/registration/EcoEnchantsCraftEnchantment.kt @@ -13,7 +13,7 @@ import org.bukkit.inventory.EquipmentSlot import org.bukkit.inventory.ItemStack import java.util.Objects -class DelegatedCraftEnchantment( +class EcoEnchantsCraftEnchantment( private val enchant: EcoEnchant, nmsEnchantment: Enchantment ) : CraftEnchantment(enchant.enchantmentKey, nmsEnchantment), EcoEnchant by enchant { @@ -104,7 +104,7 @@ class DelegatedCraftEnchantment( override fun getActiveSlots() = emptySet() override fun equals(other: Any?): Boolean { - return other is DelegatedCraftEnchantment && + return other is EcoEnchantsCraftEnchantment && other.key == this.key } @@ -113,6 +113,6 @@ class DelegatedCraftEnchantment( } override fun toString(): String { - return "DelegatedCraftEnchantment(key=$key)" + return "EcoEnchantsCraftEnchantment(key=$key)" } } diff --git a/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/registration/ModifiedVanillaCraftEnchantment.kt b/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/registration/ModifiedVanillaCraftEnchantment.kt index 7b41df49..23c30eff 100644 --- a/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/registration/ModifiedVanillaCraftEnchantment.kt +++ b/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/registration/ModifiedVanillaCraftEnchantment.kt @@ -10,4 +10,9 @@ class ModifiedVanillaCraftEnchantment( target: Enchantment ) : CraftEnchantment(key, target) { override fun getMaxLevel(): Int = this.vanillaEnchantmentData?.maxLevel ?: super.getMaxLevel() + + override fun conflictsWith(other: org.bukkit.enchantments.Enchantment): Boolean { + return this.vanillaEnchantmentData?.conflicts?.contains(other.key) ?: super.conflictsWith(other) + || other.conflictsWith(this) + } } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/registration/legacy/LegacyEnchantmentRegisterer.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/registration/legacy/LegacyEnchantmentRegisterer.kt index 3052c9ac..f1b0feea 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/registration/legacy/LegacyEnchantmentRegisterer.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/registration/legacy/LegacyEnchantmentRegisterer.kt @@ -1,20 +1,42 @@ package com.willfp.ecoenchants.enchant.registration.legacy import com.willfp.ecoenchants.enchant.EcoEnchant -import com.willfp.ecoenchants.enchant.impl.EcoEnchantBase import com.willfp.ecoenchants.enchant.registration.EnchantmentRegisterer import org.bukkit.NamespacedKey import org.bukkit.enchantments.Enchantment @Suppress("UNCHECKED_CAST") object LegacyEnchantmentRegisterer : EnchantmentRegisterer { - override fun register(enchant: EcoEnchant): Enchantment { + init { + // Allow registering new enchantments Enchantment::class.java.getDeclaredField("acceptingNew") .apply { isAccessible = true set(null, true) } + } + /** + * Register an enchantment to bukkit (for replacing vanilla CraftEnchantments) + */ + fun registerToBukkit(enchantment: Enchantment) { + Enchantment::class.java.getDeclaredField("byKey") + .apply { + isAccessible = true + (get(null) as MutableMap).apply { remove(enchantment.key) } + } + + Enchantment::class.java.getDeclaredField("byName") + .apply { + isAccessible = true + @Suppress("DEPRECATION") + (get(null) as MutableMap).apply { remove(enchantment.name) } + } + + Enchantment.registerEnchantment(enchantment) + } + + override fun register(enchant: EcoEnchant): Enchantment { val enchantment = LegacyDelegatedEnchantment(enchant) Enchantment.registerEnchantment(enchantment)