From 8141232c4675d8adfd814843f1e3661106a810e6 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Thu, 14 May 2026 14:58:01 +0200 Subject: [PATCH] add superenchant bulk operation --- .../bulk/SuperEnchantBulkOperation.java | 47 +++++++++++++++++++ .../plugins/SuperEnchantDependency.kt | 5 ++ 2 files changed, 52 insertions(+) create mode 100644 src/main/java/xyz/alexcrea/cuanvil/enchant/bulk/SuperEnchantBulkOperation.java diff --git a/src/main/java/xyz/alexcrea/cuanvil/enchant/bulk/SuperEnchantBulkOperation.java b/src/main/java/xyz/alexcrea/cuanvil/enchant/bulk/SuperEnchantBulkOperation.java new file mode 100644 index 0000000..8bc729a --- /dev/null +++ b/src/main/java/xyz/alexcrea/cuanvil/enchant/bulk/SuperEnchantBulkOperation.java @@ -0,0 +1,47 @@ +package xyz.alexcrea.cuanvil.enchant.bulk; + +import com.maddoxh.superEnchants.items.EnchantApplicator; +import com.maddoxh.superEnchants.items.EnchantReader; +import io.delilaheve.CustomAnvil; +import org.bukkit.NamespacedKey; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; +import xyz.alexcrea.cuanvil.api.EnchantmentApi; +import xyz.alexcrea.cuanvil.enchant.CAEnchantment; + +import java.util.Map; + +public class SuperEnchantBulkOperation implements BulkGetEnchantOperation, BulkCleanEnchantOperation { + + private Plugin plugin; + public SuperEnchantBulkOperation(Plugin plugin) { + this.plugin = plugin; + } + + @Override + public void bulkGet(@NotNull Map enchantmentMap, @NotNull ItemStack item, @NotNull ItemMeta meta) { + EnchantReader.INSTANCE.readEnchants(item).forEach((ench, level) -> { + var enchantment = EnchantmentApi.getByKey(NamespacedKey.fromString(ench, plugin)); + if(enchantment == null) { + CustomAnvil.log("Enchantment " + ench + " not found in custom anvil"); + return; + } + + enchantmentMap.put(enchantment, level); + } + ); + } + + @Override + public void bulkClear(@NotNull ItemStack item) { + EnchantApplicator.INSTANCE.clearAllCustomEnchants(item); + } + + @Override + public void bulkClear(@NotNull ItemStack item, @NotNull ItemMeta meta) { + // item meta is not preferred for enchantment squared clear + } + +} diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/SuperEnchantDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/SuperEnchantDependency.kt index 2135e78..11622f9 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/SuperEnchantDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/SuperEnchantDependency.kt @@ -10,6 +10,7 @@ import org.bukkit.command.CommandSender import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.plugin.RegisteredListener import xyz.alexcrea.cuanvil.api.EnchantmentApi +import xyz.alexcrea.cuanvil.enchant.bulk.SuperEnchantBulkOperation import xyz.alexcrea.cuanvil.enchant.wrapped.CASuperEnchantEnchantment import java.util.logging.Level @@ -28,6 +29,10 @@ class SuperEnchantDependency(override val plugin: SuperEnchants): GenericPluginD } field.setAccessible(true) + val bulkOpperations = SuperEnchantBulkOperation(plugin) + EnchantmentApi.addBulkGet(bulkOpperations) + EnchantmentApi.addBulkClean(bulkOpperations) + enchManager = field.get(plugin) as EnchantManager overrideReloadCommand()