From 485ba1b8a733320f0cce877a28cf1387f591cee0 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sat, 11 Jul 2020 21:58:12 +0100 Subject: [PATCH] Check the name tag exists for anvil renaming to prevent an NPE (#936) * Check the name tag exists for anvil renaming to prevent an NPE * Fix item names being empty if display tag exists with no name --- .../network/translators/inventory/AnvilInventoryTranslator.java | 2 +- .../connector/network/translators/item/ItemTranslator.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/AnvilInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/AnvilInventoryTranslator.java index c780038a..d0d3db88 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/AnvilInventoryTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/AnvilInventoryTranslator.java @@ -136,7 +136,7 @@ public class AnvilInventoryTranslator extends BlockInventoryTranslator { CompoundTag tag = item.getNbt(); if (tag != null) { CompoundTag displayTag = tag.get("display"); - if (displayTag != null) { + if (displayTag != null && displayTag.contains("Name")) { String itemName = displayTag.get("Name").getValue().toString(); TextMessage message = (TextMessage) MessageSerializer.fromString(itemName); rename = message.getText(); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java index e28e8b0c..01107a3d 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java @@ -157,7 +157,7 @@ public abstract class ItemTranslator { NbtMap tag = itemData.getTag(); if (tag != null) { NbtMap display = tag.getCompound("display"); - if (display != null && !display.isEmpty()) { + if (display != null && !display.isEmpty() && display.containsKey("Name")) { String name = display.getString("Name"); // If its not a message convert it