From 791c8b1de1f11eb0bdf7311ce01aca6487aa79d9 Mon Sep 17 00:00:00 2001 From: tastybento Date: Wed, 30 Jan 2019 17:37:16 -0800 Subject: [PATCH] Put in null checks for item meta https://github.com/BentoBoxWorld/BentoBox/issues/492 --- .../bentobox/api/panels/PanelItem.java | 53 +++++++++++-------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/api/panels/PanelItem.java b/src/main/java/world/bentobox/bentobox/api/panels/PanelItem.java index 012d3f18f..433b81966 100644 --- a/src/main/java/world/bentobox/bentobox/api/panels/PanelItem.java +++ b/src/main/java/world/bentobox/bentobox/api/panels/PanelItem.java @@ -31,6 +31,15 @@ public class PanelItem { this.playerHead = playerHead; // Get the meta meta = icon.getItemMeta(); + if (meta != null) { + // Set flags to neaten up the view + meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); + meta.addItemFlags(ItemFlag.HIDE_DESTROYS); + meta.addItemFlags(ItemFlag.HIDE_PLACED_ON); + meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); + meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS); + icon.setItemMeta(meta); + } this.clickHandler = clickHandler; @@ -39,13 +48,7 @@ public class PanelItem { setDescription(description); setGlow(glow); - // Set flags to neaten up the view - meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); - meta.addItemFlags(ItemFlag.HIDE_DESTROYS); - meta.addItemFlags(ItemFlag.HIDE_PLACED_ON); - meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); - meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS); - icon.setItemMeta(meta); + } public ItemStack getItem() { @@ -58,8 +61,10 @@ public class PanelItem { public void setDescription(List description) { this.description = description; - meta.setLore(description); - icon.setItemMeta(meta); + if (meta != null) { + meta.setLore(description); + icon.setItemMeta(meta); + } } public String getName() { @@ -68,9 +73,11 @@ public class PanelItem { public void setName(String name) { this.name = name; - meta.setDisplayName(name); - meta.setLocalizedName(name); //Localized name cannot be overridden by the player using an anvils - icon.setItemMeta(meta); + if (meta != null) { + meta.setDisplayName(name); + meta.setLocalizedName(name); //Localized name cannot be overridden by the player using an anvils + icon.setItemMeta(meta); + } } public Optional getClickHandler() { @@ -83,7 +90,10 @@ public class PanelItem { public void setGlow(boolean glow) { this.glow = glow; - meta.addEnchant(Enchantment.ARROW_DAMAGE, 0, glow); + if (meta != null) { + meta.addEnchant(Enchantment.ARROW_DAMAGE, 0, glow); + icon.setItemMeta(meta); + } } /** @@ -112,17 +122,18 @@ public class PanelItem { public void setHead(ItemStack itemStack) { this.icon = itemStack; // Get the meta - meta = icon.getItemMeta(); + if (icon.hasItemMeta()) { + meta = icon.getItemMeta(); + // Set flags to neaten up the view + meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); + meta.addItemFlags(ItemFlag.HIDE_DESTROYS); + meta.addItemFlags(ItemFlag.HIDE_PLACED_ON); + meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); + icon.setItemMeta(meta); + } // Create the final item setName(name); setDescription(description); setGlow(glow); - - // Set flags to neaten up the view - meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); - meta.addItemFlags(ItemFlag.HIDE_DESTROYS); - meta.addItemFlags(ItemFlag.HIDE_PLACED_ON); - meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); - icon.setItemMeta(meta); } }