Class ClickableItem

java.lang.Object
dev.aurelium.slate.inv.ClickableItem

public class ClickableItem extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final ClickableItem
    ClickableItem constant with no item and empty consumer.
  • Method Summary

    Modifier and Type
    Method
    Description
    canClick(Predicate<org.bukkit.entity.Player> canClick)
    Sets a test to check if a player is allowed to click the item.
    canSee(Predicate<org.bukkit.entity.Player> canSee)
    Sets a test to check if a player is allowed to see this item.
    canSee(Predicate<org.bukkit.entity.Player> canSee, org.bukkit.inventory.ItemStack fallBackItem)
    Sets a test to check if a player is allowed to see this item.
    clone(org.bukkit.inventory.ItemStack newItem)
    Clones this ClickableItem using a different item.
    cloneWithNewItem(org.bukkit.inventory.ItemStack item)
    Clones this ClickableItem while keeping its Consumer, but giving it a new ItemStack.
    empty(org.bukkit.inventory.ItemStack item)
    Creates a ClickableItem made of a given item and an empty consumer, thus doing nothing when we click on the item.
    from(org.bukkit.inventory.ItemStack item, Consumer<ItemClickData> consumer)
    Creates a ClickableItem made of a given item and a given ItemClickData's consumer.
    org.bukkit.inventory.ItemStack
    Returns the item contained in this ClickableItem disregarding the visibility test set via canSee(Predicate, ItemStack).
    org.bukkit.inventory.ItemStack
    getItem(org.bukkit.entity.Player player)
    Returns the item contained in this ClickableItem or the fallback item, if the player is not allowed to see the item.
    of(org.bukkit.inventory.ItemStack item, Consumer<org.bukkit.event.inventory.InventoryClickEvent> consumer)
    Deprecated.
    void
    Executes this ClickableItem's consumer using the given click data.
    void
    run(org.bukkit.event.inventory.InventoryClickEvent e)
    Deprecated.
    This has been replaced by run(ItemClickData).

    Methods inherited from class java.lang.Object

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

    • NONE

      public static final ClickableItem NONE
      ClickableItem constant with no item and empty consumer.
  • Method Details

    • empty

      public static ClickableItem empty(org.bukkit.inventory.ItemStack item)
      Creates a ClickableItem made of a given item and an empty consumer, thus doing nothing when we click on the item.
      Parameters:
      item - the item
      Returns:
      the created ClickableItem
    • of

      @Deprecated public static ClickableItem of(org.bukkit.inventory.ItemStack item, Consumer<org.bukkit.event.inventory.InventoryClickEvent> consumer)
      Deprecated.
      Creates a ClickableItem made of a given item and a given InventoryClickEvent's consumer.
      Parameters:
      item - the item
      consumer - the consumer which will be called when the item is clicked
      Returns:
      the created ClickableItem
    • from

      public static ClickableItem from(org.bukkit.inventory.ItemStack item, Consumer<ItemClickData> consumer)
      Creates a ClickableItem made of a given item and a given ItemClickData's consumer.
      Parameters:
      item - the item
      consumer - the consumer which will be called when the item is clicked
      Returns:
      the created ClickableItem
    • run

      @Deprecated public void run(org.bukkit.event.inventory.InventoryClickEvent e)
      Deprecated.
      This has been replaced by run(ItemClickData).
      Executes this ClickableItem's consumer using the given click event.
      Parameters:
      e - the click event
    • clone

      public ClickableItem clone(org.bukkit.inventory.ItemStack newItem)
      Clones this ClickableItem using a different item.
      Parameters:
      newItem - the new item
      Returns:
      the created ClickableItem
    • cloneWithNewItem

      public ClickableItem cloneWithNewItem(org.bukkit.inventory.ItemStack item)
      Clones this ClickableItem while keeping its Consumer, but giving it a new ItemStack.
      Parameters:
      item - the new ItemStack
      Returns:
      a new ClickableItem with its related ItemStack updated
    • run

      public void run(ItemClickData data)
      Executes this ClickableItem's consumer using the given click data.
      Parameters:
      data - the data of the click
    • getItem

      public org.bukkit.inventory.ItemStack getItem()
      Returns the item contained in this ClickableItem disregarding the visibility test set via canSee(Predicate, ItemStack).
      Warning: The item can be null.
      Returns:
      the item, or null if there is no item
    • getItem

      public org.bukkit.inventory.ItemStack getItem(org.bukkit.entity.Player player)
      Returns the item contained in this ClickableItem or the fallback item, if the player is not allowed to see the item.
      Warning: The item can be null.
      Parameters:
      player - The player to test against if he can see this item
      Returns:
      the item, the fallback item when not visible to the player, or null if there is no item
    • canSee

      public ClickableItem canSee(Predicate<org.bukkit.entity.Player> canSee)
      Sets a test to check if a player is allowed to see this item.
      Note: If the player is not allowed to see the item, in the inventory this item will be empty.
      Examples:
      • .canSee(player -> player.hasPermission("my.permission"))
      • .canSee(player -> player.getHealth() >= 10)
      Parameters:
      canSee - the test, if a player should be allowed to see this item
      Returns:
      this for a builder-like usage
      See Also:
    • canSee

      public ClickableItem canSee(Predicate<org.bukkit.entity.Player> canSee, org.bukkit.inventory.ItemStack fallBackItem)
      Sets a test to check if a player is allowed to see this item.
      If the player is not allowed to see the item, the fallback item will be used instead.
      Note: If the player is not allowed to see the item, the on click handler will not be run
      Examples:
      • .canSee(player -> player.hasPermission("my.permission"), backgroundItem)
      • .canSee(player -> player.getHealth() >= 10, backgroundItem)
      Parameters:
      canSee - the test, if a player should be allowed to see this item
      fallBackItem - the item that should be used, if the player is not allowed to see the item
      Returns:
      this for a builder-like usage
      See Also:
    • canClick

      public ClickableItem canClick(Predicate<org.bukkit.entity.Player> canClick)
      Sets a test to check if a player is allowed to click the item.
      If a player is not allowed to click this item, the on click handler provided at creation will not be run
      Parameters:
      canClick - the test, if a player should be allowed to see this item
      Returns:
      this for a builder-like usage