[SPIGOT-1505] An event that triggers when the Mending enchantment repairs an item. Created: 21/Feb/16  Updated: 26/Dec/18  Resolved: 26/Dec/18

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor
Reporter: kukelekuuk Assignee: Unassigned
Resolution: Fixed Votes: 5
Labels: None


 Description   

I want to be able to control who can and cannot use the mending enchantment. Or maybe even disable it entirely. So a cancellable event that gets triggered when the Mending enchantment uses up XP to repair an item would be nice.



 Comments   
Comment by md_5 [ 26/Dec/18 ]

This was added https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/player/PlayerItemMendEvent.html

Comment by hellboyPS [ 02/Apr/16 ]

So, I've been thinking about possible ways to do this, and this is what I've come up with.
I'd like to hear some comments whether or not this is the right approach. I'll post a PR if all checks out.

First, a summary of mending:
Looking through NMS code, mending works as follows:
When a player picks up an experience orb, a single item in the armor or main-/offhand slot with the mending enchantment gets selected at random (even if it has full durability). Then it will be repaired by twice the amount of exp the experience orb holds, but no more than the actual item damage. If there is remaining exp the player receives it as usual, resulting in a PlayerExpChangeEvent with the reduced experience value.

Proposal) PlayerItemMendingEvent (or InventoryMendItemEvent)
A Mending Event always has a player and their inventory, but I feel that a PlayerEvent would be more suitable.
The idea is to make a new event which fires when an item gets repaired by the mending enchantment. The event would be cancelable, which would result in the player receiving the full exp. There will be getters for receiving the ItemStack which will be repaired and the amount of durability restored.

Another possibility is to change the PlayerExpChangeEvent so that the mending enchant is incorporated. I personally do not see a sensible solution doing this, and as such I lean in favor of adding a new event as described above.

Maybe there are other/better ways to handle mending or improvements to this proposal? I'd love some feedback.

Generated at Sun Mar 30 17:54:41 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.