mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
Force more compilation errors
This commit is contained in:
parent
c5e1b87c61
commit
32a0765484
@ -830,130 +830,4 @@ public enum Captions implements Caption {
|
|||||||
CUSTOM_STRING("-", "-");
|
CUSTOM_STRING("-", "-");
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
|
|
||||||
public static final HashMap<String, String> replacements = new HashMap<>();
|
|
||||||
|
|
||||||
private final String defaultString;
|
|
||||||
private final String category;
|
|
||||||
private final boolean prefix;
|
|
||||||
private String translatedString;
|
|
||||||
private String[] replacementKeys;
|
|
||||||
|
|
||||||
Captions(String defaultString, boolean prefix, String category, String... replacementKeys) {
|
|
||||||
this.defaultString = defaultString;
|
|
||||||
this.translatedString = defaultString;
|
|
||||||
this.prefix = prefix;
|
|
||||||
this.category = category.toLowerCase();
|
|
||||||
this.replacementKeys = replacementKeys;
|
|
||||||
}
|
|
||||||
|
|
||||||
Captions(String defaultString, String category, String... replacementKeys) {
|
|
||||||
this(defaultString, true, category.toLowerCase(), replacementKeys);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String color(String string) {
|
|
||||||
return StringMan.replaceFromMap(string, replacements);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void load(File file) {
|
|
||||||
try {
|
|
||||||
if (!file.exists()) {
|
|
||||||
file.getParentFile().mkdirs();
|
|
||||||
file.createNewFile();
|
|
||||||
}
|
|
||||||
YamlConfiguration yml = YamlConfiguration.loadConfiguration(file);
|
|
||||||
Set<String> keys = yml.getKeys(true);
|
|
||||||
EnumSet<Captions> allEnums = EnumSet.allOf(Captions.class);
|
|
||||||
HashSet<String> allNames = new HashSet<>();
|
|
||||||
HashSet<String> categories = new HashSet<>();
|
|
||||||
for (Captions caption : allEnums) {
|
|
||||||
allNames.add(caption.name());
|
|
||||||
categories.add(caption.category.toLowerCase());
|
|
||||||
}
|
|
||||||
HashSet<Captions> captions = new HashSet<>();
|
|
||||||
boolean changed = false;
|
|
||||||
HashSet<String> toRemove = new HashSet<>();
|
|
||||||
for (String key : keys) {
|
|
||||||
if (!yml.isString(key)) {
|
|
||||||
if (!categories.contains(key)) {
|
|
||||||
toRemove.add(key);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String[] split = key.split("\\.");
|
|
||||||
String node = split[split.length - 1].toUpperCase();
|
|
||||||
Captions caption;
|
|
||||||
if (allNames.contains(node)) {
|
|
||||||
caption = valueOf(node);
|
|
||||||
} else {
|
|
||||||
caption = null;
|
|
||||||
}
|
|
||||||
if (caption != null) {
|
|
||||||
if (caption.category.startsWith("static")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String value = yml.getString(key);
|
|
||||||
if (!split[0].equalsIgnoreCase(caption.category)) {
|
|
||||||
changed = true;
|
|
||||||
yml.set(key, null);
|
|
||||||
yml.set(caption.category + '.' + caption.name().toLowerCase(), value);
|
|
||||||
}
|
|
||||||
captions.add(caption);
|
|
||||||
caption.translatedString = value;
|
|
||||||
} else {
|
|
||||||
toRemove.add(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (String remove : toRemove) {
|
|
||||||
changed = true;
|
|
||||||
yml.set(remove, null);
|
|
||||||
}
|
|
||||||
ConfigurationSection config = PlotSquared.get().style.getConfigurationSection("color");
|
|
||||||
Set<String> styles = config.getKeys(false);
|
|
||||||
// HashMap<String, String> replacements = new HashMap<>();
|
|
||||||
replacements.clear();
|
|
||||||
for (String style : styles) {
|
|
||||||
replacements.put('$' + style, '\u00A7' + config.getString(style));
|
|
||||||
}
|
|
||||||
for (char letter : "1234567890abcdefklmnor".toCharArray()) {
|
|
||||||
replacements.put("&" + letter, "\u00a7" + letter);
|
|
||||||
}
|
|
||||||
replacements.put("\\\\n", "\n");
|
|
||||||
replacements.put("\\n", "\n");
|
|
||||||
replacements.put("&-", "\n");
|
|
||||||
for (Captions caption : allEnums) {
|
|
||||||
if (!captions.contains(caption)) {
|
|
||||||
if (caption.getCategory().startsWith("static")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
changed = true;
|
|
||||||
yml.set(caption.category + '.' + caption.name().toLowerCase(),
|
|
||||||
caption.defaultString);
|
|
||||||
}
|
|
||||||
caption.translatedString =
|
|
||||||
StringMan.replaceFromMap(caption.translatedString, replacements);
|
|
||||||
}
|
|
||||||
if (changed) {
|
|
||||||
yml.save(file);
|
|
||||||
}
|
|
||||||
} catch (IOException | IllegalArgumentException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public String getTranslated() {
|
|
||||||
return this.translatedString;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean usePrefix() {
|
|
||||||
return this.prefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCategory() {
|
|
||||||
return this.category;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public String toString() {
|
|
||||||
return this.getTranslated();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user