Class Item
java.lang.Object
com.github.darksoulq.abyssallib.world.item.Item
- All Implemented Interfaces:
Cloneable
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classInternal class used to configure the visual representation of an item's tooltip. -
Field Summary
FieldsModifier and TypeFieldDescriptionThe helper object used to build and manage procedural tooltips. -
Constructor Summary
ConstructorsConstructorDescriptionItem(net.kyori.adventure.key.Key id) Constructs a new custom item definition.Item(net.kyori.adventure.key.Key id, org.bukkit.Material base) Constructs a new custom item definition.Item(org.bukkit.inventory.ItemStack stack) Internal constructor for wrapping an existing item stack. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a translation provider to this item for resolving localized text elements dynamically.static CustomBlockAttempts to find the custom block associated with a block-item.clone()Performs a deep clone of the item, including its stack, map, and tooltip state.voidcreateTooltip(Item.Tooltip tooltip) Called when a tooltip is being generated.voidcreateTooltip(Item.Tooltip tooltip, @Nullable org.bukkit.entity.Player player) Called when a tooltip is being generated for a specific viewer.booleanCompares this item against another object for equality based on Key.Retrieves the component map managing the item's state and data.getCTag()Retrieves the AbyssalLib persistent data tag for this item.<C extends DataComponent<?>>
CgetData(DataComponentType<C> type) Retrieves the data component of the specified type.net.kyori.adventure.key.KeygetId()Retrieves the unique Key associated with this item.org.bukkit.inventory.ItemStackgetStack()Retrieves the underlying Bukkit ItemStack managed by this instance.org.bukkit.inventory.ItemStackgetStack(@Nullable org.bukkit.entity.Player player) Creates a temporary clone of the item and renders it for a specific player's view.Retrieves the list of local translation providers applied to this item.booleanhasData(DataComponentType<?> type) Checks if this item possesses a specific component type.inthashCode()Generates a hash code derived from the item's unique Key.booleanChecks if this item belongs to a specificItemTag.booleanhasTag(net.kyori.adventure.key.Key id) Checks if this item belongs to a specific tag by its Key.booleanisHidden()Gets whether or not this item should be hidden in /giveonAnvil(AnvilContext ctx) Called when this item is placed in an anvil and requires custom logic.onClick(org.bukkit.entity.Player player, int slot, org.bukkit.inventory.PlayerInventory inventory, InventoryClickType type) Callback triggered when a player clicks this item inside an inventory GUI.voidonCraft(org.bukkit.entity.Player player) Called when a player successfully crafts this item.onDrop(org.bukkit.entity.Player player) Called when a player drops this item onto the ground.onHit(org.bukkit.entity.LivingEntity source, org.bukkit.entity.Entity target) Callback triggered after an entity hits another entity with this item.voidonInventoryTick(org.bukkit.entity.Player player) Called once per tick for every player that has this item in their inventory.onMine(org.bukkit.entity.LivingEntity source, org.bukkit.block.Block target) Callback triggered after an entity successfully mines a block with this item.onPickup(org.bukkit.entity.Player player) Called when a player picks this item up from the ground.voidonSlotChange(org.bukkit.entity.Player player, @Nullable Integer newSlot) Called when the item's position within a player's inventory changes.onSwapHand(org.bukkit.entity.Player player, org.bukkit.inventory.EquipmentSlot current) Called when a player uses the swap-hand key with this item.onUse(org.bukkit.entity.LivingEntity source, org.bukkit.inventory.EquipmentSlot hand, ClickType type) Callback triggered when a player uses this item while clicking into the air.onUseOn(UseContext ctx) Callback triggered when a player uses this item on a specific block or entity.static Itemresolve(org.bukkit.inventory.ItemStack stack) Resolves a standard Bukkit stack into a custom library Item.voidSets the AbyssalLib persistent data tag for this item.voidsetData(DataComponent<?> component) Adds or updates a data component for this item.voidsetHidden(boolean hidden) Sets whether or not this item should be hidden in /givevoidAdds this custom item's identity to an existing tag's logic.voidunsetData(DataComponentType<?> type) Removes the data component associated with the provided type.voidUpdates the item's data components (Lore, DisplayTooltip, TooltipStyle) based on the current state of thetooltipobject.
-
Field Details
-
tooltip
The helper object used to build and manage procedural tooltips.
-
-
Constructor Details
-
Item
@Internal public Item(org.bukkit.inventory.ItemStack stack) Internal constructor for wrapping an existing item stack.- Parameters:
stack- TheItemStackto wrap and analyze.
-
Item
public Item(net.kyori.adventure.key.Key id) Constructs a new custom item definition.- Parameters:
id- The uniqueKeyfor the item (e.g, "plugin_id:item_name").
-
Item
public Item(net.kyori.adventure.key.Key id, org.bukkit.Material base) Constructs a new custom item definition.- Parameters:
id- The uniqueKeyfor the item (e.g., "plugin_id:item_name").base- The baseMaterialused for the underlying item stack.
-
-
Method Details
-
getTranslationProviders
Retrieves the list of local translation providers applied to this item.- Returns:
- A list of
ItemTranslationProviderinstances.
-
addTranslationProvider
Adds a translation provider to this item for resolving localized text elements dynamically.- Parameters:
provider- TheItemTranslationProviderto add.
-
createTooltip
Called when a tooltip is being generated. Override to add static lines.- Parameters:
tooltip- TheItem.Tooltipinstance to populate with lines and styles.
-
createTooltip
public void createTooltip(Item.Tooltip tooltip, @Nullable @Nullable org.bukkit.entity.Player player) Called when a tooltip is being generated for a specific viewer.- Parameters:
tooltip- TheItem.Tooltipinstance to populate.player- ThePlayerviewing the item, ornullif unknown.
-
updateTooltip
public void updateTooltip()Updates the item's data components (Lore, DisplayTooltip, TooltipStyle) based on the current state of thetooltipobject. -
setData
Adds or updates a data component for this item.- Parameters:
component- TheDataComponentinstance to apply.
-
getData
Retrieves the data component of the specified type.- Type Parameters:
C- The specific type of DataComponent.- Parameters:
type- TheDataComponentTypeto look for.- Returns:
- The found component, or
nullif not set.
-
hasData
Checks if this item possesses a specific component type.- Parameters:
type- TheDataComponentTypeto verify.- Returns:
- True if the component is present, false otherwise.
-
unsetData
Removes the data component associated with the provided type.- Parameters:
type- TheDataComponentTypeidentifying the component to unset.
-
hasTag
public boolean hasTag(net.kyori.adventure.key.Key id) Checks if this item belongs to a specific tag by its Key.- Parameters:
id- TheKeyof the tag (e.g., "minecraft:swords").- Returns:
- True if the item is included in the tag.
-
hasTag
-
setTag
-
setHidden
public void setHidden(boolean hidden) Sets whether or not this item should be hidden in /give- Parameters:
hidden- whether or not to hide the item
-
isHidden
public boolean isHidden()Gets whether or not this item should be hidden in /give- Returns:
- whether or not to hide the item
-
onMine
Callback triggered after an entity successfully mines a block with this item.- Parameters:
source- TheLivingEntityperforming the mining.target- TheBlockthat was destroyed.- Returns:
- The resulting
ActionResultdetermining event continuation.
-
onHit
Callback triggered after an entity hits another entity with this item.- Parameters:
source- TheLivingEntityattacker.target- TheEntityvictim.- Returns:
- The resulting
ActionResultfor the hit event.
-
onUseOn
Callback triggered when a player uses this item on a specific block or entity.- Parameters:
ctx- TheUseContextcontaining information about the interaction.- Returns:
- The
ActionResultof the block interaction.
-
onUse
public ActionResult onUse(org.bukkit.entity.LivingEntity source, org.bukkit.inventory.EquipmentSlot hand, ClickType type) Callback triggered when a player uses this item while clicking into the air.- Parameters:
source- TheLivingEntityusing the item.hand- TheEquipmentSlotused for the click.type- TheClickType(Right-click or Left-click) performed in air.- Returns:
- The
ActionResultof the air interaction.
-
onInventoryTick
public void onInventoryTick(org.bukkit.entity.Player player) Called once per tick for every player that has this item in their inventory.- Parameters:
player- ThePlayercarrying the item.
-
onSlotChange
Called when the item's position within a player's inventory changes.- Parameters:
player- ThePlayerwhose inventory was updated.newSlot- The index of the new slot, ornullif moved out of inventory.
-
onClick
public ActionResult onClick(org.bukkit.entity.Player player, int slot, org.bukkit.inventory.PlayerInventory inventory, InventoryClickType type) Callback triggered when a player clicks this item inside an inventory GUI.- Parameters:
player- ThePlayerclicking.slot- The raw slot index clicked.inventory- ThePlayerInventoryinvolved.type- TheInventoryClickTyperepresenting the click style.- Returns:
- The
ActionResultdetermining if the click is allowed.
-
onDrop
Called when a player drops this item onto the ground.- Parameters:
player- ThePlayerwho dropped the item.- Returns:
- The
ActionResultof the drop.
-
onPickup
Called when a player picks this item up from the ground.- Parameters:
player- ThePlayerpicking up the item.- Returns:
- The
ActionResultof the pickup.
-
onSwapHand
public ActionResult onSwapHand(org.bukkit.entity.Player player, org.bukkit.inventory.EquipmentSlot current) Called when a player uses the swap-hand key with this item.- Parameters:
player- ThePlayerswapping the item.current- TheEquipmentSlotthe item was in before the swap.- Returns:
- The
ActionResultof the swap action.
-
onAnvil
Called when this item is placed in an anvil and requires custom logic.- Parameters:
ctx- TheAnvilContextcontaining the input and result slots.- Returns:
- The
ActionResultof the anvil process.
-
onCraft
public void onCraft(org.bukkit.entity.Player player) Called when a player successfully crafts this item.- Parameters:
player- ThePlayerwho completed the craft.
-
getId
public net.kyori.adventure.key.Key getId()Retrieves the unique Key associated with this item.- Returns:
- The item's unique
Key.
-
getStack
public org.bukkit.inventory.ItemStack getStack()Retrieves the underlying Bukkit ItemStack managed by this instance.- Returns:
- The underlying
ItemStack.
-
getStack
public org.bukkit.inventory.ItemStack getStack(@Nullable @Nullable org.bukkit.entity.Player player) Creates a temporary clone of the item and renders it for a specific player's view.- Parameters:
player- ThePlayerfor whom the stack is being generated.- Returns:
- A localized
ItemStackwith a customized tooltip.
-
getComponentMap
Retrieves the component map managing the item's state and data.- Returns:
- The internal
ComponentMap.
-
getCTag
-
setCTag
-
resolve
-
asBlock
Attempts to find the custom block associated with a block-item.- Parameters:
item- TheItemto analyze.- Returns:
- The
CustomBlockcounterpart, ornullif not a block.
-
clone
-
equals
-
hashCode
-