mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-28 05:35:44 +01:00
Put in null checks for item meta
https://github.com/BentoBoxWorld/BentoBox/issues/492
This commit is contained in:
parent
8dbf7ec231
commit
791c8b1de1
@ -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,9 +61,11 @@ public class PanelItem {
|
|||||||
|
|
||||||
public void setDescription(List<String> description) {
|
public void setDescription(List<String> description) {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
|
if (meta != null) {
|
||||||
meta.setLore(description);
|
meta.setLore(description);
|
||||||
icon.setItemMeta(meta);
|
icon.setItemMeta(meta);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
@ -68,10 +73,12 @@ public class PanelItem {
|
|||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
if (meta != null) {
|
||||||
meta.setDisplayName(name);
|
meta.setDisplayName(name);
|
||||||
meta.setLocalizedName(name); //Localized name cannot be overridden by the player using an anvils
|
meta.setLocalizedName(name); //Localized name cannot be overridden by the player using an anvils
|
||||||
icon.setItemMeta(meta);
|
icon.setItemMeta(meta);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Optional<ClickHandler> getClickHandler() {
|
public Optional<ClickHandler> getClickHandler() {
|
||||||
return Optional.ofNullable(clickHandler);
|
return Optional.ofNullable(clickHandler);
|
||||||
@ -83,7 +90,10 @@ public class PanelItem {
|
|||||||
|
|
||||||
public void setGlow(boolean glow) {
|
public void setGlow(boolean glow) {
|
||||||
this.glow = glow;
|
this.glow = glow;
|
||||||
|
if (meta != null) {
|
||||||
meta.addEnchant(Enchantment.ARROW_DAMAGE, 0, glow);
|
meta.addEnchant(Enchantment.ARROW_DAMAGE, 0, glow);
|
||||||
|
icon.setItemMeta(meta);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -112,12 +122,8 @@ 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
|
||||||
|
if (icon.hasItemMeta()) {
|
||||||
meta = icon.getItemMeta();
|
meta = icon.getItemMeta();
|
||||||
// Create the final item
|
|
||||||
setName(name);
|
|
||||||
setDescription(description);
|
|
||||||
setGlow(glow);
|
|
||||||
|
|
||||||
// Set flags to neaten up the view
|
// Set flags to neaten up the view
|
||||||
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||||
meta.addItemFlags(ItemFlag.HIDE_DESTROYS);
|
meta.addItemFlags(ItemFlag.HIDE_DESTROYS);
|
||||||
@ -125,4 +131,9 @@ public class PanelItem {
|
|||||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||||
icon.setItemMeta(meta);
|
icon.setItemMeta(meta);
|
||||||
}
|
}
|
||||||
|
// Create the final item
|
||||||
|
setName(name);
|
||||||
|
setDescription(description);
|
||||||
|
setGlow(glow);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user