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

Public Functions

Type Name
ENDSTONE_EVENT (PlayerInteractEvent)
PlayerInteractEvent (Player & player, Action action, ItemStack * item, Block * block_clicked, BlockFace block_face, const std::optional< Vector< float > > & 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< float > > getClickedPosition () const
Gets the exact position on the block the player interacted with.
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. A cancelled event will not be executed in the server, but will still pass to other plugins.
virtual bool isCancelled () override const
Gets the cancellation state of this event. A cancelled event will not be executed in the server, but will still pass to other plugins.
virtual void setCancelled (bool cancel) override
Sets the cancellation state of this event. A cancelled event will not be executed in the server, but will still pass to other plugins.

Public Functions inherited from endstone::ICancellable

See endstone::ICancellable

Type Name
virtual void cancel () = 0
virtual bool isCancelled () const = 0
virtual void setCancelled (bool cancel) = 0
virtual ~ICancellable () = default

Public Types Documentation

enum Action

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,
    ItemStack * item,
    Block * block_clicked,
    BlockFace block_face,
    const std::optional< Vector < float > > & 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 < float > > 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 ItemStack * endstone::PlayerInteractEvent::getItem () const

Returns:

ItemStack the item used


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