From c8b908edd32ac63f60765b52406a8fc1ee8ea686 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Thu, 6 Jul 2017 04:00:02 +1200 Subject: [PATCH] Faster translations loading for non-users --- .../disguise/utilities/TranslateType.java | 41 ++++++++++++++----- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/src/me/libraryaddict/disguise/utilities/TranslateType.java b/src/me/libraryaddict/disguise/utilities/TranslateType.java index a9b81758..5d20ca57 100644 --- a/src/me/libraryaddict/disguise/utilities/TranslateType.java +++ b/src/me/libraryaddict/disguise/utilities/TranslateType.java @@ -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,9 +36,9 @@ public enum TranslateType { if (!LibsPremium.isPremium() && DisguiseConfig.isUseTranslations()) { System.out.println("[LibsDisguises] You must purchase the plugin to use translations!"); + } else { + TranslateFiller.fillConfigs(); } - - TranslateFiller.fillConfigs(); } public void wipeTranslations() { @@ -45,10 +46,28 @@ public enum TranslateType { } 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;