From 268469f078d20ba08d4cd12122e4931dd8979d1f Mon Sep 17 00:00:00 2001 From: Tobias <23401986+Keraldi@users.noreply.github.com> Date: Tue, 5 Nov 2019 03:21:29 +0100 Subject: [PATCH] Fixes some possible NPEs in PotionEventHandler (#1668) * Fixes some possible NPEs in PotionEventHandler * Added Brackets for clarification * Update PotionEventHandlers.java --- .../potion/PotionEventHandlers.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/main/java/WayofTime/bloodmagic/potion/PotionEventHandlers.java b/src/main/java/WayofTime/bloodmagic/potion/PotionEventHandlers.java index a2805904..a79e3b1b 100644 --- a/src/main/java/WayofTime/bloodmagic/potion/PotionEventHandlers.java +++ b/src/main/java/WayofTime/bloodmagic/potion/PotionEventHandlers.java @@ -93,19 +93,25 @@ public class PotionEventHandlers { // } // } List<EntityLivingBase> noGravityList = noGravityListMap.getOrDefault(event.getEntityLiving().getEntityWorld(), Lists.newArrayList()); - if (eventEntityLiving.isPotionActive(RegistrarBloodMagic.SUSPENDED) && !eventEntityLiving.hasNoGravity()) { - eventEntityLiving.setNoGravity(true); - noGravityList.add(eventEntityLiving); - } else if (noGravityList.contains(eventEntityLiving)) { - eventEntityLiving.setNoGravity(false); - noGravityList.remove(eventEntityLiving); + if (noGravityList != null) { + if (eventEntityLiving.isPotionActive(RegistrarBloodMagic.SUSPENDED) && !eventEntityLiving.hasNoGravity()) { + eventEntityLiving.setNoGravity(true); + noGravityList.add(eventEntityLiving); + } else if (noGravityList.contains(eventEntityLiving)) { + eventEntityLiving.setNoGravity(false); + noGravityList.remove(eventEntityLiving); + } + } + + if (eventEntityLiving.isPotionActive(RegistrarBloodMagic.GROUNDED)) { + PotionEffect activeEffect = eventEntityLiving.getActivePotionEffect(RegistrarBloodMagic.GROUNDED); + if (activeEffect != null) { + if (eventEntityLiving instanceof EntityPlayer && ((EntityPlayer) eventEntityLiving).capabilities.isFlying) + eventEntityLiving.motionY -= (0.05D * (double) activeEffect.getAmplifier() + 1 - eventEntityLiving.motionY) * 0.2D; + else + eventEntityLiving.motionY -= (0.1D * (double) activeEffect.getAmplifier() + 1 - eventEntityLiving.motionY) * 0.2D; + } } - - if (eventEntityLiving.isPotionActive(RegistrarBloodMagic.GROUNDED)) - if (eventEntityLiving instanceof EntityPlayer && ((EntityPlayer) eventEntityLiving).capabilities.isFlying) - eventEntityLiving.motionY -= (0.05D * (double) (eventEntityLiving.getActivePotionEffect(RegistrarBloodMagic.GROUNDED).getAmplifier() + 1) - eventEntityLiving.motionY) * 0.2D; - else - eventEntityLiving.motionY -= (0.1D * (double) (eventEntityLiving.getActivePotionEffect(RegistrarBloodMagic.GROUNDED).getAmplifier() + 1) - eventEntityLiving.motionY) * 0.2D; if (eventEntityLiving.isPotionActive(RegistrarBloodMagic.WHIRLWIND)) { int d0 = 3;