-
Notifications
You must be signed in to change notification settings - Fork 0
Creating Custom Inventories
Neelix allows the creation of inventories in a practical way with functionalities according to the type. It is possible to create simple or paginated inventories.
| Parameter | Type | Description |
|---|---|---|
| size | int | The inventory size. |
| title | String | The inventory title. |
| lockedSlots | List<Integer> | Slots that must be blocked. Items cannot be set into locked slots. |
| items | List<NeelixInventoryItem> | The inventory items. |
main plugin class
public class MyPlugin extends JavaPlugin {
@Override
public void onEnable() {
Neelix.init(this);
NeelixSimpleInventory inventory = new NeelixSimpleInventory(54, "Minecraft Items (Simple)", null, items);
}
}| Parameter | Type | Description |
|---|---|---|
| size | int | The inventory size. |
| title | String | The inventory title. |
| lockedSlots | List<Integer> | Slots that must be blocked. Items cannot be set into locked slots. |
| items | List<NeelixInventoryItem> | The inventory items. |
| navigation | NeelixPaginatedNavigation | Responsible for navigation between pages. |
main plugin class
public class MyPlugin extends JavaPlugin {
@Override
public void onEnable() {
Neelix.init(this);
NeelixPaginatedInventory inventory = new NeelixPaginatedInventory(54, "Minecraft Items (Paginated)", null, items, new NeelixPaginatedNavigation());
}
}You can create a default paginated navigation passing no parameters to the NeelixPaginatedNavigation constructor.
The lockedSlots parameter allows the inventory to block the addition of items to certain slots, allowing for better aesthetics in inventory creation.
It is recommended to save locked slots in a configuration file, for example:
# avoid the inventory border
locked-slots: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 26, 27, 35, 36, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53]Remember: Using locked slots will decrease the amount of items per page.
Creating custom items allows the onClick event to be fired as soon as clicked on it.
BasicItem class
public class BasicItem extends NeelixInventoryItem {
public BasicItem(@Nullable int slot, ItemStack item) {
super(slot, item);
}
@Override
public void onClick(NeelixInventory inventory, Player whoClicked, int clickedSlot, ItemStack clickedItem) {
whoClicked.sendMessage("You have received the item you clicked!")
whoClicked.getInventory().addItem(clickedItem);
}
}When the slot parameter is null, Neelix will selected the next available inventory for the item automatically. This is applied for simple and paginated inventories.
The navigation of a paginated inventory consists of two main interactions:
- Click on the item NeelixNextInventoryPageItem
- Click on the item NeelixPreviousInventoryPageItem
When creating a new navigation, you need to create a new item responsible to go to next page and another to go to previous page.
main plugin class
public class MyPlugin extends JavaPlugin {
@Override
public void onEnable() {
Neelix.init(this);
NeelixPaginatedNavigation navigation = new NeelixPaginatedNavigation(
new NextInventoryPageItem(45, buildNavigationItem(Material.SPECTRAL_ARROW, "Next ->")),
new PreviousInventoryPageItem(53, buildNavigationItem(Material.SPECTRAL_ARROW, "<- Back"))
);
NeelixPaginatedInventory inventory = new NeelixPaginatedInventory(54, "Minecraft Items", null, items, navigation);
}
/** Build a new ItemStack to be used as Icon for navigation items. */
private static ItemStack buildNavigationItem(Material material, String name) {
ItemStack item = new ItemStack(material);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(ChatColor.RESET + name);
item.setItemMeta(meta);
return item;
}
}Remember: The chosen slot for the navigation items will be automatically added to the locked slots.
main plugin class
public class MyPlugin extends JavaPlugin {
@Override
public void onEnable() {
Neelix.init(this);
NeelixSimpleInventory simpleInventory = new NeelixSimpleInventory(54, "Minecraft Items (Simple)", null, items);
NeelixPaginatedInventory paginatedInventory = new NeelixPaginatedInventory(54, "Minecraft Items", null, items, new NeelixPaginatedNavigation());
Neelix.getInventoryManager().registerInventory(simpleInventory);
Neelix.getInventoryManager().registerInventory(paginatedInventory);
}
}
Creating your first custom configuration file
Creating your first subcommand
- Introduction
- Creating subcommand class
- Registering subcommands on parent command
- Registering parent command
- Using subcommand as CommandExecutor
Creating subcommand fail listener
Creating Custom Inventories WIP 🚧
- Introduction
- Creating your first Simple Inventory
- Creating your first Paginated Inventory
- What is the locked slots parameter?
- Creating Inventory Items
- Creating Custom Navigation
- Registering your inventories