Skip to content

Commit

Permalink
🛠 Fix PrepareCraft event NPE (#4972)
Browse files Browse the repository at this point in the history
* Fix PrepareCraft NPE
  • Loading branch information
AyhamAl-Ali authored Aug 15, 2022
1 parent adb687d commit c311c8e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/java/ch/njol/skript/events/EvtItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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<ItemType>() {
@Override
public boolean check(final ItemType t) {
Expand Down

0 comments on commit c311c8e

Please sign in to comment.