Skip to content

Commit 6da40ca

Browse files
committed
Merge branch 'release/1.0.3.3'
2 parents 0a7792d + 9aba69c commit 6da40ca

24 files changed

+374
-118
lines changed

changelog.md

Lines changed: 110 additions & 46 deletions
Large diffs are not rendered by default.

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.3.2</version>
6+
<version>1.0.3.3</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.3.2</version>
6+
<version>1.0.3.3</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: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import fr.maxlego08.menu.zcore.utils.ZUtils;
1717
import fr.maxlego08.menu.zcore.utils.attribute.AttributeApplier;
1818
import fr.maxlego08.menu.zcore.utils.meta.Meta;
19-
import fr.maxlego08.menu.zcore.utils.nms.NMSUtils;
2019
import fr.maxlego08.menu.zcore.utils.nms.NmsVersion;
2120
import org.bukkit.Bukkit;
2221
import org.bukkit.Color;
@@ -59,6 +58,8 @@ public class MenuItemStack extends ZUtils {
5958
private List<String> lore = new ArrayList<>();
6059
private List<ItemFlag> flags = new ArrayList<>();
6160
private String displayName;
61+
private Map<String, String> translatedDisplayName = new HashMap<>();
62+
private Map<String, List<String>> translatedLore = new HashMap<>();
6263
private boolean isGlowing;
6364
private String modelID;
6465
private Map<Enchantment, Integer> enchantments = new HashMap<>();
@@ -236,22 +237,25 @@ public ItemStack build(Player player, boolean useCache, Placeholders placeholder
236237

237238
Material finalMaterial = itemStack.getType();
238239
ItemMeta itemMeta = itemStack.getItemMeta();
240+
String locale = findPlayerLocale(player);
239241

240242
if (itemMeta != null) {
241243
if (this.displayName != null) {
242244
try {
243-
Meta.meta.updateDisplayName(itemMeta, placeholders.parse(this.displayName), offlinePlayer == null ? player : offlinePlayer);
245+
String displayName = locale == null ? this.displayName : this.translatedDisplayName.getOrDefault(locale, this.displayName);
246+
Meta.meta.updateDisplayName(itemMeta, placeholders.parse(displayName), offlinePlayer == null ? player : offlinePlayer);
244247
} catch (Exception exception) {
245248
Logger.info("Error with update display name for item " + path + " in file " + filePath + " (" + player + ", " + this.displayName + ")", Logger.LogType.ERROR);
246249
exception.printStackTrace();
247250
}
248251
}
249252

250253
if (!this.lore.isEmpty()) {
251-
Meta.meta.updateLore(itemMeta, placeholders.parse(this.lore), offlinePlayer == null ? player : offlinePlayer);
254+
List<String> lore = locale == null ? this.lore : this.translatedLore.getOrDefault(locale, this.lore);
255+
Meta.meta.updateLore(itemMeta, placeholders.parse(lore), offlinePlayer == null ? player : offlinePlayer);
252256
}
253257

254-
if (this.isGlowing && NMSUtils.getNMSVersion() != 1.7) {
258+
if (this.isGlowing) {
255259

256260
itemMeta.addEnchant(Enchantment.ARROW_DAMAGE, 1, true);
257261
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
@@ -739,4 +743,20 @@ private List<Color> getColors(MapConfiguration section, String key) {
739743

740744
return colors;
741745
}
746+
747+
public Map<String, String> getTranslatedDisplayName() {
748+
return translatedDisplayName;
749+
}
750+
751+
public void setTranslatedDisplayName(Map<String, String> translatedDisplayName) {
752+
this.translatedDisplayName = translatedDisplayName;
753+
}
754+
755+
public Map<String, List<String>> getTranslatedLore() {
756+
return translatedLore;
757+
}
758+
759+
public void setTranslatedLore(Map<String, List<String>> translatedLore) {
760+
this.translatedLore = translatedLore;
761+
}
742762
}

src/fr/maxlego08/menu/MenuPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void onEnable() {
127127
files.forEach(filePath -> {
128128
if (!new File(this.getDataFolder(), filePath).exists()) {
129129

130-
if (NMSUtils.isNewVersion()) {
130+
if (NmsVersion.nmsVersion.isNewMaterial()) {
131131
saveResource(filePath.replace("inventories/", "inventories/1_13/"), filePath, false);
132132
} else {
133133
saveResource(filePath, false);

src/fr/maxlego08/menu/ZCommandArgument.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ public class ZCommandArgument implements CommandArgument {
1111
private final String argument;
1212
private final String inventory;
1313
private final boolean isRequired;
14+
private final boolean performMainAction;
1415
private final List<Action> actions;
1516
private final List<String> autoCompletion;
1617

17-
public ZCommandArgument(String argument, String inventory, boolean isRequired, List<Action> actions, List<String> autoCompletion) {
18+
public ZCommandArgument(String argument, String inventory, boolean isRequired, boolean performMainAction, List<Action> actions, List<String> autoCompletion) {
1819
this.argument = argument;
1920
this.inventory = inventory;
2021
this.isRequired = isRequired;
22+
this.performMainAction = performMainAction;
2123
this.actions = actions;
2224
this.autoCompletion = autoCompletion;
2325
}
@@ -37,6 +39,11 @@ public List<String> getAutoCompletion() {
3739
return this.autoCompletion;
3840
}
3941

42+
@Override
43+
public boolean isPerformMainActions() {
44+
return this.performMainAction;
45+
}
46+
4047
@Override
4148
public String getArgument() {
4249
return argument;

src/fr/maxlego08/menu/ZInventory.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
import java.util.Collection;
2121
import java.util.Collections;
2222
import java.util.Comparator;
23+
import java.util.HashMap;
2324
import java.util.List;
25+
import java.util.Map;
2426
import java.util.Optional;
2527
import java.util.stream.Collectors;
2628

@@ -31,6 +33,7 @@ public class ZInventory extends ZUtils implements Inventory {
3133
private final String fileName;
3234
private final int size;
3335
private final List<Button> buttons;
36+
private Map<String, String> translatedNames = new HashMap<>();
3437
private List<Pattern> patterns;
3538
private MenuItemStack fillItemStack;
3639
private int updateInterval;
@@ -65,6 +68,12 @@ public String getName() {
6568
return this.name;
6669
}
6770

71+
@Override
72+
public String getName(Player player) {
73+
String locale = findPlayerLocale(player);
74+
return locale == null ? this.name : this.translatedNames.getOrDefault(locale, this.name);
75+
}
76+
6877
@Override
6978
public String getFileName() {
7079
return this.fileName;
@@ -238,6 +247,11 @@ public void setOpenWithItem(OpenWithItem openWithItem) {
238247
this.openWithItem = openWithItem;
239248
}
240249

250+
@Override
251+
public Map<String, String> getTranslatedName() {
252+
return this.translatedNames;
253+
}
254+
241255
public void setClearInventory(boolean clearInventory) {
242256
this.clearInventory = clearInventory;
243257
}
@@ -250,4 +264,8 @@ public List<Pattern> getPatterns() {
250264
public void setPatterns(List<Pattern> patterns) {
251265
this.patterns = patterns;
252266
}
267+
268+
public void setTranslatedNames(Map<String, String> translatedNames) {
269+
this.translatedNames = translatedNames;
270+
}
253271
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.io.File;
1414
import java.util.Collection;
1515
import java.util.List;
16+
import java.util.Map;
1617

1718
/**
1819
* The `Inventory` interface defines the structure and behavior of inventory-related operations.
@@ -37,6 +38,13 @@ public interface Inventory {
3738
*/
3839
String getName();
3940

41+
/**
42+
* Returns the translated name of the inventory.
43+
*
44+
* @return The name of the inventory.
45+
*/
46+
String getName(Player player);
47+
4048
/**
4149
* Returns the name of the file associated with the inventory.
4250
*
@@ -179,4 +187,6 @@ public interface Inventory {
179187
* @return The OpenWithItem
180188
*/
181189
OpenWithItem getOpenWithItem();
190+
191+
Map<String, String> getTranslatedName();
182192
}

src/fr/maxlego08/menu/api/command/CommandArgument.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ public interface CommandArgument {
1313
/**
1414
* Gets the command argument.
1515
*
16-
* @return The command argument.
16+
* @return The command argument as a String.
1717
*/
1818
String getArgument();
1919

2020
/**
2121
* Gets the name of the inventory to open with the argument.
2222
*
23-
* @return The optional name of the inventory associated with the argument.
23+
* @return An Optional containing the name of the inventory associated with the argument if present, otherwise an empty Optional.
2424
*/
2525
Optional<String> getInventory();
2626

@@ -31,7 +31,24 @@ public interface CommandArgument {
3131
*/
3232
boolean isRequired();
3333

34+
/**
35+
* Gets the list of actions associated with this command argument.
36+
*
37+
* @return A list of Action objects associated with the argument.
38+
*/
3439
List<Action> getActions();
3540

41+
/**
42+
* Gets a list of strings that can be used for auto-completion of this argument.
43+
*
44+
* @return A list of strings that can be used to auto-complete the argument.
45+
*/
3646
List<String> getAutoCompletion();
47+
48+
/**
49+
* Checks if the main actions should be performed when this argument is used.
50+
*
51+
* @return {@code true} if the main actions should be performed, otherwise {@code false}.
52+
*/
53+
boolean isPerformMainActions();
3754
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,20 @@ protected CommandType perform(MenuPlugin plugin) {
9696
}
9797
}
9898

99+
boolean performMainActions = lastArgument == null || lastArgument.isPerformMainActions();
100+
99101
InventoryDefault inventoryDefault = new InventoryDefault();
100102
inventoryDefault.setPlugin(plugin);
101-
this.command.getActions().forEach(action -> action.preExecute(player, null, inventoryDefault, placeholders));
103+
104+
102105
if (lastArgument != null) {
103106
lastArgument.getActions().forEach(action -> action.preExecute(player, null, inventoryDefault, placeholders));
104107
}
105108

106-
optional.ifPresent(inventory -> manager.openInventory(this.player, inventory));
109+
if (performMainActions) {
110+
this.command.getActions().forEach(action -> action.preExecute(player, null, inventoryDefault, placeholders));
111+
optional.ifPresent(inventory -> manager.openInventory(this.player, inventory));
112+
}
107113

108114
return CommandType.SUCCESS;
109115
}

0 commit comments

Comments
 (0)