From fca3ead6806bc5b762b4da9be357a7232726a0bc Mon Sep 17 00:00:00 2001 From: ASangarin Date: Sun, 20 Dec 2020 01:56:59 +0100 Subject: [PATCH] Fixed nullpointer if lore is empty when using the item browser --- .../net/Indyuce/mmoitems/gui/ItemBrowser.java | 54 ++++++++++++------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/src/main/java/net/Indyuce/mmoitems/gui/ItemBrowser.java b/src/main/java/net/Indyuce/mmoitems/gui/ItemBrowser.java index 8c1c6aa0..8f2abf38 100644 --- a/src/main/java/net/Indyuce/mmoitems/gui/ItemBrowser.java +++ b/src/main/java/net/Indyuce/mmoitems/gui/ItemBrowser.java @@ -130,29 +130,47 @@ public class ItemBrowser extends PluginInventory { } NBTItem nbtItem = NBTItem.get(item); - List newLore = new ArrayList<>(); - newLore.add(toComponent("")); - if (deleteMode) { - newLore.add(toComponent(ChatColor.RED + AltChar.cross + " CLICK TO DELETE " + AltChar.cross)); + ItemStack stack; + List lore = nbtItem.getLoreComponents(); + if(lore == null) { + stack = nbtItem.toItem(); + ItemMeta meta = stack.getItemMeta(); + List newLore = meta.getLore(); + newLore.add(""); + if (deleteMode) { + newLore.add(ChatColor.RED + AltChar.cross + " CLICK TO DELETE " + AltChar.cross); + meta.setDisplayName(ChatColor.RED + "DELETE: " + meta.getDisplayName()); + } + newLore.add(ChatColor.YELLOW + AltChar.smallListDash + " Left click to obtain this item."); + newLore.add(ChatColor.YELLOW + AltChar.smallListDash + " Right click to edit this item."); + meta.setLore(newLore); + stack.setItemMeta(meta); + } + else { + List newLore = new ArrayList<>(); + newLore.add(toComponent("")); + if (deleteMode) { + newLore.add(toComponent(ChatColor.RED + AltChar.cross + " CLICK TO DELETE " + AltChar.cross)); - BaseComponent display = nbtItem.getDisplayNameComponent(); - if (display != null && display.getExtra() != null) { - List extra = new ArrayList<>(display.getExtra()); - extra.add(0, toComponent(ChatColor.RED + "DELETE: ")); - display.setExtra(extra); - nbtItem.setDisplayNameComponent(display); + BaseComponent display = nbtItem.getDisplayNameComponent(); + if (display != null && display.getExtra() != null) { + List extra = new ArrayList<>(display.getExtra()); + extra.add(0, toComponent(ChatColor.RED + "DELETE: ")); + display.setExtra(extra); + nbtItem.setDisplayNameComponent(display); + } + + } else { + newLore.add(toComponent(ChatColor.YELLOW + AltChar.smallListDash + " Left click to obtain this item.")); + newLore.add(toComponent(ChatColor.YELLOW + AltChar.smallListDash + " Right click to edit this item.")); } - } else { - newLore.add(toComponent(ChatColor.YELLOW + AltChar.smallListDash + " Left click to obtain this item.")); - newLore.add(toComponent(ChatColor.YELLOW + AltChar.smallListDash + " Right click to edit this item.")); + lore.addAll(newLore); + nbtItem.setLoreComponents(lore); + stack = nbtItem.toItem(); } - List lore = nbtItem.getLoreComponents(); - lore.addAll(newLore); - nbtItem.setLoreComponents(lore); - - cached.put(template.getId(), nbtItem.toItem()); + cached.put(template.getId(), stack); inv.setItem(slots[n++], cached.get(template.getId())); }