|
| 1 | +# SpiGUI |
| 2 | +A comprehensive inventory menu API for Spigot with pages support. Supports Bukkit/Spigot 1.7 - 1.16 (see [Version Notes](#version-notes)). |
| 3 | +<p> |
| 4 | + <a href="https://github.com/SamJakob/SpiGUI/blob/master/LICENSE"> |
| 5 | + <img alt="License" src="https://img.shields.io/github/license/SamJakob/SpiGUI?style=for-the-badge"> |
| 6 | + </a> |
| 7 | + <a href="#"> |
| 8 | + <img alt="No Dependencies" src="https://img.shields.io/badge/dependencies-none-green?style=for-the-badge"> |
| 9 | + </a> |
| 10 | + <a href="https://jitpack.io/#com.samjakob/SpiGUI"> |
| 11 | + <img alt="JitPack" src="https://img.shields.io/jitpack/v/github/SamJakob/SpiGUI?style=for-the-badge"> |
| 12 | + </a> |
| 13 | +</p> |
| 14 | + |
| 15 | +<br><br> |
| 16 | + |
| 17 | +<p align="center"> |
| 18 | +<img width="640" src="https://user-images.githubusercontent.com/37072691/91370390-2071d400-e806-11ea-86a8-57a60138e505.gif"> |
| 19 | +<br> |
| 20 | +<small>The code for this example can be found in the library <a href="https://github.com/SamJakob/SpiGUI/blob/master/src/test/java/com/samjakob/spiguitest/SpiGUITest.java">test class</a>.</small> |
| 21 | +</p> |
| 22 | + |
| 23 | +<br><br> |
| 24 | + |
| 25 | +## Version Notes |
| 26 | +- I don't see a reason it shouldn't work in Spigot 1.7 or any version of Bukkit from 1.8 - 1.16 but it hasn't been tested on those versions. |
| 27 | +- This library has been tested on Spigot 1.8 and Spigot 1.16 and is expected to work on every version in-between. |
| 28 | +- The [ItemBuilder](https://github.com/SamJakob/SpiGUI/blob/master/src/main/java/com/samjakob/spigui/item/ItemBuilder.java) API does require that `api-version` be `"legacy"` (or not specified) for Spigot versions after 1.13. |
| 29 | + |
| 30 | +<br> |
| 31 | + |
| 32 | +## Quick Start |
| 33 | + |
| 34 | +**Step 1: Create an instance of the SpiGUI library in your plugin** |
| 35 | +```java |
| 36 | + |
| 37 | +class MyPlugin extends JavaPlugin { |
| 38 | + |
| 39 | + public static SpiGUI spiGUI; |
| 40 | + |
| 41 | + @Override |
| 42 | + public void onEnable() { |
| 43 | + // (IMPORTANT!) Registers SpiGUI event handlers (and stores plugin-wide settings for SpiGUI.) |
| 44 | + spiGUI = new SpiGUI(this); |
| 45 | + } |
| 46 | + |
| 47 | +} |
| 48 | + |
| 49 | +``` |
| 50 | + |
| 51 | +<br> |
| 52 | + |
| 53 | +**Step 2: Use the library** |
| 54 | +```java |
| 55 | +public void openMyAwesomeMenu(Player player) { |
| 56 | + |
| 57 | + // Create a GUI with 3 rows (27 slots) |
| 58 | + SGMenu myAwesomeMenu = MyPlugin.spiGUI.create("&cMy Awesome Menu", 3); |
| 59 | + |
| 60 | + // Create a button |
| 61 | + SGButton myAwesomeButton = new SGButton( |
| 62 | + // Includes an ItemBuilder class with chainable methods to easily |
| 63 | + // create menu items. |
| 64 | + new ItemBuilder(Material.WOOD).build() |
| 65 | + ).withListener((InventoryClickEvent event) -> { |
| 66 | + // Events are cancelled automatically, unless you turn it off |
| 67 | + // for your plugin or for this inventory. |
| 68 | + event.getWhoClicked().sendMessage("Hello, world!"); |
| 69 | + }); |
| 70 | + |
| 71 | + // Add the button to your GUI |
| 72 | + myAwesomeMenu.addButton(myAwesomeButton); |
| 73 | + |
| 74 | + // Show the GUI |
| 75 | + player.openInventory(myAwesomeMenu.getInventory()); |
| 76 | + |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +<br> |
| 81 | + |
| 82 | +**Step 3: Profit!** |
| 83 | + |
| 84 | +<br> |
| 85 | + |
| 86 | +## Why? |
| 87 | +Chest Inventory Menus (commonly referred to as GUIs) are the ubiquitous way to display menus, execute actions and even manage configuration in Spigot plugins. |
| 88 | +However, the Inventory API leveraged to achieve this in Spigot is not designed for menus, making code far more verbose and far less maintainable than it needs to be. |
| 89 | + |
| 90 | +SpiGUI is a rewrite of my outdated [SpigotPaginatedGUI](https://github.com/masterdoctor/SpigotPaginatedGUI) API including improvements and features I've |
| 91 | +added whilst using the API in my own software that aims to provide a highly readable and concise API for menus. |
0 commit comments