mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
add superenchant bulk operation
This commit is contained in:
parent
a1984ad5b9
commit
8141232c46
2 changed files with 52 additions and 0 deletions
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -10,6 +10,7 @@ import org.bukkit.command.CommandSender
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent
|
import org.bukkit.event.inventory.InventoryClickEvent
|
||||||
import org.bukkit.plugin.RegisteredListener
|
import org.bukkit.plugin.RegisteredListener
|
||||||
import xyz.alexcrea.cuanvil.api.EnchantmentApi
|
import xyz.alexcrea.cuanvil.api.EnchantmentApi
|
||||||
|
import xyz.alexcrea.cuanvil.enchant.bulk.SuperEnchantBulkOperation
|
||||||
import xyz.alexcrea.cuanvil.enchant.wrapped.CASuperEnchantEnchantment
|
import xyz.alexcrea.cuanvil.enchant.wrapped.CASuperEnchantEnchantment
|
||||||
import java.util.logging.Level
|
import java.util.logging.Level
|
||||||
|
|
||||||
|
|
@ -28,6 +29,10 @@ class SuperEnchantDependency(override val plugin: SuperEnchants): GenericPluginD
|
||||||
}
|
}
|
||||||
field.setAccessible(true)
|
field.setAccessible(true)
|
||||||
|
|
||||||
|
val bulkOpperations = SuperEnchantBulkOperation(plugin)
|
||||||
|
EnchantmentApi.addBulkGet(bulkOpperations)
|
||||||
|
EnchantmentApi.addBulkClean(bulkOpperations)
|
||||||
|
|
||||||
enchManager = field.get(plugin) as EnchantManager
|
enchManager = field.get(plugin) as EnchantManager
|
||||||
overrideReloadCommand()
|
overrideReloadCommand()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue