Skip to content

Commit

Permalink
Merge pull request #112 from HelpChat/fix/110-item_flags
Browse files Browse the repository at this point in the history
  • Loading branch information
darbyjack authored Jun 24, 2024
2 parents eb21b49 + ecab7c0 commit 08a8da5
Showing 1 changed file with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import com.google.common.base.Enums;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
Expand Down Expand Up @@ -133,6 +134,18 @@ public DeluxeMenusConfig(DeluxeMenus plugin) {
}
}

private List<String> getStringListFromConfig(FileConfiguration config, String path) {
if (!config.contains(path)) {
return Collections.emptyList();
}

if (config.isList(path)) {
return config.getStringList(path);
} else {
return Collections.singletonList(config.getString(path, ""));
}
}

public static boolean containsPlaceholders(String text) {
return PLACEHOLDER_PATTERN.matcher(text).find();
}
Expand Down Expand Up @@ -763,23 +776,25 @@ private Map<Integer, TreeMap<Integer, MenuItem>> loadMenuItems(FileConfiguration

// item flags
if (c.contains(currentPath + "item_flags")) {
if (c.isString(currentPath + "item_flags")) {
String flagAsString = c.getString(currentPath + "item_flags");
ItemFlag flag;
try {
flag = ItemFlag.valueOf(flagAsString.toUpperCase());
builder.itemFlags(Collections.singletonList(flag));
} catch (IllegalArgumentException | NullPointerException ignored) {
List<ItemFlag> itemFlags = new ArrayList<>();

for (String flagAsString : getStringListFromConfig(c, currentPath + "item_flags")) {
ItemFlag flag = Enums.getIfPresent(ItemFlag.class, flagAsString.toUpperCase()).orNull();

if (flag == null) {
DeluxeMenus.debug(
DebugLevel.HIGHEST,
Level.WARNING,
"Item flag: " + flagAsString + " for item: " + key + " in menu: " + name
+ " is not a valid item flag!"
DebugLevel.HIGHEST,
Level.WARNING,
"Item flag: " + flagAsString + " for item: " + key + " in menu: " + name
+ " is not a valid item flag!"
);
continue;
}
} else {
List<ItemFlag> flags = new ArrayList<>();

itemFlags.add(flag);
}

builder.itemFlags(itemFlags);
}

if (c.contains(currentPath + "data")) {
Expand Down

0 comments on commit 08a8da5

Please sign in to comment.