Class SpiGUI
java.lang.Object
com.samjakob.spigui.SpiGUI
The core class for the SpiGUI library.
One instance of the SpiGUI class is registered for each plugin using it.
The expected usage of SpiGUI is that you register a SpiGUI instance for your plugin with
One instance of the SpiGUI class is registered for each plugin using it.
The expected usage of SpiGUI is that you register a SpiGUI instance for your plugin with
new SpiGUI(this); in your class that extends
JavaPlugin. You can then use the instance you've created throughout
your project to create GUIs that use SpiGUI.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanWhether to cancel inventory click actions by default.private SGToolbarBuilderThe defaultToolbarBuilder is the plugin-wideSGToolbarBuildercalled when building pagination buttons for inventory GUIs.private booleanWhether automatic pagination should be enabled.private final org.bukkit.plugin.java.JavaPluginThe plugin that owns this instance of SpiGUI. -
Constructor Summary
ConstructorsConstructorDescriptionSpiGUI(org.bukkit.plugin.java.JavaPlugin plugin) Creates an instance of the SpiGUI library associated with a given plugin. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns the value ofblockDefaultInteractionsfor this plugin.An alias forcreate(String, int, String)with the tag set to null.Creates an inventory with a given name, tag and number of rows.findOpenWithTag(String tag) Finds a list of all open inventories with a given tag along with the player who has that inventory open.The default toolbar builder used for GUIs.booleanReturns the value ofenableAutomaticPaginationfor this plugin.voidsetBlockDefaultInteractions(boolean blockDefaultInteractions) Whether default inventory interactions should be cancelled.voidsetDefaultToolbarBuilder(SGToolbarBuilder defaultToolbarBuilder) The default toolbar builder used for GUIs.voidsetEnableAutomaticPagination(boolean enableAutomaticPagination) Whether automatic pagination should be enabled.
-
Field Details
-
plugin
private final org.bukkit.plugin.java.JavaPlugin pluginThe plugin that owns this instance of SpiGUI. -
blockDefaultInteractions
private boolean blockDefaultInteractionsWhether to cancel inventory click actions by default.
This is typically set to true so events needn't be manually cancelled every time an item is clicked in the inventory as that is the behavior most typically used with an inventory GUI.
With this set to true, you can of course useevent.setCancelled(false);(orevent.setResult(Event.Result.DEFAULT);) in your button listeners to allow the default behavior of the inventory to take place. -
enableAutomaticPagination
private boolean enableAutomaticPaginationWhether automatic pagination should be enabled.
This is set to true by default, and it means if you set an inventory slot greater than the highest slot on the inventory, a row will automatically be added containing pagination items that allow a user to scroll between different 'pages' to access all the assigned slots in the inventory.
This concept is based on an improved version of the approach taken with my SpigotPaginatedGUI library. -
defaultToolbarBuilder
The defaultToolbarBuilder is the plugin-wideSGToolbarBuildercalled when building pagination buttons for inventory GUIs.
This can be overridden per-inventory, as well as per-plugin using the appropriate methods on either the inventory class (SGMenu) or your plugin's instance ofSpiGUI.
-
-
Constructor Details
-
SpiGUI
public SpiGUI(org.bukkit.plugin.java.JavaPlugin plugin) Creates an instance of the SpiGUI library associated with a given plugin.
This is intended to be stored as a static field in your plugin with a public static getter (or a public static field - dealer's choice) and you create inventories through this class by callingcreate(String, int)on the staticSpiGUIfield.
A lengthy justification of this is provided below, should you care to read it.
Note:
The association with a plugin is an important design decision that was overlooked in this library's predecessor, SpigotPaginatedGUI.
This library is not designed to act as a standalone plugin because that is inconvenient for both developers and server administrators for such a relatively insignificant task - the library is more just a small convenience measure. However, this library still needs to register a listener under a given plugin, which is where the issue arises; which plugin should the library use to register events with. Previously, it was whichever plugin made the call toPaginatedGUI.preparefirst, however this obviously causes problems if that particular plugin is unloaded - as any other plugins using the library no longer have the listener that was registered.
This approach was therefore considered a viable compromise - each plugin registers its own listener, however the downside of this is that each inventory and the listener must now also be registered with the plugin too.
Thus, the design whereby this class is registered as a static field on aJavaPlugininstance and serves as a proxy for creating (SGMenu) inventories and an instance of theSGMenuListenerregistered with that plugin seemed like a good way to try and minimize the inconvenience of the approach.- Parameters:
plugin- The plugin using SpiGUI.
-
-
Method Details
-
create
An alias forcreate(String, int, String)with the tag set to null. Use this method if you don't need the tag, or you don't know what it's for.
The rows parameter is used in place of the size parameter of the Bukkit/Spigot inventory API. So, if you wanted an inventory of size 27, you would supply 3 as the value of therowsparameter.
Thenameparameter supports the following 'placeholders':{currentPage}: the current page the inventory is on.{maxPage}: the final page of the inventory.
- Parameters:
name- The display name of the inventory.rows- The number of rows the inventory should have per page.- Returns:
- The created inventory.
-
create
Creates an inventory with a given name, tag and number of rows. The display name is color code translated.
Thenameparameter supports the following 'placeholders':{currentPage}: the current page the inventory is on.{maxPage}: the final page of the inventory.
The rows parameter is used in place of the size parameter of the Bukkit/Spigot inventory API. So, if you wanted an inventory of size 27, you would supply 3 as the value of therowsparameter.
The tag is used when getting all open inventories (findOpenWithTag(String)) with your chosen tag. An example of where this might be useful is with a permission GUI - when the permissions are updated by one user in the GUI, it would be desirable to refresh the state of the permissions GUI for all users observing the GUI.
You might give the permissions GUI a tag of 'myPermissionsGUI', then refreshing all the open instances of the GUI would be as simple as getting all open inventories with the aforementioned tag usingfindOpenWithTag(String)and calling refresh on each GUI in the list.- Parameters:
name- The display name of the inventory.rows- The number of rows the inventory should have per page.tag- The inventory's tag.- Returns:
- The created inventory.
-
setBlockDefaultInteractions
public void setBlockDefaultInteractions(boolean blockDefaultInteractions) Whether default inventory interactions should be cancelled.- Parameters:
blockDefaultInteractions- Whether default inventory interactions should be cancelled.- See Also:
-
areDefaultInteractionsBlocked
public boolean areDefaultInteractionsBlocked()Returns the value ofblockDefaultInteractionsfor this plugin.- Returns:
- Whether default inventory interactions should be cancelled.
-
setEnableAutomaticPagination
public void setEnableAutomaticPagination(boolean enableAutomaticPagination) Whether automatic pagination should be enabled.- Parameters:
enableAutomaticPagination- Whether automatic pagination should be enabled.- See Also:
-
isAutomaticPaginationEnabled
public boolean isAutomaticPaginationEnabled()Returns the value ofenableAutomaticPaginationfor this plugin.- Returns:
- Whether automatic pagination is enabled.
-
setDefaultToolbarBuilder
The default toolbar builder used for GUIs.- Parameters:
defaultToolbarBuilder- The default toolbar builder used for GUIs.- See Also:
-
getDefaultToolbarBuilder
The default toolbar builder used for GUIs.- Returns:
- The default toolbar builder used for GUIs.
- See Also:
-
findOpenWithTag
Finds a list of all open inventories with a given tag along with the player who has that inventory open.
This returns a list ofSGOpenMenuwhich simply stores the opened inventory along with the player viewing the open inventory.
Supplying null as the tag value will get all untagged inventories.- Parameters:
tag- The tag to search for.- Returns:
- A list of
SGOpenMenuwhose inventories have the specified tag.
-