Class Frame

java.lang.Object
space.maxus.flare.ui.Frame
All Implemented Interfaces:
ReactivityProvider
Direct Known Subclasses:
PaginatedFrame, ParamFrame, ParamPaginatedFrame, SimpleFrame

public abstract class Frame extends Object implements ReactivityProvider
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 SimpleFrame
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final @NotNull Map<@NotNull ComposableSpace,@NotNull Composable>
    Elements composed inside this frame
    protected final AtomicBoolean
    Whether this frame is dirty.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    bindViewer(org.bukkit.entity.Player viewer)
    Binds a viewer to this frame.
    void
    Closes this frame
    Returns the concurrent map containing all composed elements
    void
    compose(@NotNull PackedComposable packed)
    Composes provided packed composable
    void
    compose(@NotNull ComposableSpace space, @NotNull Composable element)
    Composes provided element inside the provided space.
    void
    Composes provided elements inside the provided spaces.
    <T> T
    Attempts to get current context.
    <T> T
    Attempts to get current context.
    boolean
    drag(@NotNull Map<Slot,org.bukkit.inventory.ItemStack> newItems, @NotNull org.bukkit.event.inventory.InventoryDragEvent e)
    Called when items are dragged across this frame.
    final boolean
    fireDrag(@NotNull Map<Slot,org.bukkit.inventory.ItemStack> slots, @NotNull org.bukkit.event.inventory.InventoryDragEvent e)
     
    final void
    fireGenericClick(@NotNull Slot slot, @NotNull org.bukkit.event.inventory.InventoryClickEvent e)
     
    final boolean
    fireLeftClick(@NotNull Slot slot, @NotNull org.bukkit.event.inventory.InventoryClickEvent e)
     
    final boolean
    fireRightClick(@NotNull Slot slot, @NotNull org.bukkit.event.inventory.InventoryClickEvent e)
     
    final boolean
    fireShiftClick(@NotNull Slot slot, @NotNull org.bukkit.event.inventory.InventoryClickEvent e)
     
    final boolean
    fireShiftRequest(@NotNull org.bukkit.inventory.ItemStack shifting, @NotNull org.bukkit.event.inventory.InventoryClickEvent e)
     
    void
    genericClick(@NotNull Slot slot, @NotNull org.bukkit.event.inventory.InventoryClickEvent e)
    Called every time this frame is clicked.
    abstract @NotNull Dimensions
    Gets the dimensions of this frame's inventory
    abstract @NotNull ReactiveInventoryHolder
    Gets the Flare InventoryHolder for this frame
    Gets the default title of this frame.
    org.bukkit.entity.Player
    Viewer currently inside this frame.
    void
    Goes to the previous frame or does nothing if it is null.
    abstract void
    Called once inside the constructor
    boolean
    leftClick(@NotNull Slot slot, @NotNull org.bukkit.event.inventory.InventoryClickEvent e)
    Called when this frame is left clicked
    void
    Marks this whole frame as dirty, meaning it will be re-rendered on next tick
    void
    markDirty(@NotNull Composable source)
    Marks the provided composable's space as dirty, meaning it will be re-rendered on next tick
    void
    markDirty(@NotNull ComposableSpace space)
    Marks the provided space in this composable as dirty, meaning it will be re-rendered on next tick
    void
    Called when this frame is closed.
    void
    onOpen(@NotNull org.bukkit.entity.Player player)
    Called when this frame is opened to the player
    void
    open(org.bukkit.entity.Player player)
    Opens this frame for the provided player
    void
    Refreshes this title for current viewer.
    void
    Renders this frame to current inventory
    protected void
    renderPart(@NotNull ComposableSpace toUpdate)
    Re-renders part of this frame included inside the provided space
    void
    restorePreviousState(org.bukkit.entity.Player player)
     
    boolean
    rightClick(@NotNull Slot slot, @NotNull org.bukkit.event.inventory.InventoryClickEvent e)
    Called when this frame is right clicked
    abstract @NotNull org.bukkit.inventory.Inventory
    Gets the inventory of this frame.
    protected abstract void
    Sets the holder for this frame This is an internal method, it is only used for frame-switching
    void
    setTitle(org.bukkit.entity.Player viewer, String title)
    Sets the title of this frame and broadcasts it to the provided viewer
    boolean
    shiftClick(@NotNull Slot slot, @NotNull org.bukkit.event.inventory.InventoryClickEvent e)
    Called when this frame is shift clicked
    boolean
    shiftRequest(@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.
    void
    switchFrame(@NotNull Frame other)
    Switches this frame to another frame without reopening inventory.
    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> void
    useContext(T context)
    Sets a global context for this frame and its children components
    useState(V initial)
    Constructs a new ReactiveState

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface space.maxus.flare.react.ReactivityProvider

    useMemo, useUnboundState
  • Field Details

    • composed

      @NotNull protected final @NotNull Map<@NotNull ComposableSpace,@NotNull Composable> composed
      Elements composed inside this frame
    • isDirty

      @Internal protected final AtomicBoolean 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

      @NotNull public abstract @NotNull Dimensions getDimensions()
      Gets the dimensions of this frame's inventory
      Returns:
      the dimensions of this frame's inventory
    • getHolder

      @NotNull public abstract @NotNull ReactiveInventoryHolder getHolder()
      Gets the Flare InventoryHolder for this frame
      Returns:
      Flare InventoryHolder
    • setHolder

      @Internal protected abstract void setHolder(ReactiveInventoryHolder holder)
      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

      public <V> ReactiveState<V> useState(@Nullable V initial)
      Description copied from interface: ReactivityProvider
      Constructs a new ReactiveState
      Specified by:
      useState in interface ReactivityProvider
      Type Parameters:
      V - Type of the value inside state
      Parameters:
      initial - Initial value of the state
      Returns:
      A new ReactiveState
    • useBoundState

      @Experimental public <V> ReactiveState<V> useBoundState(@Nullable V initial)
      Description copied from interface: ReactivityProvider
      Constructs 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:
      useBoundState in interface ReactivityProvider
      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

      public void setTitle(org.bukkit.entity.Player viewer, String title)
      Sets the title of this frame and broadcasts it to the provided viewer
      Parameters:
      viewer - Viewer to broadcast the title to
      title - 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

      public void switchFrame(@NotNull @NotNull Frame other)
      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.InvalidContextValue
      Attempts 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

      protected void renderPart(@NotNull @NotNull ComposableSpace toUpdate)
      Re-renders part of this frame included inside the provided space
      Parameters:
      toUpdate - Space to be re-rendered
    • composableMap

      @NotNull public @NotNull Map<ComposableSpace,Composable> composableMap()
      Returns the concurrent map containing all composed elements
      Returns:
      Concurrent map containing all composed elements
    • compose

      public void compose(@NotNull @NotNull ComposableSpace space, @NotNull @NotNull Composable element)
      Composes provided element inside the provided space.
      Parameters:
      space - Space to compose element inside
      element - Element to be composed
    • composeAll

      public void composeAll(@NotNull @NotNull Map<ComposableSpace,Composable> elements)
      Composes provided elements inside the provided spaces.
      Parameters:
      elements - Map of spaces and elements to be composed
    • compose

      public void compose(@NotNull @NotNull PackedComposable packed)
      Composes provided packed composable
      Parameters:
      packed - Packed composable to be composed
    • markDirty

      public void markDirty(@NotNull @NotNull ComposableSpace space)
      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

      public void markDirty(@NotNull @NotNull Composable source)
      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

      @Internal public final boolean fireDrag(@NotNull @NotNull Map<Slot,org.bukkit.inventory.ItemStack> slots, @NotNull @NotNull org.bukkit.event.inventory.InventoryDragEvent e)
    • open

      public void open(org.bukkit.entity.Player player)
      Opens this frame for the provided player

      This 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 event
      stack - 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 event
      slot - 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 event
      slot - 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 event
      slot - 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 clicked
      e - 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 frame
      e - 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

      public String 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 in init()