Skip to content

Commit

Permalink
Check if anvil inventory slot items are present (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
zefir-git authored Jul 8, 2024
2 parents a52f0d8 + ff8b997 commit c6aca40
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import pro.cloudnode.smp.enchantbookplus.ConfigEnchantmentEntry;
import pro.cloudnode.smp.enchantbookplus.EnchantBookPlus;
import pro.cloudnode.smp.enchantbookplus.Permissions;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

public final class PrepareAnvil implements Listener {
Expand All @@ -24,8 +24,10 @@ public void onPrepareAnvil(final @NotNull PrepareAnvilEvent event) {
final @NotNull Optional<@NotNull ItemStack> result = Optional.ofNullable(event.getResult());
if (result.isEmpty()) return;
final @NotNull AnvilInventory inventory = event.getInventory();
final @NotNull ItemStack item = Objects.requireNonNull(inventory.getItem(0));
final @NotNull ItemStack upgrade = Objects.requireNonNull(inventory.getItem(1));
final @Nullable ItemStack item = inventory.getItem(0);
if (item == null) return;
final @Nullable ItemStack upgrade = inventory.getItem(1);
if (upgrade == null) return;
final @NotNull Map<@NotNull Enchantment, @NotNull Integer> itemEnchants =
item.getType() == Material.ENCHANTED_BOOK && item.getItemMeta() instanceof final @NotNull EnchantmentStorageMeta itemMeta ?
itemMeta.getStoredEnchants() : item.getEnchantments();
Expand Down

0 comments on commit c6aca40

Please sign in to comment.