mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 23:47:59 +01:00
Also cancel food animation when PlayerPreEatEvent is cancelled
This commit is contained in:
parent
8b79945992
commit
ca96ed3420
@ -50,6 +50,8 @@ public class UseItemListener {
|
|||||||
PlayerItemAnimationEvent.ItemAnimationType itemAnimationType = null;
|
PlayerItemAnimationEvent.ItemAnimationType itemAnimationType = null;
|
||||||
boolean riptideSpinAttack = false;
|
boolean riptideSpinAttack = false;
|
||||||
|
|
||||||
|
boolean cancelAnimation = false;
|
||||||
|
|
||||||
if (material == Material.BOW) {
|
if (material == Material.BOW) {
|
||||||
itemAnimationType = PlayerItemAnimationEvent.ItemAnimationType.BOW;
|
itemAnimationType = PlayerItemAnimationEvent.ItemAnimationType.BOW;
|
||||||
} else if (material == Material.CROSSBOW) {
|
} else if (material == Material.CROSSBOW) {
|
||||||
@ -64,9 +66,13 @@ public class UseItemListener {
|
|||||||
// Eating code, contains the eating time customisation
|
// Eating code, contains the eating time customisation
|
||||||
PlayerPreEatEvent playerPreEatEvent = new PlayerPreEatEvent(player, itemStack, hand, player.getDefaultEatingTime());
|
PlayerPreEatEvent playerPreEatEvent = new PlayerPreEatEvent(player, itemStack, hand, player.getDefaultEatingTime());
|
||||||
player.callCancellableEvent(PlayerPreEatEvent.class, playerPreEatEvent, () -> player.refreshEating(hand, playerPreEatEvent.getEatingTime()));
|
player.callCancellableEvent(PlayerPreEatEvent.class, playerPreEatEvent, () -> player.refreshEating(hand, playerPreEatEvent.getEatingTime()));
|
||||||
|
|
||||||
|
if (playerPreEatEvent.isCancelled()) {
|
||||||
|
cancelAnimation = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (itemAnimationType != null) {
|
if (!cancelAnimation && itemAnimationType != null) {
|
||||||
PlayerItemAnimationEvent playerItemAnimationEvent = new PlayerItemAnimationEvent(player, itemAnimationType);
|
PlayerItemAnimationEvent playerItemAnimationEvent = new PlayerItemAnimationEvent(player, itemAnimationType);
|
||||||
player.callCancellableEvent(PlayerItemAnimationEvent.class, playerItemAnimationEvent, () -> {
|
player.callCancellableEvent(PlayerItemAnimationEvent.class, playerItemAnimationEvent, () -> {
|
||||||
player.refreshActiveHand(true, hand == Player.Hand.OFF, riptideSpinAttack);
|
player.refreshActiveHand(true, hand == Player.Hand.OFF, riptideSpinAttack);
|
||||||
|
Loading…
Reference in New Issue
Block a user