001 package org.bukkit.event.entity; 002 003 import org.bukkit.entity.HumanEntity; 004 import org.bukkit.event.Cancellable; 005 import org.bukkit.event.HandlerList; 006 007 /** 008 * Called when a human entity's food level changes 009 */ 010 public class FoodLevelChangeEvent extends EntityEvent implements Cancellable { 011 private static final HandlerList handlers = new HandlerList(); 012 private boolean cancel = false; 013 private int level; 014 015 public FoodLevelChangeEvent(final HumanEntity what, final int level) { 016 super(what); 017 this.level = level; 018 } 019 020 @Override 021 public HumanEntity getEntity() { 022 return (HumanEntity) entity; 023 } 024 025 /** 026 * Gets the resultant food level that the entity involved in this event 027 * should be set to. 028 * <p> 029 * Where 20 is a full food bar and 0 is an empty one. 030 * 031 * @return The resultant food level 032 */ 033 public int getFoodLevel() { 034 return level; 035 } 036 037 /** 038 * Sets the resultant food level that the entity involved in this event 039 * should be set to 040 * 041 * @param level the resultant food level that the entity involved in this 042 * event should be set to 043 */ 044 public void setFoodLevel(int level) { 045 if (level > 20) level = 20; 046 else if (level < 0) level = 0; 047 048 this.level = level; 049 } 050 051 public boolean isCancelled() { 052 return cancel; 053 } 054 055 public void setCancelled(boolean cancel) { 056 this.cancel = cancel; 057 } 058 059 @Override 060 public HandlerList getHandlers() { 061 return handlers; 062 } 063 064 public static HandlerList getHandlerList() { 065 return handlers; 066 } 067 }