Cleaned up registration API

This commit is contained in:
Will FP
2023-12-09 15:57:37 +00:00
parent f3af2a0a75
commit f56acf50bb
6 changed files with 13 additions and 15 deletions

View File

@@ -2,6 +2,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.impl.EcoEnchantBase
import com.willfp.ecoenchants.enchant.registration.modern.ModernEnchantmentRegistererProxy
import com.willfp.ecoenchants.proxy.v1_20_R3.registration.EcoEnchantsCraftEnchantment
import com.willfp.ecoenchants.proxy.v1_20_R3.registration.ModifiedVanillaCraftEnchantment
@@ -79,7 +80,7 @@ class ModernEnchantmentRegisterer : ModernEnchantmentRegistererProxy {
unregisteredIntrusiveHoldersField.set(BuiltInRegistries.ENCHANTMENT, IdentityHashMap<Enchantment, Holder.Reference<Enchantment>>())
}
override fun register(enchant: EcoEnchant): Enchantment {
override fun register(enchant: EcoEnchantBase): Enchantment {
if (BuiltInRegistries.ENCHANTMENT.containsKey(CraftNamespacedKey.toMinecraft(enchant.enchantmentKey))) {
val nms = BuiltInRegistries.ENCHANTMENT[CraftNamespacedKey.toMinecraft(enchant.enchantmentKey)]
@@ -96,7 +97,7 @@ class ModernEnchantmentRegisterer : ModernEnchantmentRegistererProxy {
}
override fun unregister(enchant: EcoEnchant) {
override fun unregister(enchant: EcoEnchantBase) {
/*
You can't unregister from a minecraft registry, so we simply leave the stale reference there.

View File

@@ -3,6 +3,7 @@ package com.willfp.ecoenchants.proxy.v1_20_R3.registration
import com.willfp.eco.util.toComponent
import com.willfp.ecoenchants.display.getFormattedName
import com.willfp.ecoenchants.enchant.EcoEnchant
import com.willfp.ecoenchants.enchant.impl.EcoEnchantBase
import io.papermc.paper.enchantments.EnchantmentRarity
import net.kyori.adventure.text.Component
import net.minecraft.world.item.enchantment.Enchantment
@@ -14,7 +15,7 @@ import org.bukkit.inventory.ItemStack
import java.util.Objects
class EcoEnchantsCraftEnchantment(
private val enchant: EcoEnchant,
private val enchant: EcoEnchantBase,
nmsEnchantment: Enchantment
) : CraftEnchantment(enchant.enchantmentKey, nmsEnchantment), EcoEnchant by enchant {
init {

View File

@@ -13,11 +13,6 @@ interface EcoEnchant : KRegistrable, EcoEnchantLike {
*/
val enchantmentKey: NamespacedKey
/**
* The enchantment.
*/
override var enchantment: Enchantment
/**
* If this enchantment conflicts with all other enchantments.
*/

View File

@@ -1,10 +1,10 @@
package com.willfp.ecoenchants.enchant.registration
import com.willfp.ecoenchants.enchant.EcoEnchant
import com.willfp.ecoenchants.enchant.impl.EcoEnchantBase
import org.bukkit.enchantments.Enchantment
interface EnchantmentRegisterer {
fun register(enchant: EcoEnchant): Enchantment
fun register(enchant: EcoEnchantBase): Enchantment
fun unregister(enchant: EcoEnchant)
fun unregister(enchant: EcoEnchantBase)
}

View File

@@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchant.registration.legacy
import com.willfp.eco.util.StringUtils
import com.willfp.ecoenchants.display.getFormattedName
import com.willfp.ecoenchants.enchant.EcoEnchant
import com.willfp.ecoenchants.enchant.impl.EcoEnchantBase
import com.willfp.ecoenchants.enchant.wrap
import io.papermc.paper.enchantments.EnchantmentRarity
import net.kyori.adventure.text.Component
@@ -14,7 +15,7 @@ import org.bukkit.inventory.ItemStack
@Suppress("DEPRECATION")
class LegacyDelegatedEnchantment(
private val enchant: EcoEnchant
private val enchant: EcoEnchantBase
) : Enchantment(enchant.enchantmentKey), EcoEnchant by enchant {
init {
enchant.enchantment = this

View File

@@ -1,6 +1,6 @@
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
@@ -36,7 +36,7 @@ object LegacyEnchantmentRegisterer : EnchantmentRegisterer {
Enchantment.registerEnchantment(enchantment)
}
override fun register(enchant: EcoEnchant): Enchantment {
override fun register(enchant: EcoEnchantBase): Enchantment {
val enchantment = LegacyDelegatedEnchantment(enchant)
Enchantment.registerEnchantment(enchantment)
@@ -44,7 +44,7 @@ object LegacyEnchantmentRegisterer : EnchantmentRegisterer {
return enchantment
}
override fun unregister(enchant: EcoEnchant) {
override fun unregister(enchant: EcoEnchantBase) {
Enchantment::class.java.getDeclaredField("byKey")
.apply {
isAccessible = true