diff --git a/src/main/java/com/extendedclip/deluxemenus/config/DeluxeMenusConfig.java b/src/main/java/com/extendedclip/deluxemenus/config/DeluxeMenusConfig.java index 586d13c..14a5372 100644 --- a/src/main/java/com/extendedclip/deluxemenus/config/DeluxeMenusConfig.java +++ b/src/main/java/com/extendedclip/deluxemenus/config/DeluxeMenusConfig.java @@ -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; @@ -133,6 +134,18 @@ public DeluxeMenusConfig(DeluxeMenus plugin) { } } + private List 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(); } @@ -763,23 +776,25 @@ private Map> 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 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 flags = new ArrayList<>(); + + itemFlags.add(flag); } + + builder.itemFlags(itemFlags); } if (c.contains(currentPath + "data")) {