Skip to content

Commit 626c496

Browse files
committed
Merge branch 'release/1.0.2.7'
2 parents 65fe98f + 74e8927 commit 626c496

81 files changed

Lines changed: 853 additions & 309 deletions

File tree

Some content is hidden

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

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Don't track content of these folders
2+
target/
3+
bin/
4+
.settings/
5+
.classpath
6+
.project
7+
.idea
8+
zmenu.iml

LICENSE

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ apply only to part of the Program, that part may be used separately
351351
under those permissions, but the entire Program remains governed by
352352
this License without regard to the additional permissions.
353353

354-
When you convey a copy of a covered work, you may at your option
354+
When you convey a copy of a covered work, you may at your buttonOption
355355
remove any additional permissions from that copy, or from any part of
356356
it. (Additional permissions may be written to require their own
357357
removal in certain cases when you modify the work.) You may place
@@ -570,7 +570,7 @@ address new problems or concerns.
570570
Each version is given a distinguishing version number. If the
571571
Program specifies that a certain numbered version of the GNU General
572572
Public License "or any later version" applies to it, you have the
573-
option of following the terms and conditions either of that numbered
573+
buttonOption of following the terms and conditions either of that numbered
574574
version or of any later version published by the Free Software
575575
Foundation. If the Program does not specify a version number of the
576576
GNU General Public License, you may choose any version ever published
@@ -637,7 +637,7 @@ the "copyright" line and a pointer to where the full notice is found.
637637
This program is free software: you can redistribute it and/or modify
638638
it under the terms of the GNU General Public License as published by
639639
the Free Software Foundation, either version 3 of the License, or
640-
(at your option) any later version.
640+
(at your buttonOption) any later version.
641641

642642
This program is distributed in the hope that it will be useful,
643643
but WITHOUT ANY WARRANTY; without even the implied warranty of

changelog.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
- [x] Add anti dupe system with NMS Tag
44
- [x] Add the BACK action, to return to the previous inventory when clicking
55
- [x] Add the ability to perform actions when clicking
6-
- [ ] Improve the firework system to put more option. Being able to put several effects, power etc.
6+
- [ ] Improve the firework system to put more buttonOption. Being able to put several effects, power etc.
77
- [ ] Add a system that allows you to cache an ItemStack, so instead of returning the ItemStack at each opening, there can be several minutes without having to recreate a new ItemStack. For decorations, buttons without placeholders for example.
88
- [ ] Add an order to display the list of official addons.
99
- [ ] Add a ``/zm help`` command to send to documentation.
@@ -31,9 +31,28 @@
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.
3333
- [ ] Create a new class for loading buttons to add more elements, like a boolean to check if the button needs an itemstack
34+
- [ ] Can split a file into several and thus avoid having too large files
3435

3536
# Unreleased
3637

38+
# 1.0.2.7
39+
40+
- Start of development of the [zMenu+](https://m.zmenu.dev/4) paid addon. This addon will be available with the purchase of [Premium](https://minecraft-inventory-builder.com/account-upgrade) upgrade.
41+
- Huge API Change. This change introduces [zMenu+](https://m.zmenu.dev/4)
42+
- Create ButtonOption, allows any developer to add options that will be available for all types of buttons.
43+
- Create PaginateButton interface. This interface allows you to create buttons that need pagination. This interface will manage the number of pages in the inventory.
44+
- Add matrix support for button slots [#39](https://github.com/Maxlego08/zMenu/issues/39)
45+
- Add /zm editor, at the moment this command redirects to the online editor
46+
- Add target placeholder [#48](https://github.com/Maxlego08/zMenu/issues/48)
47+
- Fix reload command with pattern. The pattern were reload after the inventories
48+
- Fix error with InventoryPlayer
49+
- Fix NmsVersion with 1.8 and 1.9
50+
- Fix anti-dupe for old version
51+
- Fix MenuItemStack loader with placeholder check
52+
- Fix CONTAINS_STRING action for placeholder
53+
- Fix NMS with 1.20.4
54+
- Fix method ``getRealSlot`` with isPermanent
55+
3756
# 1.0.2.6
3857

3958
- Add BlockPlaceEvent for Anti Dupe
@@ -284,7 +303,7 @@ More information on the plugin documentation: https://docs.zmenu.dev/
284303
- Add method getCurrentPlayerInventory in InventoryManager
285304
- Add method buildDisplayName in Button
286305
- Add method buildLore in Button
287-
- Add updateOnClick option, update button if player click on another button
306+
- Add updateOnClick buttonOption, update button if player click on another button
288307
- Add button listener method in InventoryManager
289308
- Add check for new messages value saving
290309
- Fix placeholder verification

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.6</version>
6+
<version>1.0.2.7</version>
77
<build>
88
<sourceDirectory>src</sourceDirectory>
99
<resources>

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.6</version>
6+
<version>1.0.2.7</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: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
import fr.maxlego08.menu.zcore.utils.meta.Meta;
1616
import fr.maxlego08.menu.zcore.utils.nms.NMSUtils;
1717
import fr.maxlego08.menu.zcore.utils.nms.NmsVersion;
18+
import org.bukkit.Bukkit;
1819
import org.bukkit.Material;
20+
import org.bukkit.OfflinePlayer;
1921
import org.bukkit.enchantments.Enchantment;
2022
import org.bukkit.entity.Player;
2123
import org.bukkit.inventory.ItemFlag;
@@ -38,6 +40,7 @@ public class MenuItemStack extends ZUtils {
3840
private final String filePath;
3941
private final String path;
4042
private String material;
43+
private String targetPlayer;
4144
private String amount;
4245
private String url;
4346
private int data;
@@ -142,8 +145,10 @@ public ItemStack build(Player player, boolean useCache, Placeholders placeholder
142145
this.material = "STONE";
143146
}
144147

145-
String papiMaterial = papi(this.material, player);
146-
int amount = this.parseAmount(player);
148+
OfflinePlayer offlinePlayer = this.targetPlayer != null ? Bukkit.getOfflinePlayer(papi(placeholders.parse(this.targetPlayer), player)) : null;
149+
150+
String papiMaterial = papi(placeholders.parse(this.material), offlinePlayer == null ? player : offlinePlayer);
151+
int amount = this.parseAmount(offlinePlayer == null ? player : offlinePlayer, placeholders);
147152

148153
try {
149154
material = getMaterial(Integer.parseInt(papiMaterial));
@@ -221,15 +226,15 @@ public ItemStack build(Player player, boolean useCache, Placeholders placeholder
221226

222227
if (this.displayName != null) {
223228
try {
224-
Meta.meta.updateDisplayName(itemMeta, placeholders.parse(this.displayName), player);
229+
Meta.meta.updateDisplayName(itemMeta, placeholders.parse(this.displayName), offlinePlayer == null ? player : offlinePlayer);
225230
} catch (Exception exception) {
226231
Logger.info("Error with update display name for item " + path + " in file " + filePath + " (" + player + ", " + this.displayName + ")", Logger.LogType.ERROR);
227232
exception.printStackTrace();
228233
}
229234
}
230235

231236
if (!this.lore.isEmpty()) {
232-
Meta.meta.updateLore(itemMeta, placeholders.parse(this.lore), player);
237+
Meta.meta.updateLore(itemMeta, placeholders.parse(this.lore), offlinePlayer == null ? player : offlinePlayer);
233238
}
234239

235240
if (this.isGlowing && NMSUtils.getNMSVersion() != 1.7) {
@@ -239,7 +244,8 @@ public ItemStack build(Player player, boolean useCache, Placeholders placeholder
239244
}
240245

241246
try {
242-
int customModelData = Integer.parseInt(papi(this.modelID, player));
247+
248+
int customModelData = Integer.parseInt(papi(placeholders.parse(this.modelID), offlinePlayer == null ? player : offlinePlayer));
243249
if (customModelData != 0) itemMeta.setCustomModelData(customModelData);
244250
} catch (NumberFormatException ignored) {
245251
}
@@ -263,6 +269,21 @@ public ItemStack build(Player player, boolean useCache, Placeholders placeholder
263269
return itemStack;
264270
}
265271

272+
273+
/**
274+
* @return the target player
275+
*/
276+
public String getTargetPlayer() {
277+
return targetPlayer;
278+
}
279+
280+
/**
281+
* @param targetPlayer the targetPlayer to set
282+
*/
283+
public void setTargetPlayer(String targetPlayer) {
284+
this.targetPlayer = targetPlayer;
285+
}
286+
266287
/**
267288
* @return the material
268289
*/
@@ -275,7 +296,7 @@ public String getMaterial() {
275296
*/
276297
public void setMaterial(String material) {
277298
this.material = material;
278-
this.updatePlaceholder(amount);
299+
this.updatePlaceholder(material);
279300
}
280301

281302
/**
@@ -517,6 +538,24 @@ public int parseAmount(Player player) {
517538
return amount;
518539
}
519540

541+
public int parseAmount(Player player, Placeholders placeholders) {
542+
int amount = 1;
543+
try {
544+
amount = Integer.parseInt(papi(placeholders.parse(this.amount), player));
545+
} catch (Exception ignored) {
546+
}
547+
return amount;
548+
}
549+
550+
public int parseAmount(OfflinePlayer offlinePlayer, Placeholders placeholders) {
551+
int amount = 1;
552+
try {
553+
amount = Integer.parseInt(papi(placeholders.parse(this.amount), offlinePlayer));
554+
} catch (Exception ignored) {
555+
}
556+
return amount;
557+
}
558+
520559
/**
521560
* Let's know if the ItemStack needs a placeholder, if not then the ItemStack will be cached
522561
*
@@ -530,4 +569,5 @@ private void updatePlaceholder(String string) {
530569
public void setNeedPlaceholderAPI(boolean needPlaceholderAPI) {
531570
this.needPlaceholderAPI = needPlaceholderAPI;
532571
}
572+
533573
}

src/fr/maxlego08/menu/MenuPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ public void onEnable() {
193193
this.getSavers().forEach(saver -> saver.load(this.getPersist()));
194194

195195
LocalPlaceholder localPlaceholder = LocalPlaceholder.getInstance();
196-
localPlaceholder.register("argument_", (player, value) -> {
197-
Optional<String> optional = this.commandManager.getPlayerArgument(player, value);
196+
localPlaceholder.register("argument_", (offlinePlayer, value) -> {
197+
Optional<String> optional = this.commandManager.getPlayerArgument(offlinePlayer.getUniqueId(), value);
198198
return optional.orElse(null);
199199
});
200200

src/fr/maxlego08/menu/ZCommandManager.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,16 @@ public void setPlayerArgument(Player player, String key, String value) {
189189
}
190190

191191
@Override
192-
public Optional<String> getPlayerArgument(Player player, String key) {
193-
Map<String, String> arguments = this.playerArguments.getOrDefault(player.getUniqueId(), new HashMap<>());
192+
public Optional<String> getPlayerArgument(UUID uuid, String key) {
193+
Map<String, String> arguments = this.playerArguments.getOrDefault(uuid, new HashMap<>());
194194
return Optional.ofNullable(arguments.getOrDefault(key, null));
195195
}
196196

197+
@Override
198+
public Optional<String> getPlayerArgument(Player player, String key) {
199+
return getPlayerArgument(player.getUniqueId(), key);
200+
}
201+
197202
@Override
198203
public Optional<Command> getCommand(String commandName) {
199204
return this.getCommands().stream().filter(e -> e.getCommand().equalsIgnoreCase(commandName)).findFirst();

src/fr/maxlego08/menu/ZInventory.java

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

33
import fr.maxlego08.menu.api.Inventory;
44
import fr.maxlego08.menu.api.button.Button;
5+
import fr.maxlego08.menu.api.button.PaginateButton;
56
import fr.maxlego08.menu.api.pattern.Pattern;
67
import fr.maxlego08.menu.api.players.inventory.InventoriesPlayer;
78
import fr.maxlego08.menu.api.requirement.Requirement;
89
import fr.maxlego08.menu.api.utils.OpenWithItem;
10+
import fr.maxlego08.menu.api.utils.Placeholders;
911
import fr.maxlego08.menu.inventory.inventories.InventoryDefault;
1012
import fr.maxlego08.menu.zcore.utils.ZUtils;
1113
import fr.maxlego08.menu.zcore.utils.inventory.InventoryResult;
@@ -17,6 +19,7 @@
1719
import java.util.ArrayList;
1820
import java.util.Collection;
1921
import java.util.Collections;
22+
import java.util.Comparator;
2023
import java.util.List;
2124
import java.util.Optional;
2225
import java.util.stream.Collectors;
@@ -74,8 +77,7 @@ public Collection<Button> getButtons() {
7477

7578
@Override
7679
public <T extends Button> List<T> getButtons(Class<T> type) {
77-
return this.getButtons().stream().filter(e -> type.isAssignableFrom(e.getClass())).map(type::cast)
78-
.collect(Collectors.toList());
80+
return this.getButtons().stream().filter(e -> type.isAssignableFrom(e.getClass())).map(type::cast).collect(Collectors.toList());
7981
}
8082

8183
@Override
@@ -96,16 +98,26 @@ public int getMaxPage(Player player, Object... objects) {
9698

9799
@Override
98100
public int getMaxPage(Collection<Pattern> patterns, Player player, Object... objects) {
101+
102+
int maxPage = 1;
103+
99104
List<Button> buttons = new ArrayList<>();
100105
buttons.addAll(this.buttons);
101106
buttons.addAll(patterns.stream().flatMap(pattern -> pattern.getButtons().stream()).collect(Collectors.toList()));
102107

103108
Optional<Integer> optional = buttons.stream().map(Button::getSlot).max(Integer::compare);
104109
if (optional.isPresent()) {
105110
int maxSlot = optional.get();
106-
return (maxSlot / this.size) + 1;
111+
maxPage = (maxSlot / this.size) + 1;
107112
}
108-
return 1;
113+
114+
Optional<PaginateButton> optionalPaginate = this.buttons.stream().filter(button -> button instanceof PaginateButton).map(e -> (PaginateButton) e).sorted(Comparator.comparingInt(e -> ((PaginateButton) e).getPaginationSize(player)).reversed()).findFirst();
115+
if (optionalPaginate.isPresent()) {
116+
PaginateButton paginateButton = optionalPaginate.get();
117+
maxPage = (int) Math.ceil((double) paginateButton.getPaginationSize(player) / paginateButton.getSlots().size());
118+
}
119+
120+
return maxPage;
109121
}
110122

111123
@Override
@@ -128,7 +140,7 @@ public List<Button> sortPatterns(Pattern pattern, int page, Object... objects) {
128140
@Override
129141
public InventoryResult openInventory(Player player, InventoryDefault inventoryDefault) {
130142

131-
if (openRequirement != null && !openRequirement.execute(player, null, inventoryDefault)) {
143+
if (openRequirement != null && !openRequirement.execute(player, null, inventoryDefault, new Placeholders())) {
132144
return InventoryResult.PERMISSION;
133145
}
134146

src/fr/maxlego08/menu/ZInventoryManager.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import fr.maxlego08.menu.api.ButtonManager;
44
import fr.maxlego08.menu.api.Inventory;
55
import fr.maxlego08.menu.api.InventoryManager;
6+
import fr.maxlego08.menu.api.button.ButtonOption;
67
import fr.maxlego08.menu.api.event.FastEvent;
78
import fr.maxlego08.menu.api.event.events.ButtonLoaderRegisterEvent;
89
import fr.maxlego08.menu.api.event.events.InventoryLoadEvent;
@@ -93,6 +94,7 @@
9394
public class ZInventoryManager extends ZUtils implements InventoryManager {
9495

9596
private final Map<String, List<Inventory>> inventories = new HashMap<>();
97+
private final Map<Plugin, List<Class<? extends ButtonOption>>> buttonOptions = new HashMap<>();
9698
private final List<MaterialLoader> loaders = new ArrayList<>();
9799
private final MenuPlugin plugin;
98100
private final Map<UUID, Inventory> currentInventories = new HashMap<>();
@@ -300,7 +302,7 @@ public void loadButtons() {
300302
registerItemStackVerification(new ModelIdSimilar());
301303
registerItemStackVerification(new NameSimilar());
302304

303-
ButtonLoaderRegisterEvent event = new ButtonLoaderRegisterEvent(buttonManager);
305+
ButtonLoaderRegisterEvent event = new ButtonLoaderRegisterEvent(buttonManager, this, this.plugin.getPatternManager());
304306
event.call();
305307

306308
plugin.getWebsiteManager().loadButtons(buttonManager);
@@ -646,4 +648,27 @@ public Collection<ItemStackSimilar> getItemStackVerifications() {
646648
public ZScheduler getScheduler() {
647649
return this.plugin.getScheduler();
648650
}
651+
652+
@Override
653+
public Optional<Class<? extends ButtonOption>> getOption(String name) {
654+
return this.buttonOptions.values().stream().flatMap(List::stream).filter(buttonOption -> buttonOption.getName().equalsIgnoreCase(name)).findFirst();
655+
}
656+
657+
@Override
658+
public void registerOption(Plugin plugin, Class<? extends ButtonOption> buttonOption) {
659+
660+
if (getOption(buttonOption.getName()).isPresent()) return;
661+
662+
this.buttonOptions.computeIfAbsent(plugin, e -> new ArrayList<>()).add(buttonOption);
663+
}
664+
665+
@Override
666+
public void unregisterOptions(Plugin plugin) {
667+
this.buttonOptions.remove(plugin);
668+
}
669+
670+
@Override
671+
public Map<Plugin, List<Class<? extends ButtonOption>>> getOptions() {
672+
return this.buttonOptions;
673+
}
649674
}

0 commit comments

Comments
 (0)