From c1cc0cddf573dc3e635202244a8e00a3e6ef78fe Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Fri, 14 Jun 2019 19:41:36 +1000 Subject: [PATCH] SPIGOT-5034: FoodLevelChangeEvent add getItem method By: md_5 --- paper-server/nms-patches/FoodMetaData.patch | 2 +- .../org/bukkit/craftbukkit/event/CraftEventFactory.java | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/paper-server/nms-patches/FoodMetaData.patch b/paper-server/nms-patches/FoodMetaData.patch index 53d872776f..316c443b12 100644 --- a/paper-server/nms-patches/FoodMetaData.patch +++ b/paper-server/nms-patches/FoodMetaData.patch @@ -27,7 +27,7 @@ + int oldFoodLevel = foodLevel; - this.eat(foodinfo.getNutrition(), foodinfo.getSaturationModifier()); -+ org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(entityhuman, foodinfo.getNutrition() + oldFoodLevel); ++ org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(entityhuman, foodinfo.getNutrition() + oldFoodLevel, itemstack); + + if (!event.isCancelled()) { + this.eat(event.getFoodLevel() - oldFoodLevel, foodinfo.getSaturationModifier()); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 7e682826e0..a09240d8a7 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -980,7 +980,11 @@ public class CraftEventFactory { } public static FoodLevelChangeEvent callFoodLevelChangeEvent(EntityHuman entity, int level) { - FoodLevelChangeEvent event = new FoodLevelChangeEvent(entity.getBukkitEntity(), level); + return callFoodLevelChangeEvent(entity, level, null); + } + + public static FoodLevelChangeEvent callFoodLevelChangeEvent(EntityHuman entity, int level, ItemStack item) { + FoodLevelChangeEvent event = new FoodLevelChangeEvent(entity.getBukkitEntity(), level, (item == null) ? null : CraftItemStack.asBukkitCopy(item)); entity.getBukkitEntity().getServer().getPluginManager().callEvent(event); return event; }