From b8e1f338005eddf8d07814de2e948d20d3659693 Mon Sep 17 00:00:00 2001 From: tastybento Date: Tue, 7 May 2024 21:25:58 -0700 Subject: [PATCH] Fixes #2352 obsidian scooping NPE (#2358) --- .../flags/worldsettings/ObsidianScoopingListener.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/ObsidianScoopingListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/ObsidianScoopingListener.java index 0900d396a..25ac4051a 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/ObsidianScoopingListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/ObsidianScoopingListener.java @@ -17,6 +17,7 @@ import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; +import org.bukkit.util.RayTraceResult; import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.api.flags.FlagListener; @@ -68,12 +69,20 @@ public class ObsidianScoopingListener extends FlagListener { return lookForLava(e); } + /** + * @param e PlayerInteractEvent + * @return false if obsidian not scooped, true if scooped + */ private boolean lookForLava(PlayerInteractEvent e) { Player player = e.getPlayer(); ItemStack bucket = e.getItem(); // Get block player is looking at - Block b = e.getPlayer().rayTraceBlocks(5, FluidCollisionMode.ALWAYS).getHitBlock(); + RayTraceResult rtBlocks = e.getPlayer().rayTraceBlocks(5, FluidCollisionMode.ALWAYS); + if (rtBlocks == null) { + return false; + } + Block b = rtBlocks.getHitBlock(); if (!b.getType().equals(Material.OBSIDIAN)) { // This should not be needed but might catch some attempts return false;