From 5db13eea6051de52dec87e2e8c0800e8df4937cc Mon Sep 17 00:00:00 2001 From: jameslfc19 Date: Wed, 22 Jul 2020 18:21:45 +1000 Subject: [PATCH] SPIGOT-5950: Add PrepareSmithingEvent event --- nms-patches/ContainerSmithing.patch | 15 +++++++++++++++ .../craftbukkit/event/CraftEventFactory.java | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/nms-patches/ContainerSmithing.patch b/nms-patches/ContainerSmithing.patch index 37bc0bd782..5f6f167f3b 100644 --- a/nms-patches/ContainerSmithing.patch +++ b/nms-patches/ContainerSmithing.patch @@ -18,6 +18,21 @@ public ContainerSmithing(int i, PlayerInventory playerinventory) { this(i, playerinventory, ContainerAccess.a); +@@ -52,12 +57,12 @@ + List list = this.g.getCraftingManager().b(Recipes.SMITHING, this.repairInventory, this.g); + + if (list.isEmpty()) { +- this.resultInventory.setItem(0, ItemStack.b); ++ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareSmithingEvent(getBukkitView(), ItemStack.b); // CraftBukkit + } else { + this.h = (RecipeSmithing) list.get(0); + ItemStack itemstack = this.h.a(this.repairInventory); + +- this.resultInventory.setItem(0, itemstack); ++ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareSmithingEvent(getBukkitView(), itemstack); // CraftBukkit + } + + } @@ -68,4 +73,18 @@ return recipesmithing.a(itemstack); }); diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 1198bf6fa0..edbc1d9359 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -188,6 +188,7 @@ import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.inventory.PrepareAnvilEvent; import org.bukkit.event.inventory.PrepareItemCraftEvent; +import org.bukkit.event.inventory.PrepareSmithingEvent; import org.bukkit.event.inventory.TradeSelectEvent; import org.bukkit.event.player.PlayerBedEnterEvent; import org.bukkit.event.player.PlayerBedEnterEvent.BedEnterResult; @@ -1413,6 +1414,13 @@ public class CraftEventFactory { return event; } + public static PrepareSmithingEvent callPrepareSmithingEvent(InventoryView view, ItemStack item) { + PrepareSmithingEvent event = new PrepareSmithingEvent(view, CraftItemStack.asCraftMirror(item).clone()); + event.getView().getPlayer().getServer().getPluginManager().callEvent(event); + event.getInventory().setItem(2, event.getResult()); + return event; + } + public static EntityToggleGlideEvent callToggleGlideEvent(EntityLiving entity, boolean gliding) { EntityToggleGlideEvent event = new EntityToggleGlideEvent((LivingEntity) entity.getBukkitEntity(), gliding); entity.world.getServer().getPluginManager().callEvent(event);