Class ItemInteraction
java.lang.Object
com.github.pinont.singularitylib.api.items.ItemInteraction
Interface for defining custom item interactions.
Items with interactions can respond to player clicks and actions.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanWhether to cancel the original event when this interaction is executed.abstract voidexecute(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.static ItemInteractiongetInteraction(org.bukkit.plugin.Plugin plugin, org.bukkit.inventory.ItemStack item) Gets the interaction associated with the given ItemStack.static ObjectgetItemPersistData(org.bukkit.plugin.Plugin plugin, org.bukkit.inventory.ItemStack item, String key, org.bukkit.persistence.PersistentDataType type) Gets the persistent data of an item.getName()Gets the name of this interaction.static BooleanisItemHasPersistData(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.intGets the number of items to remove when this interaction is executed.
-
Constructor Details
-
ItemInteraction
-
-
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
-
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 checkkey- the key of the data to check fortype- 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 fromkey- the key of the data to gettype- 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
-