After the basics of a GUI there is a lot more useful features you can use.
The following are the common features in all GUIs.
The GUI filler allows you to fill in the GUI in many ways, for example, completely filling or filling the bottom or top of the GUI. You can get the filler by doing GUI#getFiller
.
Setting you fill item will fill the slots in your GUI that doesn't contain a GUI item.
// Single fill itemgui.getFiller().fill(new GuiItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE)));​// Multiple fill itemsgui.getFiller().fill(Arrays.asList(new GuiItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE)), new GuiItem(new ItemStack(Material.WHITE_STAINED_GLASS_PANE))));
Just like any other item these items can also have a click action, but they'll be the same for all the slots it is filled.
You can also set a default click action, which will be applied to every single slot in the GUI. For example if you call event.setCancelled(true)
as your default action, you no longer need to cancel it for every single item.
gui.setDefaultClickAction(event -> {// Handle your default action here});
This will display the action you set when ever the GUI is closed.
The event passed down for this action is the InventoryCloseEvent
.
gui.setCloseGuiAction(event -> {// Handle your close action});
This will display the action you set when ever the GUI is open .
The event passed down for this action is the InventoryOpenEvent
.
gui.setOpenGuiAction(event -> {// Handle your open action});
If you want to add a click action to a specif slot without needing to have to specify the item in the slot, you can simple use the setSlotAction
.
It also supports both rows and columns and slots.
// With slotgui.addSlotAction(slot, event -> {// Handle your open action});​// With rows and collumnsgui.addSlotAction(row, col, event -> {// Handle your open action});
The update
method will update the entire GUI except the title, due to how inventories work.
gui.update();
This will also update the title but you need to pass the new title down. This feature has not been tested enough.
gui.updateTitle("new title");
This is the preferable way of making updates in your GUI, for example an item that keeps refreshing, etc. This is recommended over the other ones as it'll simply change one item instead of the whole GUI. It also supports both rows and columns and slots.
// Using slotsgui.updateItem(slot, new ItemStack(Material.STONE));​// Using rows and collumnsgui.updateItem(row, col, new ItemStack(Material.STONE));
MF-GUI already comes with a built in ItemBuilder to make it easier for you to create custom items.
The framework comes with XMaterials from the XSeries included for easier multi version support.