From d08bfe8e05c2e44ad41b82b3a77464fe44648efe Mon Sep 17 00:00:00 2001 From: Genny Date: Sun, 14 Jun 2020 04:19:56 -0500 Subject: Fix nullptr exception on ray trace in damager --- src/main/java/dev/genbyte/sunfright/Damager.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/main/java/dev/genbyte/sunfright/Damager.java b/src/main/java/dev/genbyte/sunfright/Damager.java index 093dbb6..c3bbe44 100644 --- a/src/main/java/dev/genbyte/sunfright/Damager.java +++ b/src/main/java/dev/genbyte/sunfright/Damager.java @@ -78,15 +78,19 @@ public class Damager extends BukkitRunnable { public void run() { Location loc = player.getLocation(); World world = loc.getWorld(); - Block topBlock = player.getWorld().rayTraceBlocks( + RayTraceResult rtr = player.getWorld().rayTraceBlocks( loc, new Vector(0, 1, 0), world.getMaxHeight()-loc.getY() - ).getHitBlock(); + ); - if (topBlock.getLocation().getY() > player.getLocation().getY() - && topBlock.getType().equals(Material.BLACK_STAINED_GLASS)) { - return; + if (rtr != null) { + Block topBlock = rtr.getHitBlock(); + if (topBlock != null && topBlock.getLocation().getY() > player.getLocation().getY() + && topBlock.getType().equals(Material.BLACK_STAINED_GLASS) + ) { + return; + } } ItemStack helmet = player.getInventory().getHelmet(); -- cgit 1.4.1-3-g733a5