Class ItemInteraction

java.lang.Object
com.github.pinont.singularitylib.api.items.ItemInteraction

public abstract class ItemInteraction extends Object
Interface for defining custom item interactions. Items with interactions can respond to player clicks and actions.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ItemInteraction(String name, Set<org.bukkit.event.block.Action> action)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Whether to cancel the original event when this interaction is executed.
    abstract void
    execute(org.bukkit.entity.Player player)
    Executes this interaction for the given player.
    Set<org.bukkit.event.block.Action>
    Gets the set of actions that trigger this interaction.
    getInteraction(org.bukkit.plugin.Plugin plugin, org.bukkit.inventory.ItemStack item)
    Gets the interaction associated with the given ItemStack.
    static Object
    getItemPersistData(org.bukkit.plugin.Plugin plugin, org.bukkit.inventory.ItemStack item, String key, org.bukkit.persistence.PersistentDataType type)
    Gets the persistent data of an item.
    Gets the name of this interaction.
    static Boolean
    isItemHasPersistData(org.bukkit.plugin.Plugin plugin, org.bukkit.inventory.ItemStack item, String key, org.bukkit.persistence.PersistentDataType type)
    Checks if the item has persistent data of a specific type.
    int
    Gets the number of items to remove when this interaction is executed.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ItemInteraction

      public ItemInteraction(String name, Set<org.bukkit.event.block.Action> action)
  • Method Details

    • removeItemAmountOnExecute

      public int removeItemAmountOnExecute()
      Gets the number of items to remove when this interaction is executed. Default implementation returns 0 (no items consumed).
      Returns:
      the number of items to remove from the stack
    • getName

      public String getName()
      Gets the name of this interaction.
      Returns:
      the interaction name
    • getAction

      public Set<org.bukkit.event.block.Action> getAction()
      Gets the set of actions that trigger this interaction.
      Returns:
      the set of triggering actions
    • execute

      public abstract void execute(org.bukkit.entity.Player player)
      Executes this interaction for the given player.
      Parameters:
      player - the player who triggered the interaction
    • cancelEvent

      public boolean cancelEvent()
      Whether to cancel the original event when this interaction is executed. Default implementation returns true.
      Returns:
      true to cancel the event, false to allow it to continue
    • isItemHasPersistData

      public static Boolean isItemHasPersistData(org.bukkit.plugin.Plugin plugin, org.bukkit.inventory.ItemStack item, String key, org.bukkit.persistence.PersistentDataType type)
      Checks if the item has persistent data of a specific type.
      Parameters:
      item - the ItemStack to check
      key - the key of the data to check for
      type - the PersistentDataType of the data
      Returns:
      true if the data exists, false otherwise
    • getItemPersistData

      public static Object getItemPersistData(org.bukkit.plugin.Plugin plugin, org.bukkit.inventory.ItemStack item, String key, org.bukkit.persistence.PersistentDataType type)
      Gets the persistent data of an item.
      Parameters:
      item - the ItemStack to get data from
      key - the key of the data to get
      type - the PersistentDataType of the data
      Returns:
      the data value, or null if not present
    • getInteraction

      public static ItemInteraction getInteraction(org.bukkit.plugin.Plugin plugin, org.bukkit.inventory.ItemStack item)
      Gets the interaction associated with the given ItemStack.
      Parameters:
      item - the ItemStack to get the interaction for
      Returns:
      the ItemInteraction, or null if none found