Package at.hugob.plugin.library.gui
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 GUIGUIData- 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 -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedGUIHandler(Plugin plugin, GUIData guiData) Creates a GUIHandler -
Method Summary
Modifier and TypeMethodDescriptionprotected voidfill(@Nullable org.bukkit.inventory.ItemStack itemStack) Fills all slots of this gui with a specific Itemfinal @NotNull org.bukkit.inventory.InventorybooleanisInventoryItem(@Nullable org.bukkit.inventory.ItemStack itemStack) Checks if an item is from this inventoryvoidonClickBottom(org.bukkit.event.inventory.InventoryClickEvent event) Handles a Click Event which is targeted at the Bottom (Player's) Inventory of an Inventory ViewvoidonClickOutside(org.bukkit.event.inventory.InventoryClickEvent event) Handles a Click Event which is targeted at Left or Right side, outside the Inventory ViewvoidonClickTop(org.bukkit.event.inventory.InventoryClickEvent event) Handles a Click Event which is targeted at the Top (this) Inventory of an Inventory ViewvoidonClose(org.bukkit.event.inventory.InventoryCloseEvent event) Gets Triggered if this Inventory is closedvoidonDrag(org.bukkit.event.inventory.InventoryDragEvent event) Handles a Drag Event Targeted at an Inventory View that has This Inventory as the Top one.voidopen(@NotNull org.bukkit.entity.Player player) Open the GUIprotected voidsetItem(int index, @Nullable org.bukkit.inventory.ItemStack itemStack) Sets a slot in this inventory to that itemprotected voidsetItem(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 eventprotected voidsetItem(int index, @Nullable org.bukkit.inventory.ItemStack itemStack, @Nullable Predicate<org.bukkit.event.inventory.InventoryClickEvent> onClick) Sets a slot in this inventory to that itemprotected abstract voidupdate()Fills the inventory with the inventory content.
-
Field Details
-
guiItemKey
@NotNull protected final @NotNull org.bukkit.NamespacedKey guiItemKeyThe NameSpacedKey used by Inventory ItemStacks -
plugin
The Plugin that owns this GUI -
guiData
The GUIData needed for this GUI
-
-
Constructor Details
-
GUIHandler
Creates a GUIHandler- Parameters:
plugin- The Plugin Instance that owns of this GUIguiData- The data needed for this GUI to function
-
-
Method Details
-
getInventory
@NotNull public final @NotNull org.bukkit.inventory.Inventory getInventory()- Specified by:
getInventoryin interfaceorg.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 inventoryitemStack- 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 inventoryitemStack- the item that needs to be put in the inventoryonClick- 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 inventoryitemStack- the item that needs to be put in the inventoryonClick- 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
-