aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/com/leonardobishop
diff options
context:
space:
mode:
authorLMBishop <13875753+LMBishop@users.noreply.github.com>2021-02-16 01:04:58 +0000
committerLMBishop <13875753+LMBishop@users.noreply.github.com>2021-02-16 01:04:58 +0000
commit2c15c7ee927070b9e9b25bd206dc3351425d8361 (patch)
tree983916172c1a256090a961b39d2cdde1f8f60367 /src/main/java/com/leonardobishop
parent995646262b3be0c3c5ea107d1b1bb3637c0da71e (diff)
Add error checking to placeholders
Diffstat (limited to 'src/main/java/com/leonardobishop')
-rw-r--r--src/main/java/com/leonardobishop/quests/QuestsConfigLoader.java62
1 files changed, 27 insertions, 35 deletions
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<String, String> 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<ConfigProblem> 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<String> cLoreNormal = config.getStringList(path + ".lore-normal");