Skip to content
Leandro Alfonso edited this page Aug 21, 2020 · 4 revisions

GUIs with MPUtils

Here you will find how it is easier to create Graphic User Interfaces(GUIs) with MPUtils, some GUIs examples and how they work.

Table of contents:

  1. Simple GUIs
  2. Paginated GUIs
  3. Navigation bar
  4. How to create a GUI
  5. Manage GUI clicks

Simple GUIs

These are one-page GUIs. You must provide any size ranging from 9 slots to 54 slots for this GUI and any title with colors applied beforehand (see colour a string).

Some examples of simple GUIs created with MP Utils:


https://i.imgur.com/1pwkDV4.png
Simple GUI example with no items, size 18 and title "&6Example"



https://i.imgur.com/qSjzJlD.png
Simple GUI example with arbitrarily placed items, size 36 and title "&2Example2"


Paginated GUIs

These GUIs with at least one page, and an infinite amount of pages, the number of pages will update dincamically depending on the amount of items you provide. You must provide any size ranging from 18 slots to 54 slots for this GUI and any title with colors applied beforehand (see colour a string). The actual usable space you will get is the size you entered -9, this is because of the navigation bar using the last row of 9 slots.

Some examples of paginated GUIs created with MP Utils:

https://i.imgur.com/6Lod25R.png
Paginated GUI example with no items, size 45 and title "&9&lExample 3 with pages". This GUI has the default navBar, paper for the "navBar item" (the item that is set in navBar slots where there are no buttons) and a book for the "current page item", you do not see here the 2 other navBar items (previous page item and next page item) because in this case this GUi has only one page.



https://i.imgur.com/21W4xCt.png
Paginated GUI example with arbitrarily placed items in order to show the paginated feature, size 54 and title "&cExample 4 with pages". In this case we don't see the paper in the place of the "navBar item", instead we see black stained glass panes, this and every item in the navigation bar can be customized. We also see the "next page item" and the "previous page item", this is because at the moment of taking the picture, the user was on page 2 of the GUI.


Navigation bar

The last row of every paginated GUI is always reserved for the navigation bar (navBar), the purpose of this set of items used serve is navigating through the paginated GUI and letting the user know where they are standing.

It consits of 4 items with the following intended use:

  1. Previous page item. This item only is shown when there is a previous page, when clicked, it should send the user to the previous page of the paginated GUI. See Manage GUI clicks
  2. Navigation bar item. This item should not be affected by user clicks, it should just serve the purpose of filling empty spaces, you can always set this item's type to air in order to let the empty space if that is what you really wish.
  3. Current page item. This item, if shown, serves the purpose of letting the user know wich page are they standing on, and how many pages are there in the GUI. You can hide this item and a navigation bar item will be shown in its place.
  4. Next page item. This item, as you have probably already guessed, serves the purpose of driving the user towards the next page, only shown if ais next page exists.

How to create a GUI

Simple GUI

Creating a simple GUI is as simple as creating a new SimpleGUI object.

The following line of code was used to create the first simple GUI example in the Simple GUIs section.

SimpleGUI simpleGUI = new SimpleGUI(StringUtils.colorizeString('&', "&6Example"), 18, "any tag you want");

The SimpleGUI objects takes 3 parameters: Title, size, tags. Title being the title for the inventory, size being the final inventory size and tags being any tag you want that GUI object to have in order to distinguish from any other GUI object you may have.
The methods for the SimpleGUI object are the following:

Method Parameters Description
setItem int index, ItemStack item Sets the given ItemStack in the given index of the inventory.
addItem ItemStack item Adds the given ItemStack to the inventory to the first place it fits. Use setItem when possible.
setTitle String newTitle Changes the title for the inventory.
clearInventory - Removes all the items from the inventory.
openGUI Player player Opens the GUI for the given player.

Paginated GUI

Creating a paginated GUI is not much more complicated than creating a simple GUI, since MPUtils does all the pages work for you, just pass the list of items to the PaginatedGUI object and it will determine how many pages you will have.

The following lines of codes created the first paginated GUI example in the Paginated GUIs section.

List<ItemStack> items = new ArrayList<>();
// Add as many items to the items list as you want, don't worry, you can update this list of items later.
PaginatedGUI paginatedGUI = new PaginatedGUI(StringUtils.colorizeString('&', "&9&lExample 3 with pages"), 45, items, "some random tags");

The PaginatedGUI object takes 4 parameters, the first being the title, in second place the inventory size per page (this is not the final usable space, the actual usable space is the size entered minus 9 of the navBar, also, this size must be between 18 and 54 and a multiple of 9), a list of itemstacks to be dispersed over every page of the GUI, and any tags you would like to add to the object in order to distinguish it from other instances of PaginatedGUI. The methods for the PaginatedGUI object are the following:

Method Parameters Descritpion
updateItemPerPage List items Changes the list of items displayed in the GUI to the given one.
setDefaultNavBarItems - Resets the navBar items to the default ones.
setNavBar int page Updates the navBar items, replacing placeholders. This is automatically called when a user gets opened the GUI.
setSizePerPage int newSize Sets the size per GUI page to the given one.
setHasCurrentPageItem boolean hasCurrentPageItem Sets whether the "curent page item" is shown if true, else a "navbar item" is shown in its place. See Navigation bar.
setNextPageItem ItemStack nextPageItem Changes the "next page item" in the navBar for the given one. See Navigation bar.
setPreviousPageItem ItemStack previousPageItem Changes the "previous page item" in the navBar for the given one. See Navigation bar.
setCurrentPageItem ItemStack currentPageItem Changes the "navBar item" in the navBar for the for the given one. See Navigation bar.
getPreviousPageItem int page Gets the "previous page item" with the page palceholders already replaced in its name and lore. See Navigation bar.
getNavBarItem int page Gets the "navBar item" with the page placeholders already replaced in its name and lore. See Navigation bar.
getCurrentPageItem int page Gets the "current page item" with the page placeholders already replaced in its name and lore. See Navigation bar.
getNextPageItem int page Gets the "next page item" with the page placeholders already replaced in its name and lore. See Navigation bar.
getPages - Gets the total number of pages generated by the GUI with the previously given list of items.
openGUI Player player, int page Opens the GUI for the given player on the given page, if the page does not exists, it will do nothing.
setItemsForPage int page Sets the items that correspond to the given page in the inventory to be opened. Called automatically by MPUtils itself.

Manage GUI clicks

WIP...