GUI
This GUI API is based on abstract classes for both the menu and the items.
Creating the GUI
To create a GUI, you need to create a new class that extends the abstract class GUI. The methods getTitle(Player) and getButtons(Player) will be implemented. You may implement onOpen(Player) and onClose(Player) to do things for when they open or close. To adjust the size of the inventory, you must implement the size() method.
Here's an example:
public class MyGUI extends GUI {
@Override
public String getTitle(Player player) {
return "&aMy cool GUI!"; // Supports colour codes.
}
@Override
public Map<Integer, Button> getButtons(Player player) {
return new HashMap<>();
}
// Optional, default value is 9.
@Override
public int size() {
return 9 * 3;
}
// Optional
@Override
public void onOpen(Player player) {
System.out.println(player.getName() + " opened " + getTitle(player));
}
// Optional
@Override
public void onClose(Player player) {
System.out.println(player.getName() + " closed " + getTitle(player));
}
}Opening the GUI
Opening the GUI is simple, all you have to do is call new MyGUI().openGUI(player). In some scenarios, it is recommended to open it in an asynchronous task.
Adding Buttons
Adding buttons is also very simple. First you should see how to create a button which you may find here. You should create a new variable with Map<Integer, Button> and simply do map.put(0, new MyButton()) whereas 0 is the index (max: the size minus 1, min: 0) and the button is either your custom button or one of the default ones.
Here's how the getButtons(Player) method may look like:
Creating Buttons
For creating buttons, you must create a new class which extends the abstract class Button. You will need to implement the required methods and you may also implement getDamageValue(Player), getAmount(Player), onClick(Player, ClickType, int), addItemFlags(Player), and getEnchantments(Player). The names says for themselves what they do.
Here's an example of a button:
Last updated