Buttons

In this page you can see how to create a button into your GUI

After having created the GUI, you can create a new button into your GUI. To do that, you have to use the createButton() method. Here is the code:

// Create the gui with only a line
McGUI gui = new McGUI("§7Name", GuiLines.ONE_LINE, Main.getInstance());

// Create the item
GUItem item = new GUICustomItem(Material.BARRIER);
item.setName("§fClose");

// Create the button at the middle of the gui (5 - 1)
gui.createButton(item, 4, new GUIButtonEvents(() -> {
    // put here all the actions for when you interact with the button
}));

In the last example, you saw how to make a button with a generic event (An event that will be executed whenever you interact with the button). So, if you want to separate the events for when you right-click and for when you left-click, you have to make two lambdas like this:

// Create the button at the middle of the gui (5 - 1)
gui.createButton(item, 4, new GUIButtonEvents(() -> {
    // Left click actions
}, () -> { /* Right click actions */}));

Last updated

Was this helpful?