Faster translations loading for non-users

This commit is contained in:
libraryaddict 2017-07-06 04:00:02 +12:00
parent ccd0cc8528
commit c8b908edd3

View File

@ -8,6 +8,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@ -35,20 +36,38 @@ public enum TranslateType {
if (!LibsPremium.isPremium() && DisguiseConfig.isUseTranslations()) {
System.out.println("[LibsDisguises] You must purchase the plugin to use translations!");
}
} else {
TranslateFiller.fillConfigs();
}
}
public void wipeTranslations() {
translated.clear();
}
private void reload() {
translated.clear();
wipeTranslations();
if (LibsPremium.isPremium() && DisguiseConfig.isUseTranslations()) {
System.out.println("[LibsDisguises] Loading translations: " + name());
} else {
if (!file.exists()) {
try {
file.getParentFile().mkdirs();
file.createNewFile();
FileWriter writer = new FileWriter(getFile(), true);
write(writer);
writer.close();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
return;
}
if (!file.exists())
@ -90,8 +109,6 @@ public enum TranslateType {
if (translated.containsKey(message))
return;
translated.put(message, message);
message = StringEscapeUtils.escapeJava(message.replaceAll(ChatColor.COLOR_CHAR + "", "&"));
try {
@ -105,11 +122,7 @@ public enum TranslateType {
FileWriter writer = new FileWriter(getFile(), true);
if (!exists) {
writer.write("# To use translations in Lib's Disguises, you must have the purchased plugin\n");
if (this == TranslateType.MESSAGES) {
writer.write("# %s is where text is inserted, look up printf format codes if you're interested\n");
}
write(writer);
}
writer.write("\n" + (comment != null ? "# " + comment + "\n" :
@ -122,6 +135,14 @@ public enum TranslateType {
}
}
private void write(FileWriter writer) throws IOException {
writer.write("# To use translations in Lib's Disguises, you must have the purchased plugin\n");
if (this == TranslateType.MESSAGES) {
writer.write("# %s is where text is inserted, look up printf format codes if you're interested\n");
}
}
public String reverseGet(String translated) {
if (translated == null || !LibsPremium.isPremium() || !DisguiseConfig.isUseTranslations())
return translated;