Package dev.aurelium.slate.inv
Class ClickableItem
java.lang.Object
dev.aurelium.slate.inv.ClickableItem
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ClickableItemClickableItem constant with no item and empty consumer. -
Method Summary
Modifier and TypeMethodDescriptionSets a test to check if a player is allowed to click the item.Sets a test to check if a player is allowed to see this item.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 itsConsumer, but giving it a newItemStack.static ClickableItemempty(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.static ClickableItemfrom(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.ItemStackgetItem()Returns the item contained in this ClickableItem disregarding the visibility test set viacanSee(Predicate, ItemStack).org.bukkit.inventory.ItemStackgetItem(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.static ClickableItemof(org.bukkit.inventory.ItemStack item, Consumer<org.bukkit.event.inventory.InventoryClickEvent> consumer) Deprecated.voidrun(ItemClickData data) Executes this ClickableItem's consumer using the given click data.voidrun(org.bukkit.event.inventory.InventoryClickEvent e) Deprecated.This has been replaced byrun(ItemClickData).
-
Field Details
-
NONE
ClickableItem constant with no item and empty consumer.
-
-
Method Details
-
empty
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.Replaced byfrom(ItemStack, Consumer)Creates a ClickableItem made of a given item and a given InventoryClickEvent's consumer.- Parameters:
item- the itemconsumer- 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 itemconsumer- the consumer which will be called when the item is clicked- Returns:
- the created ClickableItem
-
run
Deprecated.This has been replaced byrun(ItemClickData).Executes this ClickableItem's consumer using the given click event.- Parameters:
e- the click event
-
clone
Clones this ClickableItem using a different item.- Parameters:
newItem- the new item- Returns:
- the created ClickableItem
-
cloneWithNewItem
Clones this ClickableItem while keeping itsConsumer, but giving it a newItemStack.- Parameters:
item- the newItemStack- Returns:
- a new ClickableItem with its related
ItemStackupdated
-
run
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 viacanSee(Predicate, ItemStack).
Warning: The item can benull.- Returns:
- the item, or
nullif 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 benull.- 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
nullif there is no item
-
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:
thisfor 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 itemfallBackItem- the item that should be used, if the player is not allowed to see the item- Returns:
thisfor a builder-like usage- See Also:
-
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:
thisfor a builder-like usage
-
from(ItemStack, Consumer)