Getting Started
To get started with KGui, follow these steps:
Download the Library: Download the latest version of KGui from the GitHub repository or SpigotMC.
Add KGui to Your Project: Add the KGui library to your Spigot plugin project by including it as a dependency. Here's an example of how to add KGui as a dependency in your pom.xml
file:
<dependency>
<groupId>com.github.NextDevv</groupId>
<artifactId>KGui</artifactId>
<version>1.1.4</version>
<scope>provided</scope>
</dependency>
and here's for Gradle:
repositories {
mavenCentral()
}
dependencies {
implementation 'com.github.NextDevv:KGui:1.1.4'
}
Create a GUI: Start creating your custom GUIs using KGui's intuitive API. You can define the layout, add buttons, and handle events easily. Here's an example of creating a simple GUI with a search button:
java
// Create a GUI border
GuiBorder border = new GuiBorder();
border.setDefaultItemStack(
new ItemStack(Material.RED_STAINED_GLASS_PANE)
);
// Build the GUI
KGui kGui = new KGui(PLUGIN);
kGui.init()
Inventory gui = kGui.builder(PLAYER)
.setTitle("&cItem Search")
.setRows(6)
.setBorder(border)
.addButton(Alignment.BOTTOM_CENTER, new GuiButton().setItemStack(
KItemStack.builder()
.setName("&c&lSearch")
.setMaterial(Material.COMPASS)
.build()
).setOnClick((builder, player) -> {
// Handle search button click
// ...
return null;
}))
.addItemStackClickListener((itemStack, player, builder) -> {
// Handle item click
// ...
return null;
})
.build();
kotlin
// Create a border
val border = GuiBorder()
border.defaultItemStack = ItemStack(Material.RED_STAINED_GLASS_PANE)
// Build the GUI
val kGui = KGui(PLUGIN)
kGui.init()
val gui: Inventory = kGui.builder(PLAYER)
.setTitle("&cItem Search")
.setRows(6)
.setBorder(border)
.addButton(Alignment.BOTTOM_CENTER, GuiButton().setItemStack(
KItemStack.builder()
.setName("&c&lSearch")
.setMaterial(Material.COMPASS)
.build()
).setOnClick { builder: KGui.Builder, player: Player ->
// Handle the click event
})
.addItemStackClickListener { itemStack: ItemStack, player: Player,
builder: KGui.Builder ->
// Handle the click event on the item
}
.build()
Handle Events: Implement event handlers to respond to player interactions, button clicks, and other events within your GUIs. KGui provides a simple and intuitive event system for handling events.
Test Your GUI: Test your GUI in-game to ensure it functions as expected and provides a seamless user experience.
Customize and Enhance: Customize the appearance, layout, and functionality of your GUIs to create unique and engaging interfaces for your players.
Last modified: 03 July 2024