From 546b857b9da3d7b30a76bec1a4790ebf18f24970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Sat, 11 Apr 2020 17:19:43 +0200 Subject: [PATCH] Fail default flag parsing gracefully --- .../plotsquared/plot/object/PlotArea.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java index 390787f65..4f07eb279 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java @@ -27,6 +27,7 @@ package com.github.intellectualsites.plotsquared.plot.object; import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection; import com.github.intellectualsites.plotsquared.plot.PlotSquared; +import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Configuration; import com.github.intellectualsites.plotsquared.plot.config.ConfigurationNode; import com.github.intellectualsites.plotsquared.plot.config.Settings; @@ -335,13 +336,7 @@ public abstract class PlotArea { } } } - try { - this.getFlagContainer().addAll(parseFlags(flags)); - } catch (FlagParseException e) { - e.printStackTrace(); - PlotSquared.debug("&cInvalid default flags for " + this.getWorldName() + ": " + StringMan - .join(flags, ",")); - } + this.getFlagContainer().addAll(parseFlags(flags)); this.spawnEggs = config.getBoolean("event.spawn.egg"); this.spawnCustom = config.getBoolean("event.spawn.custom"); this.spawnBreeding = config.getBoolean("event.spawn.breeding"); @@ -1017,7 +1012,7 @@ public abstract class PlotArea { this.terrain = terrain; } - private static Collection> parseFlags(List flagStrings) throws FlagParseException { + private static Collection> parseFlags(List flagStrings) { final Collection> flags = new ArrayList<>(); for (final String key : flagStrings) { final String[] split; @@ -1028,7 +1023,14 @@ public abstract class PlotArea { } final PlotFlag flagInstance = GlobalFlagContainer.getInstance().getFlagFromString(split[0]); if (flagInstance != null) { - flags.add(flagInstance.parse(split[1])); + try { + flags.add(flagInstance.parse(split[1])); + } catch (final FlagParseException e) { + PlotSquared.log(Captions.PREFIX.getTranslated() + + String.format("§2Failed to parse default flag with key §6'%s'§c and value: §6'%s'§c." + + " Reason: %s. This flag will not be added as a default flag.", + e.getFlag().getName(), e.getValue(), e.getErrorMessage())); + } } } return flags;