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

63 lines
1.5 KiB
Java
Raw Normal View History

package net.minestom.server.event.player;
2019-08-21 16:50:52 +02:00
2020-04-24 03:25:58 +02:00
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-04 00:54:36 +02:00
import net.minestom.server.event.trait.ItemEvent;
2021-06-02 07:09:15 +02:00
import net.minestom.server.event.trait.PlayerEvent;
2020-04-24 03:25:58 +02:00
import net.minestom.server.item.ItemStack;
2020-10-24 16:33:13 +02:00
import org.jetbrains.annotations.NotNull;
2019-08-21 16:50:52 +02:00
/**
* Event when an item is used without clicking on a block.
*/
2021-10-06 20:40:17 +02:00
public class PlayerUseItemEvent implements PlayerEvent, EntityInstanceEvent, ItemEvent, CancellableEvent {
2019-08-21 16:50:52 +02:00
2021-06-02 07:09:15 +02:00
private final Player player;
2020-07-24 16:11:48 +02:00
private final Player.Hand hand;
private final ItemStack itemStack;
2019-08-21 16:50:52 +02:00
private boolean cancelled;
2020-10-24 16:33:13 +02:00
public PlayerUseItemEvent(@NotNull Player player, @NotNull Player.Hand hand, @NotNull ItemStack itemStack) {
2021-06-02 07:09:15 +02:00
this.player = player;
2019-08-21 16:50:52 +02:00
this.hand = hand;
this.itemStack = itemStack;
}
2020-05-30 22:32:12 +02:00
/**
2020-10-15 21:16:31 +02:00
* Gets which hand the player used.
2020-05-30 22:32:12 +02:00
*
* @return the hand used
*/
2020-10-24 16:33:13 +02:00
@NotNull
2019-08-21 16:50:52 +02:00
public Player.Hand getHand() {
return hand;
}
2020-05-30 22:32:12 +02:00
/**
2020-10-15 21:16:31 +02:00
* Gets the item which have been used.
2020-05-30 22:32:12 +02:00
*
* @return the item
*/
2020-10-24 16:33:13 +02:00
@NotNull
2019-08-21 16:50:52 +02:00
public ItemStack getItemStack() {
return itemStack;
}
@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;
}
2019-08-21 16:50:52 +02:00
}