Skip to content

Commit

Permalink
Fix NPE from not handling null in of PotionExpiryEvent and PotionRemo…
Browse files Browse the repository at this point in the history
…veEvent
  • Loading branch information
Alan19 committed Jan 19, 2020
1 parent 54b737d commit b42b24a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

version = '0.6.3'
version = '0.6.5'
group = 'com.alan199921.astral' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'astral'

Expand Down
17 changes: 10 additions & 7 deletions src/main/java/com/alan199921/astral/events/TravelingHandlers.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.alan199921.astral.dimensions.AstralDimensions;
import com.alan199921.astral.dimensions.TeleportationTools;
import com.alan199921.astral.effects.AstralEffects;
import com.alan199921.astral.effects.AstralTravelEffect;
import com.alan199921.astral.entities.AstralEntityRegistry;
import com.alan199921.astral.entities.PhysicalBodyEntity;
import com.alan199921.astral.flight.FlightHandler;
Expand All @@ -21,7 +22,6 @@
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Effect;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MovementInput;
import net.minecraft.util.NonNullList;
Expand Down Expand Up @@ -141,23 +141,26 @@ public static void renderAstralEntities(RenderLivingEvent event) {

@SubscribeEvent
public static void travelEffectExpire(PotionEvent.PotionExpiryEvent event) {
handleAstralEffectEnd(event.getPotionEffect().getPotion(), event.getEntityLiving());
if (event.getPotionEffect() != null && event.getPotionEffect().getPotion() instanceof AstralTravelEffect) {
handleAstralEffectEnd(event.getEntityLiving());
}
}

@SubscribeEvent
public static void travelEffectRemove(PotionEvent.PotionRemoveEvent event) {
handleAstralEffectEnd(event.getPotionEffect().getPotion(), event.getEntityLiving());
if (event.getPotionEffect() != null && event.getPotionEffect().getPotion() instanceof AstralTravelEffect) {
handleAstralEffectEnd(event.getEntityLiving());
}
}

/**
* When the Astral Travel potion effect ends, remove the player's flying abilities, teleport them to the body,
* transfer the body's inventory into the player's inventory, and then kill it.
*
* @param potionEffect The potion effect that is ending
* @param entityLiving The entity that with the potion effect
*/
private static void handleAstralEffectEnd(Effect potionEffect, LivingEntity entityLiving) {
if (potionEffect.equals(AstralEffects.ASTRAL_TRAVEL) && entityLiving instanceof PlayerEntity) {
private static void handleAstralEffectEnd(LivingEntity entityLiving) {
if (entityLiving instanceof PlayerEntity) {
PlayerEntity playerEntity = (PlayerEntity) entityLiving;
playerEntity.getAttribute(LivingEntity.ENTITY_GRAVITY).removeModifier(astralGravity);
//Only run serverside
Expand Down Expand Up @@ -188,7 +191,7 @@ private static void handleAstralEffectEnd(Effect potionEffect, LivingEntity enti
});
}
}
if (potionEffect.equals(AstralEffects.ASTRAL_TRAVEL) && !entityLiving.getEntityWorld().isRemote()) {
if (!entityLiving.getEntityWorld().isRemote()) {
AstralNetwork.sendAstralEffectEnding(entityLiving);
}
}
Expand Down

1 comment on commit b42b24a

@Alan19
Copy link
Collaborator Author

@Alan19 Alan19 commented on b42b24a Jan 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closes #52

Please sign in to comment.