Put in null checks for item meta

https://github.com/BentoBoxWorld/BentoBox/issues/492
This commit is contained in:
tastybento 2019-01-30 17:37:16 -08:00
parent 8dbf7ec231
commit 791c8b1de1

View File

@ -31,6 +31,15 @@ public class PanelItem {
this.playerHead = playerHead; this.playerHead = playerHead;
// Get the meta // Get the meta
meta = icon.getItemMeta(); 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; this.clickHandler = clickHandler;
@ -39,13 +48,7 @@ public class PanelItem {
setDescription(description); setDescription(description);
setGlow(glow); 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() { public ItemStack getItem() {
@ -58,8 +61,10 @@ public class PanelItem {
public void setDescription(List<String> description) { public void setDescription(List<String> description) {
this.description = description; this.description = description;
meta.setLore(description); if (meta != null) {
icon.setItemMeta(meta); meta.setLore(description);
icon.setItemMeta(meta);
}
} }
public String getName() { public String getName() {
@ -68,9 +73,11 @@ public class PanelItem {
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
meta.setDisplayName(name); if (meta != null) {
meta.setLocalizedName(name); //Localized name cannot be overridden by the player using an anvils meta.setDisplayName(name);
icon.setItemMeta(meta); meta.setLocalizedName(name); //Localized name cannot be overridden by the player using an anvils
icon.setItemMeta(meta);
}
} }
public Optional<ClickHandler> getClickHandler() { public Optional<ClickHandler> getClickHandler() {
@ -83,7 +90,10 @@ public class PanelItem {
public void setGlow(boolean glow) { public void setGlow(boolean glow) {
this.glow = 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) { public void setHead(ItemStack itemStack) {
this.icon = itemStack; this.icon = itemStack;
// Get the meta // 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 // Create the final item
setName(name); setName(name);
setDescription(description); setDescription(description);
setGlow(glow); 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);
} }
} }