Package de.themoep.inventorygui
Class GuiStorageElement
java.lang.Object
de.themoep.inventorygui.GuiElement
de.themoep.inventorygui.GuiStorageElement
This element is used to access an
E.g. if you have five characters called "s" in the gui setup and the second element is accessed by the player then it will translate to the second slot in the inventory.
Inventory
. The slots in the inventory are selected
by searching through the whole gui the element is in and getting the number of the spot
in the character group that this element is in. E.g. if you have five characters called "s" in the gui setup and the second element is accessed by the player then it will translate to the second slot in the inventory.
-
Nested Class Summary
Nested classes/interfaces inherited from class de.themoep.inventorygui.GuiElement
GuiElement.Action, GuiElement.Click
-
Field Summary
Fields inherited from class de.themoep.inventorygui.GuiElement
gui, slots
-
Constructor Summary
ConstructorDescriptionGuiStorageElement
(char slotChar, org.bukkit.inventory.Inventory storage) An element used to access anInventory
.GuiStorageElement
(char slotChar, org.bukkit.inventory.Inventory storage, int invSlot) An element used to access a specific slot in anInventory
.GuiStorageElement
(char slotChar, org.bukkit.inventory.Inventory storage, int invSlot, Runnable applyStorage, Function<GuiStorageElement.ValidatorInfo, Boolean> placeValidator) An element used to access a specific slot in anInventory
.GuiStorageElement
(char slotChar, org.bukkit.inventory.Inventory storage, int invSlot, Runnable applyStorage, Function<GuiStorageElement.ValidatorInfo, Boolean> placeValidator, Function<GuiStorageElement.ValidatorInfo, Boolean> takeValidator) An element used to access a specific slot in anInventory
. -
Method Summary
Modifier and TypeMethodDescriptionGet the runnable that applies the storageorg.bukkit.inventory.ItemStack
getItem
(org.bukkit.entity.HumanEntity who, int slot) Get the item that is displayed by this element on a certain pageDeprecated.Get the item place validatororg.bukkit.inventory.Inventory
Get theInventory
that this element is linked to.org.bukkit.inventory.ItemStack
getStorageItem
(int slot) Deprecated.org.bukkit.inventory.ItemStack
getStorageItem
(org.bukkit.entity.HumanEntity player, int slot) Get the item in the storage that corresponds to the InventoryGui slotGet the item take validatorvoid
setApplyStorage
(Runnable applyStorage) Set what should be done to apply the storage.void
setItemValidator
(Function<GuiStorageElement.ValidatorInfo, Boolean> placeValidator) Deprecated.void
setPlaceValidator
(Function<GuiStorageElement.ValidatorInfo, Boolean> placeValidator) Set a function that can validate whether an item can be placed in the slotboolean
setStorageItem
(int slot, org.bukkit.inventory.ItemStack item) Deprecated.boolean
setStorageItem
(org.bukkit.entity.HumanEntity player, int slot, org.bukkit.inventory.ItemStack item) Set the item in the storage that corresponds to the InventoryGui slot.void
setTakeValidator
(Function<GuiStorageElement.ValidatorInfo, Boolean> takeValidator) Set a function that can validate whether an item can be taken from the slotboolean
validateItem
(int slot, org.bukkit.inventory.ItemStack item) Deprecated.boolean
validateItemPlace
(int slot, org.bukkit.inventory.ItemStack item) Validate whether an item can be placed in a slot with the item validator set insetItemValidator(Function)
boolean
validateItemTake
(int slot, org.bukkit.inventory.ItemStack item) Validate whether an item can be taken from a slot with the item validator set insetItemValidator(Function)
Methods inherited from class de.themoep.inventorygui.GuiElement
getAction, getGui, getSlotChar, getSlotIndex, getSlotIndex, getSlots, setAction, setGui, setSlots
-
Constructor Details
-
GuiStorageElement
public GuiStorageElement(char slotChar, org.bukkit.inventory.Inventory storage) An element used to access anInventory
.- Parameters:
slotChar
- The character to replace in the gui setup string.storage
- TheInventory
that this element is linked to.
-
GuiStorageElement
public GuiStorageElement(char slotChar, org.bukkit.inventory.Inventory storage, int invSlot) An element used to access a specific slot in anInventory
.- Parameters:
slotChar
- The character to replace in the gui setup string.storage
- TheInventory
that this element is linked to.invSlot
- The index of the slot to access in theInventory
.
-
GuiStorageElement
public GuiStorageElement(char slotChar, org.bukkit.inventory.Inventory storage, int invSlot, Runnable applyStorage, Function<GuiStorageElement.ValidatorInfo, Boolean> placeValidator) An element used to access a specific slot in anInventory
.- Parameters:
slotChar
- The character to replace in the gui setup string.storage
- TheInventory
that this element is linked to.invSlot
- The index of the slot to access in theInventory
.applyStorage
- Apply the storage that this element represents.placeValidator
- Should returnfalse
for items that should not work in that slot Can be null if the storage is directly linked.
-
GuiStorageElement
public GuiStorageElement(char slotChar, org.bukkit.inventory.Inventory storage, int invSlot, Runnable applyStorage, Function<GuiStorageElement.ValidatorInfo, Boolean> placeValidator, Function<GuiStorageElement.ValidatorInfo, Boolean> takeValidator) An element used to access a specific slot in anInventory
.- Parameters:
slotChar
- The character to replace in the gui setup string.storage
- TheInventory
that this element is linked to.invSlot
- The index of the slot to access in theInventory
.applyStorage
- Apply the storage that this element represents.placeValidator
- Should returnfalse
for items that should not be placeable in that slot Can be null if the storage is directly linked.takeValidator
- Should returnfalse
for items that should not be takeable in that slot Can be null if the storage is directly linked.
-
-
Method Details
-
getItem
public org.bukkit.inventory.ItemStack getItem(org.bukkit.entity.HumanEntity who, int slot) Description copied from class:GuiElement
Get the item that is displayed by this element on a certain page- Specified by:
getItem
in classGuiElement
- Parameters:
who
- The player who views the pageslot
- The slot to get the item for- Returns:
- The ItemStack that is displayed as this element
-
getStorage
public org.bukkit.inventory.Inventory getStorage()Get theInventory
that this element is linked to.- Returns:
- The
Inventory
that this element is linked to.
-
getStorageItem
Deprecated.Get the item in the storage that corresponds to the InventoryGui slot- Parameters:
slot
- The slot in the GUI- Returns:
- The
ItemStack
ornull
if the slot is outside of the item's size
-
getStorageItem
public org.bukkit.inventory.ItemStack getStorageItem(org.bukkit.entity.HumanEntity player, int slot) Get the item in the storage that corresponds to the InventoryGui slot- Parameters:
player
- The player which is using the GUI viewslot
- The slot in the GUI- Returns:
- The
ItemStack
ornull
if the slot is outside of the item's size
-
setStorageItem
Deprecated.Set the item in the storage that corresponds to the InventoryGui slot.- Parameters:
slot
- The slot in the GUIitem
- TheItemStack
to set- Returns:
true
if the item was set;false
if the slot was outside of this storage
-
setStorageItem
public boolean setStorageItem(org.bukkit.entity.HumanEntity player, int slot, org.bukkit.inventory.ItemStack item) Set the item in the storage that corresponds to the InventoryGui slot.- Parameters:
player
- The player using the GUI viewslot
- The slot in the GUIitem
- TheItemStack
to set- Returns:
true
if the item was set;false
if the slot was outside of this storage
-
getApplyStorage
Get the runnable that applies the storage- Returns:
- The storage applying runnable; might be null
-
setApplyStorage
Set what should be done to apply the storage. Not necessary if the storage is directly backed by a real inventory.- Parameters:
applyStorage
- How to apply the storage; can be null if nothing should be done
-
getItemValidator
Deprecated.Get the item place validator- Returns:
- The item place validator
-
getPlaceValidator
Get the item place validator- Returns:
- The item validator
-
getTakeValidator
Get the item take validator- Returns:
- The item take validator
-
setItemValidator
@Deprecated public void setItemValidator(Function<GuiStorageElement.ValidatorInfo, Boolean> placeValidator) Deprecated.Set a function that can validate whether an item can be placed in the slot- Parameters:
placeValidator
- The item validator that takes aGuiStorageElement.ValidatorInfo
and returnstrue
for items that should andfalse
for items that should not be placeable in that slot
-
setPlaceValidator
Set a function that can validate whether an item can be placed in the slot- Parameters:
placeValidator
- The item validator that takes aGuiStorageElement.ValidatorInfo
and returnstrue
for items that should andfalse
for items that should not be placeable in that slot
-
setTakeValidator
Set a function that can validate whether an item can be taken from the slot- Parameters:
takeValidator
- The item validator that takes aGuiStorageElement.ValidatorInfo
and returnstrue
for items that should andfalse
for items that should not be taken in that slot
-
validateItem
Deprecated.Validate whether an item can be placed in a slot with the item validator set insetItemValidator(Function)
- Parameters:
slot
- The slot the item should be tested foritem
- The item to test- Returns:
true
for items that should andfalse
for items that should not work in that slot
-
validateItemPlace
public boolean validateItemPlace(int slot, org.bukkit.inventory.ItemStack item) Validate whether an item can be placed in a slot with the item validator set insetItemValidator(Function)
- Parameters:
slot
- The slot the item should be tested foritem
- The item to test- Returns:
true
for items that should andfalse
for items that should not work in that slot
-
validateItemTake
public boolean validateItemTake(int slot, org.bukkit.inventory.ItemStack item) Validate whether an item can be taken from a slot with the item validator set insetItemValidator(Function)
- Parameters:
slot
- The slot the item should be tested foritem
- The item to test- Returns:
true
for items that should andfalse
for items that should not be taken from that slot
-
getPlaceValidator()