mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-24 00:26:16 +02:00
Add null safty for enchantment not registered and add option to ignore registered enchantment warning
This commit is contained in:
parent
050da6da5b
commit
6c02b0a09b
2 changed files with 21 additions and 3 deletions
|
|
@ -5,6 +5,7 @@ import org.bukkit.NamespacedKey;
|
|||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.enchant.bulk.BukkitEnchantBulkOperation;
|
||||
import xyz.alexcrea.cuanvil.enchant.bulk.BulkCleanEnchantOperation;
|
||||
import xyz.alexcrea.cuanvil.enchant.bulk.BulkGetEnchantOperation;
|
||||
|
|
@ -80,6 +81,10 @@ public class CAEnchantmentRegistry {
|
|||
return false;
|
||||
}
|
||||
|
||||
if(ConfigHolder.DEFAULT_CONFIG.getConfig().getBoolean("caution_secret_do_not_log_duplicated_registered_key", false)){
|
||||
return false;
|
||||
}
|
||||
|
||||
CustomAnvil.instance.getLogger().log(Level.WARNING,
|
||||
"Duplicate distinct registered enchantment. This should NOT happen any time.\n" +
|
||||
"If you are a custom anvil developer: Maybe custom anvil detected your enchantment as a bukkit enchantment. " +
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package xyz.alexcrea.cuanvil.enchant.bulk;
|
||||
|
||||
import io.delilaheve.CustomAnvil;
|
||||
import io.delilaheve.util.ItemUtil;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
|
@ -16,16 +18,27 @@ public class BukkitEnchantBulkOperation implements BulkGetEnchantOperation, Bulk
|
|||
@Override
|
||||
public void bulkGet(@NotNull Map<CAEnchantment, Integer> enchantmentMap, @NotNull ItemStack item, @NotNull ItemMeta meta) {
|
||||
if (ItemUtil.INSTANCE.isEnchantedBook(item)) {
|
||||
((EnchantmentStorageMeta)meta).getStoredEnchants().forEach((enchantment, level) ->
|
||||
enchantmentMap.put(EnchantmentApi.getByKey(enchantment.getKey()), level)
|
||||
((EnchantmentStorageMeta) meta).getStoredEnchants().forEach((enchantment, level) ->
|
||||
addEnchantment(enchantmentMap, enchantment, level)
|
||||
);
|
||||
} else {
|
||||
item.getEnchantments().forEach((enchantment, level) ->
|
||||
enchantmentMap.put(EnchantmentApi.getByKey(enchantment.getKey()), level)
|
||||
addEnchantment(enchantmentMap, enchantment, level)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public void addEnchantment(@NotNull Map<CAEnchantment, Integer> enchantmentMap, @NotNull Enchantment enchantment, int level) {
|
||||
CAEnchantment enchant = EnchantmentApi.getByKey(enchantment.getKey());
|
||||
if (enchant == null) {
|
||||
CustomAnvil.instance.getLogger().warning("Enchantment of key " + enchantment.getKey() +
|
||||
" somehow not found in CustomAnvil ?");
|
||||
return;
|
||||
}
|
||||
|
||||
enchantmentMap.put(enchant, level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bulkClear(@NotNull ItemStack item) {
|
||||
if (item.getType() != Material.ENCHANTED_BOOK) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue