mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 08:14:00 +02:00
Register new enchantment on custom anvil reload.
This commit is contained in:
parent
e48eb95aa8
commit
851489068d
3 changed files with 37 additions and 3 deletions
|
|
@ -51,8 +51,8 @@ class ReloadExecutor : CommandExecutor {
|
|||
// temporary: handle 1.21 update
|
||||
Update_1_21.handleUpdate()
|
||||
|
||||
// Register enchantment of compatible plugin and load configuration change.
|
||||
DependencyManager.handleCompatibilityConfig()
|
||||
// Handle dependency reload
|
||||
DependencyManager.handleConfigReload()
|
||||
|
||||
// Call event
|
||||
val configReadyEvent = CAConfigReadyEvent()
|
||||
|
|
|
|||
|
|
@ -44,4 +44,13 @@ object DependencyManager {
|
|||
|
||||
}
|
||||
|
||||
fun handleConfigReload(){
|
||||
// Register enchantment of compatible plugin and load configuration change.
|
||||
handleCompatibilityConfig()
|
||||
|
||||
// Then handle plugin reload
|
||||
ecoEnchantCompatibility?.handleConfigReload()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package xyz.alexcrea.cuanvil.dependency
|
||||
|
||||
import com.willfp.ecoenchants.enchant.EcoEnchant
|
||||
import com.willfp.ecoenchants.enchant.EcoEnchants
|
||||
import io.delilaheve.CustomAnvil
|
||||
import org.bukkit.event.inventory.PrepareAnvilEvent
|
||||
|
|
@ -17,15 +18,39 @@ class EcoEnchantDependency(private val ecoEnchantPlugin: Plugin) {
|
|||
PrepareAnvilEvent.getHandlerList().unregister(this.ecoEnchantPlugin)
|
||||
}
|
||||
|
||||
private var ecoEnchantOldEnchantments: MutableSet<EcoEnchant>? = null
|
||||
fun registerEnchantments() {
|
||||
CustomAnvil.instance.logger.info("Preparing Eco Enchant compatibility...")
|
||||
|
||||
for (ecoEnchant in EcoEnchants.values()) {
|
||||
val enchantments = EcoEnchants.values()
|
||||
for (ecoEnchant in enchantments) {
|
||||
EnchantmentApi.unregisterEnchantment(ecoEnchant.enchantment) // As eco enchants is loaded before custom anvil and register enchantment to registry, we need to unregister old "vanilla" enchant.
|
||||
EnchantmentApi.registerEnchantment(CAEcoEnchant(ecoEnchant))
|
||||
}
|
||||
|
||||
ecoEnchantOldEnchantments = HashSet(enchantments)
|
||||
|
||||
CustomAnvil.instance.logger.info("Eco Enchant should now work as expected !")
|
||||
}
|
||||
|
||||
fun handleConfigReload() {
|
||||
// Should not happen in known case.
|
||||
if(this.ecoEnchantOldEnchantments == null) return
|
||||
|
||||
val newEnchantments = EcoEnchants.values()
|
||||
|
||||
// Add new enchantments
|
||||
for (ecoEnchant in newEnchantments)
|
||||
if(!this.ecoEnchantOldEnchantments!!.contains(ecoEnchant))
|
||||
EnchantmentApi.registerEnchantment(CAEcoEnchant(ecoEnchant))
|
||||
|
||||
// Remove old enchantments that not now currently used
|
||||
this.ecoEnchantOldEnchantments!!.removeAll(newEnchantments)
|
||||
for (oldEnchantment in this.ecoEnchantOldEnchantments!!) {
|
||||
EnchantmentApi.unregisterEnchantment(oldEnchantment.enchantment)
|
||||
}
|
||||
|
||||
this.ecoEnchantOldEnchantments = HashSet(newEnchantments)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue