Package space.maxus.flare.ui
Class Frame
java.lang.Object
space.maxus.flare.ui.Frame
- All Implemented Interfaces:
ReactivityProvider
- Direct Known Subclasses:
PaginatedFrame,ParamFrame,ParamPaginatedFrame,SimpleFrame
The super class to all Flare frames.
A frame represents an inventory that can display composable elements.
If you want to extend a frame, it is not recommended to extend this class, instead extend
A frame represents an inventory that can display composable elements.
If you want to extend a frame, it is not recommended to extend this class, instead extend
SimpleFrame- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final @NotNull Map<@NotNull ComposableSpace,@NotNull Composable> Elements composed inside this frameprotected final AtomicBooleanWhether this frame is dirty. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidbindViewer(org.bukkit.entity.Player viewer) Binds a viewer to this frame.voidclose()Closes this frame@NotNull Map<ComposableSpace,Composable> Returns the concurrent map containing all composed elementsvoidcompose(@NotNull PackedComposable packed) Composes provided packed composablevoidcompose(@NotNull ComposableSpace space, @NotNull Composable element) Composes provided element inside the provided space.voidcomposeAll(@NotNull Map<ComposableSpace, Composable> elements) Composes provided elements inside the provided spaces.<T> Tcontext()Attempts to get current context.<T> TAttempts to get current context.booleandrag(@NotNull Map<Slot, org.bukkit.inventory.ItemStack> newItems, @NotNull org.bukkit.event.inventory.InventoryDragEvent e) Called when items are dragged across this frame.final booleanfireDrag(@NotNull Map<Slot, org.bukkit.inventory.ItemStack> slots, @NotNull org.bukkit.event.inventory.InventoryDragEvent e) final voidfireGenericClick(@NotNull Slot slot, @NotNull org.bukkit.event.inventory.InventoryClickEvent e) final booleanfireLeftClick(@NotNull Slot slot, @NotNull org.bukkit.event.inventory.InventoryClickEvent e) final booleanfireRightClick(@NotNull Slot slot, @NotNull org.bukkit.event.inventory.InventoryClickEvent e) final booleanfireShiftClick(@NotNull Slot slot, @NotNull org.bukkit.event.inventory.InventoryClickEvent e) final booleanfireShiftRequest(@NotNull org.bukkit.inventory.ItemStack shifting, @NotNull org.bukkit.event.inventory.InventoryClickEvent e) voidgenericClick(@NotNull Slot slot, @NotNull org.bukkit.event.inventory.InventoryClickEvent e) Called every time this frame is clicked.abstract @NotNull DimensionsGets the dimensions of this frame's inventoryabstract @NotNull ReactiveInventoryHolderGets the Flare InventoryHolder for this framegetTitle()Gets the default title of this frame.org.bukkit.entity.PlayerViewer currently inside this frame.voidgoBack()Goes to the previous frame or does nothing if it is null.abstract voidinit()Called once inside the constructorbooleanCalled when this frame is left clickedvoidMarks this whole frame as dirty, meaning it will be re-rendered on next tickvoidmarkDirty(@NotNull Composable source) Marks the provided composable's space as dirty, meaning it will be re-rendered on next tickvoidmarkDirty(@NotNull ComposableSpace space) Marks the provided space in this composable as dirty, meaning it will be re-rendered on next tickvoidonClose()Called when this frame is closed.voidonOpen(@NotNull org.bukkit.entity.Player player) Called when this frame is opened to the playervoidopen(org.bukkit.entity.Player player) Opens this frame for the provided playervoidRefreshes this title for current viewer.voidrender()Renders this frame to current inventoryprotected voidrenderPart(@NotNull ComposableSpace toUpdate) Re-renders part of this frame included inside the provided spacevoidrestorePreviousState(org.bukkit.entity.Player player) booleanrightClick(@NotNull Slot slot, @NotNull org.bukkit.event.inventory.InventoryClickEvent e) Called when this frame is right clickedabstract @NotNull org.bukkit.inventory.InventoryGets the inventory of this frame.protected abstract voidsetHolder(ReactiveInventoryHolder holder) Sets the holder for this frame This is an internal method, it is only used for frame-switchingvoidSets the title of this frame and broadcasts it to the provided viewerbooleanshiftClick(@NotNull Slot slot, @NotNull org.bukkit.event.inventory.InventoryClickEvent e) Called when this frame is shift clickedbooleanshiftRequest(@NotNull org.bukkit.inventory.ItemStack stack, @NotNull org.bukkit.event.inventory.InventoryClickEvent e) Called when this frame is attempted to put items into by shift click.voidswitchFrame(@NotNull Frame other) Switches this frame to another frame without reopening inventory.<V> ReactiveState<V>useBoundState(V initial) Constructs a new ReactiveState bound to this object
**Experimental**: This is an experimental hook, and it may change or be removed in the future<T> voiduseContext(T context) Sets a global context for this frame and its children components<V> ReactiveState<V>useState(V initial) Constructs a new ReactiveStateMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface space.maxus.flare.react.ReactivityProvider
useMemo, useUnboundState
-
Field Details
-
composed
Elements composed inside this frame -
isDirty
Whether this frame is dirty.This is an internal method. Value of this field should not be set externally, as it may lead to unexpected render issues.
-
-
Constructor Details
-
Frame
public Frame()
-
-
Method Details
-
init
public abstract void init()Called once inside the constructor -
selfInventory
@NotNull public abstract @NotNull org.bukkit.inventory.Inventory selfInventory()Gets the inventory of this frame.- Returns:
- the inventory of this frame.
-
getDimensions
Gets the dimensions of this frame's inventory- Returns:
- the dimensions of this frame's inventory
-
getHolder
Gets the Flare InventoryHolder for this frame- Returns:
- Flare InventoryHolder
-
setHolder
Sets the holder for this frame This is an internal method, it is only used for frame-switching- Parameters:
holder- Holder to be set
-
useState
Description copied from interface:ReactivityProviderConstructs a new ReactiveState- Specified by:
useStatein interfaceReactivityProvider- Type Parameters:
V- Type of the value inside state- Parameters:
initial- Initial value of the state- Returns:
- A new ReactiveState
-
useBoundState
Description copied from interface:ReactivityProviderConstructs a new ReactiveState bound to this object
**Experimental**: This is an experimental hook, and it may change or be removed in the future- Specified by:
useBoundStatein interfaceReactivityProvider- Type Parameters:
V- Type of the value inside state- Parameters:
initial- Initial value of the state- Returns:
- A new ReactiveState
-
useContext
public <T> void useContext(@Nullable T context) Sets a global context for this frame and its children components- Type Parameters:
T- Type of the context- Parameters:
context- Context to be set
-
setTitle
Sets the title of this frame and broadcasts it to the provided viewer- Parameters:
viewer- Viewer to broadcast the title totitle- New title of this frame
-
refreshTitle
public void refreshTitle()Refreshes this title for current viewer. -
bindViewer
@Internal public final void bindViewer(org.bukkit.entity.Player viewer) Binds a viewer to this frame.- Parameters:
viewer- Viewer to be bound
-
switchFrame
Switches this frame to another frame without reopening inventory.- Parameters:
other- Frame to switch to
-
goBack
public void goBack()Goes to the previous frame or does nothing if it is null. -
contextOrNull
@Nullable public <T> T contextOrNull()Attempts to get current context. Throws an exception if it is null.- Type Parameters:
T- Expected type of context- Returns:
- Context of provided type
-
context
@NotNull public <T> T context() throws space.maxus.flare.ui.Frame.InvalidContextValueAttempts to get current context.- Type Parameters:
T- Expected type of context- Returns:
- Context of provided type or null.
- Throws:
space.maxus.flare.ui.Frame.InvalidContextValue
-
render
public void render()Renders this frame to current inventory -
renderPart
Re-renders part of this frame included inside the provided space- Parameters:
toUpdate- Space to be re-rendered
-
composableMap
Returns the concurrent map containing all composed elements- Returns:
- Concurrent map containing all composed elements
-
compose
Composes provided element inside the provided space.- Parameters:
space- Space to compose element insideelement- Element to be composed
-
composeAll
Composes provided elements inside the provided spaces.- Parameters:
elements- Map of spaces and elements to be composed
-
compose
Composes provided packed composable- Parameters:
packed- Packed composable to be composed
-
markDirty
Marks the provided space in this composable as dirty, meaning it will be re-rendered on next tick- Parameters:
space- Space to be marked as dirty
-
markDirty
Marks the provided composable's space as dirty, meaning it will be re-rendered on next tick- Parameters:
source- Composable, which space to be marked as dirty
-
markDirty
public void markDirty()Marks this whole frame as dirty, meaning it will be re-rendered on next tick -
fireLeftClick
@Internal public final boolean fireLeftClick(@NotNull @NotNull Slot slot, @NotNull @NotNull org.bukkit.event.inventory.InventoryClickEvent e) -
fireRightClick
@Internal public final boolean fireRightClick(@NotNull @NotNull Slot slot, @NotNull @NotNull org.bukkit.event.inventory.InventoryClickEvent e) -
fireGenericClick
@Internal public final void fireGenericClick(@NotNull @NotNull Slot slot, @NotNull @NotNull org.bukkit.event.inventory.InventoryClickEvent e) -
fireShiftClick
@Internal public final boolean fireShiftClick(@NotNull @NotNull Slot slot, @NotNull @NotNull org.bukkit.event.inventory.InventoryClickEvent e) -
fireShiftRequest
@Internal public final boolean fireShiftRequest(@NotNull @NotNull org.bukkit.inventory.ItemStack shifting, @NotNull @NotNull org.bukkit.event.inventory.InventoryClickEvent e) -
fireDrag
-
open
public void open(org.bukkit.entity.Player player) Opens this frame for the provided playerThis is a partially internal method, for actually opening frames you should probably use
Flare.open(Frame, Player)- Parameters:
player- Player for whom to open
-
close
public void close()Closes this frame -
restorePreviousState
@Internal public void restorePreviousState(org.bukkit.entity.Player player) -
shiftRequest
@OverrideOnly public boolean shiftRequest(@NotNull @NotNull org.bukkit.inventory.ItemStack stack, @NotNull @NotNull org.bukkit.event.inventory.InventoryClickEvent e) Called when this frame is attempted to put items into by shift click. This means that a player clicked on an item inside their inventory, and Flare attempts to fit item inside this frame.- Parameters:
e- The click eventstack- Stack that is attempted to be moved.- Returns:
- True if the event should be cancelled, false otherwise
-
shiftClick
@OverrideOnly public boolean shiftClick(@NotNull @NotNull Slot slot, @NotNull @NotNull org.bukkit.event.inventory.InventoryClickEvent e) Called when this frame is shift clicked- Parameters:
e- The click eventslot- Slot that was clicked- Returns:
- True if the event should be cancelled, false otherwise
-
rightClick
@OverrideOnly public boolean rightClick(@NotNull @NotNull Slot slot, @NotNull @NotNull org.bukkit.event.inventory.InventoryClickEvent e) Called when this frame is right clicked- Parameters:
e- The click eventslot- Slot that was clicked- Returns:
- True if the event should be cancelled, false otherwise
-
leftClick
@OverrideOnly public boolean leftClick(@NotNull @NotNull Slot slot, @NotNull @NotNull org.bukkit.event.inventory.InventoryClickEvent e) Called when this frame is left clicked- Parameters:
e- The click eventslot- Slot that was clicked- Returns:
- True if the event should be cancelled, false otherwise
-
genericClick
@OverrideOnly public void genericClick(@NotNull @NotNull Slot slot, @NotNull @NotNull org.bukkit.event.inventory.InventoryClickEvent e) Called every time this frame is clicked.- Parameters:
slot- Slot that was clickede- The click event
-
drag
@Experimental @OverrideOnly public boolean drag(@NotNull @NotNull Map<Slot, org.bukkit.inventory.ItemStack> newItems, @NotNull @NotNull org.bukkit.event.inventory.InventoryDragEvent e) Called when items are dragged across this frame. This method is currently experimental and may not work correctly- Parameters:
newItems- Items that are dragged inside this framee- The drag event- Returns:
- True if the event should be cancelled, false otherwise.
-
onOpen
@OverrideOnly public void onOpen(@NotNull @NotNull org.bukkit.entity.Player player) Called when this frame is opened to the player- Parameters:
player- Player this frame is opened to
-
onClose
@OverrideOnly public void onClose()Called when this frame is closed.The frame may be reopened later, see
restorePreviousState(Player)for more info- See Also:
-
getTitle
Gets the default title of this frame. `A Flare $className` by default.- Returns:
- The title of this frame
-
getViewer
public org.bukkit.entity.Player getViewer()Viewer currently inside this frame. Value is null if called during initialization ininit()
-