add superenchant bulk operation

This commit is contained in:
alexcrea 2026-05-14 14:58:01 +02:00
parent a1984ad5b9
commit 8141232c46
Signed by: alexcrea
GPG key ID: E346CD16413450E3
2 changed files with 52 additions and 0 deletions

View file

@ -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<CAEnchantment, Integer> 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
}
}

View file

@ -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()