Allow ThingParsers to throw exceptions on invalid input instead of expecting them to return null.
This allows for a much more well-defined, fail-fast process, where a parser can abort on valid prefix but invalid input.
This commit is contained in:
@@ -74,12 +74,16 @@ public class MAUtils
|
||||
|
||||
List<Thing> things = new ArrayList<>();
|
||||
for (String reward : rewards.split(",")) {
|
||||
try {
|
||||
Thing thing = plugin.getThingManager().parse(reward.trim());
|
||||
if (thing == null) {
|
||||
plugin.getLogger().warning("Failed to parse reward: " + reward.trim());
|
||||
} else {
|
||||
things.add(thing);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().severe("Exception parsing reward '" + reward.trim() + "': " + e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
result.put(wave, things);
|
||||
}
|
||||
|
||||
@@ -18,13 +18,7 @@ class MoneyThingParser implements ThingParser {
|
||||
if (money == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Double value = valueOf(money);
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new MoneyThing(plugin, value);
|
||||
return new MoneyThing(plugin, Double.parseDouble(money));
|
||||
}
|
||||
|
||||
private String trimPrefix(String s) {
|
||||
@@ -36,13 +30,4 @@ class MoneyThingParser implements ThingParser {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Double valueOf(String money) {
|
||||
try {
|
||||
return Double.parseDouble(money);
|
||||
} catch (NumberFormatException e) {
|
||||
plugin.getLogger().warning("Invalid economy value: " + money);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,11 +307,15 @@ public class WaveParser
|
||||
// Rewards!
|
||||
String rew = config.getString("reward");
|
||||
if (rew != null) {
|
||||
Thing reward = arena.getPlugin().getThingManager().parse(rew);
|
||||
if (reward == null) {
|
||||
Bukkit.getLogger().warning("[MobArena] Failed to parse boss reward: " + rew);
|
||||
try {
|
||||
Thing thing = arena.getPlugin().getThingManager().parse(rew.trim());
|
||||
if (thing == null) {
|
||||
arena.getPlugin().getLogger().warning("Failed to parse boss reward: " + rew.trim());
|
||||
} else {
|
||||
result.setReward(reward);
|
||||
result.setReward(thing);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
arena.getPlugin().getLogger().severe("Exception parsing boss reward '" + rew.trim() + "': " + e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user