From c311c8ea6d1fd6a574305a0698631f1b942b6f33 Mon Sep 17 00:00:00 2001 From: Ayham Al Ali Date: Tue, 16 Aug 2022 01:55:51 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=20Fix=20PrepareCraft=20event=20NPE?= =?UTF-8?q?=20(#4972)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix PrepareCraft NPE --- src/main/java/ch/njol/skript/events/EvtItem.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/events/EvtItem.java b/src/main/java/ch/njol/skript/events/EvtItem.java index 5e82cfb297c..6524af3f2c7 100644 --- a/src/main/java/ch/njol/skript/events/EvtItem.java +++ b/src/main/java/ch/njol/skript/events/EvtItem.java @@ -32,6 +32,7 @@ import org.bukkit.event.player.PlayerItemConsumeEvent; import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.Recipe; import org.eclipse.jdt.annotation.Nullable; import ch.njol.skript.Skript; @@ -151,7 +152,13 @@ public boolean check(final Event e) { } else if (e instanceof CraftItemEvent) { is = ((CraftItemEvent) e).getRecipe().getResult(); } else if (hasPrepareCraftEvent && e instanceof PrepareItemCraftEvent) { - is = ((PrepareItemCraftEvent) e).getRecipe().getResult(); + PrepareItemCraftEvent event = (PrepareItemCraftEvent) e; + Recipe recipe = event.getRecipe(); + if (recipe != null) { + is = recipe.getResult(); + } else { + return false; + } } else if (e instanceof EntityPickupItemEvent) { is = ((EntityPickupItemEvent) e).getItem().getItemStack(); } else if (e instanceof PlayerPickupItemEvent) { @@ -170,6 +177,10 @@ public boolean check(final Event e) { assert false; return false; } + + if (is == null) + return false; + return types.check(e, new Checker() { @Override public boolean check(final ItemType t) {