mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-22 10:36:09 +01:00
Avoid exception on unpopulated lang files, fixes #2063
This commit is contained in:
parent
e38e6006c4
commit
43e9b6a7ae
@ -201,7 +201,7 @@ public class Lang {
|
|||||||
+ File.separator + "strings.yml");
|
+ File.separator + "strings.yml");
|
||||||
final File langFile_new = new File(plugin.getPluginDataFolder(), File.separator + "lang" + File.separator + iso
|
final File langFile_new = new File(plugin.getPluginDataFolder(), File.separator + "lang" + File.separator + iso
|
||||||
+ File.separator + "strings_new.yml");
|
+ File.separator + "strings_new.yml");
|
||||||
final boolean exists_new = langFile_new.exists();
|
boolean exists_new = langFile_new.exists();
|
||||||
final LinkedHashMap<String, String> allStrings = new LinkedHashMap<>();
|
final LinkedHashMap<String, String> allStrings = new LinkedHashMap<>();
|
||||||
if (!(langFile.exists() && iso.split("-").length > 1)) {
|
if (!(langFile.exists() && iso.split("-").length > 1)) {
|
||||||
if (defaultLang.isEmpty()) {
|
if (defaultLang.isEmpty()) {
|
||||||
@ -225,21 +225,22 @@ public class Lang {
|
|||||||
allStrings.put(key, config.getString(key));
|
allStrings.put(key, config.getString(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FileConfiguration config = null;
|
FileConfiguration config;
|
||||||
try {
|
if (langFile.length() > 4) {
|
||||||
config = YamlConfiguration
|
config = YamlConfiguration
|
||||||
.loadConfiguration(new InputStreamReader(new FileInputStream(langFile), StandardCharsets.UTF_8));
|
.loadConfiguration(new InputStreamReader(new FileInputStream(langFile), StandardCharsets.UTF_8));
|
||||||
} catch (Exception e) {
|
} else {
|
||||||
plugin.getPluginLogger().severe("Unable to load config for language " + iso);
|
config = YamlConfiguration.loadConfiguration(new InputStreamReader(Objects
|
||||||
e.printStackTrace();
|
.requireNonNull(plugin.getPluginResource("strings.yml")), StandardCharsets.UTF_8));
|
||||||
}
|
|
||||||
if (config == null) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
FileConfiguration config_new = null;
|
FileConfiguration config_new = null;
|
||||||
if (exists_new) {
|
if (exists_new) {
|
||||||
|
if (langFile_new.length() > 5) {
|
||||||
config_new = YamlConfiguration.loadConfiguration(new InputStreamReader(
|
config_new = YamlConfiguration.loadConfiguration(new InputStreamReader(
|
||||||
new FileInputStream(langFile_new), StandardCharsets.UTF_8));
|
new FileInputStream(langFile_new), StandardCharsets.UTF_8));
|
||||||
|
} else {
|
||||||
|
exists_new = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Load user's lang file and determine new strings
|
// Load user's lang file and determine new strings
|
||||||
for (final String key : config.getKeys(false)) {
|
for (final String key : config.getKeys(false)) {
|
||||||
@ -308,7 +309,11 @@ public class Lang {
|
|||||||
} else {
|
} else {
|
||||||
otherLang.put(iso, allStrings);
|
otherLang.put(iso, allStrings);
|
||||||
}
|
}
|
||||||
|
if (langFile.length() > 4) {
|
||||||
plugin.getPluginLogger().info("Loaded language " + iso + ". Translations via Crowdin");
|
plugin.getPluginLogger().info("Loaded language " + iso + ". Translations via Crowdin");
|
||||||
|
} else {
|
||||||
|
plugin.getPluginLogger().info("Failed to load language " + iso + " due to lack of translations");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class LangToken {
|
private static class LangToken {
|
||||||
|
Loading…
Reference in New Issue
Block a user