2020-05-12 18:40:04 +02:00
|
|
|
package net.minestom.server.event.player;
|
|
|
|
|
|
|
|
import net.minestom.server.entity.Player;
|
|
|
|
import net.minestom.server.event.CancellableEvent;
|
|
|
|
import net.minestom.server.item.ItemStack;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called before the PlayerEatEvent and can be used to change the eating time
|
|
|
|
* or to cancel its processing, cancelling the event means that the player will
|
2020-10-15 21:16:31 +02:00
|
|
|
* continue the animation indefinitely.
|
2020-05-12 18:40:04 +02:00
|
|
|
*/
|
|
|
|
public class PlayerPreEatEvent extends CancellableEvent {
|
|
|
|
|
2020-07-24 16:11:48 +02:00
|
|
|
private final Player player;
|
|
|
|
private final ItemStack foodItem;
|
2020-05-12 18:40:04 +02:00
|
|
|
private long eatingTime;
|
|
|
|
|
|
|
|
public PlayerPreEatEvent(Player player, ItemStack foodItem, long eatingTime) {
|
|
|
|
this.player = player;
|
|
|
|
this.foodItem = foodItem;
|
|
|
|
this.eatingTime = eatingTime;
|
|
|
|
}
|
|
|
|
|
2020-05-30 22:32:12 +02:00
|
|
|
/**
|
2020-10-15 21:16:31 +02:00
|
|
|
* The player who is trying to eat.
|
2020-05-30 22:32:12 +02:00
|
|
|
*
|
|
|
|
* @return the concerned player
|
|
|
|
*/
|
2020-05-12 18:40:04 +02:00
|
|
|
public Player getPlayer() {
|
|
|
|
return player;
|
|
|
|
}
|
|
|
|
|
2020-05-30 22:32:12 +02:00
|
|
|
/**
|
2020-10-15 21:16:31 +02:00
|
|
|
* The food item which will be eaten.
|
2020-05-30 22:32:12 +02:00
|
|
|
*
|
|
|
|
* @return the food item
|
|
|
|
*/
|
2020-05-12 18:40:04 +02:00
|
|
|
public ItemStack getFoodItem() {
|
|
|
|
return foodItem;
|
|
|
|
}
|
|
|
|
|
2020-05-30 22:32:12 +02:00
|
|
|
/**
|
2020-10-15 21:16:31 +02:00
|
|
|
* Gets the food eating time.
|
2020-05-30 22:32:12 +02:00
|
|
|
* <p>
|
2020-10-15 21:16:31 +02:00
|
|
|
* This is by default {@link Player#getDefaultEatingTime()}.
|
2020-05-30 22:32:12 +02:00
|
|
|
*
|
|
|
|
* @return the eating time
|
|
|
|
*/
|
2020-05-12 18:40:04 +02:00
|
|
|
public long getEatingTime() {
|
|
|
|
return eatingTime;
|
|
|
|
}
|
|
|
|
|
2020-05-30 22:32:12 +02:00
|
|
|
/**
|
2020-10-15 21:16:31 +02:00
|
|
|
* Changes the food eating time.
|
2020-05-30 22:32:12 +02:00
|
|
|
*
|
|
|
|
* @param eatingTime the new eating time
|
|
|
|
*/
|
2020-05-12 18:40:04 +02:00
|
|
|
public void setEatingTime(long eatingTime) {
|
|
|
|
this.eatingTime = eatingTime;
|
|
|
|
}
|
|
|
|
}
|