summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Adams <dinnerbone@dinnerbone.com>2011-12-01 05:17:22 +0000
committerNathan Adams <dinnerbone@dinnerbone.com>2011-12-01 05:21:03 +0000
commitd02a2eb49df479037a2b6410dc5a6a483ca8a1f9 (patch)
treef2bd7ce16d369210ee83961e3df120c49c82574b
parent4ce061ccbe44f24fa8394152f19c200e5dcd92f2 (diff)
downloadcraftbukkit-d02a2eb49df479037a2b6410dc5a6a483ca8a1f9.tar
craftbukkit-d02a2eb49df479037a2b6410dc5a6a483ca8a1f9.tar.gz
craftbukkit-d02a2eb49df479037a2b6410dc5a6a483ca8a1f9.tar.lz
craftbukkit-d02a2eb49df479037a2b6410dc5a6a483ca8a1f9.tar.xz
craftbukkit-d02a2eb49df479037a2b6410dc5a6a483ca8a1f9.zip
Fixed rare NPEs with CraftItemStack. This fixes BUKKIT-51
-rw-r--r--src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java8
1 files changed, 5 insertions, 3 deletions
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<Enchantment, Integer> getEnchantments() {
Map<Enchantment, Integer> result = new HashMap<Enchantment, Integer>();
- 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<Enchantment, Integer> enchantments) {
+ if (item == null) return;
+
NBTTagCompound tag = item.tag;
NBTTagList list = new NBTTagList("ench");