mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-21 14:55:17 +01:00
Registration improvements
This commit is contained in:
parent
80792b8ae1
commit
250607ecb2
@ -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<NamespacedKey, org.bukkit.enchantments.Enchantment>).apply { remove(key) }
|
||||
}
|
||||
|
||||
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byName")
|
||||
.apply {
|
||||
isAccessible = true
|
||||
(get(null) as MutableMap<String, org.bukkit.enchantments.Enchantment>).apply { remove(name) }
|
||||
}
|
||||
|
||||
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("acceptingNew")
|
||||
.apply {
|
||||
isAccessible = true
|
||||
set(null, true)
|
||||
}
|
||||
|
||||
org.bukkit.enchantments.Enchantment.registerEnchantment(this)
|
||||
}
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<NamespacedKey, org.bukkit.enchantments.Enchantment>).apply { remove(key) }
|
||||
}
|
||||
|
||||
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byName")
|
||||
.apply {
|
||||
isAccessible = true
|
||||
(get(null) as MutableMap<String, org.bukkit.enchantments.Enchantment>).apply { remove(name) }
|
||||
}
|
||||
|
||||
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("acceptingNew")
|
||||
.apply {
|
||||
isAccessible = true
|
||||
set(null, true)
|
||||
}
|
||||
|
||||
org.bukkit.enchantments.Enchantment.registerEnchantment(this)
|
||||
}
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<NamespacedKey, org.bukkit.enchantments.Enchantment>).apply { remove(key) }
|
||||
}
|
||||
|
||||
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byName")
|
||||
.apply {
|
||||
isAccessible = true
|
||||
(get(null) as MutableMap<String, org.bukkit.enchantments.Enchantment>).apply { remove(name) }
|
||||
}
|
||||
|
||||
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("acceptingNew")
|
||||
.apply {
|
||||
isAccessible = true
|
||||
set(null, true)
|
||||
}
|
||||
|
||||
org.bukkit.enchantments.Enchantment.registerEnchantment(this)
|
||||
}
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<NamespacedKey, org.bukkit.enchantments.Enchantment>).apply { remove(key) }
|
||||
}
|
||||
|
||||
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byName")
|
||||
.apply {
|
||||
isAccessible = true
|
||||
(get(null) as MutableMap<String, org.bukkit.enchantments.Enchantment>).apply { remove(name) }
|
||||
}
|
||||
|
||||
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("acceptingNew")
|
||||
.apply {
|
||||
isAccessible = true
|
||||
set(null, true)
|
||||
}
|
||||
|
||||
org.bukkit.enchantments.Enchantment.registerEnchantment(this)
|
||||
}
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<NamespacedKey, org.bukkit.enchantments.Enchantment>).apply { remove(key) }
|
||||
}
|
||||
|
||||
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byName")
|
||||
.apply {
|
||||
isAccessible = true
|
||||
(get(null) as MutableMap<String, org.bukkit.enchantments.Enchantment>).apply { remove(name) }
|
||||
}
|
||||
|
||||
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("acceptingNew")
|
||||
.apply {
|
||||
isAccessible = true
|
||||
set(null, true)
|
||||
}
|
||||
|
||||
org.bukkit.enchantments.Enchantment.registerEnchantment(this)
|
||||
}
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<NamespacedKey, org.bukkit.enchantments.Enchantment>).apply { remove(key) }
|
||||
}
|
||||
|
||||
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byName")
|
||||
.apply {
|
||||
isAccessible = true
|
||||
(get(null) as MutableMap<String, org.bukkit.enchantments.Enchantment>).apply { remove(name) }
|
||||
}
|
||||
|
||||
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("acceptingNew")
|
||||
.apply {
|
||||
isAccessible = true
|
||||
set(null, true)
|
||||
}
|
||||
|
||||
org.bukkit.enchantments.Enchantment.registerEnchantment(this)
|
||||
}
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<NamespacedKey, org.bukkit.enchantments.Enchantment>).apply { remove(key) }
|
||||
}
|
||||
|
||||
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byName")
|
||||
.apply {
|
||||
isAccessible = true
|
||||
(get(null) as MutableMap<String, org.bukkit.enchantments.Enchantment>).apply { remove(name) }
|
||||
}
|
||||
|
||||
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("acceptingNew")
|
||||
.apply {
|
||||
isAccessible = true
|
||||
set(null, true)
|
||||
}
|
||||
|
||||
org.bukkit.enchantments.Enchantment.registerEnchantment(this)
|
||||
}
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<NamespacedKey, org.bukkit.enchantments.Enchantment>).apply { remove(key) }
|
||||
}
|
||||
|
||||
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byName")
|
||||
.apply {
|
||||
isAccessible = true
|
||||
(get(null) as MutableMap<String, org.bukkit.enchantments.Enchantment>).apply { remove(name) }
|
||||
}
|
||||
|
||||
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("acceptingNew")
|
||||
.apply {
|
||||
isAccessible = true
|
||||
set(null, true)
|
||||
}
|
||||
|
||||
org.bukkit.enchantments.Enchantment.registerEnchantment(this)
|
||||
}
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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<EquipmentSlot>()
|
||||
|
||||
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)"
|
||||
}
|
||||
}
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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<NamespacedKey, Enchantment>).apply { remove(enchantment.key) }
|
||||
}
|
||||
|
||||
Enchantment::class.java.getDeclaredField("byName")
|
||||
.apply {
|
||||
isAccessible = true
|
||||
@Suppress("DEPRECATION")
|
||||
(get(null) as MutableMap<String, Enchantment>).apply { remove(enchantment.name) }
|
||||
}
|
||||
|
||||
Enchantment.registerEnchantment(enchantment)
|
||||
}
|
||||
|
||||
override fun register(enchant: EcoEnchant): Enchantment {
|
||||
val enchantment = LegacyDelegatedEnchantment(enchant)
|
||||
|
||||
Enchantment.registerEnchantment(enchantment)
|
||||
|
Loading…
Reference in New Issue
Block a user