Skip to content

huanmeng-qwq/Gui

Repository files navigation

Gui

Version javadoc Servers Code-Size Repo-Size License Language Last-Commit

Lightweight Inventory API for Bukkit(Paper/Spigot) plugins, with 1.8.8 to 1.21 support.

Useful links

Features

  • Works with all versions from 1.8.8 to 1.21.x
  • Easy to use
  • Kotlin DSL
  • Paper support
  • Adventure components support

Maven

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.2.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <relocations>
                    <relocation>
                        <pattern>me.huanmeng.gui.gui</pattern>
                        <!-- Replace 'com.yourpackage' with the package of your plugin ! -->
                        <shadedPattern>com.yourpackage.gui</shadedPattern>
                    </relocation>
                </relocations>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>com.huanmeng-qwq</groupId>
        <artifactId>bukkit-gui</artifactId>
        <version>2.6.1</version>
    </dependency>

    <!--Kotlin DSL-->

    <dependency>
        <groupId>com.huanmeng-qwq</groupId>
        <artifactId>bukkit-gui-kotlin-dsl</artifactId>
        <version>2.6.1</version>
    </dependency>
</dependencies>

When using Maven, make sure to build directly with Maven and not with your IDE configuration. (on IntelliJ IDEA: in the Maven tab on the right, in Lifecycle, use package).

Gradle

plugins {
    id("com.gradleup.shadow") version "8.3.0"
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'com.huanmeng-qwq:bukkit-gui:2.6.1'
    // Kotlin DSL
    implementation 'com.huanmeng-qwq:bukkit-gui-kotlin-dsl:2.6.1'
}

shadowJar {
    // Replace 'com.yourpackage' with the package of your plugin
    relocate 'me.huanmeng.gui', 'com.yourpackage.huanmeng.gui'
}

Use

Creating a Gui

Just create a GuiCustom:

Java

import me.huanmeng.gui.gui.impl.GuiCustom;
import me.huanmeng.gui.gui.slot.Slot;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

public class Example extends JavaPlugin {
    @Override
    public void onEnable() {
        new GuiManager(this);
    }

    @Override
    public void onDisable() {
        GuiManager.instance().close();
    }

    public static void open(Player player) {
        GuiCustom gui = new GuiCustom(player);
        // Set the line
        gui.line(3);

        // Set the title
        gui.title("Test Gui");

        // Add an apple
        gui.draw().set(Slot.of(1), Button.of(player-> new ItemStack(Material.APPLE)));

        // Open for player
        gui.openGui();
    }
}

Kotlin DSL

GuiCustom Dsl
import org.bukkit.entity.Player

fun openGui(player: Player) {
    player.openGui {
        draw {
            setButton(buildSlot(0)) {
                var a = 1
                showingItem = buildButtonItem {
                    ItemStack(Material.values()[a++])
                }
                updateClick {
                    it.inventory.addItem(showingItem!!.get(it))
                }
            }
        }
    }
}
GuiPage Dsl
import org.bukkit.entity.Player

fun openPageGui(player: Player) {
    buildPagedGui {
        allItems = buildButtons {
            for (i in 0..60) {
                button {
                    showingItem = buildButtonItem(ItemStack(Material.values()[i]))
                }
            }
        }
        elementsPerPage = size() - 9
        elementSlots = buildSlotsByLine { line ->
            return@buildSlotsByLine buildList {
                for (i in 0..9 * line) {
                    add(buildSlot(i))
                }
            }
        }
        pageSetting {
            PageSettings.normal(this)
        }
    }.openGui(player)
}
PageSetting Dsl
buildPagedGui {
    pageSetting {
        buildPageSetting {
            button {
                buildPageButton {
                    types(PageButtonTypes.PREVIOUS)
                    setButton {
                        showingItem = buildButtonItem(ItemStack(Material.ARROW))
                    }
                    click(PlayerClickPageButtonInterface.simple())
                }
            }
            button {
                buildPageButton {
                    types(PageButtonTypes.NEXT)
                    setButton {
                        showingItem = buildButtonItem(ItemStack(Material.ARROW))
                    }
                    handleClick { _, gui, buttonType ->
                        buttonType.changePage(gui)
                    }
                }
            }
        }
    }
    // Do something...
}

Adventure support

For servers on modern PaperMC versions, The Gui project supports using Adventure components instead of strings, by using the method gui.title(Component).

About

A lightweight Minecraft Bukkit GUI library, supporting versions 1.8.8-1.21.x, offering a user-friendly inventory interface API and Kotlin DSL support

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors