SPIGOT-5034: FoodLevelChangeEvent add getItem method

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot 2019-06-14 19:41:36 +10:00
parent 95dbf2457d
commit c1cc0cddf5
2 changed files with 6 additions and 2 deletions

View file

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

View file

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