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

79 lines
2.0 KiB
Java
Raw Normal View History

package net.minestom.server.event.player;
import net.minestom.server.entity.Player;
2021-06-09 07:11:01 +02:00
import net.minestom.server.event.trait.CancellableEvent;
2021-10-06 20:40:17 +02:00
import net.minestom.server.event.trait.EntityInstanceEvent;
2021-06-02 07:09:15 +02:00
import net.minestom.server.event.trait.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.
*/
2021-10-06 20:40:17 +02:00
public class PlayerPreEatEvent implements PlayerEvent, EntityInstanceEvent, CancellableEvent {
2021-06-02 07:09:15 +02:00
private final Player player;
2020-07-24 16:11:48 +02:00
private final ItemStack foodItem;
2021-04-13 22:59:40 +02:00
private final Player.Hand hand;
private long eatingTime;
private boolean cancelled;
2021-04-13 22:59:40 +02:00
public PlayerPreEatEvent(@NotNull Player player, @NotNull ItemStack foodItem, @NotNull Player.Hand hand, long eatingTime) {
2021-06-02 07:09:15 +02:00
this.player = player;
this.foodItem = foodItem;
2021-04-13 22:59:40 +02:00
this.hand = hand;
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
*/
2021-04-13 22:59:40 +02:00
public @NotNull ItemStack getFoodItem() {
return foodItem;
}
2021-04-13 22:59:40 +02:00
public @NotNull Player.Hand getHand() {
return hand;
}
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;
}
2021-06-02 07:09:15 +02:00
@Override
public @NotNull Player getPlayer() {
return player;
}
}