Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.inventory.EquipmentSlotGroup;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Locale;
import java.util.Map;
Expand All @@ -17,7 +18,11 @@
* Value object for encapsulating all data needed for an attribute modifier on an item: the attribute, operation, amount, and slot.
* Provides deserialization and conversion to Bukkit AttributeModifier.
*/
public record AttributeWrapper(Attribute attribute, AttributeModifier.Operation operation, double amount, EquipmentSlotGroup slot) {
public record AttributeWrapper(Attribute attribute, AttributeModifier.Operation operation, double amount, EquipmentSlotGroup slot, @Nullable NamespacedKey namespacedKey) {

AttributeWrapper(Attribute attribute, AttributeModifier.Operation operation, double amount, EquipmentSlotGroup slot) {
this(attribute, operation, amount, slot, null);
}

public static AttributeWrapper deserialize(@NotNull Map<String, Object> attributeMap) {
var attribute = Registry.ATTRIBUTE.get(Objects.requireNonNull(NamespacedKey.fromString(((String) attributeMap.get("attribute")).toLowerCase(Locale.ROOT))));
Expand All @@ -30,6 +35,6 @@ public static AttributeWrapper deserialize(@NotNull Map<String, Object> attribut
}

public AttributeModifier toAttributeModifier(MenuPlugin plugin) {
return new AttributeModifier(new NamespacedKey(plugin, UUID.randomUUID().toString()), amount, operation, slot);
return new AttributeModifier(Objects.requireNonNullElseGet(this.namespacedKey, () -> new NamespacedKey(plugin, UUID.randomUUID().toString())), amount, operation, slot);
}
}
19 changes: 2 additions & 17 deletions Common/src/main/java/fr/maxlego08/menu/ZMenuItemStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import fr.maxlego08.menu.api.utils.Placeholders;
import fr.maxlego08.menu.common.context.ZBuildContext;
import fr.maxlego08.menu.common.utils.ZUtils;
import fr.maxlego08.menu.common.utils.itemstack.MenuItemStackFormMap;
import fr.maxlego08.menu.common.utils.itemstack.MenuItemStackFromItemStack;
import fr.maxlego08.menu.common.utils.nms.NmsVersion;
import fr.maxlego08.menu.zcore.logger.Logger;
Expand All @@ -39,6 +38,7 @@
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.NonNull;

import javax.annotation.Nullable;
import java.io.File;
import java.util.*;

Expand Down Expand Up @@ -102,19 +102,6 @@ public static ZMenuItemStack fromItemStack(InventoryManager manager, ItemStack i
return MenuItemStackFromItemStack.fromItemStack(manager, itemStack);
}

/**
* Build a MenuItemStack from a map.
*
* @param inventoryManager the inventoryManager of the item
* @param file the file where the item is saved
* @param path the path of the item in the file
* @param map the map which contains the item data
* @return the menuItemStack
*/
public static ZMenuItemStack fromMap(InventoryManager inventoryManager, File file, String path, Map<String, Object> map) {
return MenuItemStackFormMap.fromMap(inventoryManager, file, path, map);
}

/**
* @return the inventoryManager
*/
Expand Down Expand Up @@ -358,9 +345,7 @@ private void applyEnchantments(Material finalMaterial, ItemMeta itemMeta) {

private void applyFlags(ItemMeta itemMeta) {
for (ItemFlag flag : this.flags) {
if (flag != null) {
itemMeta.addItemFlags(flag);
}
itemMeta.addItemFlags(flag);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ public enum Permission {
ZMENU_CONVERT,
ZMENU_LIST,
ZMENU_TEST_DUPE,
ZMENU_OPEN_ITEM,
ZMENU_CREATE,
ZMENU_DOWNLOAD,
ZMENU_LOGIN,
ZMENU_MARKETPLACE,
ZMENU_INVENTORIES,
ZMENU_DESCRIPTION,
ZMENU_DOWNLOAD,
ZMENU_LOGIN,
ZMENU_MARKETPLACE,
ZMENU_INVENTORIES,
ZMENU_DESCRIPTION,
ZMENU_OPEN_DIALOG,
ZMENU_RELOAD_DIALOG,
ZMENU_DUMPLOG,
ZMENU_CONTRIBUTORS,
ZMENU_GIVE_ITEM,
ZMENU_GIVE_OPEN_ITEM,
ZMENU_EDITOR,
ZMENU_VERSION,

ZMENU_ADDONS,
ZMENU_DOCUMENTATION;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/fr/maxlego08/menu/ZInventoryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import fr.maxlego08.menu.common.utils.ZUtils;
import fr.maxlego08.menu.common.utils.cache.YamlFileCache;
import fr.maxlego08.menu.common.utils.cache.YamlFileCacheEntry;
import fr.maxlego08.menu.common.utils.itemstack.MenuItemStackFormMap;
import fr.maxlego08.menu.common.utils.nms.ItemStackUtils;
import fr.maxlego08.menu.common.utils.yaml.YamlParser;
import fr.maxlego08.menu.hooks.dialogs.loader.body.ItemBodyLoader;
Expand Down Expand Up @@ -130,7 +129,9 @@ public MenuItemStack loadItemStack(YamlConfiguration configuration, String path,

@Override
public MenuItemStack loadItemStack(File file, String path, Map<String, Object> map) {
return MenuItemStackFormMap.fromMap(this, file, path, map);
YamlConfiguration configuration = new YamlConfiguration();
configuration.set("item", map);
return new MenuItemStackLoader(this).load(configuration, "item", file);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package fr.maxlego08.menu.command.commands;

import fr.maxlego08.menu.ZMenuPlugin;
import fr.maxlego08.menu.command.VCommand;
import fr.maxlego08.menu.api.utils.Message;
import fr.maxlego08.menu.command.VCommand;
import fr.maxlego08.menu.common.enums.Permission;
import fr.maxlego08.menu.zcore.utils.commands.CommandType;

public class CommandMenuEditor extends VCommand {
Expand All @@ -11,6 +12,7 @@ public CommandMenuEditor(ZMenuPlugin plugin) {
super(plugin);
this.addSubCommand("editor");
this.setDescription(Message.DESCRIPTION_EDITOR);
this.setPermission(Permission.ZMENU_EDITOR);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class CommandMenuGiveOpenItem extends VCommand {

public CommandMenuGiveOpenItem(ZMenuPlugin plugin) {
super(plugin);
this.setPermission(Permission.ZMENU_OPEN_ITEM);
this.setPermission(Permission.ZMENU_GIVE_OPEN_ITEM);
this.setDescription(Message.DESCRIPTION_OPEN_ITEM);
this.addSubCommand("giveopenitem");
this.addSubCommand("goi");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package fr.maxlego08.menu.command.commands;

import fr.maxlego08.menu.ZMenuPlugin;
import fr.maxlego08.menu.command.VCommand;
import fr.maxlego08.menu.api.utils.Message;
import fr.maxlego08.menu.command.VCommand;
import fr.maxlego08.menu.common.enums.Permission;
import fr.maxlego08.menu.zcore.utils.commands.CommandType;

public class CommandMenuVersion extends VCommand {

public CommandMenuVersion(ZMenuPlugin plugin) {
super(plugin);
this.setDescription(Message.DESCRIPTION_VERSION);
this.setPermission(Permission.ZMENU_VERSION);
this.addSubCommand("version", "v", "ver");
}

Expand Down
54 changes: 44 additions & 10 deletions src/main/java/fr/maxlego08/menu/loader/MenuItemStackLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import fr.maxlego08.menu.api.loader.ItemComponentLoader;
import fr.maxlego08.menu.api.utils.Loader;
import fr.maxlego08.menu.api.utils.LoreType;
import fr.maxlego08.menu.api.utils.TrimHelper;
import fr.maxlego08.menu.common.context.ZBuildContext;
import fr.maxlego08.menu.common.utils.ZUtils;
import fr.maxlego08.menu.common.utils.nms.NmsVersion;
Expand All @@ -35,6 +34,7 @@
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

@SuppressWarnings("deprecation")
public class MenuItemStackLoader extends ZUtils implements Loader<MenuItemStack> {
Expand All @@ -53,6 +53,9 @@ public MenuItemStackLoader(InventoryManager manager) {
* Load ItemStack
*/
public MenuItemStack load(@NonNull YamlConfiguration configuration, @NonNull String path, Object... objects) {
if (!path.isEmpty() && !path.endsWith("."))
path = path + ".";


File file = (File) objects[0];

Expand Down Expand Up @@ -96,7 +99,9 @@ public MenuItemStack load(@NonNull YamlConfiguration configuration, @NonNull Str
List<String> flagStrings = configuration.getStringList(path + "flags");
List<ItemFlag> flags = new ArrayList<>(flagStrings.size());
for (String flagName : flagStrings) {
flags.add(this.getFlag(flagName));
ItemFlag flag = this.getFlag(flagName);
if (flag != null)
flags.add(flag);
}
menuItemStack.setFlags(flags);

Expand Down Expand Up @@ -520,18 +525,47 @@ private void loadNewItemStacks(ZMenuItemStack menuItemStack, YamlConfiguration c
private void loadTrims(ZMenuItemStack menuItemStack, YamlConfiguration configuration, String path, File file) {
boolean enableTrim = configuration.getBoolean(path + "trim.enable", false);
if (enableTrim) {
TrimHelper trimHelper = new TrimHelper();
TrimPattern trimPattern = trimHelper.getTrimPatterns().get(configuration.getString(path + "trim.pattern", "").toLowerCase());
if (trimPattern == null) {
String patternKey = configuration.getString(path + "trim.pattern", "").toLowerCase();
TrimPattern trimPattern = null;
try {
NamespacedKey patternNamespace = NamespacedKey.fromString(patternKey);
if (patternNamespace != null) {
trimPattern = Registry.TRIM_PATTERN.get(patternNamespace);
}
if (trimPattern == null) {
enableTrim = false;
String joinedNames = Registry.TRIM_PATTERN.stream()
.map(TrimPattern::getKey)
.map(NamespacedKey::toString)
.collect(Collectors.joining(", "));
Logger.info("Trim pattern '" + patternKey + "' was not found for item '" + file.getAbsolutePath() + "'. Available patterns: " + joinedNames, Logger.LogType.ERROR);
}
} catch (Exception e) {
enableTrim = false;
Bukkit.getLogger().severe("Trim pattern " + configuration.getString(path + "trim.pattern", "") + " was not found for item " + file.getAbsolutePath());
Logger.info("Invalid namespace for trim pattern: '" + patternKey + "' in file '" + file.getAbsolutePath() + "'", Logger.LogType.ERROR);
}
TrimMaterial trimMaterial = trimHelper.getTrimMaterials().get(configuration.getString(path + "trim.material", "").toLowerCase());
if (trimMaterial == null) {

String materialKey = configuration.getString(path + "trim.material", "").toLowerCase();
TrimMaterial trimMaterial = null;
try {
NamespacedKey materialNamespace = NamespacedKey.fromString(materialKey);
if (materialNamespace != null) {
trimMaterial = Registry.TRIM_MATERIAL.get(materialNamespace);
}
if (trimMaterial == null) {
enableTrim = false;
String joinedNames = Registry.TRIM_MATERIAL.stream()
.map(TrimMaterial::getKey)
.map(NamespacedKey::toString)
.collect(Collectors.joining(", "));
Logger.info("Trim material '" + materialKey + "' was not found for item '" + file.getAbsolutePath() + "'. Available materials: " + joinedNames, Logger.LogType.ERROR);
}
} catch (Exception e) {
enableTrim = false;
Bukkit.getLogger().severe("Trim material " + configuration.getString(path + "trim.material", "") + " was not found for item " + file.getAbsolutePath());
Logger.info("Invalid namespace for trim material: '" + materialKey + "' in file '" + file.getAbsolutePath() + "'", Logger.LogType.ERROR);
}
menuItemStack.setTrimConfiguration(new TrimConfiguration(enableTrim, trimMaterial, trimPattern));
if (trimMaterial != null && trimPattern != null)
menuItemStack.setTrimConfiguration(new TrimConfiguration(enableTrim, trimMaterial, trimPattern));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public SpigotAttributeModifiersItemComponentLoader(MenuPlugin plugin){
if (attribute == null) continue;
try {
AttributeModifier deserialize = AttributeModifier.deserialize(map);
modifiersWrapper.add(new AttributeWrapper(attribute, deserialize.getOperation(), deserialize.getAmount(), deserialize.getSlotGroup()));
modifiersWrapper.add(new AttributeWrapper(attribute, deserialize.getOperation(), deserialize.getAmount(), deserialize.getSlotGroup(), deserialize.getKey()));
} catch (IllegalArgumentException e) {
if (Configuration.enableDebug){
Logger.info("Error deserializing attribute modifier for attribute " + attribute.name() + ": " + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public SpigotEnchantmentGlintOverrideItemComponentLoader(){
@Override
public @Nullable ItemComponent load(@NotNull MenuItemStackContext context, @NotNull File file, @NotNull YamlConfiguration configuration, @NotNull String path, @Nullable ConfigurationSection componentSection) {
path = normalizePath(path);
boolean hasGlint = configuration.getBoolean(path, false);
return hasGlint ? new EnchantmentGlintOverrideComponent(true) : null;
Object obj = configuration.get(path);
if (obj == null) return null;
return obj instanceof Boolean hasGlint ? new EnchantmentGlintOverrideComponent(hasGlint) : null;
}
}
Loading