From fe6257bb38c417c78dea9d2e1b229c32443c7b70 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+DoctorMacc@users.noreply.github.com> Date: Sat, 23 May 2020 21:16:11 -0400 Subject: [PATCH] Check if firework item explosions tag is null (#626) --- .../translators/nbt/FireworkTranslator.java | 66 ++++++++++--------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/FireworkTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/FireworkTranslator.java index 77e14e5a..849df3a4 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/FireworkTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/FireworkTranslator.java @@ -39,49 +39,51 @@ public class FireworkTranslator extends NbtItemStackTranslator { CompoundTag fireworks = itemTag.get("Fireworks"); ListTag explosions = fireworks.get("Explosions"); - for (Tag effect : explosions.getValue()) { - CompoundTag effectData = (CompoundTag) effect; + if (explosions != null) { + for (Tag effect : explosions.getValue()) { + CompoundTag effectData = (CompoundTag) effect; - CompoundTag newEffectData = new CompoundTag(""); + CompoundTag newEffectData = new CompoundTag(""); - if (effectData.get("Type") != null) { - newEffectData.put(new ByteTag("FireworkType", (Byte) effectData.get("Type").getValue())); - } - - if (effectData.get("Colors") != null) { - int[] oldColors = (int[]) effectData.get("Colors").getValue(); - byte[] colors = new byte[oldColors.length]; - - int i = 0; - for (int color : oldColors) { - colors[i++] = FireworkColor.fromJavaID(color).getBedrockID(); + if (effectData.get("Type") != null) { + newEffectData.put(new ByteTag("FireworkType", (Byte) effectData.get("Type").getValue())); } - newEffectData.put(new ByteArrayTag("FireworkColor", colors)); - } + if (effectData.get("Colors") != null) { + int[] oldColors = (int[]) effectData.get("Colors").getValue(); + byte[] colors = new byte[oldColors.length]; - if (effectData.get("FadeColors") != null) { - int[] oldColors = (int[]) effectData.get("FadeColors").getValue(); - byte[] colors = new byte[oldColors.length]; + int i = 0; + for (int color : oldColors) { + colors[i++] = FireworkColor.fromJavaID(color).getBedrockID(); + } - int i = 0; - for (int color : oldColors) { - colors[i++] = FireworkColor.fromJavaID(color).getBedrockID(); + newEffectData.put(new ByteArrayTag("FireworkColor", colors)); } - newEffectData.put(new ByteArrayTag("FireworkFade", colors)); - } + if (effectData.get("FadeColors") != null) { + int[] oldColors = (int[]) effectData.get("FadeColors").getValue(); + byte[] colors = new byte[oldColors.length]; - if (effectData.get("Trail") != null) { - newEffectData.put(new ByteTag("FireworkTrail", (Byte) effectData.get("Trail").getValue())); - } + int i = 0; + for (int color : oldColors) { + colors[i++] = FireworkColor.fromJavaID(color).getBedrockID(); + } - if (effectData.get("Flicker") != null) { - newEffectData.put(new ByteTag("FireworkFlicker", (Byte) effectData.get("Flicker").getValue())); - } + newEffectData.put(new ByteArrayTag("FireworkFade", colors)); + } - explosions.remove(effect); - explosions.add(newEffectData); + if (effectData.get("Trail") != null) { + newEffectData.put(new ByteTag("FireworkTrail", (Byte) effectData.get("Trail").getValue())); + } + + if (effectData.get("Flicker") != null) { + newEffectData.put(new ByteTag("FireworkFlicker", (Byte) effectData.get("Flicker").getValue())); + } + + explosions.remove(effect); + explosions.add(newEffectData); + } } }