Skip to content

Commit 5c1467f

Browse files
committed
Minecraft 1.20 & add Adventure support
Closes #16
1 parent 48b51ee commit 5c1467f

3 files changed

Lines changed: 33 additions & 20 deletions

File tree

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Lightweight and easy-to-use inventory API for Bukkit plugins.
66

77
## Features
88
* Very small (less than 400 lines of code with the JavaDoc) and no dependencies
9-
* Works with all Bukkit versions from 1.7.10 to 1.19
9+
* Works with all Bukkit/Spigot/Paper versions from 1.7.10 to 1.20
10+
* Simple [Adventure components support](#adventure-components-support)
1011
* Supports custom inventories (size, title and type)
1112
* Easy to use
1213
* Option to prevent a player from closing the inventory
@@ -54,7 +55,7 @@ Lightweight and easy-to-use inventory API for Bukkit plugins.
5455
<dependency>
5556
<groupId>fr.mrmicky</groupId>
5657
<artifactId>FastInv</artifactId>
57-
<version>3.0.3</version>
58+
<version>3.0.4</version>
5859
</dependency>
5960
</dependencies>
6061
```
@@ -70,7 +71,7 @@ repositories {
7071
}
7172
7273
dependencies {
73-
implementation 'fr.mrmicky:FastInv:3.0.3'
74+
implementation 'fr.mrmicky:FastInv:3.0.4'
7475
}
7576
7677
shadowJar {
@@ -177,3 +178,12 @@ if (inventory.getHolder() instanceof FastInv) {
177178
FastInv fastInv = (FastInv) inventory.getHolder();
178179
}
179180
```
181+
182+
### Adventure components support
183+
184+
FastInv supports [Adventure components](https://github.com/KyoriPowered/adventure) for inventory titles on [PaperMC](https://papermc.io/) servers:
185+
```java
186+
Component title = Component.text("Hello World");
187+
188+
FastInv inv = new FastInv(owner -> Bukkit.createInventory(owner, 27, title));
189+
```

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.3</version>
9+
<version>3.0.4</version>
1010

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

src/main/java/fr/mrmicky/fastinv/FastInv.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.util.Map;
4040
import java.util.Objects;
4141
import java.util.function.Consumer;
42+
import java.util.function.Function;
4243
import java.util.function.Predicate;
4344
import java.util.stream.IntStream;
4445

@@ -47,7 +48,7 @@
4748
* The project is on <a href="https://github.com/MrMicky-FR/FastInv">GitHub</a>.
4849
*
4950
* @author MrMicky
50-
* @version 3.0.3
51+
* @version 3.0.4
5152
*/
5253
public class FastInv implements InventoryHolder {
5354

@@ -66,7 +67,7 @@ public class FastInv implements InventoryHolder {
6667
* @param size The size of the inventory.
6768
*/
6869
public FastInv(int size) {
69-
this(size, InventoryType.CHEST.getDefaultTitle());
70+
this(owner -> Bukkit.createInventory(owner, size));
7071
}
7172

7273
/**
@@ -76,7 +77,7 @@ public FastInv(int size) {
7677
* @param title The title (name) of the inventory.
7778
*/
7879
public FastInv(int size, String title) {
79-
this(size, InventoryType.CHEST, title);
80+
this(owner -> Bukkit.createInventory(owner, size, title));
8081
}
8182

8283
/**
@@ -85,7 +86,7 @@ public FastInv(int size, String title) {
8586
* @param type The type of the inventory.
8687
*/
8788
public FastInv(InventoryType type) {
88-
this(Objects.requireNonNull(type, "type"), type.getDefaultTitle());
89+
this(owner -> Bukkit.createInventory(owner, type));
8990
}
9091

9192
/**
@@ -95,19 +96,18 @@ public FastInv(InventoryType type) {
9596
* @param title The title of the inventory.
9697
*/
9798
public FastInv(InventoryType type, String title) {
98-
this(0, Objects.requireNonNull(type, "type"), title);
99+
this(owner -> Bukkit.createInventory(owner, type, title));
99100
}
100101

101-
private FastInv(int size, InventoryType type, String title) {
102-
if (type == InventoryType.CHEST && size > 0) {
103-
this.inventory = Bukkit.createInventory(this, size, title);
104-
} else {
105-
this.inventory = Bukkit.createInventory(this, type, title);
106-
}
102+
public FastInv(Function<InventoryHolder, Inventory> inventoryFunction) {
103+
Objects.requireNonNull(inventoryFunction, "inventoryFunction");
104+
Inventory inv = inventoryFunction.apply(this);
107105

108-
if (this.inventory.getHolder() != this) {
109-
throw new IllegalStateException("Inventory holder is not FastInv, found: " + this.inventory.getHolder());
106+
if (inv.getHolder() != this) {
107+
throw new IllegalStateException("Inventory holder is not FastInv, found: " + inv.getHolder());
110108
}
109+
110+
this.inventory = inv;
111111
}
112112

113113
protected void onOpen(InventoryOpenEvent event) {
@@ -132,7 +132,7 @@ public void addItem(ItemStack item) {
132132
* Add an {@link ItemStack} to the inventory on the first empty slot with a click handler.
133133
*
134134
* @param item The item to add.
135-
* @param handler The the click handler for the item.
135+
* @param handler The click handler for the item.
136136
*/
137137
public void addItem(ItemStack item, Consumer<InventoryClickEvent> handler) {
138138
int slot = this.inventory.firstEmpty();
@@ -290,7 +290,8 @@ public void open(Player player) {
290290
*/
291291
public int[] getBorders() {
292292
int size = this.inventory.getSize();
293-
return IntStream.range(0, size).filter(i -> size < 27 || i < 9 || i % 9 == 0 || (i - 8) % 9 == 0 || i > size - 9).toArray();
293+
return IntStream.range(0, size).filter(i -> size < 27 || i < 9
294+
|| i % 9 == 0 || (i - 8) % 9 == 0 || i > size - 9).toArray();
294295
}
295296

296297
/**
@@ -300,7 +301,9 @@ public int[] getBorders() {
300301
*/
301302
public int[] getCorners() {
302303
int size = this.inventory.getSize();
303-
return IntStream.range(0, size).filter(i -> i < 2 || (i > 6 && i < 10) || i == 17 || i == size - 18 || (i > size - 11 && i < size - 7) || i > size - 3).toArray();
304+
return IntStream.range(0, size).filter(i -> i < 2 || (i > 6 && i < 10)
305+
|| i == 17 || i == size - 18
306+
|| (i > size - 11 && i < size - 7) || i > size - 3).toArray();
304307
}
305308

306309
/**

0 commit comments

Comments
 (0)