Bukkit/CraftBukkit — pull request #1366 by NathanWolf (2014-04-21 19:19:57+00:00)
Title: Fix Custom Item Enchanting

This preserves @t00thpick1 's special-case fix for enchanting books,
but will allow custom enchanting of other items.

The original change (ac1a2d0233eff169efcc7c807cbf799b57bf2306)
unfortunately broke enchanting in my plugin in a bad way since 1.7.2 R3
- the item enchant event (which is how my plugin determines to enchant
the item) occurs before the "enchants added" check is made - but then
the event effectively cancels itself and doesn't spend XP, meaning my
players can enchant their items for free.

If there is a better way to fix this issue but still allow custom
enchanting (meaning modifying a custom item in a way other than adding
built-in enchants) I'd be open for it, but I would really like to get
this fixed since it's the only thing blocking me from moving forward
with my plugin's compatibility.

Another option for me would be to return a "dummy" enchant, and then
remove it from the item when the player takes it, but that seems a bit
hacky. That is probably what I'll do if you don't accept this change,
though. :)