Skip to content
This repository was archived by the owner on Jul 24, 2021. It is now read-only.

Commit 38fbb37

Browse files
authored
🔖 Version 1.2.0
2 parents 13fb8c3 + 502ef1a commit 38fbb37

File tree

5 files changed

+89
-2
lines changed

5 files changed

+89
-2
lines changed

‎build.gradle‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group 'fr.bakaaless'
7-
version '1.1.0'
7+
version '1.2.0'
88

99
def spigotVersion = '1.16'
1010
def subVersion = '.5'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

‎src/main/java/fr/bakaaless/api/inventory/InventoryAPI.java‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,17 @@ public InventoryAPI setBorder(final Function<Object, ItemStack> function, final
451451
return this;
452452
}
453453

454+
public InventoryAPI applyTemplate(final Template template) {
455+
template.getItems().forEach(item ->
456+
this.addItem(item.clone())
457+
);
458+
return this;
459+
}
460+
461+
public Template generateTemplate() {
462+
return new Template(this.getItems());
463+
}
464+
454465
/**
455466
* Build and open the inventory to a player
456467
* @param player The player to open the inventory
@@ -562,4 +573,22 @@ public void onDrag(final InventoryDragEvent e) {
562573
this.items.stream().filter(item -> e.getInventorySlots().contains(item.getSlot()) || e.getRawSlots().contains(item.getSlot()))
563574
.forEach(item -> e.setCancelled(e.isCancelled() || item.isCancelled()));
564575
}
576+
577+
@Override
578+
public String toString() {
579+
return "InventoryAPI{" +
580+
"inventory=" + this.inventory +
581+
", size=" + this.size +
582+
", title='" + this.title + '\'' +
583+
", type=" + this.type +
584+
", items=" + this.items +
585+
", function=" + this.function +
586+
", closeEvent=" + this.closeEvent +
587+
", clickEvent=" + this.clickEvent +
588+
", interactionCancel=" + this.interactionCancel +
589+
", refreshed=" + this.refreshed +
590+
", build=" + this.build +
591+
", plugin=" + this.plugin +
592+
'}';
593+
}
565594
}

‎src/main/java/fr/bakaaless/api/inventory/ItemAPI.java‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ public ItemAPI(final int slot, final Function<Object, ItemStack> function, final
4747
this.consumer = consumer;
4848
}
4949

50+
/**
51+
* @param slot The slot where will be located the item.
52+
* @param item The wished ItemStack
53+
* @param function A function that return an ItemStack, for the refresh task
54+
* @param cancelled The boolean to enable/disable the interaction protection for this slot
55+
* @param consumer A lambda expression that correspond to the executed code when item is clicked
56+
*/
57+
private ItemAPI(final int slot, final ItemStack item, final Function<Object, ItemStack> function, final boolean cancelled, final Consumer<InventoryClickEvent> consumer) {
58+
this.slot = slot;
59+
this.item = item;
60+
this.function = function;
61+
this.item = new ItemStack(Material.AIR);
62+
this.refresh(this);
63+
this.cancelled = cancelled;
64+
this.consumer = consumer;
65+
}
66+
5067
/**
5168
* Refresh this item at its slot.
5269
* @param o An {@link InventoryAPI} instance.
@@ -124,4 +141,19 @@ public void setCancelled(final boolean cancelled) {
124141
public void setConsumer(final Consumer<InventoryClickEvent> consumer) {
125142
this.consumer = consumer;
126143
}
144+
145+
public ItemAPI clone() {
146+
return new ItemAPI(this.slot, this.item, this.function, this.cancelled, this.consumer);
147+
}
148+
149+
@Override
150+
public String toString() {
151+
return "ItemAPI{" +
152+
"slot=" + this.slot +
153+
", function=" + this.function +
154+
", item=" + this.item +
155+
", cancelled=" + this.cancelled +
156+
", consumer=" + this.consumer +
157+
'}';
158+
}
127159
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package fr.bakaaless.api.inventory;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class Template {
7+
8+
private final List<ItemAPI> items;
9+
10+
public Template(final List<ItemAPI> items) {
11+
this.items = new ArrayList<>();
12+
for (final ItemAPI item : items)
13+
this.items.add(item.clone());
14+
}
15+
16+
public List<ItemAPI> getItems() {
17+
return this.items;
18+
}
19+
20+
@Override
21+
public String toString() {
22+
return "Template{" +
23+
"items=" + this.items +
24+
'}';
25+
}
26+
}

0 commit comments

Comments
 (0)