Lightweight Inventory API for Bukkit(Paper/Folia/Spigot) plugins, with 1.8.8 to 1.21 support.
- Works with all versions from 1.8.8 to 1.21
- Very small (around 3k lines of code with the JavaDoc) and no dependencies
- Easy to use
- Kotlin DSL
- Adventure components support
<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.opensource.bukkit.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.2.2</version>
</dependency>
<!--Kotlin DSL-->
<dependency>
<groupId>com.huanmeng-qwq</groupId>
<artifactId>Bukkit-Gui-kotlin-dsl</artifactId>
<version>2.2.2</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
).
plugins {
id 'com.github.johnrengelman.shadow' version '8.1.1'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'com.huanmeng-qwq:Bukkit-Gui:2.2.2'
// Kotlin DSL
implementation 'com.huanmeng-qwq:Bukkit-Gui-kotlin-dsl:2.2.2'
}
shadowJar {
// Replace 'com.yourpackage' with the package of your plugin
relocate 'me.huanmeng.opensource.bukkit.gui', 'com.yourpackage.gui'
}
Just create a GuiCustom
:
import me.huanmeng.opensource.bukkit.gui.impl.GuiCustom;
import me.huanmeng.opensource.bukkit.gui.slot.Slot;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class Example {
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();
}
}
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...
}
For servers on modern PaperMC versions, The Gui project supports
using Adventure components instead of strings,
by using the method gui.title(Component)
.
JetBrains, creators of the IntelliJ IDEA, supports Gui with one of their Open Source Licenses. IntelliJ IDEA is the recommended IDE for working with Gui.