Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Improve FoodLevelChangeEvent. Adds BUKKIT-3581 #42

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
84 changes: 82 additions & 2 deletions src/main/java/org/bukkit/event/entity/FoodLevelChangeEvent.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.bukkit.event.entity;

import org.bukkit.Material;
import org.bukkit.entity.HumanEntity;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
Expand All @@ -10,18 +11,38 @@
public class FoodLevelChangeEvent extends EntityEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancel = false;
private Material food;
private int level;
private float saturation;
private float exhaustion;

@Deprecated
public FoodLevelChangeEvent(final HumanEntity what, final int level) {
this(what, null, level, level, 0.0F);
}

public FoodLevelChangeEvent(final HumanEntity what, final Material food, final int level, final float saturation, final float exhaustion) {
super(what);
this.food = food;
this.level = level;
this.saturation = saturation;
this.exhaustion = exhaustion;
}

@Override
public HumanEntity getEntity() {
return (HumanEntity) entity;
}

/**
* Gets the food being eaten in this event.
*
* @return the food eaten by the entity
*/
public Material getFood() {
return food;
}

/**
* Gets the resultant food level that the entity involved in this event
* should be set to.
Expand All @@ -42,12 +63,71 @@ public int getFoodLevel() {
* event should be set to
*/
public void setFoodLevel(int level) {
if (level > 20) level = 20;
else if (level < 0) level = 0;
if (level > 20) {
level = 20;
} else if (level < 0) {
level = 0;
}

this.level = level;
}

/**
* Gets the resultant saturation that the entity involved in this event
* should be set to. An entity can never have a higher saturation than
* their current food level.
*
* @return The resultant saturation
*/
public float getSaturation() {
return saturation;
}

/**
* Sets the resultant saturation that the entity involved in this event
* should be set to.
*
* @param saturation the resultant saturation that the entity involved in this
* event should be set to
*/
public void setSaturation(float saturation) {
if (saturation > level) {
saturation = level;
} else if (saturation < 0) {
saturation = 0;
}

this.saturation = saturation;
}

/**
* Gets the resultant food level that the entity involved in this event
* should be set to. Exhaustion cannot exceed 40.0F
*
* @return The resultant exhaustion level
*/
public float getExhaustion() {
return exhaustion;
}

/**
* Sets the resultant exhaustion level that the entity involved in this event
* should be set to. Exhaustion will be clamped to 0.0F - 40.0F before being
* set within the event.
*
* @param exhaustion the resultant exhaustion level that the entity involved in this
* event should be set to
*/
public void setExhaustion(float exhaustion) {
if (exhaustion > 40.0F) {
exhaustion = 40.0F;
} else if (exhaustion < 0) {
exhaustion = 0;
}

this.exhaustion = exhaustion;
}

public boolean isCancelled() {
return cancel;
}
Expand Down