Skip to content

Commit 3c1c247

Browse files
committed
Merge branch 'release/1.0.2.5'
2 parents d4b116b + a8aab47 commit 3c1c247

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+462
-72
lines changed

changelog.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,27 @@
2424
- [ ] Add the Pagination button, it will allow to take an input number, an output number and browse the value number
2525
- [ ] Add a way to display the list of online players in a button list
2626
- [ ] Add Citizen and [ZNPCsPlus](https://www.spigotmc.org/resources/znpcsplus.109380/) support to open an inventory by clicking on an NPC
27-
- [ ] Add a tool to transform ItemStack to base64 and vice versa. This tool can be used to all my plugins.
27+
- [x] Add a tool to transform ItemStack to base64 and vice versa. This tool can be used to all my plugins.
2828
- [ ] Fix the bug about the `clearInventory: true`. It does not restore inventory when the menu is closed.
2929
- [ ] Add the support for the `http://textures.minecraft.net/texture/e34969c2684e4f62d5f87875460441a9f849d296c01e4c621636bb6acda696f7` in the URL of a custom head.
3030
- [ ] Update pom.xml for add {projet.version} in plugin.yml
3131
- [ ] Add matrix support for slot (like this: https://abstractmenus.github.io/docs/general/item_format.html#way-4-matrix)
3232
- [ ] Adding more logs on the errors that can occur with custom items like ItemAdder, this will cause an error but the user will not have the information of why, for example when the item does not exist.
33+
- [ ] Create a new class for loading buttons to add more elements, like a boolean to check if the button needs an itemstack
3334

3435
# Unreleased
3536

37+
# 1.0.2.5
38+
39+
- Add new lore as string support
40+
- Fix itemstack amount of 0
41+
- Support file with space
42+
- Improved API, added many new methods to make API more permissive.
43+
- Patterns can now be on multiple pages
44+
- Add custom sound to SoundOption
45+
- Added ability to add arguments and select page for INVENTORY button [#45](https://github.com/Maxlego08/zMenu/issues/45)
46+
- Change update interval to milliseconds [#37](https://github.com/Maxlego08/zMenu/issues/37)
47+
3648
# 1.0.2.4
3749

3850
- Added replacement of , by . for placeholders requirements. If your placeholder returns a number with a comma instead of a period, the plugin can handle that.

dependency-reduced-pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>fr.maxlego08</groupId>
55
<artifactId>zmenu</artifactId>
6-
<version>1.0.2.3</version>
6+
<version>1.0.2.5</version>
77
<build>
88
<sourceDirectory>src</sourceDirectory>
99
<plugins>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>fr.maxlego08</groupId>
55
<artifactId>zmenu</artifactId>
6-
<version>1.0.2.4</version>
6+
<version>1.0.2.5</version>
77
<properties>
88
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
99
<maven.compiler.source>8</maven.compiler.source>

src/fr/maxlego08/menu/MenuItemStack.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public ItemStack build(Player player, boolean useCache) {
200200
return null;
201201
}
202202

203-
itemStack.setAmount(amount);
203+
itemStack.setAmount(amount <= 0 ? 1 : amount);
204204

205205
if (this.durability != 0) {
206206
itemStack.setDurability((short) this.durability);

src/fr/maxlego08/menu/MenuPlugin.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ public void onEnable() {
216216
Logger.info("DupeManager: " + this.dupeManager);
217217
}
218218

219+
Logger.info("");
220+
Logger.info("You can support zMenu by upgrading your account here: https://minecraft-inventory-builder.com/account-upgrade");
221+
Logger.info("zMenu’s site includes an inventory editor (under development), a marketplace (already available) is a forum (under development)");
222+
Logger.info("");
223+
219224
this.postEnable();
220225
}
221226

src/fr/maxlego08/menu/ZInventory.java

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22

33
import fr.maxlego08.menu.api.Inventory;
44
import fr.maxlego08.menu.api.button.Button;
5-
import fr.maxlego08.menu.api.utils.OpenWithItem;
65
import fr.maxlego08.menu.api.pattern.Pattern;
76
import fr.maxlego08.menu.api.players.inventory.InventoriesPlayer;
87
import fr.maxlego08.menu.api.requirement.Requirement;
8+
import fr.maxlego08.menu.api.utils.OpenWithItem;
99
import fr.maxlego08.menu.inventory.inventories.InventoryDefault;
1010
import fr.maxlego08.menu.zcore.utils.inventory.InventoryResult;
1111
import org.bukkit.entity.Player;
1212
import org.bukkit.inventory.InventoryHolder;
1313
import org.bukkit.plugin.Plugin;
1414

1515
import java.io.File;
16+
import java.util.ArrayList;
1617
import java.util.Collection;
1718
import java.util.Collections;
1819
import java.util.List;
@@ -82,6 +83,7 @@ public Plugin getPlugin() {
8283
}
8384

8485
@Override
86+
@Deprecated
8587
public int getMaxPage(Player player, Object... objects) {
8688
Optional<Integer> optional = this.buttons.stream().map(Button::getSlot).max(Integer::compare);
8789
if (optional.isPresent()) {
@@ -91,6 +93,20 @@ public int getMaxPage(Player player, Object... objects) {
9193
return 1;
9294
}
9395

96+
@Override
97+
public int getMaxPage(Collection<Pattern> patterns, Player player, Object... objects) {
98+
List<Button> buttons = new ArrayList<>();
99+
buttons.addAll(this.buttons);
100+
buttons.addAll(patterns.stream().flatMap(pattern -> pattern.getButtons().stream()).collect(Collectors.toList()));
101+
102+
Optional<Integer> optional = buttons.stream().map(Button::getSlot).max(Integer::compare);
103+
if (optional.isPresent()) {
104+
int maxSlot = optional.get();
105+
return (maxSlot / this.size) + 1;
106+
}
107+
return 1;
108+
}
109+
94110
@Override
95111
public List<Button> sortButtons(int page, Object... objects) {
96112
return this.buttons.stream().filter(button -> {
@@ -99,6 +115,15 @@ public List<Button> sortButtons(int page, Object... objects) {
99115
}).collect(Collectors.toList());
100116
}
101117

118+
@Override
119+
public List<Button> sortPatterns(Pattern pattern, int page, Object... objects) {
120+
if (!pattern.enableMultiPage()) return new ArrayList<>(pattern.getButtons());
121+
return pattern.getButtons().stream().filter(button -> {
122+
int slot = button.getRealSlot(this.size, page);
123+
return slot >= 0 && slot < this.size;
124+
}).collect(Collectors.toList());
125+
}
126+
102127
@Override
103128
public InventoryResult openInventory(Player player, InventoryDefault inventoryDefault) {
104129

@@ -187,6 +212,10 @@ public Requirement getOpenRequirement() {
187212
return this.openRequirement;
188213
}
189214

215+
public void setOpenRequirement(Requirement openRequirement) {
216+
this.openRequirement = openRequirement;
217+
}
218+
190219
@Override
191220
public OpenWithItem getOpenWithItem() {
192221
return this.openWithItem;
@@ -196,10 +225,6 @@ public void setOpenWithItem(OpenWithItem openWithItem) {
196225
this.openWithItem = openWithItem;
197226
}
198227

199-
public void setOpenRequirement(Requirement openRequirement) {
200-
this.openRequirement = openRequirement;
201-
}
202-
203228
public void setClearInventory(boolean clearInventory) {
204229
this.clearInventory = clearInventory;
205230
}

src/fr/maxlego08/menu/ZInventoryManager.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import fr.maxlego08.menu.loader.actions.PlayerCommandLoader;
4141
import fr.maxlego08.menu.loader.actions.ShopkeeperLoader;
4242
import fr.maxlego08.menu.loader.actions.SoundLoader;
43+
import fr.maxlego08.menu.loader.actions.TitleLoader;
4344
import fr.maxlego08.menu.loader.permissible.ItemPermissibleLoader;
4445
import fr.maxlego08.menu.loader.permissible.PermissionPermissibleLoader;
4546
import fr.maxlego08.menu.loader.permissible.PlaceholderPermissibleLoader;
@@ -269,6 +270,7 @@ public void loadButtons() {
269270
buttonManager.registerAction(new ConsoleCommandLoader());
270271
buttonManager.registerAction(new fr.maxlego08.menu.loader.actions.BackLoader(this.plugin));
271272
buttonManager.registerAction(new ShopkeeperLoader());
273+
buttonManager.registerAction(new TitleLoader());
272274

273275
// Loading ButtonLoader
274276
// The first step will be to load the buttons in the plugin, so each
@@ -277,7 +279,7 @@ public void loadButtons() {
277279
buttonManager.register(new NoneLoader(this.plugin, ZNoneButton.class, "none"));
278280
buttonManager.register(new NoneLoader(this.plugin, ZNoneButton.class, "none_slot"));
279281
buttonManager.register(new NoneLoader(this.plugin, ZNoneButton.class, "perform_command"));
280-
buttonManager.register(new fr.maxlego08.menu.button.loader.InventoryLoader(this.plugin, this));
282+
buttonManager.register(new fr.maxlego08.menu.button.loader.InventoryLoader(this.plugin, this, this.plugin.getCommandManager()));
281283
buttonManager.register(new BackLoader(this.plugin, this));
282284
buttonManager.register(new HomeLoader(this.plugin, this));
283285
buttonManager.register(new NextLoader(this.plugin, this));

src/fr/maxlego08/menu/api/Inventory.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,19 @@ public interface Inventory {
8181
* @param objects Additional elements.
8282
* @return The maximum number of pages.
8383
*/
84+
@Deprecated
8485
int getMaxPage(Player player, Object... objects);
8586

87+
/**
88+
* Returns the maximum number of pages for the inventory.
89+
*
90+
* @param patterns Pattern list
91+
* @param player The player for whom the page count is determined.
92+
* @param objects Additional elements.
93+
* @return The maximum number of pages.
94+
*/
95+
int getMaxPage(Collection<Pattern> patterns, Player player, Object... objects);
96+
8697
/**
8798
* Sorts the buttons based on the current page and additional elements.
8899
*
@@ -92,6 +103,16 @@ public interface Inventory {
92103
*/
93104
List<Button> sortButtons(int page, Object... objects);
94105

106+
/**
107+
* Sorts the pattern buttons based on the current page and additional elements.
108+
*
109+
* @param pattern The pattern
110+
* @param page The current page.
111+
* @param objects Additional elements.
112+
* @return A list of sorted buttons.
113+
*/
114+
List<Button> sortPatterns(Pattern pattern, int page, Object... objects);
115+
95116
/**
96117
* Opens the inventory for a player and returns the result of the operation.
97118
*

src/fr/maxlego08/menu/api/button/Button.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import fr.maxlego08.menu.inventory.inventories.InventoryDefault;
1111
import org.bukkit.entity.Player;
1212
import org.bukkit.event.inventory.InventoryClickEvent;
13+
import org.bukkit.event.inventory.InventoryDragEvent;
1314
import org.bukkit.inventory.ItemStack;
1415

1516
import java.util.List;
@@ -251,4 +252,34 @@ public interface Button extends PermissibleButton, PlaceholderButton, SlotButton
251252
* @return actions
252253
*/
253254
List<Action> getActions();
255+
256+
/**
257+
* Called when the player drags items within the inventory or from their player inventory into the zMenu inventory.
258+
* This method allows for custom drag behavior to be implemented, providing flexibility in how items can be moved
259+
* around within an inventory and how these actions interact with the overall functionality of the menu.
260+
*
261+
* Implementations can use this method to prevent unwanted item movements, to trigger specific actions when
262+
* certain items are dragged to specific slots, or to manage the addition or removal of items in custom ways
263+
* that align with the menu's logic and requirements.
264+
*
265+
* @param event The inventory drag event that occurred, containing details about the drag action.
266+
* @param player The player who performed the drag action.
267+
* @param inventoryDefault The zMenu inventory where the drag action occurred, providing context for the action
268+
* and allowing for inventory-specific handling.
269+
*/
270+
void onDrag(InventoryDragEvent event, Player player, InventoryDefault inventoryDefault);
271+
272+
/**
273+
* Called when the player clicks an item within the zMenu inventory. This method is a general handler for all
274+
* inventory click events, offering a centralized way to manage interactions within the inventory. It can be used
275+
* to implement custom click behavior on a global scale, regardless of the specific button or slot clicked.
276+
*
277+
* @param event The inventory click event that occurred, including details such as the click type
278+
* and the slot that was clicked.
279+
* @param player The player who performed the click action.
280+
* @param inventoryDefault The zMenu inventory where the click action occurred, providing the context needed
281+
* to appropriately respond to the interaction.
282+
*/
283+
void onInventoryClick(InventoryClickEvent event, Player player, InventoryDefault inventoryDefault);
284+
254285
}

src/fr/maxlego08/menu/api/button/buttons/InventoryButton.java

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,49 @@
22

33
import fr.maxlego08.menu.api.button.Button;
44

5+
import java.util.List;
6+
57
/**
6-
* Represents a button that allows the player to open a new inventory.
7-
* The inventory to be opened is specified by its unique identifier.
8+
* Represents a button within a user interface in a Minecraft plugin that allows the player
9+
* to open a new inventory. This interface extends the basic functionality of a Button
10+
* to specifically handle inventory interactions, enabling the creation of complex GUIs
11+
* where actions can lead to different inventory screens.
12+
* <p>
13+
* The inventory to be opened by this button is identified by a unique identifier, allowing
14+
* for dynamic and flexible GUI navigation based on the game's logic or player's actions.
15+
* Additional parameters such as arguments and page numbers can be used to further customize
16+
* the behavior or content of the inventory to be opened.
17+
* </p>
818
*/
919
public interface InventoryButton extends Button {
1020

1121
/**
12-
* Returns the unique identifier of the inventory to be opened.
22+
* Returns the unique identifier of the inventory to be opened when this button is interacted with.
23+
* This identifier is used to determine which inventory screen is to be displayed to the player,
24+
* facilitating the linking of multiple GUI screens within the plugin.
1325
*
14-
* @return The identifier of the target inventory.
26+
* @return The unique identifier of the target inventory as a {@code String}.
1527
*/
1628
String getInventory();
1729

18-
// Additional documentation or context can be added here if needed
30+
/**
31+
* Provides a list of arguments that may be required for opening the inventory.
32+
* These arguments can include specific details or parameters that modify the
33+
* inventory's appearance or functionality, allowing for a dynamic and contextual
34+
* user experience based on the game's state or player's input.
35+
*
36+
* @return A list of {@code String} arguments that are associated with the inventory to be opened.
37+
*/
38+
List<String> getArguments();
39+
40+
/**
41+
* Retrieves the page number of the inventory to be opened if the inventory supports pagination.
42+
* This is useful for inventories that display a large amount of content that is divided across
43+
* multiple pages, allowing users to navigate through pages of items or options.
44+
*
45+
* @return The page number as an {@code int} indicating which page of the inventory should be shown.
46+
*/
47+
int getToPage();
1948

2049
}
50+

0 commit comments

Comments
 (0)