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 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
ConstructorDescriptionGuiStateElement
(char slotChar, boolean switchStateOnClick, int defaultState, GuiStateElement.State... states) An element that can switch between certain states.GuiStateElement
(char slotChar, boolean switchStateOnClick, GuiStateElement.State... states) An element that can switch between certain states.GuiStateElement
(char slotChar, boolean switchStateOnClick, String defaultState, GuiStateElement.State... states) An element that can switch between certain states.GuiStateElement
(char slotChar, boolean switchStateOnClick, Supplier<String> queryState, GuiStateElement.State... states) An element that can switch between certain states.GuiStateElement
(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.void
setSwitchStateOnClick
(boolean switchStateOnClick) Set whether the state of this element should switch each time it is clickedboolean
Get whether the state of this element should switch each time it is clickedMethods inherited from class de.themoep.inventorygui.GuiElement
getAction, getGui, getSlotChar, getSlotIndex, getSlotIndex, getSlots, setAction, setSlots
-
Constructor Details
-
GuiStateElement
public GuiStateElement(char slotChar, boolean switchStateOnClick, int defaultState, GuiStateElement.State... states) An element that can switch between certain states.- Parameters:
slotChar
- The character to replace in the gui setup string.switchStateOnClick
- Whether to switch the state when clicked.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. It will automatically switch to the next state when clicked.- 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
public GuiStateElement(char slotChar, boolean switchStateOnClick, String defaultState, GuiStateElement.State... states) An element that can switch between certain states.- Parameters:
slotChar
- The character to replace in the gui setup string.switchStateOnClick
- Whether to switch the state when clicked.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. It will automatically switch to the next state when clicked.- 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
public GuiStateElement(char slotChar, boolean switchStateOnClick, Supplier<String> queryState, GuiStateElement.State... states) An element that can switch between certain states.- Parameters:
slotChar
- The character to replace in the gui setup string.switchStateOnClick
- Whether to switch the state when clicked.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. It will automatically switch to the next state when clicked.- 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.switchStateOnClick
- Whether to switch the state when clicked.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
-
shouldSwitchStateOnClick
public boolean shouldSwitchStateOnClick()Get whether the state of this element should switch each time it is clicked- Returns:
- Whether the state of this element should switch each time it is clicked
-
setSwitchStateOnClick
public void setSwitchStateOnClick(boolean switchStateOnClick) Set whether the state of this element should switch each time it is clicked- Parameters:
switchStateOnClick
- Whether the state of this element should switch each time it is clicked
-
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.
-