From d02a2eb49df479037a2b6410dc5a6a483ca8a1f9 Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Thu, 1 Dec 2011 05:17:22 +0000 Subject: Fixed rare NPEs with CraftItemStack. This fixes BUKKIT-51 --- .../java/org/bukkit/craftbukkit/inventory/CraftItemStack.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java index 81bd9885..cd621272 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java @@ -3,7 +3,6 @@ package org.bukkit.craftbukkit.inventory; import java.util.HashMap; import java.util.Map; import net.minecraft.server.EnchantmentManager; -import net.minecraft.server.NBTBase; import net.minecraft.server.NBTTagCompound; import net.minecraft.server.NBTTagList; import org.bukkit.enchantments.Enchantment; @@ -135,7 +134,7 @@ public class CraftItemStack extends ItemStack { @Override public int getMaxStackSize() { - return item.getItem().getMaxStackSize(); + return (item == null) ? 0 : item.getItem().getMaxStackSize(); } @Override @@ -152,6 +151,7 @@ public class CraftItemStack extends ItemStack { @Override public int getEnchantmentLevel(Enchantment ench) { + if (item == null) return 0; return EnchantmentManager.getEnchantmentLevel(ench.getId(), item); } @@ -168,7 +168,7 @@ public class CraftItemStack extends ItemStack { @Override public Map getEnchantments() { Map result = new HashMap(); - NBTTagList list = item.getEnchantments(); + NBTTagList list = (item == null) ? null : item.getEnchantments(); if (list == null) { return result; @@ -185,6 +185,8 @@ public class CraftItemStack extends ItemStack { } private void rebuildEnchantments(Map enchantments) { + if (item == null) return; + NBTTagCompound tag = item.tag; NBTTagList list = new NBTTagList("ench"); -- cgit v1.2.3