Fixes #2352 obsidian scooping NPE (#2358)

This commit is contained in:
tastybento 2024-05-07 21:25:58 -07:00 committed by GitHub
parent d8891796cd
commit b8e1f33800
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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;