Skip to content

Commit c6aca40

Browse files
authored
Check if anvil inventory slot items are present (#14)
2 parents a52f0d8 + ff8b997 commit c6aca40

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/main/java/pro/cloudnode/smp/enchantbookplus/event/PrepareAnvil.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
import org.bukkit.inventory.ItemStack;
1010
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
1111
import org.jetbrains.annotations.NotNull;
12+
import org.jetbrains.annotations.Nullable;
1213
import pro.cloudnode.smp.enchantbookplus.ConfigEnchantmentEntry;
1314
import pro.cloudnode.smp.enchantbookplus.EnchantBookPlus;
1415
import pro.cloudnode.smp.enchantbookplus.Permissions;
1516

1617
import java.util.HashMap;
1718
import java.util.Map;
18-
import java.util.Objects;
1919
import java.util.Optional;
2020

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

0 commit comments

Comments
 (0)