Skip to content

Commit 152c1aa

Browse files
committed
Better error-checking in crafting.yml
1 parent f7594a0 commit 152c1aa

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

src/main/java/io/github/thatsmusic99/headsplus/config/HeadsPlusCrafting.java

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,24 @@ private void checkOverload(String key) {
111111

112112
public List<String> getLore(String key) {
113113
List<String> lore = new ArrayList<>();
114-
if (config.get(key + ".lore").equals("{default}")) {
115-
for (String str : config.getStringList("base-item.lore")) {
116-
lore.add(messages.formatMsg(str, null)
117-
.replaceAll("\\{type}", config.getString(key + ".display-type"))
118-
.replaceAll("\\{price}", String.valueOf(getPrice(key))));
114+
try {
115+
if (config.get(key + ".lore").equals("{default}")) {
116+
for (String str : config.getStringList("base-item.lore")) {
117+
lore.add(messages.formatMsg(str, null)
118+
.replaceAll("\\{type}", config.getString(key + ".display-type"))
119+
.replaceAll("\\{price}", String.valueOf(getPrice(key))));
120+
}
121+
} else {
122+
for (String str : config.getStringList(key + ".lore")) {
123+
lore.add(messages.formatMsg(str, null));
124+
}
119125
}
120-
} else {
126+
} catch (NullPointerException ex) {
121127
for (String str : config.getStringList(key + ".lore")) {
122128
lore.add(messages.formatMsg(str, null));
123129
}
124130
}
131+
125132
return lore;
126133
}
127134

@@ -139,12 +146,19 @@ public double getPrice(String key) {
139146
}
140147

141148
public String getDisplayName(String key) {
142-
if (config.get(key + ".display-name").equals("{default}")) {
149+
try {
150+
if (config.get(key + ".display-name").equals("{default}")) {
151+
return messages.formatMsg(config.getString("base-item.display-name"), null)
152+
.replaceAll("\\{type}", config.getString(key + ".display-type"));
153+
} else {
154+
return messages.formatMsg(config.getString(key + ".display-name"), null)
155+
.replaceAll("\\{type}", config.getString(key + ".display-type"));
156+
}
157+
} catch (NullPointerException ex) {
158+
HeadsPlus.getInstance().getLogger().warning("No display name found for " + key + ", using default...");
143159
return messages.formatMsg(config.getString("base-item.display-name"), null)
144160
.replaceAll("\\{type}", config.getString(key + ".display-type"));
145-
} else {
146-
return messages.formatMsg(config.getString(key + ".display-name"), null)
147-
.replaceAll("\\{type}", config.getString(key + ".display-type"));
148161
}
162+
149163
}
150164
}

0 commit comments

Comments
 (0)