Skip to content

Latest commit

 

History

History
242 lines (202 loc) · 6.43 KB

README.md

File metadata and controls

242 lines (202 loc) · 6.43 KB

Gui

Version 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.

Features

  • 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

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.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.4.0</version>
    </dependency>

    <!--Kotlin DSL-->

    <dependency>
        <groupId>com.huanmeng-qwq</groupId>
        <artifactId>bukkit-gui-kotlin-dsl</artifactId>
        <version>2.4.0</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.4.0'
    // Kotlin DSL
    implementation 'com.huanmeng-qwq:bukkit-gui-kotlin-dsl:2.4.0'
}

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

Use

Creating a Gui

Just create a GuiCustom:

Java

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 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).

Support

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.