Package studio.mevera.lotus.api.button
Record Class CycleButton
java.lang.Object
java.lang.Record
studio.mevera.lotus.api.button.CycleButton
- All Implemented Interfaces:
Button
public record CycleButton(@NotNull List<Button> states, int currentIndex, @NotNull DataRegistry data)
extends Record
implements Button
A multi-state button that advances through its
states() on each click. The displayed
item is delegated to the active state, so any Button variant — static label, clickable
with side-effect, etc. — can serve as a state.
On click the active state's own Button.dispatch(MenuView, InventoryClickEvent) runs
first (so users may attach per-state behaviour such as "play this sound"); the button then
replaces itself in the view's Content with a copy
positioned at the next index, modulo states.size(). The cycle wraps.
Typical uses: tri-state filter toggles ("OFF / WHITELIST / BLACKLIST"), difficulty selectors, page-size pickers — anywhere a single slot needs to step through a small enumeration.
Immutability: the record itself is immutable; "advancing state" produces a new
CycleButton and writes it to the slot. Do not rely on a particular CycleButton
instance persisting across clicks — observe the slot's current button via
ContentView.get(Slot).
-
Constructor Summary
ConstructorsConstructorDescriptionCycleButton(@NotNull List<Button> states, int currentIndex, @NotNull DataRegistry data) Creates an instance of aCycleButtonrecord class. -
Method Summary
Modifier and TypeMethodDescription@NotNull CycleButtonadvanced()@NotNull Buttoncurrent()Returns the currently active child button.intReturns the value of thecurrentIndexrecord component.@NotNull DataRegistrydata()Returns the value of thedatarecord component.voiddispatch(@NotNull MenuView<?, ?> view, @NotNull org.bukkit.event.inventory.InventoryClickEvent event) final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.@NotNull org.bukkit.inventory.ItemStackitem()states()Returns the value of thestatesrecord component.final StringtoString()Returns a string representation of this record class.@NotNull CycleButtonwithItem(@NotNull org.bukkit.inventory.ItemStack item) Replaces the displayed item.
-
Constructor Details
-
CycleButton
public CycleButton(@NotNull @NotNull List<Button> states, int currentIndex, @NotNull @NotNull DataRegistry data) Creates an instance of aCycleButtonrecord class.- Parameters:
states- the value for thestatesrecord componentcurrentIndex- the value for thecurrentIndexrecord componentdata- the value for thedatarecord component
-
-
Method Details
-
item
@NotNull public @NotNull org.bukkit.inventory.ItemStack item() -
current
Returns the currently active child button. -
advanced
- Returns:
- a new
CycleButtonpositioned one step forward (wrapping at the end).
-
withItem
@NotNull public @NotNull CycleButton withItem(@NotNull @NotNull org.bukkit.inventory.ItemStack item) Replaces the displayed item. Because the rendered item is normally derived from the active state, this overrides only the current state's item by wrapping it in aStaticButtonwith the new item; behaviour of the active state is preserved by copying it first. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
states
Returns the value of thestatesrecord component.- Returns:
- the value of the
statesrecord component
-
currentIndex
public int currentIndex()Returns the value of thecurrentIndexrecord component.- Returns:
- the value of the
currentIndexrecord component
-
data
Returns the value of thedatarecord component.
-