From d22ee51633159b314890eb8eadf95670d7deafe9 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Tue, 11 Apr 2023 13:15:17 -0400 Subject: [PATCH] Fix NPEs in CrossbowItem --- .../org/geysermc/geyser/item/type/CrossbowItem.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/item/type/CrossbowItem.java b/core/src/main/java/org/geysermc/geyser/item/type/CrossbowItem.java index c0f37086b..756cd69ba 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/CrossbowItem.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/CrossbowItem.java @@ -32,6 +32,7 @@ import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData; import org.geysermc.geyser.registry.type.ItemMapping; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.inventory.item.ItemTranslator; +import org.jetbrains.annotations.Nullable; public class CrossbowItem extends Item { public CrossbowItem(String javaIdentifier, Builder builder) { @@ -45,12 +46,12 @@ public class CrossbowItem extends Item { ListTag chargedProjectiles = tag.get("ChargedProjectiles"); if (chargedProjectiles != null) { if (!chargedProjectiles.getValue().isEmpty()) { - CompoundTag projectile = (CompoundTag) chargedProjectiles.getValue().get(0); + CompoundTag javaProjectileAsNbt = (CompoundTag) chargedProjectiles.getValue().get(0); - ItemMapping projectileMapping = session.getItemMappings().getMapping((String) projectile.get("id").getValue()); + ItemMapping projectileMapping = session.getItemMappings().getMapping((String) javaProjectileAsNbt.get("id").getValue()); if (projectileMapping == null) return; - CompoundTag projectileTag = projectile.get("tag"); - ItemStack itemStack = new ItemStack(projectileMapping.getJavaItem().javaId(), (byte) projectile.get("Count").getValue(), projectileTag); + @Nullable CompoundTag projectileTag = javaProjectileAsNbt.get("tag"); + ItemStack itemStack = new ItemStack(projectileMapping.getJavaItem().javaId(), (byte) javaProjectileAsNbt.get("Count").getValue(), projectileTag); ItemData itemData = ItemTranslator.translateToBedrock(session, itemStack); CompoundTag newProjectile = new CompoundTag("chargedItem"); @@ -59,7 +60,7 @@ public class CrossbowItem extends Item { newProjectile.put(new ShortTag("Damage", (short) itemData.getDamage())); - projectileTag.put(newProjectile); + tag.put(newProjectile); } } }