From 43431ba65b012ffc5fc5d3df399dfcbd07bb69b6 Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 14 Jun 2019 19:41:36 +1000 Subject: [PATCH] SPIGOT-5034: FoodLevelChangeEvent add getItem method --- nms-patches/FoodMetaData.patch | 2 +- .../org/bukkit/craftbukkit/event/CraftEventFactory.java | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/nms-patches/FoodMetaData.patch b/nms-patches/FoodMetaData.patch index 53d872776f..316c443b12 100644 --- a/nms-patches/FoodMetaData.patch +++ b/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/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 7e682826e0..a09240d8a7 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/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; }