Expand PlayerItemMendEvent

This commit is contained in:
Jake Potrebic
2022-01-20 18:11:20 -08:00
parent 605fb41674
commit 79ffc3e056
3 changed files with 13 additions and 8 deletions

View File

@@ -215,12 +215,15 @@
}
}
@@ -266,12 +359,20 @@
@@ -266,12 +359,23 @@
ItemStack itemstack = ((EnchantedItemInUse) optional.get()).itemStack();
int j = EnchantmentHelper.modifyDurabilityToRepairFromXp(player.serverLevel(), itemstack, amount);
int k = Math.min(j, itemstack.getDamageValue());
+ // CraftBukkit start
+ org.bukkit.event.player.PlayerItemMendEvent event = CraftEventFactory.callPlayerItemMendEvent(player, this, itemstack, optional.get().inSlot(), k);
+ // Paper start - mending event
+ final int consumedExperience = k > 0 ? k * amount / j : 0;
+ org.bukkit.event.player.PlayerItemMendEvent event = CraftEventFactory.callPlayerItemMendEvent(player, this, itemstack, optional.get().inSlot(), k, consumedExperience);
+ // Paper end - mending event
+ k = event.getRepairAmount();
+ if (event.isCancelled()) {
+ return amount;
@@ -229,14 +232,15 @@
itemstack.setDamageValue(itemstack.getDamageValue() - k);
if (k > 0) {
int l = amount - k * amount / j;
- int l = amount - k * amount / j;
+ int l = amount - k * amount / j; // Paper - diff on change - expand PlayerMendEvents
if (l > 0) {
+ // this.value = l; // CraftBukkit - update exp value of orb for PlayerItemMendEvent calls // Paper - the value field should not be mutated here because it doesn't take "count" into account
return this.repairPlayerItems(player, l);
}
}
@@ -291,6 +392,24 @@
@@ -291,6 +395,24 @@
}
public static int getExperienceValue(int value) {