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(":");
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("<EFBFBD>", ",");
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() {

View File

@ -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<Flag<?>, Object> parseFlags(List<String> flagStrings) {
HashMap<Flag<?>, Object> map = new HashMap<>();

View File

@ -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<PlotArea>() {
@Override public void run(PlotArea value) {
if (duplicate != null) {
if (duplicate != null) {
PS.get().foreachPlotArea(new RunnableVal<PlotArea>() {
@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<Plot>() {
@Override public void run(Plot value) {
if (duplicate != null) {
});
PS.get().foreachPlotRaw(new RunnableVal<Plot>() {
@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));
}
}
});
});
}
}
}