Class SGMenuListener
java.lang.Object
com.samjakob.spigui.menu.SGMenuListener
- All Implemented Interfaces:
org.bukkit.event.Listener
The
You must register this class as an event listener in your plugin's
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 -
Constructor Summary
ConstructorsConstructorDescriptionSGMenuListener(org.bukkit.plugin.java.JavaPlugin owner, SpiGUI spiGUI) Initialize an SGMenuListener for the specified plugin. -
Method Summary
Modifier and TypeMethodDescriptionvoidonAdjacentInventoryClick(org.bukkit.event.inventory.InventoryClickEvent event) Blocks events that occur in adjacent inventories to an SGMenu when those events would affect the SGMenu.voidonInventoryClick(org.bukkit.event.inventory.InventoryClickEvent event) Overrides the click event for an SGMenu.voidonInventoryClose(org.bukkit.event.inventory.InventoryCloseEvent event) Overrides the close event for an SGMenu.voidonInventoryDrag(org.bukkit.event.inventory.InventoryDragEvent event) Overrides the drag event for an SGMenu.private static booleanshouldIgnoreInventoryEvent(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 thisSGMenuListenerclass.private booleanslotsIncludeTopInventory(org.bukkit.inventory.InventoryView view, Set<Integer> slots) Checks whether the specified set of slots includes any slots in the top inventory of the specifiedInventoryView.static booleanwillHandleInventoryEvent(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.
-
Field Details
-
owner
private final org.bukkit.plugin.java.JavaPlugin ownerThe plugin that this listener is registered for. -
spiGUI
-
-
Constructor Details
-
SGMenuListener
-
-
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 thisSGMenuListenerclass.
Alternatively, if the inventory is null, or the inventory is not associated with theSGMenuclass (i.e.,inventory.getHolderis 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 (inSGMenuListener) 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 theSGMenuinventory belongs to your plugin.- Parameters:
plugin- TheJavaPluginplugin 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 SpiGUISGMenuand, 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 SpiGUISGMenuand, if it is, the drag event is captured and cancelled.
If this behavior is undesirable, it can be overridden by creating anInventoryDragEventhandler of your own - which you can do by registering an event handler and checkingwillHandleInventoryEvent(JavaPlugin, Inventory)returns true. You can identify the specific inventory withSGMenu.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 SpiGUISGMenuand, 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 specifiedInventoryView.- Parameters:
view- The relevantInventoryView.slots- The set of slots to check.- Returns:
- True if the set of slots includes any slots in the top inventory, otherwise false.
-