Minestom/src/main/java/net/minestom/server/event/player/PlayerPreEatEvent.java

67 lines
1.6 KiB
Java
Raw Normal View History

package net.minestom.server.event.player;
import net.minestom.server.entity.Player;
import net.minestom.server.event.CancellableEvent;
import net.minestom.server.event.PlayerEvent;
import net.minestom.server.item.ItemStack;
2020-10-24 16:33:13 +02:00
import org.jetbrains.annotations.NotNull;
/**
* 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.
*/
public class PlayerPreEatEvent extends PlayerEvent implements CancellableEvent {
2020-07-24 16:11:48 +02:00
private final ItemStack foodItem;
private long eatingTime;
private boolean cancelled;
2020-10-24 16:33:13 +02:00
public PlayerPreEatEvent(@NotNull Player player, @NotNull ItemStack foodItem, long eatingTime) {
super(player);
this.foodItem = foodItem;
this.eatingTime = eatingTime;
}
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-10-24 16:33:13 +02:00
@NotNull
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
*/
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
*/
public void setEatingTime(long eatingTime) {
this.eatingTime = eatingTime;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
}