Skip to content

Class endstone::PlayerInteractEvent

ClassList > endstone > PlayerInteractEvent

Represents an event that is called when a player right-clicks a block.

  • #include <endstone/event/player/player_interact_event.h>

Inherits the following classes: endstone::Cancellable

Public Types

Type Name
enum Action
Represents the type of interaction that triggered this event.

Public Functions

Type Name
ENDSTONE_EVENT (PlayerInteractEvent)
PlayerInteractEvent (Player & player, Action action, std::optional< ItemStack > item, Block * block_clicked, BlockFace block_face, std::optional< Vector > clicked_position)
Action getAction () const
Returns the action type.
Block * getBlock () const
Returns the clicked block.
BlockFace getBlockFace () const
Returns the face of the block that was clicked.
std::optional< Vector > getClickedPosition () const
Gets the exact position on the block the player interacted with.
const std::optional< ItemStack > & getItem () const
Returns the item in hand represented by this event.
bool hasBlock () const
Check if this event involved a block.
bool hasItem () const
Check if this event involved an item.

Public Functions inherited from endstone::Cancellable

See endstone::Cancellable

Type Name
virtual void cancel ()
Cancel this event.
virtual bool isCancelled () override const
Gets the cancellation state of this event.
virtual void setCancelled (bool cancel) override
Sets the cancellation state of this event.

Public Functions inherited from endstone::ICancellable

See endstone::ICancellable

Type Name
virtual void cancel () = 0
Cancels this event.
virtual bool isCancelled () const = 0
Gets the cancellation state of this event.
virtual void setCancelled (bool cancel) = 0
Sets the cancellation state of this event.
virtual ~ICancellable () = default

Public Types Documentation

enum Action

Represents the type of interaction that triggered this event.

enum endstone::PlayerInteractEvent::Action {
    LeftClickBlock,
    RightClickBlock,
    LeftClickAir,
    RightClickAir
};


Public Functions Documentation

function ENDSTONE_EVENT

endstone::PlayerInteractEvent::ENDSTONE_EVENT (
    PlayerInteractEvent
) 

function PlayerInteractEvent

inline endstone::PlayerInteractEvent::PlayerInteractEvent (
    Player & player,
    Action action,
    std::optional< ItemStack > item,
    Block * block_clicked,
    BlockFace block_face,
    std::optional< Vector > clicked_position
) 

function getAction

Returns the action type.

inline Action endstone::PlayerInteractEvent::getAction () const

Returns:

Action returns the type of interaction


function getBlock

Returns the clicked block.

inline Block * endstone::PlayerInteractEvent::getBlock () const

Returns:

Block returns the block clicked with this item.


function getBlockFace

Returns the face of the block that was clicked.

inline BlockFace endstone::PlayerInteractEvent::getBlockFace () const

Returns:

BlockFace returns the face of the block that was clicked


function getClickedPosition

Gets the exact position on the block the player interacted with.

inline std::optional< Vector > endstone::PlayerInteractEvent::getClickedPosition () const

Note:

This will be std::nullopt outside of Action::RightClickBlock

Note:

All vector components are between 0.0 and 1.0 inclusive.

Returns:

the clicked position.


function getItem

Returns the item in hand represented by this event.

inline const std::optional< ItemStack > & endstone::PlayerInteractEvent::getItem () const

Returns:

ItemStack the item used, or std::nullopt if no item


function hasBlock

Check if this event involved a block.

inline bool endstone::PlayerInteractEvent::hasBlock () const

Returns:

boolean true if it did


function hasItem

Check if this event involved an item.

inline bool endstone::PlayerInteractEvent::hasItem () const

Returns:

boolean true if it did



The documentation for this class was generated from the following file include/endstone/event/player/player_interact_event.h