Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
FoodLevelChangeEvent.java
1 package org.bukkit.event.entity;
2 
6 
7 /**
8  * Called when a human entity's food level changes
9  */
10 public class FoodLevelChangeEvent extends EntityEvent implements Cancellable {
11  private static final HandlerList handlers = new HandlerList();
12  private boolean cancel = false;
13  private int level;
14 
15  public FoodLevelChangeEvent(final HumanEntity what, final int level) {
16  super(what);
17  this.level = level;
18  }
19 
20  @Override
21  public HumanEntity getEntity() {
22  return (HumanEntity) entity;
23  }
24 
25  /**
26  * Gets the resultant food level that the entity involved in this event
27  * should be set to.
28  * <p>
29  * Where 20 is a full food bar and 0 is an empty one.
30  *
31  * @return The resultant food level
32  */
33  public int getFoodLevel() {
34  return level;
35  }
36 
37  /**
38  * Sets the resultant food level that the entity involved in this event
39  * should be set to
40  *
41  * @param level the resultant food level that the entity involved in this
42  * event should be set to
43  */
44  public void setFoodLevel(int level) {
45  if (level > 20) level = 20;
46  else if (level < 0) level = 0;
47 
48  this.level = level;
49  }
50 
51  public boolean isCancelled() {
52  return cancel;
53  }
54 
55  public void setCancelled(boolean cancel) {
56  this.cancel = cancel;
57  }
58 
59  @Override
60  public HandlerList getHandlers() {
61  return handlers;
62  }
63 
64  public static HandlerList getHandlerList() {
65  return handlers;
66  }
67 }