From f291437ada07a961f054047bad66d676cf969ff2 Mon Sep 17 00:00:00 2001 From: HEROOSTECH <56263050+HEROOSTECH@users.noreply.github.com> Date: Wed, 4 Jan 2023 01:11:17 +0100 Subject: [PATCH] Hand in PlayerItemAnimationEvent (#1650) * Hand in PlayerItemAnimationEvent * Hand in PlayerItemAnimationEvent --- .../event/player/PlayerItemAnimationEvent.java | 14 ++++++++++++-- .../minestom/server/listener/UseItemListener.java | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/minestom/server/event/player/PlayerItemAnimationEvent.java b/src/main/java/net/minestom/server/event/player/PlayerItemAnimationEvent.java index 1801603f8..9340ba45c 100644 --- a/src/main/java/net/minestom/server/event/player/PlayerItemAnimationEvent.java +++ b/src/main/java/net/minestom/server/event/player/PlayerItemAnimationEvent.java @@ -14,12 +14,13 @@ public class PlayerItemAnimationEvent implements PlayerInstanceEvent, Cancellabl private final Player player; private final ItemAnimationType itemAnimationType; - + private final Player.Hand hand; private boolean cancelled; - public PlayerItemAnimationEvent(@NotNull Player player, @NotNull ItemAnimationType itemAnimationType) { + public PlayerItemAnimationEvent(@NotNull Player player, @NotNull ItemAnimationType itemAnimationType, @NotNull Player.Hand hand) { this.player = player; this.itemAnimationType = itemAnimationType; + this.hand = hand; } /** @@ -31,6 +32,15 @@ public class PlayerItemAnimationEvent implements PlayerInstanceEvent, Cancellabl return itemAnimationType; } + /** + * Gets the hand that was used. + * + * @return the hand + */ + public @NotNull Player.Hand getHand() { + return hand; + } + @Override public @NotNull Player getPlayer() { return player; diff --git a/src/main/java/net/minestom/server/listener/UseItemListener.java b/src/main/java/net/minestom/server/listener/UseItemListener.java index a6d556c32..28996a921 100644 --- a/src/main/java/net/minestom/server/listener/UseItemListener.java +++ b/src/main/java/net/minestom/server/listener/UseItemListener.java @@ -66,7 +66,7 @@ public class UseItemListener { } if (!cancelAnimation && itemAnimationType != null) { - PlayerItemAnimationEvent playerItemAnimationEvent = new PlayerItemAnimationEvent(player, itemAnimationType); + PlayerItemAnimationEvent playerItemAnimationEvent = new PlayerItemAnimationEvent(player, itemAnimationType, hand); EventDispatcher.callCancellable(playerItemAnimationEvent, () -> { player.refreshActiveHand(true, hand == Player.Hand.OFF, riptideSpinAttack); player.sendPacketToViewers(player.getMetadataPacket());