Use Bulk operation object for bukkit and enchantment² enchants.

This commit is contained in:
alexcrea 2024-07-11 16:19:10 +02:00
parent d3252eecbd
commit b89a8951b7
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
5 changed files with 73 additions and 40 deletions

View file

@ -116,7 +116,7 @@ class CustomAnvil : JavaPlugin() {
if (!ConfigHolder.loadDefaultConfig()) return
// Register enchantments
CAEnchantmentRegistry.getInstance().registerStartupEnchantments()
CAEnchantmentRegistry.getInstance().registerBukkit()
DependencyManager.registerEnchantments()
val enchantReadyEvent = CAEnchantRegistryReadyEvent()

View file

@ -13,6 +13,7 @@ import xyz.alexcrea.cuanvil.api.EnchantmentApi
import xyz.alexcrea.cuanvil.api.MaterialGroupApi
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry
import xyz.alexcrea.cuanvil.enchant.bulk.EnchantSquaredBulkOperation
import xyz.alexcrea.cuanvil.enchant.wrapped.CAEnchantSquaredEnchantment
import xyz.alexcrea.cuanvil.group.IncludeGroup
import java.util.*
@ -36,10 +37,17 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin)
fun registerEnchantments(){
CustomAnvil.instance.logger.info("Preparing Enchantment Squared compatibility...")
// Register enchantments
for (enchant in CustomEnchantManager.getInstance().allEnchants.values) {
EnchantmentApi.registerEnchantment(CAEnchantSquaredEnchantment(enchant))
}
// Register bulk operation
val bulkOpperations = EnchantSquaredBulkOperation()
EnchantmentApi.addBulkGet(bulkOpperations)
EnchantmentApi.addBulkClean(bulkOpperations)
}
fun getEnchantmentsSquared(item: ItemStack, enchantments: MutableMap<CAEnchantment, Int>) {
@ -51,10 +59,6 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin)
}
fun clearEnchantments(item: ItemStack) {
CustomEnchantManager.getInstance().removeAllEnchants(item)
}
fun getKeyFromEnchant(enchant: CustomEnchant): NamespacedKey{
return NamespacedKey.fromString(enchant.type.lowercase(Locale.getDefault()), this.enchantmentSquaredPlugin)!!
}