From bdb88226252f029f6b752c0a83740eb74f7a4ba8 Mon Sep 17 00:00:00 2001 From: Senmori Date: Tue, 21 Nov 2017 10:17:31 +1100 Subject: [PATCH] SPIGOT-1505: PlayerItemMendEvent --- nms-patches/EntityExperienceOrb.patch | 20 ++++++++++++++++--- .../craftbukkit/event/CraftEventFactory.java | 9 +++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/nms-patches/EntityExperienceOrb.patch b/nms-patches/EntityExperienceOrb.patch index 24aa1aba1a..bd249662b0 100644 --- a/nms-patches/EntityExperienceOrb.patch +++ b/nms-patches/EntityExperienceOrb.patch @@ -46,8 +46,22 @@ } this.move(EnumMoveType.SELF, this.motX, this.motY, this.motZ); -@@ -153,7 +172,7 @@ - } +@@ -148,12 +167,18 @@ + if (!itemstack.isEmpty() && itemstack.h()) { + int i = Math.min(this.d(this.value), itemstack.i()); + +- this.value -= this.c(i); +- itemstack.setData(itemstack.i() - i); +- } ++ // CraftBukkit start ++ org.bukkit.event.player.PlayerItemMendEvent event = CraftEventFactory.callPlayerItemMendEvent(entityhuman, this, itemstack, i); ++ i = event.getRepairAmount(); ++ if (!event.isCancelled()) { ++ this.value -= this.c(i); ++ itemstack.setData(itemstack.i() - i); ++ } ++ // CraftBukkit end ++ } if (this.value > 0) { - entityhuman.giveExp(this.value); @@ -55,7 +69,7 @@ } this.die(); -@@ -175,6 +194,24 @@ +@@ -175,6 +200,24 @@ } public static int getOrbValue(int i) { diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 1f8f580f60..a8c09481c8 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -36,6 +36,7 @@ import org.bukkit.entity.AreaEffectCloud; import org.bukkit.entity.Arrow; import org.bukkit.entity.Creeper; import org.bukkit.entity.EntityType; +import org.bukkit.entity.ExperienceOrb; import org.bukkit.entity.Firework; import org.bukkit.entity.LightningStrike; import org.bukkit.entity.LivingEntity; @@ -647,6 +648,14 @@ public class CraftEventFactory { return event; } + public static PlayerItemMendEvent callPlayerItemMendEvent(EntityHuman entity, EntityExperienceOrb orb, net.minecraft.server.ItemStack nmsMendedItem, int repairAmount) { + Player player = (Player) entity.getBukkitEntity(); + org.bukkit.inventory.ItemStack bukkitStack = CraftItemStack.asCraftMirror(nmsMendedItem); + PlayerItemMendEvent event = new PlayerItemMendEvent(player, bukkitStack, (ExperienceOrb) orb.getBukkitEntity(), repairAmount); + Bukkit.getPluginManager().callEvent(event); + return event; + } + public static boolean handleBlockGrowEvent(World world, int x, int y, int z, net.minecraft.server.Block type, int data) { Block block = world.getWorld().getBlockAt(x, y, z); CraftBlockState state = (CraftBlockState) block.getState();