Lightweight and easy-to-use inventory API for Bukkit plugins. Based on MrMicky-FR/FastInv. Javadocs here.
- Very small (less than 400 lines of code with the JavaDoc) and no dependencies
- Works with all Bukkit versions from 1.7.10 to 1.17.
- Supports custom inventories (size, title and type)
- Easy to use
- Option to prevent a player from closing the inventory
- The Bukkit inventory can still be directly used
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<relocations>
<relocation>
<pattern>us.jcedeno.libs.rapidinv</pattern>
<!-- Replace 'com.yourpackae' with the package of your plugin ! -->
<shadedPattern>com.yourpackage.rapidinv</shadedPattern>
</relocation>
</relocations>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.noobstersmc</groupId>
<artifactId>RapidInv</artifactId>
<version>v0.0.1</version>
</dependency>
</dependencies>
plugins {
id 'com.github.johnrengelman.shadow' version '6.1.0'
}
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.noobstersmc:RapidInv:v0.0.1'
}
shadowJar {
// Replace 'com.yourpackage' with the package of your plugin
relocate 'us.jcedeno.libs.rapidinv', 'com.yourpackage.rapidinv'
}
Just copy RapidInv.java
and RapidInvManager.java
in your plugin.
You can also add ItemBuilder.java
if you need.
Before creating inventories, you just need to register your plugin by adding RapidInvManager.register(this);
in the onEnable()
method of your plugin:
@Override
public void onEnable() {
RapidInvManager.register(this);
}
Now you can create an inventory by make a class that extends RapidInv
, and add items in the constructor.
You can also override onClick
, onClose
and onOpen
if you need.
Small example inventory:
import us.jcedeno.libs.rapidinv.RapidInv;
import us.jcedeno.libs.rapidinv.ItemBuilder;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.inventory.ItemStack;
public class ExampleInventory extends RapidInv {
private boolean preventClose = false;
public ExampleInventory() {
super(45, ChatColor.GOLD + "Example inventory");
// Just add a random item
setItem(22, new ItemStack(Material.IRON_SWORD), e -> e.getWhoClicked().sendMessage("You clicked on the sword"));
// Add some blocks to the borders
setItems(getBorders(), new ItemBuilder(Material.LAPIS_BLOCK).name(" ").build());
// Add a simple item to prevent closing the inventory
setItem(34, new ItemBuilder(Material.BARRIER).name(ChatColor.RED + "Prevent close").build(), e -> {
this.preventClose = !this.preventClose;
});
// Prevent from closing when preventClose is to true
setCloseFilter(p -> this.preventClose);
}
@Override
public void onOpen(InventoryOpenEvent event) {
event.getPlayer().sendMessage(ChatColor.GOLD + "You opened the inventory");
}
@Override
public void onClose(InventoryCloseEvent event) {
event.getPlayer().sendMessage(ChatColor.GOLD + "You closed the inventory");
}
@Override
public void onClick(InventoryClickEvent event) {
// do something
}
}
Now you can open the inventory:
new ExampleInventory().open(player);
If you prefer you can create a 'compact' inventory that doesn't require an entire class, but this is not recommended.
RapidInv inv = new RapidInv(InventoryType.DISPENSER, "Example compact inventory");
inv.setItem(4, new ItemStack(Material.NAME_TAG), e -> e.getWhoClicked().sendMessage("You clicked on the name tag"));
inv.addClickHandler(e -> player.sendMessage("You clicked on slot " + e.getSlot()));
inv.addCloseHandler(e -> player.sendMessage(ChatColor.YELLOW + "Inventory closed"));
inv.open(player);
You can easily get the RapidInv instance from a Bukkit inventory with the holder:
if (inventory.getHolder() instanceof RapidInv) {
RapidInv rapidinv = (RapidInv) inventory.getHolder();
}