Class ScrollableItems

java.lang.Object
de.marcely.bedwars.tools.gui.ScrollableItems

public class ScrollableItems extends Object
A list of items that with multiple pages to scroll through

Items will be displayed on a ChestGUI in a predefined area. First configure it as your liking, and then call draw() to add it.

  • Constructor Details

    • ScrollableItems

      public ScrollableItems(ChestGUI gui, int minX, int maxX, int minY, int maxY)
      Construct a new element.
      Parameters:
      gui - The GUI to later draw the items on
      minX - The minimum x slot at which the first item shall be at
      maxX - The maximum x slot at which the last item of the row shall be at
      minY - The minimum y slot at which the first item of the column shall be at
      maxY - The maximum y slot at which the last item shall be at
      Throws:
      IllegalStateException - if the area wouldn't fit inside a ChestGUI
      IllegalStateException - if min is greater than max
      IllegalStateException - if the available area is 2 or smaller
  • Method Details

    • addItem

      public void addItem(GUIItem item)
      Add an item that shall be shown.

      Automatically draws in case draw() has been called before.

      Parameters:
      item - The item to add
    • setItems

      public void setItems(List<GUIItem> items)
      Replaces all existing items with new ones.

      Automatically draws in case draw() has been called before.

      Parameters:
      items - The items to add
    • getItems

      public List<GUIItem> getItems()
      Get all items that shall be shown.
      Returns:
      A mutable list with all shown items
    • getMaxPages

      public int getMaxPages()
      Get the maximum amount of pages the player can scroll through.
      Returns:
      Amount of existing pages, minimum is always 1
    • setCurrentPage

      public void setCurrentPage(int page)
      Set the current page we are looking at.

      Automatically draws in case draw() has been called before.

      Parameters:
      page - The new current page. Starts at 0
    • getCurrentPage

      public int getCurrentPage()
      Get the current page we are looking at.
      Returns:
      The current page. Starts at 0
    • setPrevPageItem

      public void setPrevPageItem(ItemStack is)
      Set the item that represents the button to go back a page.

      Automatically draws in case draw() has been called before.

      Parameters:
      is - The item for going back a page
    • setNextPageItem

      public void setNextPageItem(ItemStack is)
      Set the item that represents the button to go forward a page.

      Automatically draws in case draw() has been called before.

      Parameters:
      is - The item for going forward a page
    • setPageChangeListener

      public void setPageChangeListener(@Nullable @Nullable Consumer<Player> listener)
      Set the listener that gets called whenever a player changes the page.

      May be useful for e.g. playing sounds.

      By default, the "setupgui-click-switch" sound is played from sounds.yml.

      Parameters:
      listener - The new listener, may be null
    • setDefaultPageChangeItems

      public void setDefaultPageChangeItems(@Nullable @Nullable Player player)
      Define default items (arrows with text) for the page change items.
      Parameters:
      player - The player whose language shall be used for the item's name. May be null
    • draw

      public void draw()
      Redraws the whole area.

      You usually only have to call this once after adding all items and configuring it properly.

      Throws:
      IllegalStateException - If no item for the prev / next page buttons has been set
    • disableRedraw

      public void disableRedraw()
      Disables automatic redraw, after draw() has been called.

      This is useful if you want to change e.g. items en-mass. Do note that auto-redraw is enabled again once you call draw().