net.minestom.server.event.player.PlayerPreEatEvent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of minestom-snapshots Show documentation
Show all versions of minestom-snapshots Show documentation
1.20.4 Lightweight Minecraft server
package net.minestom.server.event.player;
import net.minestom.server.entity.Player;
import net.minestom.server.event.trait.CancellableEvent;
import net.minestom.server.event.trait.ItemEvent;
import net.minestom.server.event.trait.PlayerInstanceEvent;
import net.minestom.server.item.ItemStack;
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
* continue the animation indefinitely.
*/
public class PlayerPreEatEvent implements ItemEvent, PlayerInstanceEvent, CancellableEvent {
private final Player player;
private final ItemStack foodItem;
private final Player.Hand hand;
private long eatingTime;
private boolean cancelled;
public PlayerPreEatEvent(@NotNull Player player, @NotNull ItemStack foodItem, @NotNull Player.Hand hand, long eatingTime) {
this.player = player;
this.foodItem = foodItem;
this.hand = hand;
this.eatingTime = eatingTime;
}
/**
* The food item which will be eaten.
*
* @return the food item
* @deprecated use getItemStack() for the eaten item
*/
@Deprecated
public @NotNull ItemStack getFoodItem() {
return foodItem;
}
public @NotNull Player.Hand getHand() {
return hand;
}
/**
* Gets the food eating time in ticks.
*
* @return the eating time
*/
public long getEatingTime() {
return eatingTime;
}
/**
* Changes the food eating time.
*
* @param eatingTime the new eating time in ticks
*/
public void setEatingTime(long eatingTime) {
this.eatingTime = eatingTime;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
@Override
public @NotNull Player getPlayer() {
return player;
}
/**
* The food item which will be eaten.
*
* @return the food item
*/
@Override
public @NotNull ItemStack getItemStack() { return foodItem; }
}