Class GUIHandler<Plugin extends org.bukkit.plugin.java.JavaPlugin,GUIData extends GUIData>

java.lang.Object
at.hugob.plugin.library.gui.GUIHandler<Plugin,GUIData>
Type Parameters:
Plugin - The plugin which owns this GUI
GUIData - The GUIData that is needed for this GUI to function
All Implemented Interfaces:
org.bukkit.inventory.InventoryHolder

public abstract class GUIHandler<Plugin extends org.bukkit.plugin.java.JavaPlugin,GUIData extends GUIData> extends Object implements org.bukkit.inventory.InventoryHolder
Manages the GUI and is also the Holder of the GUI Inventory
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final GUIData
    The GUIData needed for this GUI
    protected final @NotNull org.bukkit.NamespacedKey
    The NameSpacedKey used by Inventory ItemStacks
    protected final Plugin
    The Plugin that owns this GUI
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    GUIHandler(Plugin plugin, GUIData guiData)
    Creates a GUIHandler
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    fill(@Nullable org.bukkit.inventory.ItemStack itemStack)
    Fills all slots of this gui with a specific Item
    final @NotNull org.bukkit.inventory.Inventory
     
    boolean
    isInventoryItem(@Nullable org.bukkit.inventory.ItemStack itemStack)
    Checks if an item is from this inventory
    void
    onClickBottom(org.bukkit.event.inventory.InventoryClickEvent event)
    Handles a Click Event which is targeted at the Bottom (Player's) Inventory of an Inventory View
    void
    onClickOutside(org.bukkit.event.inventory.InventoryClickEvent event)
    Handles a Click Event which is targeted at Left or Right side, outside the Inventory View
    void
    onClickTop(org.bukkit.event.inventory.InventoryClickEvent event)
    Handles a Click Event which is targeted at the Top (this) Inventory of an Inventory View
    void
    onClose(org.bukkit.event.inventory.InventoryCloseEvent event)
    Gets Triggered if this Inventory is closed
    void
    onDrag(org.bukkit.event.inventory.InventoryDragEvent event)
    Handles a Drag Event Targeted at an Inventory View that has This Inventory as the Top one.
    void
    open(@NotNull org.bukkit.entity.Player player)
    Open the GUI
    protected void
    setItem(int index, @Nullable org.bukkit.inventory.ItemStack itemStack)
    Sets a slot in this inventory to that item
    protected void
    setItem(int index, @Nullable org.bukkit.inventory.ItemStack itemStack, @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> onClick)
    Sets a slot in this inventory to that item and implicitly cancels the event
    protected void
    setItem(int index, @Nullable org.bukkit.inventory.ItemStack itemStack, @Nullable Predicate<org.bukkit.event.inventory.InventoryClickEvent> onClick)
    Sets a slot in this inventory to that item
    protected abstract void
    Fills the inventory with the inventory content.

    Methods inherited from class java.lang.Object

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

    • guiItemKey

      @NotNull protected final @NotNull org.bukkit.NamespacedKey guiItemKey
      The NameSpacedKey used by Inventory ItemStacks
    • plugin

      @NotNull protected final Plugin extends org.bukkit.plugin.java.JavaPlugin plugin
      The Plugin that owns this GUI
    • guiData

      @NotNull protected final GUIData extends GUIData guiData
      The GUIData needed for this GUI
  • Constructor Details

    • GUIHandler

      protected GUIHandler(@NotNull Plugin plugin, @NotNull GUIData guiData)
      Creates a GUIHandler
      Parameters:
      plugin - The Plugin Instance that owns of this GUI
      guiData - The data needed for this GUI to function
  • Method Details

    • getInventory

      @NotNull public final @NotNull org.bukkit.inventory.Inventory getInventory()
      Specified by:
      getInventory in interface org.bukkit.inventory.InventoryHolder
    • open

      public void open(@NotNull @NotNull org.bukkit.entity.Player player)
      Open the GUI
      Parameters:
      player - the player who will see this GUI
    • isInventoryItem

      public boolean isInventoryItem(@Nullable @Nullable org.bukkit.inventory.ItemStack itemStack)
      Checks if an item is from this inventory
      Parameters:
      itemStack - The item to check
      Returns:
      true if it is an item from this inventory
    • fill

      protected void fill(@Nullable @Nullable org.bukkit.inventory.ItemStack itemStack)
      Fills all slots of this gui with a specific Item
      Parameters:
      itemStack - The ItemStack that will be in every slot
    • update

      protected abstract void update()
      Fills the inventory with the inventory content. Try to not use fillAll and instead only replace what is necessary
    • setItem

      protected void setItem(int index, @Nullable @Nullable org.bukkit.inventory.ItemStack itemStack)
      Sets a slot in this inventory to that item
      Parameters:
      index - the slot in the inventory
      itemStack - the item that needs to be put in the inventory
    • setItem

      protected void setItem(int index, @Nullable @Nullable org.bukkit.inventory.ItemStack itemStack, @Nullable @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> onClick)
      Sets a slot in this inventory to that item and implicitly cancels the event
      Parameters:
      index - the slot in the inventory
      itemStack - the item that needs to be put in the inventory
      onClick - This will be executed when someone Clicks on this item and cancels the event
    • setItem

      protected void setItem(int index, @Nullable @Nullable org.bukkit.inventory.ItemStack itemStack, @Nullable @Nullable Predicate<org.bukkit.event.inventory.InventoryClickEvent> onClick)
      Sets a slot in this inventory to that item
      Parameters:
      index - the slot in the inventory
      itemStack - the item that needs to be put in the inventory
      onClick - This will be executed when someone Clicks on this item, returns true when the event should be cancelled
    • onClickTop

      public void onClickTop(org.bukkit.event.inventory.InventoryClickEvent event)
      Handles a Click Event which is targeted at the Top (this) Inventory of an Inventory View
      Parameters:
      event - The InventoryClickEvent Targeted at the Top Inventory
    • onClickBottom

      public void onClickBottom(org.bukkit.event.inventory.InventoryClickEvent event)
      Handles a Click Event which is targeted at the Bottom (Player's) Inventory of an Inventory View
      Parameters:
      event - The InventoryClickEvent Targeted at the Bottom Inventory
    • onClickOutside

      public void onClickOutside(org.bukkit.event.inventory.InventoryClickEvent event)
      Handles a Click Event which is targeted at Left or Right side, outside the Inventory View
      Parameters:
      event - The InventoryClickEvent Targeted outside the Inventory
    • onDrag

      public void onDrag(org.bukkit.event.inventory.InventoryDragEvent event)
      Handles a Drag Event Targeted at an Inventory View that has This Inventory as the Top one.
      Parameters:
      event - The InventoryDragEvent Targeted at an InventoryView that contains this inventory
    • onClose

      public void onClose(org.bukkit.event.inventory.InventoryCloseEvent event)
      Gets Triggered if this Inventory is closed
      Parameters:
      event - The InventoryCloseEvent that contains this Inventory