Skip to content

Commit f26804b

Browse files
committed
feat(README): Updated READMEs.
1 parent 3186a02 commit f26804b

File tree

2 files changed

+182
-29
lines changed

2 files changed

+182
-29
lines changed

README-en.md

Lines changed: 165 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ This library has two main classes:
88

99
[🇫🇷 Egalement disponible en Français !](https://github.com/hashtek-mc/hashgui/blob/main/README.md)
1010

11+
## Installation
12+
13+
After installation, the .jar file is located in the `builds/libs/` folder.
14+
15+
### Linux / MacOS :
16+
17+
```shell
18+
./gradlew make
19+
```
20+
21+
### Windows
22+
23+
```shell
24+
.\gradlew.bat make
25+
```
26+
1127
## HashItem
1228

1329
### Usage
@@ -58,16 +74,18 @@ Inventory#addItem(item.getItemStack());
5874
* `removeEnchant()`: Removes an enchantment from the item
5975
* `build()`: Builds the item so it can be used
6076

61-
### 🖱️ Click handler
77+
### Handlers
6278

63-
It is possible to define the action executed when an item is clicked in an inventory.
79+
An Handler is a code snippet which will be executed when a player will perform a certain action\
80+
with an item.
81+
82+
### Usage (example : Click handler)
6483

65-
**Example:**
6684
```java
6785
ClickHandler clickHandler = new ClickHandler()
6886
.addClickType(ClickType.LEFT)
6987
.setClickAction((Player player, HashGui gui, ItemStack clickedItem, int clickedSlot) -> {
70-
// Actions to do when item is clicked.
88+
// Actions to perform on click.
7189
});
7290

7391
HashItem item = new HashItem(Material.COMPASS)
@@ -86,43 +104,87 @@ if you don't want them to execute the same thing.
86104
If two items must have the same name but a different click handler, then mess with the color codes so that it's not
87105
visible from the player's point of view 😉 (`"§cHi"` and `"§r§cHi"` are different but look the same on player's POV)
88106

107+
### Click handler
108+
109+
You can define the action executed when a player clicks on an item in a GUI.
110+
111+
#### Features :
112+
113+
- Click type (left click, right click, shift + click...)
114+
```java
115+
ClickHandler#addClickType(ClickType.LEFT);
116+
ClickHandler#addClickTypes(ClickType.SHIFT_LEFT, ClickType.SHIFT_RIGHT); // Adds multiple click types at once.
117+
ClickHandler#addAllClickTypes(); // Adds every click type.
118+
```
119+
89120
> [!TIP]
90121
> See [ClickType](https://helpch.at/docs/1.8/org/bukkit/event/inventory/ClickType.html) enum (from `org.bukkit`).
91122
92123
### 🫱 Interaction handler
93124

94-
It is possible to define the action executed when a player interacts with an item.
125+
You can define the action executed when a player interacts with an item.
95126

96-
**Example:**
127+
#### Features :
128+
129+
- Interaction type (left click, right click, in the air, or not...)
97130
```java
98-
InteractionHandler interactionHandler = new InteractionHandler()
99-
.addInteractionType(Action.RIGHT_CLICK_AIR)
100-
.setClickAction((Player player, ItemStack clickedItem, int clickedSlot) -> {
101-
// Actions to do when item is interacted with.
102-
});
103-
104-
HashItem item = new HashItem(Material.COMPASS)
105-
.addInteractionHandler(interactionHandler)
106-
.build(guiManager);
131+
InteractHandler#addInteractType(Action.LEFT_CLICK_AIR);
132+
InteractHandler#addInteractTypes(Action.RIGHT_CLICK_AIR, Action.RIGHT_CLICK_BLOCK); // Adds multiple interaction types at once.
133+
InteractHandler#addAllInteractTypes(); // Adds every interaction types.
107134
```
108135

109-
> [!WARNING]
110-
> Just like ClickHandler, `guiManager` (in the `build()` function) must be an instance of
111-
[HashGuiManager](#hashguimanager), which must be stored at the root of your plugin.
112-
This instance takes care of detecting clicks and executing the appropriate action depending on the item.
113-
114-
> [!WARNING]
115-
> Item targeting is based on its `displayName`, so be careful not to give the same name to two items
116-
if you don't want them to execute the same thing.
117-
If two items must have the same name but a different click handler, then mess with the color codes so that it's not
118-
visible from the player's point of view 😉 (`"§cHi"` and `"§r§cHi"` are different but look the same on player's POV)
119-
120136
> [!TIP]
121137
> See [Action](https://helpch.at/docs/1.8/index.html?org/bukkit/event/block/Action.html) enum (from `org.bukkit`).
122138
139+
### 🫱 Hold handler
140+
141+
You can define the action executed when a player holds (or takes off) an item in his hand.
142+
143+
#### Features :
144+
145+
- Hold action (action executed when the player takes the item in his hand)
146+
```java
147+
HoldAction action = (Player player, ItemStack item, int slot) -> {
148+
// ...
149+
};
150+
151+
HoldHandler#setHoldAction(action);
152+
```
153+
154+
- Not hold action (action executed when the player takes the item off his hand)
155+
```java
156+
HoldAction action = (Player player, ItemStack item, int slot) -> {
157+
// ...
158+
};
159+
160+
HoldHandler#setNotHoldAction(action);
161+
```
162+
163+
> [!CAUTION]
164+
> Armors are compatible with `HoldHandler`.\
165+
> However, if you use the `PlayerInventory#setHelmet` function (or another method to define an armor piece),
166+
> `HoldHandler` will NOT detect it automatically.\
167+
> You must call the `HashGuiHold#refreshArmorState(Player player)` function to refresh the detection.
168+
169+
### 🫱 Hit handler
170+
171+
You can define the action executed when a player hits another player with an item.
172+
173+
#### Features :
174+
175+
- Death only (executes the action only if the hit results in a death)
176+
```java
177+
HitHandler#setOnlyKill(true);
178+
```
179+
180+
### 🫱 Destroy handler
181+
182+
You can define the action executed when a player breaks a block with an item.
183+
184+
123185
### HashGuiManager
124186

125-
In order to make click & interaction handlers working, you need to create an instance of `HashGuiManager` at the root
187+
In order to make handlers working, you need to create an instance of `HashGuiManager` at the root
126188
of your plugin and give this instance to your custom item build.
127189

128190
**Example:**
@@ -279,4 +341,79 @@ If a letter has no assigned item, this one will be used:
279341
> [!CAUTION]
280342
> Space character (` `) can't be used, as it serves as void.
281343
282-
## Made with 💜 by [Lysandre B.](https://github.com/Shuvlyy)[![wakatime](https://wakatime.com/badge/user/2f50fe6c-0368-4bef-aa01-3a67193b63f8/project/018d7a18-67ef-47e3-a6c4-5c8cc4b45021.svg)](https://wakatime.com/badge/user/2f50fe6c-0368-4bef-aa01-3a67193b63f8/project/018d7a18-67ef-47e3-a6c4-5c8cc4b45021) + [![wakatime](https://wakatime.com/badge/user/2f50fe6c-0368-4bef-aa01-3a67193b63f8/project/018d794b-8bf6-46ef-acb3-549287335474.svg)](https://wakatime.com/badge/user/2f50fe6c-0368-4bef-aa01-3a67193b63f8/project/018d794b-8bf6-46ef-acb3-549287335474)
344+
## PaginatedHashGui
345+
346+
`PaginatedHashGui` is a `HashGui` with a pagination system.
347+
348+
### Usage
349+
350+
```java
351+
String title = "Paginated menu";
352+
int linesAmount = 6;
353+
354+
PaginatedHashGui gui = new PaginatedHashGui(title, linesAmount, guiManager); // guiManager must be an instance of HashGuiManager.
355+
356+
HashItem previousPage = new HashItem(Material.ARROW)
357+
.setName("Previous page");
358+
359+
HashItem nextPage = new HashItem(Material.ARROW)
360+
.setName("Next page");
361+
362+
gui.setPreviousPageItem(previousPage); // When clicking on previousPage, the GUI will refresh to the previous page.
363+
gui.setNextPageItem(nextPage); // When clicking on previousPage, the GUI will refresh to the next page.
364+
```
365+
366+
#### Features
367+
368+
* `setPreviousPageItem(HashItem item)` : Refreshes the GUI to the previous page (if possible)
369+
* `setNextPageItem(HashItem item)` : Refreshes the GUI to the next page (if possible)
370+
* `update(Player player)` : Refreshes the GUI (for the pages)
371+
* `clearPageContent()` : Visually clears current page (used for refreshing)
372+
* `addPage(Page page)` : Adds a new page
373+
* `createNewPage()` : Creates a fresh new page and adds it
374+
* `clearPages()` : Deletes all pages
375+
376+
### Pages
377+
378+
#### Page creation
379+
380+
```java
381+
PaginatedHashGui gui;
382+
383+
Page page = gui.createNewPage(); // Creates a new page and adds it to the GUI
384+
385+
/* OR */
386+
387+
Page page = new Page(gui); // Creates a new page
388+
gui.addPage(page); // Adds it to the GUI
389+
```
390+
391+
#### Features
392+
* `addItem(HashItem item)` : Adds an item in the page at the first free slot
393+
* `setItem(int slot, HashItem item)` : Adds an item in the page at a specific slot
394+
* `removeItem(int slot)` : Removes the item linked to a slot
395+
* `clearItems()` : Clears page's items
396+
397+
> [!TIP]
398+
> By default, at the creation of a `PaginatedHashGui`, a fresh new page will be automatically created and added.
399+
400+
#### Page management
401+
402+
```java
403+
Page page;
404+
405+
HashItem item1 = new HashItem(Material.BED);
406+
HashItem item2 = new HashItem(Material.BEDROCK);
407+
408+
page.addItem(item1);
409+
page.setItem(8, item2);
410+
page.removeItem(8);
411+
```
412+
413+
> [!WARNING]
414+
> * For `Page#addItem()`, if no slots are free, a `IllegalArgumentException` will be thrown.
415+
> * For `Page#setItem()` or `Page#removeItem()`, if the given slot is not free, the same exception will be thrown.
416+
> * **A slot is considered not free if it's not valid (below 0 or greater than the maximum capacity of the GUI)
417+
> or if an item is already present at this slot in the parent GUI.**
418+
419+
## Made with 💜 by [Lysandre B.](https://github.com/Shuvlyy)[![wakatime](https://wakatime.com/badge/user/2f50fe6c-0368-4bef-aa01-3a67193b63f8/project/018d794b-8bf6-46ef-acb3-549287335474.svg)](https://wakatime.com/badge/user/2f50fe6c-0368-4bef-aa01-3a67193b63f8/project/018d794b-8bf6-46ef-acb3-549287335474) + [![wakatime](https://wakatime.com/badge/user/2f50fe6c-0368-4bef-aa01-3a67193b63f8/project/018d7a18-67ef-47e3-a6c4-5c8cc4b45021.svg)](https://wakatime.com/badge/user/2f50fe6c-0368-4bef-aa01-3a67193b63f8/project/018d7a18-67ef-47e3-a6c4-5c8cc4b45021)

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ Cette librairie est constituée de deux classes principales :
99

1010
[🇬🇧 Also available in English!](https://github.com/hashtek-mc/hashgui/blob/main/README-en.md)
1111

12+
## Installation
13+
14+
Après installation, le .jar se trouve dans le dossier `builds/libs/`.
15+
16+
### Linux / MacOS :
17+
18+
```shell
19+
./gradlew make
20+
```
21+
22+
### Windows
23+
24+
```shell
25+
.\gradlew.bat make
26+
```
27+
1228
## HashItem
1329

1430
### Utilisation
@@ -120,7 +136,7 @@ Il est possible de définir l'action exécutée lors d'une interaction avec l'it
120136
```java
121137
InteractHandler#addInteractType(Action.LEFT_CLICK_AIR);
122138
InteractHandler#addInteractTypes(Action.RIGHT_CLICK_AIR, Action.RIGHT_CLICK_BLOCK); // Ajoute plusieurs types d'interactions en une fois.
123-
InteractHandler#addAllInteractTypes(); // Ajoute tous les types de clic possibles.
139+
InteractHandler#addAllInteractTypes(); // Ajoute tous les types d'interaction possibles.
124140
```
125141

126142
> [!TIP]

0 commit comments

Comments
 (0)