Package de.themoep.inventorygui
Class GuiStateElement
java.lang.Object
de.themoep.inventorygui.GuiElement
de.themoep.inventorygui.GuiStateElement
An element that can switch between certain states. It automatically handles the switching
of the item in the slot that corresponds to the state that the element is in.
-
Nested Class Summary
Nested ClassesNested 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
ConstructorsConstructorDescriptionGuiStateElement
(char slotChar, int defaultState, GuiStateElement.State... states) An element that can switch between certain states.GuiStateElement
(char slotChar, GuiStateElement.State... states) An element that can switch between certain states.GuiStateElement
(char slotChar, String defaultState, GuiStateElement.State... states) An element that can switch between certain states.GuiStateElement
(char slotChar, Supplier<String> queryState, GuiStateElement.State... states) An element that can switch between certain states. -
Method Summary
Modifier and TypeMethodDescriptionorg.bukkit.inventory.ItemStack
getItem
(org.bukkit.entity.HumanEntity who, int slot) Get the item that is displayed by this element on a certain pagegetState()
Get the current state of this elementboolean
isSilent()
Get whether or not this element should make a sound when interacted withLoop through the states of this elementLoop through the states of this element backwardsvoid
setGui
(InventoryGui gui) Set the gui this element belongs tovoid
setSilent
(boolean silent) Set whether or not this element should make a sound when interacted withvoid
Set the current state with the state's key.Methods inherited from class de.themoep.inventorygui.GuiElement
getAction, getGui, getSlotChar, getSlotIndex, getSlotIndex, getSlots, setAction, setSlots
-
Constructor Details
-
GuiStateElement
An element that can switch between certain states.- Parameters:
slotChar
- The character to replace in the gui setup string.defaultState
- The index of the default state.states
- The list of differentGuiStateElement.State
s that this element can have.
-
GuiStateElement
An element that can switch between certain states.- Parameters:
slotChar
- The character to replace in the gui setup string.defaultState
- The key of the default state.states
- The list of differentGuiStateElement.State
s that this element can have.
-
GuiStateElement
An element that can switch between certain states.- Parameters:
slotChar
- The character to replace in the gui setup string.queryState
- Supplier for the current state.states
- The list of differentGuiStateElement.State
s that this element can have.
-
GuiStateElement
An element that can switch between certain states. The first state will be the default one.- Parameters:
slotChar
- The character to replace in the gui setup string.states
- The list of differentGuiStateElement.State
s that this element can have.
-
-
Method Details
-
nextState
Loop through the states of this element- Returns:
- The new state (next one to the old)
-
previousState
Loop through the states of this element backwards- Returns:
- The new state (previous one to the old)
-
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
-
setGui
Description copied from class:GuiElement
Set the gui this element belongs to- Overrides:
setGui
in classGuiElement
- Parameters:
gui
- The GUI that this element is in
-
getState
Get the current state of this element- Returns:
- The current state of this element
-
isSilent
public boolean isSilent()Get whether or not this element should make a sound when interacted with- Returns:
- Whether or not to make a sound when interacted with
-
setSilent
public void setSilent(boolean silent) Set whether or not this element should make a sound when interacted with- Parameters:
silent
- Whether or not to make a sound when interacted with
-
setState
Set the current state with the state's key. Does not trigger the state's change.- Parameters:
key
- The key to search for.- Throws:
IllegalArgumentException
- Thrown if there is no state with the provided key.
-