Skip to content

huanmeng-qwq/Gui

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gui

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

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

Features

  • Works with all versions from 1.8.8 to 1.20.1
  • 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.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).

Gradle

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'
}

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

About

一个允许您快速创建Gui的库,基于Bukkit/Spigot实现,非插件,需自行引入作为依赖库。

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published