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;
|
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
|
|
|
|
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
|
|
|
*/
|
2021-06-04 00:54:36 +02:00
|
|
|
public class PlayerUseItemEvent implements PlayerEvent, 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
|
|
|
|
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) {
|
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;
|
|
|
|
}
|
2020-12-16 03:21:59 +01:00
|
|
|
|
|
|
|
@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
|
|
|
}
|