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