2020-05-07 15:46:21 +02:00
|
|
|
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;
|
2020-05-07 15:46:21 +02:00
|
|
|
import net.minestom.server.event.CancellableEvent;
|
2020-12-16 03:21:59 +01:00
|
|
|
import net.minestom.server.event.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
|
|
|
|
2020-05-03 22:44:38 +02:00
|
|
|
/**
|
2020-10-22 19:18:08 +02:00
|
|
|
* Event when an item is used without clicking on a block.
|
2020-05-03 22:44:38 +02:00
|
|
|
*/
|
2020-12-16 03:21:59 +01:00
|
|
|
public class PlayerUseItemEvent extends PlayerEvent implements CancellableEvent {
|
2019-08-21 16:50:52 +02:00
|
|
|
|
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
|
|
|
|
2020-12-16 03:21:59 +01:00
|
|
|
private boolean cancelled;
|
|
|
|
|
2020-10-24 16:33:13 +02:00
|
|
|
public PlayerUseItemEvent(@NotNull Player player, @NotNull Player.Hand hand, @NotNull ItemStack itemStack) {
|
2020-12-16 03:21:59 +01:00
|
|
|
super(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;
|
|
|
|
}
|
2020-12-16 03:21:59 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isCancelled() {
|
|
|
|
return cancelled;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setCancelled(boolean cancel) {
|
|
|
|
this.cancelled = cancel;
|
|
|
|
}
|
2019-08-21 16:50:52 +02:00
|
|
|
}
|