Skip to content

Commit d4b116b

Browse files
committed
Merge branch 'release/1.0.2.4'
2 parents 14e20c0 + 0680b4a commit d4b116b

18 files changed

Lines changed: 127 additions & 147 deletions

File tree

changelog.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,22 @@
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
31+
- [ ] Add matrix support for slot (like this: https://abstractmenus.github.io/docs/general/item_format.html#way-4-matrix)
32+
- [ ] 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.
3133

3234
# Unreleased
3335

36+
# 1.0.2.4
37+
38+
- 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.
39+
- Added base64 MaterialLoader. Allows to load ItemStack with all the data it can contain.
40+
- Added cooldown on button click. The default cooldown will be 350ms.
41+
- Fix Folia with VersionChecker [#35](https://github.com/Maxlego08/zMenu/issues/35)
42+
- Fix error with mini message format in 1.16
43+
- Fix JUMP Button
44+
- Change `/zm save <item name> <base64/yml>`, saves an element in YML or base64 format. The base64 format will save the itemStack with all its data.
45+
- Change `page` from JUMP Button to `toPage`
46+
3447
# 1.0.2.3
3548

3649
- Fixed the pattern display, they will now appear first and let the more important buttons pass over

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.4</version>
77
<properties>
88
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
99
<maven.compiler.source>8</maven.compiler.source>

src/fr/maxlego08/menu/MenuPlugin.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ public void onEnable() {
164164
this.addSave(this.commandManager);
165165
this.addSave(this.dataManager);
166166

167+
this.inventoryManager.registerMaterialLoader(new Base64Loader());
167168
if (this.isEnable(Plugins.HEADDATABASE)) {
168169
this.inventoryManager.registerMaterialLoader(new HeadDatabaseLoader());
169170
}

src/fr/maxlego08/menu/ZInventoryManager.java

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@
1010
import fr.maxlego08.menu.api.itemstack.ItemStackSimilar;
1111
import fr.maxlego08.menu.api.loader.MaterialLoader;
1212
import fr.maxlego08.menu.api.utils.MetaUpdater;
13+
import fr.maxlego08.menu.api.utils.OpenWithItem;
1314
import fr.maxlego08.menu.button.buttons.ZNoneButton;
14-
import fr.maxlego08.menu.button.loader.*;
15+
import fr.maxlego08.menu.button.loader.BackLoader;
16+
import fr.maxlego08.menu.button.loader.HomeLoader;
17+
import fr.maxlego08.menu.button.loader.JumpLoader;
18+
import fr.maxlego08.menu.button.loader.MainMenuLoader;
19+
import fr.maxlego08.menu.button.loader.NextLoader;
20+
import fr.maxlego08.menu.button.loader.NoneLoader;
21+
import fr.maxlego08.menu.button.loader.PreviousLoader;
1522
import fr.maxlego08.menu.exceptions.InventoryException;
1623
import fr.maxlego08.menu.exceptions.InventoryFileNotFound;
17-
import fr.maxlego08.menu.api.utils.OpenWithItem;
1824
import fr.maxlego08.menu.inventory.inventories.InventoryDefault;
1925
import fr.maxlego08.menu.itemstack.FullSimilar;
2026
import fr.maxlego08.menu.itemstack.LoreSimilar;
@@ -46,6 +52,7 @@
4652
import fr.maxlego08.menu.zcore.utils.ZUtils;
4753
import fr.maxlego08.menu.zcore.utils.loader.Loader;
4854
import fr.maxlego08.menu.zcore.utils.meta.Meta;
55+
import fr.maxlego08.menu.zcore.utils.nms.ItemStackUtils;
4956
import fr.maxlego08.menu.zcore.utils.storage.Persist;
5057
import org.bukkit.Bukkit;
5158
import org.bukkit.command.CommandSender;
@@ -519,7 +526,7 @@ public void updateInventory(Player player) {
519526
}
520527

521528
@Override
522-
public void saveItem(CommandSender sender, ItemStack itemStack, String name) {
529+
public void saveItem(CommandSender sender, ItemStack itemStack, String name, String type) {
523530

524531
File file = new File(this.plugin.getDataFolder(), "save_items.yml");
525532
if (!file.exists()) {
@@ -530,9 +537,9 @@ public void saveItem(CommandSender sender, ItemStack itemStack, String name) {
530537
}
531538
}
532539

533-
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(file);
540+
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(file);
534541

535-
ConfigurationSection configurationSection = yamlConfiguration.getConfigurationSection("items.");
542+
ConfigurationSection configurationSection = configuration.getConfigurationSection("items.");
536543
if (configurationSection != null) {
537544
Set<String> names = configurationSection.getKeys(false);
538545
if (names.contains(name)) {
@@ -543,9 +550,25 @@ public void saveItem(CommandSender sender, ItemStack itemStack, String name) {
543550

544551
Loader<MenuItemStack> loader = new MenuItemStackLoader(this);
545552
MenuItemStack menuItemStack = MenuItemStack.fromItemStack(this, itemStack);
546-
loader.save(menuItemStack, yamlConfiguration, "items." + name + ".", file);
553+
if (type.equalsIgnoreCase("yml")) {
554+
loader.save(menuItemStack, configuration, "items." + name + ".", file);
555+
} else if (type.equalsIgnoreCase("base64")) {
556+
557+
String base64 = ItemStackUtils.serializeItemStack(itemStack);
558+
configuration.set("items." + name + ".material", "base64:" + base64);
559+
try {
560+
configuration.save(file);
561+
} catch (IOException exception) {
562+
exception.printStackTrace();
563+
}
564+
565+
} else {
566+
message(sender, Message.SAVE_ERROR_TYPE, "%name%", name);
567+
return;
568+
}
547569

548570
message(sender, Message.SAVE_SUCCESS, "%name%", name);
571+
549572
}
550573

551574
@EventHandler

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,9 @@ public interface InventoryManager extends Savable, Listener {
345345
* @param sender Command Sender
346346
* @param itemStack The itemStack
347347
* @param name The item name
348+
* @param type
348349
*/
349-
void saveItem(CommandSender sender, ItemStack itemStack, String name);
350+
void saveItem(CommandSender sender, ItemStack itemStack, String name, String type);
350351

351352
/**
352353
* Transforms a string list into a click list type.

src/fr/maxlego08/menu/button/buttons/ZJumpButton.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class ZJumpButton extends ZNextButton {
1313
private final InventoryManager inventoryManager;
1414

1515
/**
16-
* @param page the real page(start from 0)
16+
* @param page the real page(start from 0)
1717
* @param inventoryManager the inventory manager
1818
*/
1919
public ZJumpButton(InventoryManager inventoryManager, int page) {
@@ -32,6 +32,6 @@ public void onClick(Player player, InventoryClickEvent event, InventoryDefault i
3232

3333
@Override
3434
public boolean checkPermission(Player player, InventoryDefault inventory) {
35-
return page >= 0 && page <= inventory.getMaxPage();
35+
return this.page != inventory.getPage();
3636
}
3737
}

src/fr/maxlego08/menu/button/loader/JumpLoader.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package fr.maxlego08.menu.button.loader;
22

3-
import fr.maxlego08.menu.MenuPlugin;
43
import fr.maxlego08.menu.api.InventoryManager;
54
import fr.maxlego08.menu.api.button.Button;
65
import fr.maxlego08.menu.api.button.DefaultButtonValue;
@@ -35,7 +34,7 @@ public Plugin getPlugin() {
3534

3635
@Override
3736
public Button load(YamlConfiguration configuration, String path, DefaultButtonValue defaultButtonValue) {
38-
int page = configuration.getInt(path + "page");
37+
int page = configuration.getInt(path + "toPage");
3938
return new ZJumpButton(this.inventoryManager, page);
4039
}
4140
}

src/fr/maxlego08/menu/command/commands/CommandMenuSave.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99
import org.bukkit.Material;
1010
import org.bukkit.inventory.ItemStack;
1111

12+
import java.util.Arrays;
13+
1214
public class CommandMenuSave extends VCommand {
1315

1416
public CommandMenuSave(MenuPlugin plugin) {
1517
super(plugin);
1618
this.addSubCommand("save");
1719
this.addRequireArg("item name");
20+
this.addRequireArg("type", (a, b) -> Arrays.asList("yml", "base64"));
1821
this.setDescription(Message.DESCRIPTION_SAVE);
1922
this.setPermission(Permission.ZMENU_SAVE);
2023
this.setConsoleCanUse(false);
@@ -25,13 +28,15 @@ protected CommandType perform(MenuPlugin plugin) {
2528

2629
InventoryManager inventoryManager = plugin.getInventoryManager();
2730
String name = this.argAsString(0);
31+
String type = this.argAsString(1);
32+
2833
ItemStack itemStack = this.player.getItemInHand();
2934
if (itemStack == null || itemStack.getType() == Material.AIR) {
3035
message(this.sender, Message.SAVE_ERROR_EMPTY);
3136
return CommandType.DEFAULT;
3237
}
3338

34-
inventoryManager.saveItem(sender, itemStack, name);
39+
inventoryManager.saveItem(sender, itemStack, name, type);
3540

3641
return CommandType.SUCCESS;
3742
}

src/fr/maxlego08/menu/inventory/VInventory.java

Lines changed: 1 addition & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -43,88 +43,39 @@ public int getId() {
4343
return id;
4444
}
4545

46-
/**
47-
* Inventory Id
48-
*
49-
* @param id
50-
* @return
51-
*/
5246
public VInventory setId(int id) {
5347
this.id = id;
5448
return this;
5549
}
5650

57-
/**
58-
* Allows you to create the spigot inventory object
59-
*
60-
* @param name
61-
*/
6251
protected void createInventory(String name) {
6352
createInventory(name, 54);
6453
}
6554

66-
/**
67-
* Allows you to create the spigot inventory object
68-
*
69-
* @param name - Inventory name
70-
* @param size - Inventory Size
71-
*/
7255
protected void createInventory(String name, int size) {
7356
this.guiName = name;
7457
this.inventory = Bukkit.createInventory(this, size, name);
7558
}
7659

77-
/**
78-
* Allows you to create the spigot inventory object
79-
*
80-
* @param name - Inventory name
81-
* @param size - Inventory Size
82-
*/
8360
protected void createMetaInventory(String name, int size) {
8461
this.guiName = name;
8562
this.inventory = Meta.meta.createInventory(name, size, this);
8663
}
8764

88-
/**
89-
* Create default inventory with default size and name
90-
*/
9165
private void createDefaultInventory() {
9266
if (this.inventory == null) {
9367
this.inventory = Bukkit.createInventory(this, 54, "§cDefault Inventory");
9468
}
9569
}
9670

97-
/**
98-
* Adding an item to the inventory
99-
*
100-
* @param slot - Inventory slot
101-
* @param material - ItemStack material
102-
* @param name - ItemStack name
103-
* @return ItemButton
104-
*/
10571
public ItemButton addItem(int slot, Material material, String name) {
10672
return addItem(slot, new ItemBuilder(material, name).build());
10773
}
10874

109-
/**
110-
* Adding an item to the inventory
111-
*
112-
* @param slot - Inventory slot
113-
* @param item - ItemBuild
114-
* @return ItemButton
115-
*/
11675
public ItemButton addItem(int slot, ItemBuilder item) {
11776
return addItem(slot, item.build());
11877
}
11978

120-
/**
121-
* Adding an itemStack to the inventory
122-
* Creates the default inventory if it does not exist
123-
*
124-
* @param slot - Inventory slot
125-
* @param itemStack - ItemStack
126-
* @return ItemButton
127-
*/
12879
public ItemButton addItem(int slot, ItemStack itemStack) {
12980

13081
createDefaultInventory();
@@ -145,85 +96,42 @@ public ItemButton addItem(int slot, ItemStack itemStack) {
14596
return button;
14697
}
14798

148-
/**
149-
* Allows you to remove an item from the list of items
150-
*
151-
* @param slot
152-
*/
15399
public void removeItem(int slot) {
154100
this.items.remove(slot);
155101
}
156102

157-
/**
158-
* Allows you to delete all items
159-
*/
160103
public void clearItem() {
161104
this.items.clear();
162105
}
163106

164-
/**
165-
* Allows you to retrieve all items
166-
*
167-
* @return
168-
*/
169107
public Map<Integer, ItemButton> getItems() {
170108
return items;
171109
}
172110

173-
/**
174-
* If the click in the inventory is disabled (which is the default)
175-
* then it will return true
176-
*
177-
* @return vrai ou faux
178-
*/
179111
public boolean isDisableClick() {
180112
return disableClick;
181113
}
182114

183-
/**
184-
* Change the ability to click in the inventory
185-
*
186-
* @param disableClick
187-
*/
188115
public void setDisableClick(boolean disableClick) {
189116
this.disableClick = disableClick;
190117
}
191118

192-
/**
193-
* Allows to recover the player
194-
*
195-
* @return player
196-
*/
197119
public Player getPlayer() {
198120
return player;
199121
}
200122

201-
/**
202-
* Allows you to retrieve the page
203-
*
204-
* @return the page
205-
*/
206123
public int getPage() {
207124
return page;
208125
}
209126

210-
/**
211-
* @return the args
212-
*/
213127
public Object[] getArgs() {
214128
return args;
215129
}
216130

217-
/**
218-
* @return the inventory
219-
*/
220131
public Inventory getSpigotInventory() {
221132
return inventory;
222133
}
223134

224-
/**
225-
* @return the guiName
226-
*/
227135
public String getGuiName() {
228136
return guiName;
229137
}
@@ -245,19 +153,10 @@ protected void onPreClose(InventoryCloseEvent event, MenuPlugin plugin, Player p
245153
this.onClose(event, plugin, player);
246154
}
247155

248-
/**
249-
* @param event
250-
* @param plugin
251-
* @param player
252-
*/
156+
253157
protected void onClose(InventoryCloseEvent event, MenuPlugin plugin, Player player) {
254158
}
255159

256-
/**
257-
* @param event
258-
* @param plugin
259-
* @param player
260-
*/
261160
protected void onDrag(InventoryDragEvent event, MenuPlugin plugin, Player player) {
262161
}
263162

0 commit comments

Comments
 (0)