Skip to content
Dark Litss edited this page Sep 15, 2020 · 1 revision

Welcome to the SimplestGUI wiki! This wiki will show you how to build a GUI with SimplestGUI.

Getting started

Import dependency.

Assuming you are using Maven.
First, add my repository:

        <repository>
            <id>lss233-repo</id>
            <name>Lss233's Mirror</name>
            <url>https://lss233.littleservice.cn/repositories/minecraft</url>
        </repository>

Then, add this dependency:

	<dependency>
	    <groupId>com.lss233</groupId>
	    <artifactId>SimplestGUI</artifactId>
	    <version>1.0-SNAPSHOT</version>
	</dependency>

Tip: Remember to replace the 1.0-SNAPSHOT version with the latest version:

Delcare dependency

Add following to your plugin.yml:

depend: [SimplestGUI]

Creating a GUI

First, let's make a GUI class that extends GUI, you will get:

public class TestGUI extends Gui{

    public TestGUI(Player player) {
        super(TestPlugin.getInstance(), player, "A test gui", 9);
    }

    @Override
    protected void draw() {

    }

    @Override
    protected void onClosed() {

    }
}

draw()

This method will be called everytime the gui is opened to the player.
You can put components inside this method.

setComponent(int, Component)

This method puts a component to the GUI.
A component is an ItemStack showing on the Inventory.

onClosed()

This method will be called everytime the gui is closed by player.

Adding a component

Let's put a button on the second slot.

    @Override
    protected void draw() {
        setComponent(1, new Component.Builder()
                .icon(Material.CARROT_STICK)
                .title("Test button")
                .lore(Arrays.asList("A", "Test", "BUTTON"))
                .click((user, click) -> {
                    if(click.equals(ClickType.LEFT)){
                        user.sendMessage("You left clicked this");
                    } else if(click.equals(ClickType.RIGHT)) {
                        user.sendMessage("You right clicked this");
                    }
                })
                .build());
    }

Cool, isn't it?

Show it to the player

    TestGUI gui = new TestGUI(player);
    gui.open();

And... it is done!

If you want to know some more advanced usage, check out our other chapters on the wiki!