SPIGOT-5950: Add PrepareSmithingEvent event

This commit is contained in:
jameslfc19 2020-07-22 18:21:45 +10:00 committed by md_5
parent 8b831a9652
commit 5db13eea60
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
2 changed files with 23 additions and 0 deletions

View File

@ -18,6 +18,21 @@
public ContainerSmithing(int i, PlayerInventory playerinventory) {
this(i, playerinventory, ContainerAccess.a);
@@ -52,12 +57,12 @@
List<RecipeSmithing> 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);
});

View File

@ -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);