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

Commit a557147

Browse files
AlessevanSkylyxx
andauthored
📝Add JavaDoc (#7)
Co-authored-by: Skylyxx <57291985+Skylyxx@users.noreply.github.com>
1 parent 9bfdc0a commit a557147

File tree

3 files changed

+201
-1
lines changed

3 files changed

+201
-1
lines changed

‎README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ inventory.addItem(S, o -> {
4848
inventory.build(player);
4949
```
5050

51+
## Documentation
52+
53+
âž  La documentation Java est disponible [ici](https://javadoc.jitpack.io/com/github/BakaAless/InventoryAPI/latest/javadoc/).
54+
5155
## Intégration
5256

5357
[![Release](https://jitpack.io/v/BakaAless/InventoryAPI.svg)](https://jitpack.io/#BakaAless/InventoryAPI)

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

Lines changed: 162 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
import java.util.logging.Level;
2323
import java.util.stream.IntStream;
2424

25+
/**
26+
* The main object of <b>InventoryAPI</b>, used to build inventories.
27+
*/
2528
public class InventoryAPI implements Listener {
2629

2730
private Inventory inventory;
@@ -47,14 +50,29 @@ private InventoryAPI(final JavaPlugin plugin) {
4750
private InventoryAPI() {
4851
}
4952

53+
/**
54+
* Create an <b>InventoryAPI</b> instance.
55+
* @param plugin An instance of the main class of your plugin.
56+
* @return New InventoryAPI object
57+
*/
5058
public static InventoryAPI create(final JavaPlugin plugin) {
5159
return new InventoryAPI(plugin);
5260
}
5361

62+
/**
63+
* Same as {@link #create(JavaPlugin)} but you can give directly the class.
64+
* @param plugin The class object of your main class. (Like MyPlugin.class)
65+
* @return New InventoryAPI object
66+
*/
5467
public static InventoryAPI create(final Class<? extends JavaPlugin> plugin) {
5568
return new InventoryAPI(JavaPlugin.getProvidingPlugin(plugin));
5669
}
5770

71+
/**
72+
* Set the size of your inventory
73+
* @param size The size of the inventory (Multiple of 9, 54 at the maximum)
74+
* @return Your InventoryAPI object
75+
*/
5876
public InventoryAPI setSize(final int size) {
5977
if (build) {
6078
this.plugin.getLogger().log(Level.WARNING, "Can't edit \"size\" option in InventoryAPI 'cause the inventory is already built");
@@ -72,6 +90,11 @@ public InventoryAPI setSize(final int size) {
7290
return this;
7391
}
7492

93+
/**
94+
* Set the title of your inventory
95+
* @param title The title of your inventory
96+
* @return Your InventoryAPI object
97+
*/
7598
public InventoryAPI setTitle(final String title) {
7699
if (build) {
77100
this.plugin.getLogger().log(Level.WARNING, "Can't edit \"title\" option in InventoryAPI 'cause the inventory is already built");
@@ -85,6 +108,11 @@ public InventoryAPI setTitle(final String title) {
85108
return this;
86109
}
87110

111+
/**
112+
* Enable the refresh status (Every 2 ticks).
113+
* @param refreshed A boolean to enable/disable the refresh status
114+
* @return Your InventoryAPI object
115+
*/
88116
public InventoryAPI setRefresh(final boolean refreshed) {
89117
if (build) {
90118
this.plugin.getLogger().log(Level.WARNING, "Can't edit \"refresh\" option in InventoryAPI 'cause the inventory is already built");
@@ -94,7 +122,12 @@ public InventoryAPI setRefresh(final boolean refreshed) {
94122
return this;
95123
}
96124

97-
public InventoryAPI setFunction(Consumer<InventoryAPI> function) {
125+
/**
126+
* Define all of the content of the refresh function.
127+
* @param function A consumer, that will contains all of your modifications.
128+
* @return Your InventoryAPI object
129+
*/
130+
public InventoryAPI setFunction(final Consumer<InventoryAPI> function) {
98131
if (build) {
99132
this.plugin.getLogger().log(Level.WARNING, "Can't edit \"function\" option in InventoryAPI 'cause the inventory is already built");
100133
return this;
@@ -103,23 +136,44 @@ public InventoryAPI setFunction(Consumer<InventoryAPI> function) {
103136
return this;
104137
}
105138

139+
/**
140+
* Enable interaction protection for your Inventory
141+
* @param interactionCancelled A boolean, to enable/disable
142+
* @return Your InventoryAPI object
143+
*/
106144
public InventoryAPI setInteractionCancelled(final boolean interactionCancelled) {
107145
this.interactionCancel = interactionCancelled;
108146
return this;
109147
}
110148

149+
/**
150+
* Get the size of your inventory.
151+
* @return The size of your Inventory, an integer.
152+
*/
111153
public int getSize() {
112154
return this.size;
113155
}
114156

157+
/**
158+
* Get the title of your inventory
159+
* @return The title of your Inventory, a string.
160+
*/
115161
public String getTitle() {
116162
return this.title;
117163
}
118164

165+
/**
166+
* Get the list of your inventory's items
167+
* @return The items in your inventory, a list of {@link ItemAPI}
168+
*/
119169
public List<ItemAPI> getItems() {
120170
return this.items;
121171
}
122172

173+
/**
174+
* Get the boolean of the refresh task.
175+
* @return A boolean, true if enabled, else false.
176+
*/
123177
public boolean isRefreshed() {
124178
return this.refreshed;
125179
}
@@ -132,14 +186,27 @@ Inventory getInventory() {
132186
return this.inventory;
133187
}
134188

189+
/**
190+
* Get the consumer of the refresh task of your Inventory.
191+
* @return A consumer, that correspond to the refresh task.
192+
*/
135193
public Consumer<InventoryAPI> getFunction() {
136194
return function;
137195
}
138196

197+
/**
198+
* Get the interactionCancelled boolean.
199+
* @return A boolean, true if interaction protection is enabled, else false.
200+
*/
139201
public boolean isInteractionCancelled() {
140202
return this.interactionCancel;
141203
}
142204

205+
/**
206+
* Clear a slot of your inventory
207+
* @param slot The id of the slot, an integer
208+
* @return Your InventoryAPI object
209+
*/
143210
public InventoryAPI clearSlot(final int slot) {
144211
Optional<ItemAPI> itemAPI = Optional.empty();
145212
for (final Iterator<ItemAPI> it = this.items.iterator(); it.hasNext(); itemAPI = Optional.ofNullable(it.next())) {
@@ -151,78 +218,169 @@ public InventoryAPI clearSlot(final int slot) {
151218
return this;
152219
}
153220

221+
/**
222+
* Get the item that correspond to the given slot.
223+
* @param slot The id of the slot, an integer
224+
* @return An {@link ItemAPI} object if slot is set, else null.
225+
*/
154226
public Optional<ItemAPI> getItem(final int slot) {
155227
return this.items.stream().filter(item -> item.getSlot() == slot).findFirst();
156228
}
157229

230+
/**
231+
* Set an item in a slot of your inventory.
232+
* @param slot The id of the slot, an integer
233+
* @param itemStack The ItemStack to set
234+
* @return Your InventoryAPI object
235+
*/
158236
public InventoryAPI addItem(final int slot, final ItemStack itemStack) {
159237
return this.addItem(slot, itemStack, true, inventoryClickEvent -> {
160238
});
161239
}
162240

241+
/**
242+
* Set an item in a slot of your inventory.
243+
* @param slot The id of the slot, an integer
244+
* @param function A function that return an ItemStack, for the refresh task.
245+
* @return Your InventoryAPI object
246+
*/
163247
public InventoryAPI addItem(final int slot, final Function<Object, ItemStack> function) {
164248
return this.addItem(slot, function, true, inventoryClickEvent -> {
165249
});
166250
}
167251

252+
/**
253+
* Same as {@link #addItem(int, ItemStack)}, except you can change the interaction protection for this slot.
254+
* @param slot The id of the slot, an integer
255+
* @param itemStack The ItemStack to set
256+
* @param cancelled The boolean to enable/disable the interaction protection for this slot
257+
* @return Your InventoryAPI object
258+
*/
168259
public InventoryAPI addItem(final int slot, final ItemStack itemStack, final boolean cancelled) {
169260
return this.addItem(slot, itemStack, cancelled, inventoryClickEvent -> {
170261
});
171262
}
172263

264+
/**
265+
* Same as {@link #addItem(int, Function, boolean)}, except you can change the interaction protection for this slot.
266+
* @param slot The id of the slot, an integer
267+
* @param function A function that return an ItemStack, for the refresh task.
268+
* @param cancelled The boolean to enable/disable the interaction protection for this slot
269+
* @return Your InventoryAPI object
270+
*/
173271
public InventoryAPI addItem(final int slot, final Function<Object, ItemStack> function, final boolean cancelled) {
174272
return this.addItem(slot, function, cancelled, inventoryClickEvent -> {
175273
});
176274
}
177275

276+
/**
277+
* Same as {@link #addItem(int, ItemStack, boolean, Consumer)}, except you can add custom actions to the InventoryClickEvent.
278+
* @param slot The id of the slot, an integer
279+
* @param itemStack The ItemStack to set
280+
* @param cancelled The boolean to enable/disable the interaction protection for this slot
281+
* @param consumer A lambda expression that correspond to the executed code when item is clicked
282+
* @return Your InventoryAPI object
283+
*/
178284
public InventoryAPI addItem(final int slot, final ItemStack itemStack, final boolean cancelled, final Consumer<InventoryClickEvent> consumer) {
179285
return this.addItem(new ItemAPI(slot, itemStack, cancelled, consumer));
180286
}
181287

288+
/**
289+
* Same as {@link #addItem(int, Function, boolean, Consumer)}, except you can add custom actions to the InventoryClickEvent.
290+
* @param slot The id of the slot, an integer
291+
* @param function A function that return an ItemStack, for the refresh task
292+
* @param cancelled The boolean to enable/disable the interaction protection for this slot
293+
* @param consumer A lambda expression that correspond to the executed code when item is clicked
294+
* @return Your InventoryAPI object
295+
*/
182296
public InventoryAPI addItem(final int slot, final Function<Object, ItemStack> function, final boolean cancelled, final Consumer<InventoryClickEvent> consumer) {
183297
return this.addItem(new ItemAPI(slot, function, cancelled, consumer));
184298
}
185299

300+
/**
301+
* Set an item in your inventory, using {@link ItemAPI}
302+
* @param itemAPI An {@link ItemAPI}
303+
* @return Your InventoryAPI object
304+
*/
186305
public InventoryAPI addItem(final ItemAPI itemAPI) {
187306
this.clearSlot(itemAPI.getSlot());
188307
this.items.add(itemAPI);
189308
return this;
190309
}
191310

311+
/**
312+
* Get the borders of your inventory, depends of the size of the inventory
313+
* @return An integer array, that contains all the slots of the border
314+
*/
192315
public int[] getBorders() {
193316
return IntStream.range(0, this.size).filter(i -> this.size < 27 || i < 9 || i % 9 == 0 || (i - 8) % 9 == 0 || i > this.size - 9).toArray();
194317
}
195318

319+
/**
320+
* Set the item in the border of your inventory.
321+
* @param itemStack The item to set, an ItemStack
322+
* @return Your InventoryAPI object
323+
*/
196324
public InventoryAPI setBorder(final ItemStack itemStack) {
197325
for (int index : this.getBorders())
198326
this.addItem(index, itemStack, true, inventoryClickEvent -> {});
199327
return this;
200328
}
201329

330+
/**
331+
* Same as {@link #setBorder(ItemStack)}
332+
* @param itemStack The item to set, an ItemStack
333+
* @param cancelled The boolean to enable/disable the interaction protection for this slot
334+
* @return Your InventoryAPI object
335+
*/
202336
public InventoryAPI setBorder(final ItemStack itemStack, final boolean cancelled) {
203337
for (int index : this.getBorders())
204338
this.addItem(index, itemStack, cancelled, inventoryClickEvent -> {});
205339
return this;
206340
}
207341

342+
/**
343+
* Same as {@link #setBorder(ItemStack, boolean, Consumer)}, except you give a Function instead of an ItemStack
344+
* @param function A function that return an ItemStack, for the refresh task
345+
* @param cancelled The boolean to enable/disable the interaction protection for this slot
346+
* @return Your InventoryAPI object
347+
*/
208348
public InventoryAPI setBorder(final Function<Object, ItemStack> function, final boolean cancelled) {
209349
for (int index : this.getBorders())
210350
this.addItem(index, function, cancelled, inventoryClickEvent -> {});
211351
return this;
212352
}
213353

354+
/**
355+
* Same as {@link #setBorder(ItemStack, boolean)}, except you
356+
* @param itemStack The item to set, an ItemStack
357+
* @param cancelled The boolean to enable/disable the interaction protection for this slot
358+
* @param consumer A lambda expression that correspond to the executed code when item is clicked
359+
* @return Your InventoryAPI object
360+
*/
214361
public InventoryAPI setBorder(final ItemStack itemStack, final boolean cancelled, final Consumer<InventoryClickEvent> consumer) {
215362
for (int index : this.getBorders())
216363
this.addItem(index, itemStack, cancelled, consumer);
217364
return this;
218365
}
219366

367+
/**
368+
* Same as {@link #setBorder(ItemStack, boolean, Consumer)}, except you give a Function instead of an ItemStack
369+
* @param function A function that return an ItemStack, for the refresh task
370+
* @param cancelled The boolean to enable/disable the interaction protection for this slot
371+
* @param consumer A lambda expression that correspond to the executed code when item is clicked
372+
* @return Your InventoryAPI object
373+
*/
220374
public InventoryAPI setBorder(final Function<Object, ItemStack> function, final boolean cancelled, final Consumer<InventoryClickEvent> consumer) {
221375
for (int index : this.getBorders())
222376
this.addItem(index, function, cancelled, consumer);
223377
return this;
224378
}
225379

380+
/**
381+
* Build and open the inventory to a player
382+
* @param player The player to open the inventory
383+
*/
226384
public void build(final Player player) {
227385
this.build = true;
228386
if (this.inventory == null) {
@@ -252,6 +410,9 @@ public void build(final Player player) {
252410
}
253411
}
254412

413+
/**
414+
* Stop the refresh method for this inventory
415+
*/
255416
public void stop() {
256417
HandlerList.unregisterAll(this);
257418
if (this.refreshed)

0 commit comments

Comments
 (0)