From ca368c2f9f61f2794e3fce0a017c3cf1c536c886 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Fri, 14 Jun 2019 19:41:02 +1000 Subject: [PATCH] SPIGOT-5034: FoodLevelChangeEvent add getItem method By: md_5 --- .../event/entity/FoodLevelChangeEvent.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/paper-api/src/main/java/org/bukkit/event/entity/FoodLevelChangeEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/FoodLevelChangeEvent.java index 221cf69837..7f4c5ea860 100644 --- a/paper-api/src/main/java/org/bukkit/event/entity/FoodLevelChangeEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/entity/FoodLevelChangeEvent.java @@ -3,7 +3,9 @@ package org.bukkit.event.entity; import org.bukkit.entity.HumanEntity; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; +import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * Called when a human entity's food level changes @@ -12,10 +14,16 @@ public class FoodLevelChangeEvent extends EntityEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); private boolean cancel = false; private int level; + private final ItemStack item; public FoodLevelChangeEvent(@NotNull final HumanEntity what, final int level) { + this(what, level, null); + } + + public FoodLevelChangeEvent(@NotNull final HumanEntity what, final int level, @Nullable final ItemStack item) { super(what); this.level = level; + this.item = item; } @NotNull @@ -24,6 +32,16 @@ public class FoodLevelChangeEvent extends EntityEvent implements Cancellable { return (HumanEntity) entity; } + /** + * Gets the item that triggered this event, if any. + * + * @return an ItemStack for the item being consumed + */ + @Nullable + public ItemStack getItem() { + return (item == null) ? null : item.clone(); + } + /** * Gets the resultant food level that the entity involved in this event * should be set to.