From 6b8f49d2e116f5b8d5993e02f4c16cafaf8c8568 Mon Sep 17 00:00:00 2001 From: Will FP Date: Mon, 4 Nov 2024 17:21:28 +0000 Subject: [PATCH] Fixed registry unfreezing on 1.21.3 --- .../v1_21_3/ModernEnchantmentRegisterer.kt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/eco-core/core-nms/v1_21_3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_21_3/ModernEnchantmentRegisterer.kt b/eco-core/core-nms/v1_21_3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_21_3/ModernEnchantmentRegisterer.kt index 08cb5d1f..73d3ea5a 100644 --- a/eco-core/core-nms/v1_21_3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_21_3/ModernEnchantmentRegisterer.kt +++ b/eco-core/core-nms/v1_21_3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_21_3/ModernEnchantmentRegisterer.kt @@ -18,6 +18,7 @@ import org.bukkit.craftbukkit.CraftRegistry import org.bukkit.craftbukkit.CraftServer import org.bukkit.craftbukkit.util.CraftNamespacedKey import org.bukkit.enchantments.Enchantment +import java.lang.reflect.Modifier import java.util.IdentityHashMap import java.util.function.BiFunction @@ -34,6 +35,11 @@ class ModernEnchantmentRegisterer : ModernEnchantmentRegistererProxy { .filter { it.type.isPrimitive }[0] .apply { isAccessible = true } + private val allTags = MappedRegistry::class.java + .declaredFields + .filter { it.type.name.contains("TagSet") }[0] + .apply { isAccessible = true } + private val unregisteredIntrusiveHoldersField = MappedRegistry::class.java .declaredFields .last { it.type == Map::class.java } @@ -81,6 +87,21 @@ class ModernEnchantmentRegisterer : ModernEnchantmentRegistererProxy { IdentityHashMap>() ) + + /* + Creating an unbound tag set requires using reflection because the inner class is + package-private, so we just find the method manually. + */ + + val unboundTagSet = MappedRegistry::class.java + .declaredClasses[0] + .declaredMethods + .filter { Modifier.isStatic(it.modifiers) } + .filter { it.parameterCount == 0 }[0] + .apply { isAccessible = true } + .invoke(null) + + allTags.set(enchantmentRegistry, unboundTagSet) } override fun register(enchant: EcoEnchantBase): Enchantment {