diff --git a/src/main/java/net/citizensnpcs/Citizens.java b/src/main/java/net/citizensnpcs/Citizens.java index 7a0fccb44..f582d89a1 100644 --- a/src/main/java/net/citizensnpcs/Citizens.java +++ b/src/main/java/net/citizensnpcs/Citizens.java @@ -199,10 +199,10 @@ public class Citizens extends JavaPlugin implements CitizensPlugin { getServer().getPluginManager().disablePlugin(this); return; } + config = new Settings(getDataFolder()); setupTranslator(); registerScriptHelpers(); - config = new Settings(getDataFolder()); saves = NPCDataStore.create(getDataFolder()); if (saves == null) { Messaging.severeTr(Messages.FAILED_LOAD_SAVES); diff --git a/src/main/java/net/citizensnpcs/Settings.java b/src/main/java/net/citizensnpcs/Settings.java index 6006cfc69..d0b09036c 100644 --- a/src/main/java/net/citizensnpcs/Settings.java +++ b/src/main/java/net/citizensnpcs/Settings.java @@ -7,8 +7,6 @@ import java.util.List; import net.citizensnpcs.api.util.DataKey; import net.citizensnpcs.api.util.Storage; import net.citizensnpcs.api.util.YamlStorage; -import net.citizensnpcs.util.Messages; -import net.citizensnpcs.util.Messaging; import com.google.common.collect.Lists; @@ -23,7 +21,6 @@ public class Settings { config.load(); for (Setting setting : Setting.values()) { if (!root.keyExists(setting.path)) { - Messaging.logTr(Messages.WRITING_DEFAULT_SETTING, setting.path); setting.setAtKey(root); } else setting.loadFromKey(root); diff --git a/src/main/java/net/citizensnpcs/util/Translator.java b/src/main/java/net/citizensnpcs/util/Translator.java index 103b75dd3..aacedaf8d 100644 --- a/src/main/java/net/citizensnpcs/util/Translator.java +++ b/src/main/java/net/citizensnpcs/util/Translator.java @@ -3,6 +3,7 @@ package net.citizensnpcs.util; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; @@ -13,6 +14,8 @@ import java.util.MissingResourceException; import java.util.ResourceBundle; import com.google.common.collect.Maps; +import com.google.common.io.Files; +import com.google.common.io.InputSupplier; public class Translator { private final Locale defaultLocale; @@ -110,13 +113,50 @@ public class Translator { } else { string = string.replaceFirst("/", ""); InputStream stream = Translator.class.getResourceAsStream('/' + string); - if (stream != null) + if (stream != null) { + new Thread(new SaveResourceThread(folder, string)).start(); return stream; + } } return super.getResourceAsStream(string); } } + private static class SaveResourceThread implements Runnable { + private final String fileName; + private final File rootFolder; + + private SaveResourceThread(File rootFolder, String fileName) { + this.rootFolder = rootFolder; + this.fileName = fileName; + } + + @Override + public void run() { + File file = new File(rootFolder, fileName); + if (file.exists()) + return; + final InputStream stream = Translator.class.getResourceAsStream('/' + fileName); + if (stream == null) + return; + InputSupplier in = new InputSupplier() { + @Override + public InputStream getInput() throws IOException { + return stream; + } + }; + try { + File to = File.createTempFile(fileName, null, rootFolder); + to.deleteOnExit(); + Files.copy(in, to); + if (!file.exists()) + to.renameTo(file); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + private static Translator instance; public static final String PREFIX = "messages"; diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index 1a12e0fa0..b7e67f885 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -7,7 +7,6 @@ citizens.commands.invalid-number=That is not a valid number. citizens.commands.npc.age.cannot-be-aged=The mob type '{0}' cannot be aged. citizens.commands.npc.age.invalid-age=Invalid age. Valid ages are adult, baby, number between -24000 and 0 citizens.commands.npc.age.set=[[{0}]] is now [[{1}]]. -citizens.notifications.missing-translations=Missing translations file for locale {0}. Defaulting to en locale. citizens.commands.npc.behaviour.added=Behaviours added. citizens.commands.npc.behaviour.removed=Behaviours removed. citizens.commands.npc.controllable.not-controllable=[[{0}]] is not controllable. @@ -115,6 +114,7 @@ citizens.notifications.incompatible-version=v{0} is not compatible with Minecraf citizens.notifications.locale=Using locale {0}. citizens.notifications.metrics-load-error=Unable to start metrics: {0}. citizens.notifications.metrics-started=Metrics started. +citizens.notifications.missing-translations=Missing translations file for locale {0}. Defaulting to en locale. citizens.notifications.npc-name-not-found=Could not find a name for ID '{0}'. citizens.notifications.npc-not-found=No NPC could be found. citizens.notifications.npcs-loaded=Loaded {0} NPCs ({1} spawned).