Catch exceptions when deserialising spell nbt

This commit is contained in:
Sollace 2022-10-07 16:51:46 +02:00
parent 4a73cae094
commit fc792c930e

View file

@ -7,6 +7,7 @@ import java.util.stream.Stream;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.spongepowered.include.com.google.common.base.Objects; 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.Affine;
import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.Caster;
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
@ -107,14 +108,18 @@ public interface Spell extends NbtSerialisable, Affine {
@Nullable @Nullable
static Spell readNbt(@Nullable NbtCompound compound) { static Spell readNbt(@Nullable NbtCompound compound) {
if (compound != null && compound.contains("effect_id")) { try {
Spell effect = SpellType.getKey(compound).withTraits().create(); if (compound != null && compound.contains("effect_id")) {
Spell effect = SpellType.getKey(compound).withTraits().create();
if (effect != null) { if (effect != null) {
effect.fromNBT(compound); effect.fromNBT(compound);
}
return effect;
} }
} catch (Exception e) {
return effect; Unicopia.LOGGER.fatal("Invalid spell nbt {}", e);
} }
return null; return null;