java.lang.Object
me.despical.inventoryframework.pane.Pane
Direct Known Subclasses:
CycleButton, MasonryPane, OutlinePane, PaginatedPane, StaticPane, ToggleButton, VariableBar

public abstract class Pane extends Object
The base class for all panes.
Since:
1.0.1

Created at 04.09.2020

Author:
Despical
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    An enum representing the rendering priorities for the panes.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
    Length is horizontal, height is vertical
    protected int
    Length is horizontal, height is vertical
    protected @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent>
    The consumer that will be called once a players clicks in the gui
    protected int
    The starting position of this pane, which is 0 by default
    protected int
    The starting position of this pane, which is 0 by default
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Pane(int length, int height)
    Constructs a new default pane, with no position
    protected
    Pane(int x, int y, int length, int height)
    Constructs a new default pane
    protected
    Pane(int x, int y, int length, int height, @NotNull Pane.Priority priority)
    Constructs a new default pane
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract void
    Clears the entire pane of any items/panes.
    abstract boolean
    click(@NotNull Gui gui, @NotNull org.bukkit.event.inventory.InventoryClickEvent event, int paneOffsetX, int paneOffsetY, int maxLength, int maxHeight)
    Called whenever there is being clicked on this pane
    abstract void
    display(@NotNull Gui gui, @NotNull org.bukkit.inventory.Inventory inventory, @NotNull org.bukkit.inventory.PlayerInventory playerInventory, int paneOffsetX, int paneOffsetY, int maxLength, int maxHeight)
    Has to set all the items in the right spot inside the inventory
    protected static <T extends GuiItem>
    T
    findMatchingItem(@NotNull Collection<T> items, @NotNull org.bukkit.inventory.ItemStack item)
    Finds a type of GuiItem from the provided collection of items based on the provided ItemStack.
    int
    Returns the height of this pane
    abstract @NotNull Collection<GuiItem>
    Gets all the items in this pane and all underlying panes.
    int
    Returns the length of this pane
    abstract @NotNull Collection<Pane>
    Gets all the panes in this panes, including any child panes from other panes.
    @NotNull Pane.Priority
    Returns the priority of the pane
    static @NotNull Map<String,Function<String,Object>>
    Returns the property mappings used when loading properties from an XML file.
    int
    Gets the x coordinate of this pane
    int
    Gets the y coordinate of this pane
    boolean
    Returns the pane's visibility state
    static void
    load(@NotNull Pane pane, @NotNull Object instance, @NotNull Element element)
     
    static @NotNull GuiItem
    loadItem(@NotNull Object instance, @NotNull Element element)
    Loads an item from an instance and an element
    static void
    registerProperty(@NotNull String attributeName, @NotNull Function<String,Object> function)
    Registers a property that can be used inside an XML file to add additional new properties.
    void
    setHeight(int height)
    Set the height of this pane
    void
    setLength(int length)
    Set the length of this pane
    void
    setOnClick(@Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> onClick)
    Set the consumer that should be called whenever this gui is clicked in.
    void
    setOnLocalClick(@Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> onLocalClick)
    Set the consumer that should be called whenever this gui is clicked in.
    void
    setPriority(@NotNull Pane.Priority priority)
    Sets the priority of this pane
    void
    setVisible(boolean visible)
    Sets whether this pane is visible or not
    void
    setX(int x)
    Set the x coordinate of this pane
    void
    setY(int y)
    Set the y coordinate of this pane

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • x

      protected int x
      The starting position of this pane, which is 0 by default
    • y

      protected int y
      The starting position of this pane, which is 0 by default
    • length

      protected int length
      Length is horizontal, height is vertical
    • height

      protected int height
      Length is horizontal, height is vertical
    • onClick

      @Nullable protected @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> onClick
      The consumer that will be called once a players clicks in the gui
  • Constructor Details

    • Pane

      protected Pane(int x, int y, int length, int height, @NotNull @NotNull Pane.Priority priority)
      Constructs a new default pane
      Parameters:
      x - the upper left x coordinate of the pane
      y - the upper left y coordinate of the pane
      length - the length of the pane
      height - the height of the pane
      priority - the priority of the pane
    • Pane

      protected Pane(int length, int height)
      Constructs a new default pane, with no position
      Parameters:
      length - the length of the pane
      height - the height of the pane
    • Pane

      protected Pane(int x, int y, int length, int height)
      Constructs a new default pane
      Parameters:
      x - the upper left x coordinate of the pane
      y - the upper left y coordinate of the pane
      length - the length of the pane
      height - the height of the pane
  • Method Details

    • loadItem

      @NotNull @Contract(pure=true) public static @NotNull GuiItem loadItem(@NotNull @NotNull Object instance, @NotNull @NotNull Element element)
      Loads an item from an instance and an element
      Parameters:
      instance - the instance
      element - the element
      Returns:
      the gui item
    • load

      public static void load(@NotNull @NotNull Pane pane, @NotNull @NotNull Object instance, @NotNull @NotNull Element element)
    • findMatchingItem

      @Nullable @Contract(pure=true) protected static <T extends GuiItem> T findMatchingItem(@NotNull @NotNull Collection<T> items, @NotNull @NotNull org.bukkit.inventory.ItemStack item)
      Finds a type of GuiItem from the provided collection of items based on the provided ItemStack. The items will be compared using internal data. When the item does not have this data, this method will return null. If the item does have such data, but its value cannot be found in the provided list, null is also returned. This method will not mutate any of the provided arguments, nor any of the contents inside of the arguments. The provided collection may be unmodifiable if preferred. This method will always return a type of GuiItem that is in the provided collection - when the returned result is not null - such that an element E inside the provided collection reference equals the returned type of GuiItem.
      Type Parameters:
      T - a type of GuiItem, which will be used in the provided collection and as return type
      Parameters:
      items - a collection of items in which will be searched
      item - the item for which an GuiItem should be found
      Returns:
      the found type of GuiItem or null if none was found
      Since:
      1.0.1
    • registerProperty

      public static void registerProperty(@NotNull @NotNull String attributeName, @NotNull @NotNull Function<String,Object> function)
      Registers a property that can be used inside an XML file to add additional new properties. The use of Gui.registerProperty(String, Function) is preferred over this method.
      Parameters:
      attributeName - the name of the property. This is the same name you'll be using to specify the property type in the XML file.
      function - how the property should be processed. This converts the raw text input from the XML node value into the correct object type.
      Throws:
      IllegalArgumentException - when a property with this name is already registered.
    • getPropertyMappings

      @NotNull @Contract(pure=true) public static @NotNull Map<String,Function<String,Object>> getPropertyMappings()
      Returns the property mappings used when loading properties from an XML file.
      Returns:
      the property mappings
    • getLength

      @Contract(pure=true) public int getLength()
      Returns the length of this pane
      Returns:
      the length
    • setLength

      public void setLength(int length)
      Set the length of this pane
      Parameters:
      length - the new length
    • getHeight

      @Contract(pure=true) public int getHeight()
      Returns the height of this pane
      Returns:
      the height
    • setHeight

      public void setHeight(int height)
      Set the height of this pane
      Parameters:
      height - the new height
    • getX

      @Contract(pure=true) public int getX()
      Gets the x coordinate of this pane
      Returns:
      the x coordinate
    • setX

      public void setX(int x)
      Set the x coordinate of this pane
      Parameters:
      x - the new x coordinate
    • getY

      @Contract(pure=true) public int getY()
      Gets the y coordinate of this pane
      Returns:
      the y coordinate
    • setY

      public void setY(int y)
      Set the y coordinate of this pane
      Parameters:
      y - the new y coordinate
    • display

      public abstract void display(@NotNull @NotNull Gui gui, @NotNull @NotNull org.bukkit.inventory.Inventory inventory, @NotNull @NotNull org.bukkit.inventory.PlayerInventory playerInventory, int paneOffsetX, int paneOffsetY, int maxLength, int maxHeight)
      Has to set all the items in the right spot inside the inventory
      Parameters:
      gui - the gui for which we're rendering
      inventory - the inventory that the items should be displayed in
      playerInventory - the player's inventory
      paneOffsetX - the pane's offset on the x axis
      paneOffsetY - the pane's offset on the y axis
      maxLength - the maximum length of the pane
      maxHeight - the maximum height of the pane
    • isVisible

      @Contract(pure=true) public boolean isVisible()
      Returns the pane's visibility state
      Returns:
      the pane's visibility
    • setVisible

      public void setVisible(boolean visible)
      Sets whether this pane is visible or not
      Parameters:
      visible - the pane's visibility
    • click

      public abstract boolean click(@NotNull @NotNull Gui gui, @NotNull @NotNull org.bukkit.event.inventory.InventoryClickEvent event, int paneOffsetX, int paneOffsetY, int maxLength, int maxHeight)
      Called whenever there is being clicked on this pane
      Parameters:
      gui - the gui this event stems from
      event - the event that occurred while clicking on this item
      paneOffsetX - the pane's offset on the x axis
      paneOffsetY - the pane's offset on the y axis
      maxLength - the maximum length of the pane
      maxHeight - the maximum height of the pane
      Returns:
      whether the item was found or not
    • getPriority

      @NotNull public @NotNull Pane.Priority getPriority()
      Returns the priority of the pane
      Returns:
      the priority
    • setPriority

      public void setPriority(@NotNull @NotNull Pane.Priority priority)
      Sets the priority of this pane
      Parameters:
      priority - the priority
    • getItems

      @NotNull @Contract(pure=true) public abstract @NotNull Collection<GuiItem> getItems()
      Gets all the items in this pane and all underlying panes. The returned collection is not guaranteed to be mutable or to be a view of the underlying data. (So changes to the gui are not guaranteed to be visible in the returned value.)
      Returns:
      all items
    • getPanes

      @NotNull @Contract(pure=true) public abstract @NotNull Collection<Pane> getPanes()
      Gets all the panes in this panes, including any child panes from other panes. The returned collection is not guaranteed to be mutable or to be a view of the underlying data. (So changes to the gui are not guaranteed to be visible in the returned value.)
      Returns:
      all panes
    • clear

      public abstract void clear()
      Clears the entire pane of any items/panes. Underlying panes will not be cleared.
      Since:
      1.0.1
    • setOnClick

      public void setOnClick(@Nullable @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> onClick)
      Set the consumer that should be called whenever this gui is clicked in.
      Parameters:
      onClick - the consumer that gets called
      Since:
      1.0.1
    • setOnLocalClick

      public void setOnLocalClick(@Nullable @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> onLocalClick)
      Set the consumer that should be called whenever this gui is clicked in.
      Parameters:
      onLocalClick - the consumer that gets called