Fix issues with new Locale.

This commit is contained in:
Rsl1122 2017-08-10 15:07:01 +03:00
parent 46622d7993
commit 6dea4ecb95
2 changed files with 22 additions and 16 deletions

View File

@ -25,7 +25,7 @@ public enum Settings {
COMBINE_COMMAND_ALIASES_TO_MAIN_COMMAND("Customization.Data.CombineCommandAliasesToMainCommand"), COMBINE_COMMAND_ALIASES_TO_MAIN_COMMAND("Customization.Data.CombineCommandAliasesToMainCommand"),
SECURITY_IP_UUID("Settings.WebServer.Security.DisplayIPsAndUUIDs"), SECURITY_IP_UUID("Settings.WebServer.Security.DisplayIPsAndUUIDs"),
PLAYERLIST_SHOW_IMAGES("Customization.SmallHeadImagesOnAnalysisPlayerlist"), PLAYERLIST_SHOW_IMAGES("Customization.SmallHeadImagesOnAnalysisPlayerlist"),
WRITE_NEW_LOCALE("WriteNewLocaleFileOnStart"), WRITE_NEW_LOCALE("Settings.WriteNewLocaleFileOnStart"),
// Integer // Integer
ANALYSIS_MINUTES_FOR_ACTIVE("Settings.Analysis.MinutesPlayedUntilConsidiredActive"), ANALYSIS_MINUTES_FOR_ACTIVE("Settings.Analysis.MinutesPlayedUntilConsidiredActive"),
SAVE_CACHE_MIN("Settings.Cache.DataCache.SaveEveryXMinutes"), SAVE_CACHE_MIN("Settings.Cache.DataCache.SaveEveryXMinutes"),

View File

@ -17,6 +17,7 @@ import org.bukkit.ChatColor;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -42,10 +43,11 @@ public class Locale {
messages = new HashMap<>(); messages = new HashMap<>();
} }
public void loadLocale() throws IOException { public void loadLocale() {
String locale = Settings.LOCALE.toString().toUpperCase(); String locale = Settings.LOCALE.toString().toUpperCase();
Benchmark.start("Initializing locale"); Benchmark.start("Initializing locale");
loadDefault(); loadDefault();
try {
if (Settings.WRITE_NEW_LOCALE.isTrue()) { if (Settings.WRITE_NEW_LOCALE.isTrue()) {
writeNewDefaultLocale(); writeNewDefaultLocale();
} }
@ -57,6 +59,10 @@ public class Locale {
} else { } else {
loadFromResource("locale_" + locale + ".txt"); loadFromResource("locale_" + locale + ".txt");
} }
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
}
Benchmark.stop("Enable", "Initializing locale"); Benchmark.stop("Enable", "Initializing locale");
} }
@ -68,9 +74,9 @@ public class Locale {
.get().length() + 2; .get().length() + 2;
List<String> lines = messages.entrySet().stream() List<String> lines = messages.entrySet().stream()
.sorted(new LocaleEntryComparator()) .sorted(new LocaleEntryComparator())
.map(entry -> getSpacedIdentifier(entry.getKey().getIdentifier(), length) + "| " + entry.getValue().toString()) .map(entry -> getSpacedIdentifier(entry.getKey().getIdentifier(), length) + "|| " + entry.getValue().toString())
.collect(Collectors.toList()); .collect(Collectors.toList());
Files.write(new File(plugin.getDataFolder(), "locale.txt").toPath(), lines); Files.write(new File(plugin.getDataFolder(), "locale.txt").toPath(), lines, StandardCharsets.UTF_8);
plugin.getConfig().set(Settings.WRITE_NEW_LOCALE.getPath(), false); plugin.getConfig().set(Settings.WRITE_NEW_LOCALE.getPath(), false);
} }
@ -278,7 +284,7 @@ public class Locale {
} }
private void loadFromFile(File localeFile) throws IOException { private void loadFromFile(File localeFile) throws IOException {
loadFromContents(Files.lines(localeFile.toPath()).collect(Collectors.toList()), "Custom File"); loadFromContents(Files.lines(localeFile.toPath(), StandardCharsets.UTF_8).collect(Collectors.toList()), "Custom File");
} }
private void loadFromResource(String fileName) { private void loadFromResource(String fileName) {
@ -297,7 +303,7 @@ public class Locale {
Log.info("Using Locale: " + name); Log.info("Using Locale: " + name);
Map<String, Msg> identifiers = Msg.getIdentifiers(); Map<String, Msg> identifiers = Msg.getIdentifiers();
locale.forEach(line -> { locale.forEach(line -> {
String[] split = line.split(" \\| "); String[] split = line.split(" \\|\\| ");
if (split.length == 2) { if (split.length == 2) {
String identifier = split[0].trim(); String identifier = split[0].trim();
Msg msg = identifiers.get(identifier); Msg msg = identifiers.get(identifier);