From 2c15c7ee927070b9e9b25bd206dc3351425d8361 Mon Sep 17 00:00:00 2001 From: LMBishop <13875753+LMBishop@users.noreply.github.com> Date: Tue, 16 Feb 2021 01:04:58 +0000 Subject: Add error checking to placeholders --- .../leonardobishop/quests/QuestsConfigLoader.java | 62 ++++++++++------------ 1 file changed, 27 insertions(+), 35 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/com/leonardobishop/quests/QuestsConfigLoader.java b/src/main/java/com/leonardobishop/quests/QuestsConfigLoader.java index 24e89264..d1921c29 100644 --- a/src/main/java/com/leonardobishop/quests/QuestsConfigLoader.java +++ b/src/main/java/com/leonardobishop/quests/QuestsConfigLoader.java @@ -170,12 +170,6 @@ public class QuestsConfigLoader { String category = config.getString("options.category"); Map placeholders = new HashMap<>(); - if (config.isConfigurationSection("placeholders")) { - for (String p : config.getConfigurationSection("placeholders").getKeys(false)) { - placeholders.put(p, config.getString("placeholders." + p)); - } - } - if (category == null) category = ""; Quest quest; @@ -211,41 +205,20 @@ public class QuestsConfigLoader { quest.registerTask(task); } - Pattern pattern = Pattern.compile("\\{([^}]+)}"); for (String line : displayItem.getLoreNormal()) { - Matcher matcher = pattern.matcher(line); - while (matcher.find()) { - String[] parts = matcher.group(1).split(":"); - boolean match = false; - for (Task t : quest.getTasks()) { - if (t.getId().equals(parts[0])) { - match = true; - break; - } - } - if (!match) - configProblems.add(new ConfigProblem(ConfigProblemType.WARNING, - ConfigProblemDescriptions.UNKNOWN_TASK_REFERENCE.getDescription(parts[0]), "display.lore-normal")); - } + findInvalidTaskReferences(quest, line, configProblems, "display.lore-normal"); } for (String line : displayItem.getLoreStarted()) { - Matcher matcher = pattern.matcher(line); - while (matcher.find()) { - String[] parts = matcher.group(1).split(":"); - boolean match = false; - for (Task t : quest.getTasks()) { - if (t.getId().equals(parts[0])) { - match = true; - break; - } - } - if (!match) - configProblems.add(new ConfigProblem(ConfigProblemType.WARNING, - ConfigProblemDescriptions.UNKNOWN_TASK_REFERENCE.getDescription(parts[0]), "display.lore-started")); - } + findInvalidTaskReferences(quest, line, configProblems, "display.lore-started"); } + if (config.isConfigurationSection("placeholders")) { + for (String p : config.getConfigurationSection("placeholders").getKeys(false)) { + placeholders.put(p, config.getString("placeholders." + p)); + findInvalidTaskReferences(quest, config.getString("placeholders." + p), configProblems, "placeholders." + p); + } + } pathToQuest.put(relativeLocation.getPath(), quest); if (!configProblems.isEmpty()) { filesWithProblems.put(relativeLocation.getPath(), configProblems); @@ -308,6 +281,25 @@ public class QuestsConfigLoader { return problemsCount; } + private void findInvalidTaskReferences(Quest quest, String s, List configProblems, String location) { + Pattern pattern = Pattern.compile("\\{([^}]+)}"); + + Matcher matcher = pattern.matcher(s); + while (matcher.find()) { + String[] parts = matcher.group(1).split(":"); + boolean match = false; + for (Task t : quest.getTasks()) { + if (t.getId().equals(parts[0])) { + match = true; + break; + } + } + if (!match) + configProblems.add(new ConfigProblem(ConfigProblemType.WARNING, + ConfigProblemDescriptions.UNKNOWN_TASK_REFERENCE.getDescription(parts[0]), location)); + } + } + private QItemStack getQItemStack(String path, FileConfiguration config) { String cName = config.getString(path + ".name", path + ".name"); List cLoreNormal = config.getStringList(path + ".lore-normal"); -- cgit v1.2.3-70-g09d2