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
ConstructorsConstructorDescriptionUseContext(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 TypeMethodDescription@Nullable org.bukkit.block.BlockFaceGets the face of the block that was clicked.final booleanIndicates whether some other object is "equal to" this one.org.bukkit.inventory.EquipmentSlothand()Gets the hand used for the interaction.final inthashCode()Returns a hash code value for this object.org.bukkit.entity.LivingEntitysource()Gets the entity that used the item.@Nullable org.bukkit.block.BlockGets the block involved in the interaction.@Nullable org.bukkit.entity.EntityGets the entity involved in the interaction.final StringtoString()Returns a string representation of this record class.type()Gets the type of click performed.
-
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- TheLivingEntityperforming the action.targetBlock- TheBlockbeing interacted with, if any.blockFace- TheBlockFaceclicked, if any.targetEntity- TheEntitybeing interacted with, if any.type- TheClickTypeused for this interaction.hand- TheEquipmentSlotrepresenting the hand used.
-
-
Method Details
-
source
public org.bukkit.entity.LivingEntity source()Gets the entity that used the item.- Returns:
- The
LivingEntitysource.
-
targetBlock
@Nullable public @Nullable org.bukkit.block.Block targetBlock()Gets the block involved in the interaction.- Returns:
- The targeted
Block, ornullif 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, ornullif no block was targeted.
-
targetEntity
@Nullable public @Nullable org.bukkit.entity.Entity targetEntity()Gets the entity involved in the interaction.- Returns:
- The targeted
Entity, ornullif no entity was targeted.
-
type
-
hand
public org.bukkit.inventory.EquipmentSlot hand()Gets the hand used for the interaction.- Returns:
- The
EquipmentSlot(HAND or OFF_HAND).
-
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object).
-