-
-
Notifications
You must be signed in to change notification settings - Fork 25
GUIs
This component displays complexe Minecraft GUIs with ease.
Documentation | JavaDoc |
Loader class (for loadComponents )
|
fr.zcraft.zlib.components.gui.Gui |
zLib comes with a full-featured component to create GUIs (Graphical User Interfaces), either read-only or read-and-write. There is also a specific class to ask for any text through a sign.
All chest GUIs are created using a class extending ActionGui
. The only method you have to override is onUpdate
, called when the GUI is created or updated.
In this method, you'll first have to define the GUI's properties, using the setSize
and setTitle
methods. Then, to populate the GUI with items, use the action
methods. They all take an action name (keep that in mind, we will talk about them later), then a slot ID (from 0 to the size minus one), and finally some kind of ItemStack (an ItemStack
, an ItemStackBuilder
, or some variants with a Material
, title, lore... directly).
Simple enough. As example, you may have this now:
public class MyGUI extends ActionGui
{
@Override
public void onUpdate()
{
setTitle(ChatColor.BLACK + "My toasting GUI!");
setSize(9); // One line
action("my_action", 0, new ItemStack(Material.CARROT));
action("close", 8, Material.BARRIER, "Close GUI");
}
}
You can open this GUI using this method—it's the same for all zLib GUIs, where player
is a Player
.
Gui.open(player, new MyGUI());
Ok so, now, if you execute this, you'll have a nice GUI. How to do something when the player clicks somewhere? It's really easy.
Remember the names we gave to the actions? These will be used to reference methods executed when the item representing the action is clicked. You'll just have to annotate the method with @GuiAction
, like so:
@GuiAction("my_action")
private void the_method_executing_my_action()
{
// do something (anything!)
}
Yes, that's all! To give another example, here is a working implementation of the second action defined in the example:
@GuiAction("close")
private void close_gui()
{
close();
}
(see the javadoc to get a list of usable methods in GUIs; don't forget to check parent classes too!).
The action methods can either take no argument, or the underlying InventoryClickEvent
.
Getting started
Components
Tools
Pour démarrer
Composants
- Commandes
- Configuration
- Internationalisation
- GUIs
- Barres latérales
- Services de travail en arrière plan
- NBT
-
Composants personnalisés
Outils