From fc792c930e41ce05c7fedb150e53e79ee02bad8b Mon Sep 17 00:00:00 2001 From: Sollace Date: Fri, 7 Oct 2022 16:51:46 +0200 Subject: [PATCH] Catch exceptions when deserialising spell nbt --- .../unicopia/ability/magic/spell/Spell.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/Spell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/Spell.java index f8b6808b..70763235 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/Spell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/Spell.java @@ -7,6 +7,7 @@ import java.util.stream.Stream; import org.jetbrains.annotations.Nullable; import org.spongepowered.include.com.google.common.base.Objects; +import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.ability.magic.Affine; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; @@ -107,14 +108,18 @@ public interface Spell extends NbtSerialisable, Affine { @Nullable static Spell readNbt(@Nullable NbtCompound compound) { - if (compound != null && compound.contains("effect_id")) { - Spell effect = SpellType.getKey(compound).withTraits().create(); + try { + if (compound != null && compound.contains("effect_id")) { + Spell effect = SpellType.getKey(compound).withTraits().create(); - if (effect != null) { - effect.fromNBT(compound); + if (effect != null) { + effect.fromNBT(compound); + } + + return effect; } - - return effect; + } catch (Exception e) { + Unicopia.LOGGER.fatal("Invalid spell nbt {}", e); } return null;