summaryrefslogtreecommitdiffstats
path: root/src/main/java/net
diff options
context:
space:
mode:
authort00thpick1 <t00thpick1dirko@gmail.com>2014-01-21 19:07:25 -0500
committerNate Mortensen <nate.richard.mortensen@gmail.com>2014-02-06 16:49:10 -0700
commit66471a53263ce8a3df673ef32627187ecdecae7c (patch)
tree0e8998142bea420019e03d7763dce0cd56231de0 /src/main/java/net
parent068d8a807b7978643fafe8009f86854db8c97606 (diff)
downloadcraftbukkit-66471a53263ce8a3df673ef32627187ecdecae7c.tar
craftbukkit-66471a53263ce8a3df673ef32627187ecdecae7c.tar.gz
craftbukkit-66471a53263ce8a3df673ef32627187ecdecae7c.tar.lz
craftbukkit-66471a53263ce8a3df673ef32627187ecdecae7c.tar.xz
craftbukkit-66471a53263ce8a3df673ef32627187ecdecae7c.zip
[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).
Diffstat (limited to 'src/main/java/net')
-rw-r--r--src/main/java/net/minecraft/server/ContainerEnchantTable.java15
1 files 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 97a06f70..cc36e2bb 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<org.bukkit.enchantments.Enchantment, Integer> 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);