From 66471a53263ce8a3df673ef32627187ecdecae7c Mon Sep 17 00:00:00 2001 From: t00thpick1 Date: Tue, 21 Jan 2014 19:07:25 -0500 Subject: [PATCH] [Bleeding] Correctly enchant books. Fixes BUKKIT-5302 Books can now recieve more than one enchantment. As such, breaking out of the loop after only 1 enchantment is applied is not the correct behavior. This commit also reworks some of the logic surrounding the application of enchantments to the item. By checking if the event doesn't add any enchantments rather than if the original enchantments list is empty, the application code is only reached if enchantments are applied, rendering the "applied" boolean no longer necessary. The ItemStack's Item should only be set once, so it is now set outside of the loop based upon whether or not "flag" is true (with "flag" being whether or not the ItemStack's Item is a book). --- .../minecraft/server/ContainerEnchantTable.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/minecraft/server/ContainerEnchantTable.java b/src/main/java/net/minecraft/server/ContainerEnchantTable.java index 97a06f70d9..cc36e2bb01 100644 --- a/src/main/java/net/minecraft/server/ContainerEnchantTable.java +++ b/src/main/java/net/minecraft/server/ContainerEnchantTable.java @@ -167,11 +167,14 @@ public class ContainerEnchantTable extends Container { this.world.getServer().getPluginManager().callEvent(event); int level = event.getExpLevelCost(); - if (event.isCancelled() || (level > entityhuman.expLevel && !entityhuman.abilities.canInstantlyBuild) || enchants.isEmpty()) { + if (event.isCancelled() || (level > entityhuman.expLevel && !entityhuman.abilities.canInstantlyBuild) || event.getEnchantsToAdd().isEmpty()) { return false; } - boolean applied = !flag; + if (flag) { + itemstack.setItem(Items.ENCHANTED_BOOK); + } + for (Map.Entry entry : event.getEnchantsToAdd().entrySet()) { try { if (flag) { @@ -182,9 +185,6 @@ public class ContainerEnchantTable extends Container { EnchantmentInstance enchantment = new EnchantmentInstance(enchantId, entry.getValue()); Items.ENCHANTED_BOOK.a(itemstack, enchantment); - applied = true; - itemstack.setItem((Item) Items.ENCHANTED_BOOK); - break; } else { item.addEnchantment(entry.getKey(), entry.getValue()); } @@ -193,10 +193,7 @@ public class ContainerEnchantTable extends Container { } } - // Only down level if we've applied the enchantments - if (applied) { - entityhuman.levelDown(-level); - } + entityhuman.levelDown(-level); // CraftBukkit end this.a(this.enchantSlots);