From ca776b29128ef79a18211bc09b4fe38bd3bd25fb Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Tue, 12 Jul 2016 22:12:14 +1000 Subject: [PATCH] Fixes #1226 --- .../plot/database/SQLManager.java | 15 +++------- .../plot/flag/FlagManager.java | 13 ++++++++ .../intellectualcrafters/plot/flag/Flags.java | 30 +++++++------------ 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index 0d91604ba..64bdaafef 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -1816,14 +1816,7 @@ public class SQLManager implements AbstractDB { String[] split = element.split(":"); try { String flag_str = split[1].replaceAll("¯", ":").replaceAll("\u00B4", ","); - Flag flag = FlagManager.getFlag(split[0],true); - if (flag == null) { - flag = new StringFlag(split[0]) { - @Override public String getValueDescription() { - return "Generic Filler Flag"; - } - }; - } + Flag flag = FlagManager.getOrCreateFlag(split[0]); flags.put(flag, flag.parseValue(flag_str)); } catch (Exception e) { e.printStackTrace(); @@ -1832,7 +1825,7 @@ public class SQLManager implements AbstractDB { } else { element = element.replaceAll("\u00AF", ":").replaceAll("\u00B4", ","); if (StringMan.isAlpha(element.replaceAll("_", "").replaceAll("-", ""))) { - Flag flag = FlagManager.getFlag(element,true); + Flag flag = FlagManager.getOrCreateFlag(element); if (flag == null) { flag = new StringFlag(element) { @Override public String getValueDescription() { @@ -2634,7 +2627,7 @@ public class SQLManager implements AbstractDB { if (element.contains(":")) { String[] split = element.split(":"); String flag_str = split[1].replaceAll("\u00AF", ":").replaceAll("�", ","); - Flag flag = FlagManager.getFlag(split[0],true); + Flag flag = FlagManager.getOrCreateFlag(split[0]); if (flag == null) { flag = new StringFlag(split[0]) { @Override public String getValueDescription() { @@ -2644,7 +2637,7 @@ public class SQLManager implements AbstractDB { } flags.put(flag, flag.parseValue(flag_str)); } else { - Flag flag = FlagManager.getFlag(element,true); + Flag flag = FlagManager.getOrCreateFlag(element); if (flag == null) { flag = new StringFlag(element) { @Override public String getValueDescription() { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java index aa8154feb..bd7c1bb97 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java @@ -317,6 +317,19 @@ public class FlagManager { return flag; } + public static Flag getOrCreateFlag(String string) { + Flag flag = Flags.getFlag(string); + if (flag == null) { + flag = new StringFlag(string) { + @Override public String getValueDescription() { + return "Generic Filler Flag"; + } + }; + flag.register(); + } + return flag; + } + public static Map, Object> parseFlags(List flagStrings) { HashMap, Object> map = new HashMap<>(); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/Flags.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/Flags.java index fc991ea21..7b8247d25 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/Flags.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/Flags.java @@ -152,35 +152,25 @@ public final class Flags { public static void registerFlag(final Flag flag) { final Flag duplicate = flags.put(flag.getName(), flag); - PS.get().foreachPlotArea(new RunnableVal() { - @Override public void run(PlotArea value) { - if (duplicate != null) { + if (duplicate != null) { + PS.get().foreachPlotArea(new RunnableVal() { + @Override public void run(PlotArea value) { Object remove; if (value.DEFAULT_FLAGS.containsKey(duplicate)) { remove = value.DEFAULT_FLAGS.remove(duplicate); - if (!(remove instanceof String)) { - //error message? maybe? - return; - } - value.DEFAULT_FLAGS.put(flag,flag.parseValue((String) remove)); + value.DEFAULT_FLAGS.put(flag,flag.parseValue("" + remove)); } } - } - }); - PS.get().foreachPlotRaw(new RunnableVal() { - @Override public void run(Plot value) { - if (duplicate != null) { + }); + PS.get().foreachPlotRaw(new RunnableVal() { + @Override public void run(Plot value) { Object remove = null; if (value.getFlags().containsKey(duplicate)) { remove = value.getFlags().remove(duplicate); } - if (!(remove instanceof String)) { - //error message? maybe? - return; - } - value.getFlags().put(flag,flag.parseValue((String) remove)); + value.getFlags().put(flag,flag.parseValue("" + remove)); } - } - }); + }); + } } }