From 16321dd4ff2671db1295630ee8b024a857a0bda3 Mon Sep 17 00:00:00 2001 From: luisc Date: Sun, 6 Mar 2022 13:47:47 -0600 Subject: [PATCH] Added hasLore() function to ScriptItemStack Fixed getLore() null pointer error --- .../noppes/npcs/scripted/ScriptItemStack.java | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/main/java/noppes/npcs/scripted/ScriptItemStack.java b/src/main/java/noppes/npcs/scripted/ScriptItemStack.java index 23764c5c1..81fb082a0 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptItemStack.java +++ b/src/main/java/noppes/npcs/scripted/ScriptItemStack.java @@ -224,23 +224,33 @@ public class ScriptItemStack implements IItemStack { } public String[] getLore() { - NBTTagCompound compound = this.item.getTagCompound().getCompoundTag("display"); - if (compound != null && compound.func_150299_b("Lore") == 9) { - NBTTagList nbttaglist = compound.getTagList("Lore", 8); - if (nbttaglist.tagCount() < 1) { - return new String[0]; - } else { - List lore = new ArrayList(); + if (this.item.getTagCompound() != null) { + NBTTagCompound compound = this.item.getTagCompound().getCompoundTag("display"); + if(compound != null && compound.func_150299_b("Lore") == 9) { + NBTTagList nbttaglist = compound.getTagList("Lore", 8); + if (nbttaglist.tagCount() > 0) { + List lore = new ArrayList(); - for(int i = 0; i < nbttaglist.tagCount(); ++i) { - lore.add(nbttaglist.getStringTagAt(i)); + for (int i = 0; i < nbttaglist.tagCount(); ++i) { + lore.add(nbttaglist.getStringTagAt(i)); + } + + return (String[]) ((String[]) lore.toArray(new String[lore.size()])); } - - return (String[])((String[])lore.toArray(new String[lore.size()])); } - } else { - return new String[0]; } + return new String[0]; + } + + public boolean hasLore() { + if (this.item.getTagCompound() != null) { + NBTTagCompound compound = this.item.getTagCompound().getCompoundTag("display"); + if (compound != null && compound.func_150299_b("Lore") == 9) { + NBTTagList nbttaglist = compound.getTagList("Lore", 8); + return nbttaglist.tagCount() > 0; + } + } + return false; } public void setLore(String[] lore) {