From 4ac2b08320f0298cbb2a66eefc5b3db5bb68e2ef Mon Sep 17 00:00:00 2001 From: Tahg Date: Sat, 3 Mar 2012 05:59:20 -0500 Subject: [PATCH] Added missing null check for enchantments. Fixes BUKKIT-897 --- .../server/ContainerEnchantTable.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/minecraft/server/ContainerEnchantTable.java b/src/main/java/net/minecraft/server/ContainerEnchantTable.java index 1a6619b339..d321b1bdf3 100644 --- a/src/main/java/net/minecraft/server/ContainerEnchantTable.java +++ b/src/main/java/net/minecraft/server/ContainerEnchantTable.java @@ -150,22 +150,22 @@ public class ContainerEnchantTable extends Container { if (!this.world.isStatic) { List list = EnchantmentManager.b(this.l, itemstack, this.costs[i]); - // CraftBukkit start - Map enchants = new HashMap(); - for (Object obj : list) { - EnchantmentInstance instance = (EnchantmentInstance) obj; - enchants.put(org.bukkit.enchantments.Enchantment.getById(instance.enchantment.id), instance.level); - } - CraftItemStack item = new CraftItemStack(itemstack); + if (list != null) { + // CraftBukkit start + Map enchants = new HashMap(); + for (Object obj : list) { + EnchantmentInstance instance = (EnchantmentInstance) obj; + enchants.put(org.bukkit.enchantments.Enchantment.getById(instance.enchantment.id), instance.level); + } + CraftItemStack item = new CraftItemStack(itemstack); - EnchantItemEvent event = new EnchantItemEvent((Player) entityhuman.bukkitEntity, this.getBukkitView(), this.world.getWorld().getBlockAt(this.x, this.y, this.z), item, this.costs[i], enchants, i); - this.world.getServer().getPluginManager().callEvent(event); + EnchantItemEvent event = new EnchantItemEvent((Player) entityhuman.bukkitEntity, this.getBukkitView(), this.world.getWorld().getBlockAt(this.x, this.y, this.z), item, this.costs[i], enchants, i); + this.world.getServer().getPluginManager().callEvent(event); - int level = event.getExpLevelCost(); - if (event.isCancelled() || (level > entityhuman.expLevel)) { - return false; - } - if (enchants.isEmpty() == false) { + int level = event.getExpLevelCost(); + if (event.isCancelled() || (level > entityhuman.expLevel) || enchants.isEmpty()) { + return false; + } entityhuman.levelDown(level); for (Map.Entry entry : event.getEnchantsToAdd().entrySet()) { try {