Check for null items when editing events, fixes #444

This commit is contained in:
BuildTools 2018-12-12 01:37:49 -05:00
parent e908af7599
commit c5dabefc32
2 changed files with 11 additions and 3 deletions

View File

@ -404,9 +404,11 @@ public class EventFactory implements ConversationAbandonedListener {
text += ChatColor.BLUE + "" + ChatColor.BOLD + "5" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("eventEditorSetItems") + "\n";
LinkedList<ItemStack> items = (LinkedList<ItemStack>) context.getSessionData(CK.E_ITEMS);
for (ItemStack is : items) {
if (is != null) {
text += ChatColor.GRAY + " - " + ItemUtil.getString(is) + "\n";
}
}
}
if (context.getSessionData(CK.E_EXPLOSIONS) == null) {
text += ChatColor.BLUE + "" + ChatColor.BOLD + "6" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("eventEditorSetExplosions") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n";
} else {

View File

@ -403,10 +403,13 @@ public class ItemUtil {
* Format is ([display]name:durability) x (amount)
*
* @param is ItemStack to check
* @return true display or item name, plus durability and amount
* @return true display or item name, plus durability and amount, if stack is not null
*/
@SuppressWarnings("deprecation")
public static String getString(ItemStack is) {
if (is == null) {
return null;
}
String text;
if (is.hasItemMeta() && is.getItemMeta().hasDisplayName()) {
text = "" + ChatColor.DARK_AQUA + ChatColor.ITALIC + is.getItemMeta().getDisplayName() + ChatColor.RESET + ChatColor.AQUA + " x " + is.getAmount();
@ -424,9 +427,12 @@ public class ItemUtil {
* Returns a formatted display name. If none exists, returns item name.
*
* @param is ItemStack to check
* @return true display or item name
* @return true display or item name, if stack is not null
*/
public static String getName(ItemStack is) {
if (is == null) {
return null;
}
String text = "";
if (is.hasItemMeta() && is.getItemMeta().hasDisplayName()) {
text = "" + ChatColor.DARK_AQUA + ChatColor.ITALIC + is.getItemMeta().getDisplayName();