Class SGMenuListener

java.lang.Object
com.samjakob.spigui.menu.SGMenuListener
All Implemented Interfaces:
org.bukkit.event.Listener

public class SGMenuListener extends Object implements org.bukkit.event.Listener
The SGMenuListener handles SpiGUI events on behalf of a plugin that uses SpiGUI.
You must register this class as an event listener in your plugin's onEnable method by initializing SpiGUI there and passing your plugin instance to SpiGUI's constructor.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final org.bukkit.plugin.java.JavaPlugin
    The plugin that this listener is registered for.
    private final SpiGUI
    The instance of SpiGUI this listener is operating for.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SGMenuListener(org.bukkit.plugin.java.JavaPlugin owner, SpiGUI spiGUI)
    Initialize an SGMenuListener for the specified plugin.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    onAdjacentInventoryClick(org.bukkit.event.inventory.InventoryClickEvent event)
    Blocks events that occur in adjacent inventories to an SGMenu when those events would affect the SGMenu.
    void
    onInventoryClick(org.bukkit.event.inventory.InventoryClickEvent event)
    Overrides the click event for an SGMenu.
    void
    onInventoryClose(org.bukkit.event.inventory.InventoryCloseEvent event)
    Overrides the close event for an SGMenu.
    void
    onInventoryDrag(org.bukkit.event.inventory.InventoryDragEvent event)
    Overrides the drag event for an SGMenu.
    private static boolean
    shouldIgnoreInventoryEvent(org.bukkit.inventory.Inventory inventory)
    Returns false if the specified inventory exists and is an SGMenu, as that implies the inventory event should be handled by this SGMenuListener class.
    private boolean
    slotsIncludeTopInventory(org.bukkit.inventory.InventoryView view, Set<Integer> slots)
    Checks whether the specified set of slots includes any slots in the top inventory of the specified InventoryView.
    static boolean
    willHandleInventoryEvent(org.bukkit.plugin.java.JavaPlugin plugin, org.bukkit.inventory.Inventory inventory)
    Allows a plugin to determine whether an inventory event will be handled by SpiGUI.

    Methods inherited from class java.lang.Object

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

    • owner

      private final org.bukkit.plugin.java.JavaPlugin owner
      The plugin that this listener is registered for.
    • spiGUI

      private final SpiGUI spiGUI
      The instance of SpiGUI this listener is operating for.
  • Constructor Details

    • SGMenuListener

      public SGMenuListener(org.bukkit.plugin.java.JavaPlugin owner, SpiGUI spiGUI)
      Initialize an SGMenuListener for the specified plugin.
      Parameters:
      owner - The plugin that this listener is registered for.
      spiGUI - The instance of SpiGUI this listener is operating for.
  • Method Details

    • shouldIgnoreInventoryEvent

      private static boolean shouldIgnoreInventoryEvent(org.bukkit.inventory.Inventory inventory)
      Returns false if the specified inventory exists and is an SGMenu, as that implies the inventory event should be handled by this SGMenuListener class.
      Alternatively, if the inventory is null, or the inventory is not associated with the SGMenu class (i.e., inventory.getHolder is null), this returns true signalling that the event should not be processed.
      Parameters:
      inventory - The inventory to check.
      Returns:
      False if inventory event should be handled by SGMenuListener, true if not.
    • willHandleInventoryEvent

      public static boolean willHandleInventoryEvent(org.bukkit.plugin.java.JavaPlugin plugin, org.bukkit.inventory.Inventory inventory)
      Allows a plugin to determine whether an inventory event will be handled by SpiGUI.
      You can use this to override SpiGUI's event handlers (in SGMenuListener) with custom functionality, should you need to.
      The plugin parameter refers to your plugin, the one using SpiGUI. It needs to be passed in here so that SpiGUI can check whether the SGMenu inventory belongs to your plugin.
      Parameters:
      plugin - The JavaPlugin plugin instance.
      inventory - The inventory to check.
      Returns:
      True if it will, otherwise false.
    • onInventoryClick

      public void onInventoryClick(org.bukkit.event.inventory.InventoryClickEvent event)
      Overrides the click event for an SGMenu. This is automatically registered into a plugin using SpiGUI when SpiGUI is initialized in that plugin.
      The respective inventory is first checked to ensure that it is a SpiGUI SGMenu and, if it is, whether a pagination button was clicked, finally (if not a pagination button) the event is delegated to the inventory the click occurred in.
      Parameters:
      event - The event to handle.
      See Also:
    • onAdjacentInventoryClick

      public void onAdjacentInventoryClick(org.bukkit.event.inventory.InventoryClickEvent event)
      Blocks events that occur in adjacent inventories to an SGMenu when those events would affect the SGMenu. (For example, double-clicking on an item in the player's inventory that is the same as an item in the SGMenu.)
      Parameters:
      event - The event to handle.
      See Also:
    • onInventoryDrag

      public void onInventoryDrag(org.bukkit.event.inventory.InventoryDragEvent event)
      Overrides the drag event for an SGMenu. This is automatically registered into a plugin using SpiGUI when SpiGUI is initialized in that plugin.
      The respective inventory is first checked to ensure that it is a SpiGUI SGMenu and, if it is, the drag event is captured and cancelled.
      If this behavior is undesirable, it can be overridden by creating an InventoryDragEvent handler of your own - which you can do by registering an event handler and checking willHandleInventoryEvent(JavaPlugin, Inventory) returns true. You can identify the specific inventory with SGMenu.getTag().
      Parameters:
      event - The event to handle.
      See Also:
    • onInventoryClose

      public void onInventoryClose(org.bukkit.event.inventory.InventoryCloseEvent event)
      Overrides the close event for an SGMenu. This is automatically registered into a plugin using SpiGUI when SpiGUI is initialized in that plugin.
      The respective inventory is first checked to ensure that it is a SpiGUI SGMenu and, if it is, the close event is delegated to a handler for that inventory, if one exists.
      Parameters:
      event - The event to handle.
      See Also:
    • slotsIncludeTopInventory

      private boolean slotsIncludeTopInventory(org.bukkit.inventory.InventoryView view, Set<Integer> slots)
      Checks whether the specified set of slots includes any slots in the top inventory of the specified InventoryView.
      Parameters:
      view - The relevant InventoryView.
      slots - The set of slots to check.
      Returns:
      True if the set of slots includes any slots in the top inventory, otherwise false.