This commit is contained in:
Jesse Boyd 2016-07-12 22:12:14 +10:00
parent e859a7f56c
commit ca776b2912
3 changed files with 27 additions and 31 deletions

View File

@ -1816,14 +1816,7 @@ public class SQLManager implements AbstractDB {
String[] split = element.split(":"); String[] split = element.split(":");
try { try {
String flag_str = split[1].replaceAll("¯", ":").replaceAll("\u00B4", ","); String flag_str = split[1].replaceAll("¯", ":").replaceAll("\u00B4", ",");
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() {
return "Generic Filler Flag";
}
};
}
flags.put(flag, flag.parseValue(flag_str)); flags.put(flag, flag.parseValue(flag_str));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -1832,7 +1825,7 @@ public class SQLManager implements AbstractDB {
} else { } else {
element = element.replaceAll("\u00AF", ":").replaceAll("\u00B4", ","); element = element.replaceAll("\u00AF", ":").replaceAll("\u00B4", ",");
if (StringMan.isAlpha(element.replaceAll("_", "").replaceAll("-", ""))) { if (StringMan.isAlpha(element.replaceAll("_", "").replaceAll("-", ""))) {
Flag flag = FlagManager.getFlag(element,true); Flag flag = FlagManager.getOrCreateFlag(element);
if (flag == null) { if (flag == null) {
flag = new StringFlag(element) { flag = new StringFlag(element) {
@Override public String getValueDescription() { @Override public String getValueDescription() {
@ -2634,7 +2627,7 @@ public class SQLManager implements AbstractDB {
if (element.contains(":")) { if (element.contains(":")) {
String[] split = element.split(":"); String[] split = element.split(":");
String flag_str = split[1].replaceAll("\u00AF", ":").replaceAll("<EFBFBD>", ","); String flag_str = split[1].replaceAll("\u00AF", ":").replaceAll("<EFBFBD>", ",");
Flag flag = FlagManager.getFlag(split[0],true); Flag flag = FlagManager.getOrCreateFlag(split[0]);
if (flag == null) { if (flag == null) {
flag = new StringFlag(split[0]) { flag = new StringFlag(split[0]) {
@Override public String getValueDescription() { @Override public String getValueDescription() {
@ -2644,7 +2637,7 @@ public class SQLManager implements AbstractDB {
} }
flags.put(flag, flag.parseValue(flag_str)); flags.put(flag, flag.parseValue(flag_str));
} else { } else {
Flag flag = FlagManager.getFlag(element,true); Flag flag = FlagManager.getOrCreateFlag(element);
if (flag == null) { if (flag == null) {
flag = new StringFlag(element) { flag = new StringFlag(element) {
@Override public String getValueDescription() { @Override public String getValueDescription() {

View File

@ -317,6 +317,19 @@ public class FlagManager {
return flag; 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<Flag<?>, Object> parseFlags(List<String> flagStrings) { public static Map<Flag<?>, Object> parseFlags(List<String> flagStrings) {
HashMap<Flag<?>, Object> map = new HashMap<>(); HashMap<Flag<?>, Object> map = new HashMap<>();

View File

@ -152,35 +152,25 @@ public final class Flags {
public static void registerFlag(final Flag<?> flag) { public static void registerFlag(final Flag<?> flag) {
final Flag<?> duplicate = flags.put(flag.getName(), flag); final Flag<?> duplicate = flags.put(flag.getName(), flag);
PS.get().foreachPlotArea(new RunnableVal<PlotArea>() { if (duplicate != null) {
@Override public void run(PlotArea value) { PS.get().foreachPlotArea(new RunnableVal<PlotArea>() {
if (duplicate != null) { @Override public void run(PlotArea value) {
Object remove; Object remove;
if (value.DEFAULT_FLAGS.containsKey(duplicate)) { if (value.DEFAULT_FLAGS.containsKey(duplicate)) {
remove = value.DEFAULT_FLAGS.remove(duplicate); remove = value.DEFAULT_FLAGS.remove(duplicate);
if (!(remove instanceof String)) { value.DEFAULT_FLAGS.put(flag,flag.parseValue("" + remove));
//error message? maybe?
return;
}
value.DEFAULT_FLAGS.put(flag,flag.parseValue((String) remove));
} }
} }
} });
}); PS.get().foreachPlotRaw(new RunnableVal<Plot>() {
PS.get().foreachPlotRaw(new RunnableVal<Plot>() { @Override public void run(Plot value) {
@Override public void run(Plot value) {
if (duplicate != null) {
Object remove = null; Object remove = null;
if (value.getFlags().containsKey(duplicate)) { if (value.getFlags().containsKey(duplicate)) {
remove = value.getFlags().remove(duplicate); remove = value.getFlags().remove(duplicate);
} }
if (!(remove instanceof String)) { value.getFlags().put(flag,flag.parseValue("" + remove));
//error message? maybe?
return;
}
value.getFlags().put(flag,flag.parseValue((String) remove));
} }
} });
}); }
} }
} }