java.lang.Object
com.github.stefvanschie.inventoryframework.gui.type.util.Gui
Direct Known Subclasses:
BeaconGui, NamedGui

public abstract class Gui extends Object
The base class of all GUIs
  • Field Details

    • plugin

      @NotNull protected final @NotNull Plugin plugin
      The plugin that owns this gui
    • inventory

      protected Inventory inventory
      The inventory of this gui
    • humanEntityCache

      @NotNull protected final @NotNull HumanEntityCache humanEntityCache
      A player cache for storing player's inventories
    • onTopClick

      @Nullable protected @Nullable Consumer<InventoryClickEvent> onTopClick
      The consumer that will be called once a players clicks in the top-half of the gui
    • onBottomClick

      @Nullable protected @Nullable Consumer<InventoryClickEvent> onBottomClick
      The consumer that will be called once a players clicks in the bottom-half of the gui
    • onGlobalClick

      @Nullable protected @Nullable Consumer<InventoryClickEvent> onGlobalClick
      The consumer that will be called once a players clicks in the gui or in their inventory
    • onOutsideClick

      @Nullable protected @Nullable Consumer<InventoryClickEvent> onOutsideClick
      The consumer that will be called once a player clicks outside of the gui screen
    • onTopDrag

      @Nullable protected @Nullable Consumer<InventoryDragEvent> onTopDrag
      The consumer that will be called once a player drags in the top-half of the gui
    • onBottomDrag

      @Nullable protected @Nullable Consumer<InventoryDragEvent> onBottomDrag
      The consumer that will be called once a player drags in the bottom-half of the gui
    • onGlobalDrag

      @Nullable protected @Nullable Consumer<InventoryDragEvent> onGlobalDrag
      The consumer that will be called once a player drags in the gui or their inventory
    • onClose

      @Nullable protected @Nullable Consumer<InventoryCloseEvent> onClose
      The consumer that will be called once a player closes the gui
  • Constructor Details

    • Gui

      public Gui(@NotNull @NotNull Plugin plugin)
      Constructs a new gui with the provided plugin.
      Parameters:
      plugin - the plugin
      Since:
      0.10.8
  • Method Details

    • show

      public abstract void show(@NotNull @NotNull HumanEntity humanEntity)
      Shows a gui to a player
      Parameters:
      humanEntity - the human entity to show the gui to
    • copy

      @NotNull @Contract(pure=true) public abstract @NotNull Gui copy()
      Makes a copy of this gui and returns it. This makes a deep copy of the gui. This entails that the underlying panes will be copied as per their Pane.copy() and miscellaneous data will be copied. The copy of this gui, will however have no viewers even if this gui currently has viewers. With this, cache data for viewers will also be non-existent for the copied gui. The original owning plugin of the gui is preserved, but the plugin will not be deeply copied. The returned gui will never be reference equal to the current gui.
      Returns:
      a copy of the gui
      Since:
      0.6.2
    • click

      public abstract void click(@NotNull @NotNull InventoryClickEvent event)
      This should delegate the provided inventory click event to the right pane, which can then handle this click event further. This should not call any internal click handlers, since those will already have been activated.
      Parameters:
      event - the event to delegate
      Since:
      0.8.0
    • isPlayerInventoryUsed

      public abstract boolean isPlayerInventoryUsed()
      Gets whether the player inventory is currently in use. This means whether the player inventory currently has an item in it.
      Returns:
      true if the player inventory is occupied, false otherwise
      Since:
      0.8.0
    • getViewerCount

      @Contract(pure=true) public abstract int getViewerCount()
      Gets the count of HumanEntity instances that are currently viewing this GUI.
      Returns:
      the count of viewers
      Since:
      0.5.19
    • getViewers

      @NotNull @Contract(pure=true) public abstract @NotNull List<HumanEntity> getViewers()
      Gets a mutable snapshot of the current HumanEntity viewers of this GUI. This is a snapshot (copy) and not a view, therefore modifications aren't visible.
      Returns:
      a snapshot of the current viewers
      Since:
      0.5.19
      See Also:
    • update

      public void update()
      Update the gui for everyone
    • addInventory

      protected void addInventory(@NotNull @NotNull Inventory inventory, @NotNull @NotNull Gui gui)
      Adds the specified inventory and gui, so we can properly intercept clicks.
      Parameters:
      inventory - the inventory for the specified gui
      gui - the gui belonging to the specified inventory
      Since:
      0.8.1
    • getGui

      @Nullable @Contract(pure=true) public static @Nullable Gui getGui(@NotNull @NotNull Inventory inventory)
      Gets a gui from the specified inventory. Only guis of type beacon, brewing stand, dispenser, dropper, furnace and hopper can be retrieved.
      Parameters:
      inventory - the inventory to get the gui from
      Returns:
      the gui or null if the inventory doesn't have an accompanying gui
      Since:
      0.8.1
    • getHumanEntityCache

      @NotNull @Contract(pure=true) public @NotNull HumanEntityCache getHumanEntityCache()
      Gets the human entity cache used for this gui
      Returns:
      the human entity cache
      Since:
      0.5.4
      See Also:
    • load

      @Nullable public static @Nullable Gui load(@NotNull @NotNull Object instance, @NotNull @NotNull InputStream inputStream, @NotNull @NotNull Plugin plugin)
      Loads a Gui from a given input stream.
      Parameters:
      instance - the class instance for all reflection lookups
      inputStream - the file
      Returns:
      the gui or null if the loading failed
      Throws:
      XMLLoadException - if loading could not finish successfully, due to e.g., a malformed file
      Since:
      0.10.8
      See Also:
    • load

      @Nullable public static @Nullable Gui load(@NotNull @NotNull Object instance, @NotNull @NotNull InputStream inputStream)
      Loads a Gui from a given input stream. Returns null instead of throwing an exception in case of a failure.
      Parameters:
      instance - the class instance for all reflection lookups
      inputStream - the file
      Returns:
      the gui or null if the loading failed
      Throws:
      XMLLoadException - if loading could not finish successfully, due to e.g., a malformed file
    • initializeOrThrow

      protected void initializeOrThrow(@NotNull @NotNull Object instance, @NotNull @NotNull Element element)
      Initializes standard fields from a Gui from a given input stream. Throws a RuntimeException instead of returning null in case of a failure.
      Parameters:
      instance - the class instance for all reflection lookups
      element - the gui element
      See Also:
    • setOnTopClick

      public void setOnTopClick(@Nullable @Nullable Consumer<InventoryClickEvent> onTopClick)
      Set the consumer that should be called whenever this gui is clicked in.
      Parameters:
      onTopClick - the consumer that gets called
    • callOnTopClick

      public void callOnTopClick(@NotNull @NotNull InventoryClickEvent event)
      Calls the consumer (if it's not null) that was specified using setOnTopClick(Consumer), so the consumer that should be called whenever this gui is clicked in. Catches and logs all exceptions the consumer might throw.
      Parameters:
      event - the event to handle
      Since:
      0.6.0
    • setOnBottomClick

      public void setOnBottomClick(@Nullable @Nullable Consumer<InventoryClickEvent> onBottomClick)
      Set the consumer that should be called whenever the inventory is clicked in.
      Parameters:
      onBottomClick - the consumer that gets called
    • callOnBottomClick

      public void callOnBottomClick(@NotNull @NotNull InventoryClickEvent event)
      Calls the consumer (if it's not null) that was specified using setOnBottomClick(Consumer), so the consumer that should be called whenever the inventory is clicked in. Catches and logs all exceptions the consumer might throw.
      Parameters:
      event - the event to handle
      Since:
      0.6.0
    • setOnGlobalClick

      public void setOnGlobalClick(@Nullable @Nullable Consumer<InventoryClickEvent> onGlobalClick)
      Set the consumer that should be called whenever this gui or inventory is clicked in.
      Parameters:
      onGlobalClick - the consumer that gets called
    • callOnGlobalClick

      public void callOnGlobalClick(@NotNull @NotNull InventoryClickEvent event)
      Calls the consumer (if it's not null) that was specified using setOnGlobalClick(Consumer), so the consumer that should be called whenever this gui or inventory is clicked in. Catches and logs all exceptions the consumer might throw.
      Parameters:
      event - the event to handle
      Since:
      0.6.0
    • setOnOutsideClick

      public void setOnOutsideClick(@Nullable @Nullable Consumer<InventoryClickEvent> onOutsideClick)
      Set the consumer that should be called whenever a player clicks outside the gui.
      Parameters:
      onOutsideClick - the consumer that gets called
      Since:
      0.5.7
    • callOnOutsideClick

      public void callOnOutsideClick(@NotNull @NotNull InventoryClickEvent event)
      Calls the consumer (if it's not null) that was specified using setOnOutsideClick(Consumer), so the consumer that should be called whenever a player clicks outside the gui. Catches and logs all exceptions the consumer might throw.
      Parameters:
      event - the event to handle
      Since:
      0.6.0
    • setOnTopDrag

      public void setOnTopDrag(@Nullable @Nullable Consumer<InventoryDragEvent> onTopDrag)
      Set the consumer that should be called whenever this gui's top half is dragged in.
      Parameters:
      onTopDrag - the consumer that gets called
      Since:
      0.9.0
    • callOnTopDrag

      public void callOnTopDrag(@NotNull @NotNull InventoryDragEvent event)
      Calls the consumer (if it's not null) that was specified using setOnTopDrag(Consumer), so the consumer that should be called whenever this gui's top half is dragged in. Catches and logs all exceptions the consumer might throw.
      Parameters:
      event - the event to handle
      Since:
      0.9.0
    • setOnBottomDrag

      public void setOnBottomDrag(@Nullable @Nullable Consumer<InventoryDragEvent> onBottomDrag)
      Set the consumer that should be called whenever the inventory is dragged in.
      Parameters:
      onBottomDrag - the consumer that gets called
      Since:
      0.9.0
    • callOnBottomDrag

      public void callOnBottomDrag(@NotNull @NotNull InventoryDragEvent event)
      Calls the consumer (if it's not null) that was specified using setOnBottomDrag(Consumer), so the consumer that should be called whenever the inventory is dragged in. Catches and logs all exceptions the consumer might throw.
      Parameters:
      event - the event to handle
      Since:
      0.9.0
    • setOnGlobalDrag

      public void setOnGlobalDrag(@Nullable @Nullable Consumer<InventoryDragEvent> onGlobalDrag)
      Set the consumer that should be called whenever this gui or inventory is dragged in.
      Parameters:
      onGlobalDrag - the consumer that gets called
      Since:
      0.9.0
    • callOnGlobalDrag

      public void callOnGlobalDrag(@NotNull @NotNull InventoryDragEvent event)
      Calls the consumer (if it's not null) that was specified using setOnGlobalDrag(Consumer), so the consumer that should be called whenever this gui or inventory is dragged in. Catches and logs all exceptions the consumer might throw.
      Parameters:
      event - the event to handle
      Since:
      0.6.0
    • setOnClose

      public void setOnClose(@Nullable @Nullable Consumer<InventoryCloseEvent> onClose)
      Set the consumer that should be called whenever this gui is closed.
      Parameters:
      onClose - the consumer that gets called
    • callOnClose

      public void callOnClose(@NotNull @NotNull InventoryCloseEvent event)
      Calls the consumer (if it's not null) that was specified using setOnClose(Consumer), so the consumer that should be called whenever this gui is closed. Catches and logs all exceptions the consumer might throw.
      Parameters:
      event - the event to handle
      Since:
      0.6.0
    • callCallback

      protected <T extends InventoryEvent> void callCallback(@Nullable @Nullable Consumer<? super T> callback, @NotNull T event, @NotNull @NotNull String callbackName)
      Calls the specified consumer (if it's not null) with the specified parameter, catching and logging all exceptions it might throw.
      Type Parameters:
      T - the type of the value the consumer is accepting
      Parameters:
      callback - the consumer to call if it isn't null
      event - the value the consumer should accept
      callbackName - the name of the action, used for logging
    • isUpdating

      @Contract(pure=true) public boolean isUpdating()
      Gets whether this gui is being updated, as invoked by update(). This returns true if this is the case and false otherwise.
      Returns:
      whether this gui is being updated
      Since:
      0.5.15
    • 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.
      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.
    • registerPane

      public static void registerPane(@NotNull @NotNull String name, @NotNull @NotNull TriFunction<? super Object,? super Element,? super Plugin,? extends Pane> triFunction)
      Registers a name that can be used inside an XML file to add custom panes
      Parameters:
      name - the name of the pane to be used in the XML file
      triFunction - how the pane loading should be processed
      Throws:
      IllegalArgumentException - when a pane with this name is already registered
      Since:
      0.10.8
      See Also:
    • registerPane

      public static void registerPane(@NotNull @NotNull String name, @NotNull @NotNull BiFunction<Object,Element,Pane> biFunction)
      Registers a name that can be used inside an XML file to add custom panes
      Parameters:
      name - the name of the pane to be used in the XML file
      biFunction - how the pane loading should be processed
      Throws:
      IllegalArgumentException - when a pane with this name is already registered
    • registerGui

      public static void registerGui(@NotNull @NotNull String name, @NotNull @NotNull TriFunction<? super Object,? super Element,? super Plugin,? extends Gui> triFunction)
      Registers a type that can be used inside an XML file to specify the gui type
      Parameters:
      name - the name of the type of gui to be used in an XML file
      triFunction - how the gui creation should be processed
      Throws:
      IllegalArgumentException - when a gui type with this name is already registered
      Since:
      0.10.8
    • registerGui

      @Deprecated public static void registerGui(@NotNull @NotNull String name, @NotNull @NotNull BiFunction<? super Object,? super Element,? extends Gui> biFunction)
      Deprecated.
      this method is no longer used internally and has been superseded by registerPane(String, TriFunction)
      Registers a type that can be used inside an XML file to specify the gui type
      Parameters:
      name - the name of the type of gui to be used in an XML file
      biFunction - how the gui creation should be processed
      Throws:
      IllegalArgumentException - when a gui type with this name is already registered
    • loadPane

      @NotNull public static @NotNull Pane loadPane(@NotNull @NotNull Object instance, @NotNull @NotNull Node node, @NotNull @NotNull Plugin plugin)
      Loads a pane by the given instance and node
      Parameters:
      instance - the instance
      node - the node
      plugin - the plugin to load the pane with
      Returns:
      the pane
      Throws:
      XMLLoadException - if the name of the node does not correspond to a valid pane.
      Since:
      0.10.8
    • loadPane

      @NotNull public static @NotNull Pane loadPane(@NotNull @NotNull Object instance, @NotNull @NotNull Node node)
      Loads a pane by the given instance and node
      Parameters:
      instance - the instance
      node - the node
      Returns:
      the pane