Record Class UseContext

java.lang.Object
java.lang.Record
com.github.darksoulq.abyssallib.server.event.context.item.UseContext
Record Components:
source - The entity that initiated the item use.
targetBlock - The block that was clicked, or null if the interaction was in the air or on an entity.
blockFace - The specific face of the block that was clicked, or null if not applicable.
targetEntity - The entity that was clicked, or null if the interaction was on a block or in the air.
type - The specific type of click (Right-click or Left-click) performed.
hand - The hand (Main or Off-hand) that was used to perform the interaction.

public record UseContext(org.bukkit.entity.LivingEntity source, @Nullable org.bukkit.block.Block targetBlock, @Nullable org.bukkit.block.BlockFace blockFace, @Nullable org.bukkit.entity.Entity targetEntity, ClickType type, org.bukkit.inventory.EquipmentSlot hand) extends Record
A context object representing the details of an item interaction.

This class encapsulates all relevant data when an item is used, including the interacting entity, the block or entity targeted, and the hand/click type used.

  • Constructor Summary

    Constructors
    Constructor
    Description
    UseContext(org.bukkit.entity.LivingEntity source, @Nullable org.bukkit.block.Block targetBlock, @Nullable org.bukkit.block.BlockFace blockFace, @Nullable org.bukkit.entity.Entity targetEntity, ClickType type, org.bukkit.inventory.EquipmentSlot hand)
    Constructs a new UseContext with all interaction details.
  • Method Summary

    Modifier and Type
    Method
    Description
    @Nullable org.bukkit.block.BlockFace
    Gets the face of the block that was clicked.
    final boolean
    Indicates whether some other object is "equal to" this one.
    org.bukkit.inventory.EquipmentSlot
    Gets the hand used for the interaction.
    final int
    Returns a hash code value for this object.
    org.bukkit.entity.LivingEntity
    Gets the entity that used the item.
    @Nullable org.bukkit.block.Block
    Gets the block involved in the interaction.
    @Nullable org.bukkit.entity.Entity
    Gets the entity involved in the interaction.
    final String
    Returns a string representation of this record class.
    Gets the type of click performed.

    Methods inherited from class Object

    getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • UseContext

      public UseContext(org.bukkit.entity.LivingEntity source, @Nullable @Nullable org.bukkit.block.Block targetBlock, @Nullable @Nullable org.bukkit.block.BlockFace blockFace, @Nullable @Nullable org.bukkit.entity.Entity targetEntity, ClickType type, org.bukkit.inventory.EquipmentSlot hand)
      Constructs a new UseContext with all interaction details.
      Parameters:
      source - The LivingEntity performing the action.
      targetBlock - The Block being interacted with, if any.
      blockFace - The BlockFace clicked, if any.
      targetEntity - The Entity being interacted with, if any.
      type - The ClickType used for this interaction.
      hand - The EquipmentSlot representing the hand used.
  • Method Details

    • source

      public org.bukkit.entity.LivingEntity source()
      Gets the entity that used the item.
      Returns:
      The LivingEntity source.
    • targetBlock

      @Nullable public @Nullable org.bukkit.block.Block targetBlock()
      Gets the block involved in the interaction.
      Returns:
      The targeted Block, or null if no block was targeted.
    • blockFace

      @Nullable public @Nullable org.bukkit.block.BlockFace blockFace()
      Gets the face of the block that was clicked.
      Returns:
      The BlockFace, or null if no block was targeted.
    • targetEntity

      @Nullable public @Nullable org.bukkit.entity.Entity targetEntity()
      Gets the entity involved in the interaction.
      Returns:
      The targeted Entity, or null if no entity was targeted.
    • type

      public ClickType type()
      Gets the type of click performed.
      Returns:
      The ClickType (e.g., RIGHT_CLICK or LEFT_CLICK).
    • hand

      public org.bukkit.inventory.EquipmentSlot hand()
      Gets the hand used for the interaction.
      Returns:
      The EquipmentSlot (HAND or OFF_HAND).
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.