Skip to content

Commit 0c47a78

Browse files
committed
Add PaginatedFastInv and rewrite JavaDoc
Closes #7 and closes #22
1 parent 9fa174b commit 0c47a78

5 files changed

Lines changed: 528 additions & 65 deletions

File tree

README.md

Lines changed: 75 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# FastInv
2+
23
[![JitPack](https://jitpack.io/v/fr.mrmicky/FastInv.svg)](https://jitpack.io/#fr.mrmicky/FastInv)
3-
[![Discord](https://img.shields.io/discord/390919659874156560.svg?colorB=5865f2&label=Discord&logo=discord&logoColor=white)](https://discord.gg/q9UwaBT)
44

55
Lightweight and easy-to-use inventory API for Bukkit plugins.
66

77
## Features
8-
* Very small (less than 400 lines of code with the JavaDoc) and no dependencies
9-
* Works with all Bukkit/Spigot/Paper versions from 1.7.10 to 1.20
10-
* Simple [Adventure components support](#adventure-components-support)
8+
9+
* Lightweight (less than 400 lines of code with the JavaDoc) and no dependencies
10+
* Compatible with all Minecraft versions starting with 1.7.10
11+
* [Adventure components support](#adventure-components-support)
1112
* Supports custom inventories (size, title and type)
1213
* Easy to use
1314
* Option to prevent a player from closing the inventory
@@ -16,13 +17,14 @@ Lightweight and easy-to-use inventory API for Bukkit plugins.
1617
## Installation
1718

1819
### Maven
20+
1921
```xml
2022
<build>
2123
<plugins>
2224
<plugin>
2325
<groupId>org.apache.maven.plugins</groupId>
2426
<artifactId>maven-shade-plugin</artifactId>
25-
<version>3.3.0<</version>
27+
<version>3.3.0</version>
2628
<executions>
2729
<execution>
2830
<phase>package</phase>
@@ -55,23 +57,24 @@ Lightweight and easy-to-use inventory API for Bukkit plugins.
5557
<dependency>
5658
<groupId>fr.mrmicky</groupId>
5759
<artifactId>FastInv</artifactId>
58-
<version>3.0.4</version>
60+
<version>3.1.0</version>
5961
</dependency>
6062
</dependencies>
6163
```
6264

6365
### Gradle
66+
6467
```groovy
6568
plugins {
66-
id 'com.github.johnrengelman.shadow' version '7.1.2'
69+
id 'com.gradleup.shadow' version '8.3.0'
6770
}
6871
6972
repositories {
7073
maven { url 'https://jitpack.io' }
7174
}
7275
7376
dependencies {
74-
implementation 'fr.mrmicky:FastInv:3.0.4'
77+
implementation 'fr.mrmicky:FastInv:3.1.0'
7578
}
7679
7780
shadowJar {
@@ -88,6 +91,7 @@ You can also add `ItemBuilder.java` if you need.
8891
## Usage
8992

9093
### Register FastInv
94+
9195
Before creating inventories, you just need to register your plugin by adding `FastInvManager.register(this);` in the `onEnable()` method of your plugin:
9296
```java
9397
@Override
@@ -98,10 +102,10 @@ public void onEnable() {
98102

99103
### Creating an inventory class
100104

101-
Now you can create an inventory by make a class that extends `FastInv`, and add items in the constructor.
105+
Now you can create an inventory by creating a class that extends `FastInv`, and adding items in the constructor.
102106
You can also override `onClick`, `onClose` and `onOpen` if you need.
103107

104-
Small example inventory:
108+
Basic example inventory:
105109

106110
```java
107111
package fr.mrmicky.fastinv.test;
@@ -154,13 +158,70 @@ public class ExampleInventory extends FastInv {
154158
}
155159
```
156160

157-
Now you can open the inventory:
161+
The inventory can be opened with the `open(player)` method:
158162
```java
159163
new ExampleInventory().open(player);
160164
```
161165

166+
### Paginated inventory
167+
168+
FastInv also supports paginated inventories, which can be created by using `PaginatedFastInv` instead of `FastInv`.
169+
170+
Content can be added to the inventory using `addContent` or `setContent`, and pagination items can be added with `previousPageItem` and `nextPageItem`.
171+
172+
You can also use `onPageChange` to execute code when the page changes, and the `#currentPage()`, `#lastPage()`, `#isFirstPage()` and `#isLastPage()` methods to get information about the current page.
173+
```java
174+
import org.bukkit.Material;
175+
import org.bukkit.inventory.ItemStack;
176+
177+
public class ExamplePaginatedInventory extends PaginatedFastInv {
178+
179+
private static final InventoryScheme SCHEME = new InventoryScheme()
180+
.mask(" 1111111 ")
181+
.mask(" 1111111 ")
182+
.bindPagination('1');
183+
184+
public ExamplePaginatedInventory() {
185+
super(27, "Example paginated inventory");
186+
187+
// Add pagination items to the inventory
188+
// These items are automatically updated when the page changes and displayed only if needed
189+
previousPageItem(20, p -> new ItemBuilder(Material.ARROW).name("Page " + p + "/" + lastPage()).build());
190+
nextPageItem(24, p -> new ItemBuilder(Material.ARROW).name("Page " + p + "/" + lastPage()).build());
191+
192+
// Add some paginated content to the inventory
193+
for (int i = 1; i < 64; i++) {
194+
addContent(new ItemStack(Material.GOLDEN_APPLE, i),
195+
e -> e.getWhoClicked().sendMessage("You clicked on paginated item"));
196+
}
197+
198+
// The setContent method can also be used to set the index of a specific item of the paginated content
199+
setContent(42, new ItemStack(Material.APPLE, 42));
200+
201+
// Non-paginated items can also still be added to the inventory if needed
202+
setItem(26, new ItemBuilder(Material.BARRIER).name("Close").build(),
203+
e -> e.getWhoClicked().closeInventory());
204+
205+
// The pagination layout can also be customized with a mask instead of the default one
206+
SCHEME.apply(this);
207+
}
208+
209+
@Override // Optional method to handle the page change event if needed
210+
protected void onPageChange(int page) {
211+
// Called after the page change
212+
setItem(18, new ItemBuilder(Material.PAPER).name("Current page " + page).build());
213+
}
214+
}
215+
```
216+
217+
Like a normal inventory, you can open the paginated inventory with `open(player)`:
218+
```java
219+
new ExamplePaginatedInventory().open(player);
220+
```
221+
162222
### Creating a 'compact' inventory
163-
If you prefer, you can create a 'compact' inventory that doesn't require an entire class, but this is not recommended.
223+
224+
Instead of creating a new class for each inventory, a 'compact' inventory can be created directly:
164225

165226
```java
166227
FastInv inv = new FastInv(InventoryType.DISPENSER, "Example compact inventory");
@@ -171,6 +232,8 @@ inv.addCloseHandler(e -> player.sendMessage(ChatColor.YELLOW + "Inventory closed
171232
inv.open(player);
172233
```
173234

235+
In the same way, you can also create a 'compact' paginated inventory.
236+
174237
### Get the FastInv instance
175238
You can easily get the FastInv instance from a Bukkit inventory with the holder:
176239
```java

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>fr.mrmicky</groupId>
88
<artifactId>fastinv</artifactId>
9-
<version>3.0.4</version>
9+
<version>3.1.0</version>
1010

1111
<name>FastInv</name>
1212
<description>Lightweight and easy-to-use inventory API for Bukkit plugins.</description>

0 commit comments

Comments
 (0)