diff options
Diffstat (limited to 'src/main/java/org')
4 files changed, 68 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/event/Event.java b/src/main/java/org/bukkit/event/Event.java index efb609be..be6749f7 100644 --- a/src/main/java/org/bukkit/event/Event.java +++ b/src/main/java/org/bukkit/event/Event.java @@ -703,6 +703,12 @@ public abstract class Event implements Serializable { * @see org.bukkit.event.entity.EndermanPlaceEvent */ ENDERMAN_PLACE (Category.LIVING_ENTITY), + /** + * Called when a human entity's food level changes + * + * @see org.bukkit.event.entity.FoodLevelChangeEvent + */ + FOOD_LEVEL_CHANGE (Category.LIVING_ENTITY), /** * WEATHER EVENTS diff --git a/src/main/java/org/bukkit/event/entity/EntityListener.java b/src/main/java/org/bukkit/event/entity/EntityListener.java index 00a7b568..20fb9bbe 100644 --- a/src/main/java/org/bukkit/event/entity/EntityListener.java +++ b/src/main/java/org/bukkit/event/entity/EntityListener.java @@ -148,4 +148,11 @@ public class EntityListener implements Listener { * @param event Relevant event details */ public void onEndermanPlace(EndermanPlaceEvent event) {} + + /** + * Called when a human entity's food level changes + * + * @param event Relevant event details + */ + public void onFoodLevelChange(FoodLevelChangeEvent event) {} } diff --git a/src/main/java/org/bukkit/event/entity/FoodLevelChangeEvent.java b/src/main/java/org/bukkit/event/entity/FoodLevelChangeEvent.java new file mode 100644 index 00000000..4adacfef --- /dev/null +++ b/src/main/java/org/bukkit/event/entity/FoodLevelChangeEvent.java @@ -0,0 +1,48 @@ +package org.bukkit.event.entity; + +import org.bukkit.entity.Entity; +import org.bukkit.event.Cancellable; + +/** + * Called when a human entity's food level changes + */ +public class FoodLevelChangeEvent extends EntityEvent implements Cancellable { + private boolean cancel = false; + private int level; + + public FoodLevelChangeEvent(Entity what, int level) { + super(Type.FOOD_LEVEL_CHANGE, what); + this.level = level; + } + + /** + * Gets the resultant food level that the entity involved in this event should be set to. + * <br /><br /> + * Where 20 is a full food bar and 0 is an empty one. + * + * @return The resultant food level + */ + public int getFoodLevel() { + return level; + } + + /** + * Sets the resultant food level that the entity involved in this event should be set to + * + * @param level the resultant food level that the entity involved in this event should be set to + */ + public void setFoodLevel(int level) { + if (level > 20) level = 20; + else if (level < 0) level = 0; + + this.level = level; + } + + public boolean isCancelled() { + return cancel; + } + + public void setCancelled(boolean cancel) { + this.cancel = cancel; + } +} diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index 0693da62..8466664c 100644 --- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -783,6 +783,13 @@ public class JavaPluginLoader implements PluginLoader { } }; + case FOOD_LEVEL_CHANGE: + return new EventExecutor() { + public void execute(Listener listener, Event event) { + ((EntityListener) listener).onFoodLevelChange((FoodLevelChangeEvent) event); + } + }; + // Vehicle Events case VEHICLE_CREATE: return new EventExecutor() { |