From 3cdf4517a80253c419d6db94370c78a69edb37a4 Mon Sep 17 00:00:00 2001 From: Tobias Date: Thu, 5 Sep 2019 03:38:52 +0200 Subject: [PATCH] Fixed some black magic that occurred when a mob was summoned in a world that was loaded but didn't have a list entry that is supposed to be generated on world load. (#1618) --- .../bloodmagic/potion/PotionEventHandlers.java | 5 +++-- .../util/handler/event/GenericHandler.java | 12 ++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/WayofTime/bloodmagic/potion/PotionEventHandlers.java b/src/main/java/WayofTime/bloodmagic/potion/PotionEventHandlers.java index 18d12e9c..a2805904 100644 --- a/src/main/java/WayofTime/bloodmagic/potion/PotionEventHandlers.java +++ b/src/main/java/WayofTime/bloodmagic/potion/PotionEventHandlers.java @@ -3,6 +3,7 @@ package WayofTime.bloodmagic.potion; import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.core.RegistrarBloodMagic; import WayofTime.bloodmagic.event.SacrificeKnifeUsedEvent; +import com.google.common.collect.Lists; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.IProjectile; @@ -55,7 +56,7 @@ public class PotionEventHandlers { @SubscribeEvent public static void onEntityUpdate(LivingEvent.LivingUpdateEvent event) { EntityLivingBase eventEntityLiving = event.getEntityLiving(); - List flightList = flightListMap.get(eventEntityLiving.getEntityWorld()); + List flightList = flightListMap.getOrDefault(eventEntityLiving.getEntityWorld(), Lists.newArrayList()); if (eventEntityLiving instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) eventEntityLiving; @@ -91,7 +92,7 @@ public class PotionEventHandlers { // } // } // } - List noGravityList = noGravityListMap.get(event.getEntityLiving().getEntityWorld()); + List noGravityList = noGravityListMap.getOrDefault(event.getEntityLiving().getEntityWorld(), Lists.newArrayList()); if (eventEntityLiving.isPotionActive(RegistrarBloodMagic.SUSPENDED) && !eventEntityLiving.hasNoGravity()) { eventEntityLiving.setNoGravity(true); noGravityList.add(eventEntityLiving); diff --git a/src/main/java/WayofTime/bloodmagic/util/handler/event/GenericHandler.java b/src/main/java/WayofTime/bloodmagic/util/handler/event/GenericHandler.java index e2548df8..9a2c457d 100644 --- a/src/main/java/WayofTime/bloodmagic/util/handler/event/GenericHandler.java +++ b/src/main/java/WayofTime/bloodmagic/util/handler/event/GenericHandler.java @@ -555,11 +555,11 @@ public class GenericHandler { @SubscribeEvent public static void onWorldUnload(WorldEvent.Unload event) { World world = event.getWorld(); - bounceMapMap.getOrDefault(world, Collections.emptyMap()).clear(); - filledHandMapMap.getOrDefault(world, Collections.emptyMap()).clear(); - attackTaskMapMap.getOrDefault(world, Collections.emptyMap()).clear(); - targetTaskMapMap.getOrDefault(world, Collections.emptyMap()).clear(); - PotionEventHandlers.flightListMap.getOrDefault(world, Collections.emptyList()).clear(); - PotionEventHandlers.noGravityListMap.getOrDefault(world, Collections.emptyList()).clear(); + bounceMapMap.remove(world); + filledHandMapMap.remove(world); + attackTaskMapMap.remove(world); + targetTaskMapMap.remove(world); + PotionEventHandlers.flightListMap.remove(world); + PotionEventHandlers.noGravityListMap.remove(world); } }