Fixed nullpointer if lore is empty when using the item browser

This commit is contained in:
ASangarin 2020-12-20 01:56:59 +01:00
parent cf7fa29c81
commit fca3ead680

View File

@ -130,6 +130,23 @@ public class ItemBrowser extends PluginInventory {
}
NBTItem nbtItem = NBTItem.get(item);
ItemStack stack;
List<BaseComponent> lore = nbtItem.getLoreComponents();
if(lore == null) {
stack = nbtItem.toItem();
ItemMeta meta = stack.getItemMeta();
List<String> 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<BaseComponent> newLore = new ArrayList<>();
newLore.add(toComponent(""));
if (deleteMode) {
@ -148,11 +165,12 @@ public class ItemBrowser extends PluginInventory {
newLore.add(toComponent(ChatColor.YELLOW + AltChar.smallListDash + " Right click to edit this item."));
}
List<BaseComponent> lore = nbtItem.getLoreComponents();
lore.addAll(newLore);
nbtItem.setLoreComponents(lore);
stack = nbtItem.toItem();
}
cached.put(template.getId(), nbtItem.toItem());
cached.put(template.getId(), stack);
inv.setItem(slots[n++], cached.get(template.getId()));
}