SmartInvs
Search…
Introduction

SmartInvs

SmartInvs is a modern API for easily using inventories with Bukkit to make awesome GUIs. This book contains a guide on how to use this API to create your own amazing GUIs!
This API requires Java 8 to work.

Features

  • Inventories of any type (workbench, chest, furnace, ...)
  • Customizable size when possible (chest, ...)
  • Custom titles
  • Allows to prevent the player from closing its inventory
  • Custom listeners for the event related to the inventory
  • Iterator for inventory slots
  • Page system
  • Util methods to fill an inventory's row/column/borders/...
  • Actions when player clicks on an item
  • Update methods to edit the content of the inventory every tick

Usage

To use the SmartInvs API, either:
  • Put it in the plugins folder of your server, add it to your dependencies in your plugin.yml (e.g. depend: [SmartInvs]) and add it to the dependencies in your IDE.
  • Put it inside your plugin jar, initialize an InventoryManager in your plugin (don't forget to call the init() method), and add a .manager(invManager) to your SmartInventory Builders.
You can download the latest version on the Releases page on Github.
You can also use a build system:

Gradle

1
repositories {
2
mavenCentral()
3
}
4
5
dependencies {
6
compile 'fr.minuskube.inv:smart-invs:1.2.7'
7
}
Copied!

Maven

1
<dependency>
2
<groupId>fr.minuskube.inv</groupId>
3
<artifactId>smart-invs</artifactId>
4
<version>1.2.7</version>
5
</dependency>
Copied!

Preview

Here is a simple preview of an inventory.
1
public class SimpleInventory implements InventoryProvider {
2
3
public static final SmartInventory INVENTORY = SmartInventory.builder()
4
.id("myInventory")
5
.provider(new SimpleInventory())
6
.size(3, 9)
7
.title(ChatColor.BLUE + "My Awesome Inventory!")
8
.build();
9
10
private final Random random = new Random();
11
12
@Override
13
public void init(Player player, InventoryContents contents) {
14
contents.fillBorders(ClickableItem.empty(new ItemStack(Material.STAINED_GLASS_PANE)));
15
16
contents.set(1, 1, ClickableItem.of(new ItemStack(Material.CARROT_ITEM),
17
e -> player.sendMessage(ChatColor.GOLD + "You clicked on a potato.")));
18
19
contents.set(1, 7, ClickableItem.of(new ItemStack(Material.BARRIER),
20
e -> player.closeInventory()));
21
}
22
23
@Override
24
public void update(Player player, InventoryContents contents) {
25
int state = contents.property("state", 0);
26
contents.setProperty("state", state + 1);
27
28
if(state % 5 != 0)
29
return;
30
31
short durability = (short) random.nextInt(15);
32
33
ItemStack glass = new ItemStack(Material.STAINED_GLASS_PANE, 1, durability);
34
contents.fillBorders(ClickableItem.empty(glass));
35
}
36
37
}
Copied!
And there is the result:
If we click on the carrot, we receive the message You clicked on a potato, and if we click on the barrier, the inventory is closed.
The source code is available on Github! If you have some issues with the API, please open an issue on Github.
Last modified 1yr ago