If you like our project, please join our Discord!
- 0. Features
- 1. Installation
- 2. Shading + Relocating (Very important!)
- 3. GUI Usage
- 4. InteractiveItem Usage
- 5. Pagination Usage
- 6. Utilities
- 7. Putting it all together
- Easy to use
- Capable of creating complex GUIs
- Maintainer has (unfortunately) a lot of free time
- Pagination (TODO!)
<repositories>
<repository>
<id>digitality-repo-releases</id>
<url>https://repo.digitality.dev/releases</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>dev.digitality</groupId>
<artifactId>digitalgui</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
repositories {
maven {
name "digitalityRepoReleases"
url "https://repo.digitality.dev/releases"
}
}
dependencies {
implementation "dev.digitality:digitalgui:1.0.1"
}
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<configuration>
<relocations>
<relocation>
<pattern>dev.digitality.digitalgui</pattern>
<shadedPattern>your.package.here.digitalgui</shadedPattern>
</relocation>
</relocations>
</configuration>
</plugin>
</plugins>
</build>
plugins {
id "com.github.johnrengelman.shadow" version "8.1.1"
}
shadowJar {
relocate "dev.digitality.digitalgui", "your.package.here.digitalgui"
}
This isn't what exactly makes the GUI interactive, please check the section below.
To register the API, you need to call the DigitalGUI.register()
method. You can (and should) do this in your onEnable()
method. You need to do this only once.
@Override
public void onEnable() {
DigitalGUI.register(this);
}
To create a GUI you need to make a separate class implementing the IGUI
interface and getInventory()
method.
If you wish to pass anything, such as a player, you can do so by adding parameters to the constructor.
public class ExampleGUI implements IGUI {
private final Player player;
public ExampleGUI(Player player) {
this.player = player;
}
@Override
public Inventory getInventory() {
Inventory inventory = Bukkit.createInventory(this, 9, "Example GUI"); // Don't forget the "this"!
inventory.setItem(0, new ItemStack(Material.DIAMOND));
return inventory;
}
}
Opening a GUI as simple as calling the getInventory()
method.
player.openInventory(new ExampleGUI(player).getInventory());
To register the API, you need to call the DigitalGUI.register()
method. You can (and should) do this in your onEnable()
method. You need to do this only once.
@Override
public void onEnable() {
DigitalGUI.register(this);
}
InteractiveItem serves as a clickable drop-in replacement for ItemStack. This means, that everything you can do with ItemStacks works with InteractiveItems as well. InteractiveItem also works with both InventoryClickEvent and PlayerInteractEvent. This means, that you can use InteractiveItems in both GUIs and in the world.
This includes, but is not limited to:
- Setting the item's name with one line
- Setting the item's lore with one line
- Setting the item's glow with one line
- Setting left/right click actions
Creating an InteractiveItem is as simple as creating a new instance of the class. You can optionally specify the slot, the item's name and the item's lore. See the source code for more.
InteractiveItem item = new InteractiveItem(Material.DIAMOND, 0, "§aDiamond", "§7This is a diamond.");
To set the click handler, you need to call the onClick()
method. This method takes a function as a parameter, with player and click type as parameters.
item.onClick((player, clickType) -> {
player.sendMessage("You clicked the diamond!");
});
You can also use onLeftClick and onRightClick methods, which take a function with player as a parameter.
item.onLeftClick(player -> {
player.sendMessage("You left clicked the diamond!");
});
To set the glow, you need to call the setGlow()
method. This method takes a boolean as a parameter.
item.setGlow(true);
TODO!
You can use the fillInventory()
method to fill an inventory with an item and create a frame around it.
Inventory inventory = Bukkit.createInventory(this, 9, "Example GUI"); // Don't forget the "this"!
ItemStack fillerItem = new ItemStack(Material.GRAY_STAINED_GLASS_PANE);
ItemStack borderItem = new ItemStack(Material.BLACK_STAINED_GLASS_PANE);
DigitalGUI.fillInventory(inventory, fillerItem, borderItem);
Here is a final example which you can use as a reference.
public class ExampleGUI implements IGUI {
private final Player player;
public ExampleGUI(Player player) {
this.player = player;
}
@Override
public Inventory getInventory() {
Inventory inventory = Bukkit.createInventory(this, 9, "Example GUI"); // Don't forget the "this"!
DigitalGUI.fillInventory(inventory, new InteractiveItem(Material.GRAY_STAINED_GLASS_PANE, 0, "§7"), new InteractiveItem(Material.BLACK_STAINED_GLASS_PANE, 0, "§7"));
InteractiveItem item = new InteractiveItem(Material.DIAMOND, 0, "§aDiamond", "§7This is a diamond.")
.onClick((player, clickType) -> { // This will run for any click action
player.sendMessage("You clicked the diamond!");
})
.onLeftClick(player -> { // This will run on left click, regardless of whether it was InventoryClickEvent or PlayerInteractEvent
player.sendMessage("You left clicked the diamond!");
})
.onRightClick(player -> { // This will run on right click, regardless of whether it was InventoryClickEvent or PlayerInteractEvent
player.sendMessage("You right clicked the diamond!");
});
inventory.setItem(item.getSlot(), item);
return inventory;
}
}