mirror of
https://github.com/PikaMug/Quests.git
synced 2025-03-02 11:31:10 +01:00
Support non-English characters in lang files, untested, fixes #116
This commit is contained in:
parent
2f08800e8c
commit
341cafb17a
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<groupId>me.blackvein.quests</groupId>
|
<groupId>me.blackvein.quests</groupId>
|
||||||
<artifactId>quests</artifactId>
|
<artifactId>quests</artifactId>
|
||||||
<version>3.0.7</version>
|
<version>3.0.8</version>
|
||||||
<name>quests</name>
|
<name>quests</name>
|
||||||
<url>https://github.com/FlyingPikachu/Quests/</url>
|
<url>https://github.com/FlyingPikachu/Quests/</url>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package me.blackvein.quests.util;
|
package me.blackvein.quests.util;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
@ -9,6 +12,7 @@ import java.util.Map;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
@ -959,7 +963,7 @@ public class Lang {
|
|||||||
langMap.put("questSaveError", "An error occurred while saving.");
|
langMap.put("questSaveError", "An error occurred while saving.");
|
||||||
langMap.put("questBlacklisted", "You are blacklisted. Contact an admin if this is in error.");
|
langMap.put("questBlacklisted", "You are blacklisted. Contact an admin if this is in error.");
|
||||||
//
|
//
|
||||||
File file = new File(plugin.getDataFolder(), "/lang/" + lang + ".yml");
|
File file = new File(plugin.getDataFolder(), File.separator + "lang" + File.separator + lang + ".yml");
|
||||||
YamlConfiguration langFile = YamlConfiguration.loadConfiguration(file);
|
YamlConfiguration langFile = YamlConfiguration.loadConfiguration(file);
|
||||||
for (Entry<String, Object> e : langFile.getValues(true).entrySet()) {
|
for (Entry<String, Object> e : langFile.getValues(true).entrySet()) {
|
||||||
langMap.put(e.getKey(), (String) e.getValue());
|
langMap.put(e.getKey(), (String) e.getValue());
|
||||||
@ -968,8 +972,8 @@ public class Lang {
|
|||||||
|
|
||||||
public void saveNewLang() {
|
public void saveNewLang() {
|
||||||
FileConfiguration data = new YamlConfiguration();
|
FileConfiguration data = new YamlConfiguration();
|
||||||
File dir = new File(plugin.getDataFolder(), "/lang");
|
File dir = new File(plugin.getDataFolder(), File.separator + "lang");
|
||||||
File file = new File(plugin.getDataFolder(), "/lang/en.yml");
|
File file = new File(plugin.getDataFolder(), File.separator + "lang" + File.separator + "en.yml");
|
||||||
for (Entry<String, String> e : langMap.entrySet()) {
|
for (Entry<String, String> e : langMap.entrySet()) {
|
||||||
data.set(e.getKey(), e.getValue());
|
data.set(e.getKey(), e.getValue());
|
||||||
}
|
}
|
||||||
@ -988,7 +992,7 @@ public class Lang {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void loadLang() {
|
public void loadLang() {
|
||||||
File langFile = new File(plugin.getDataFolder(), "/lang/" + lang + ".yml");
|
File langFile = new File(plugin.getDataFolder(), File.separator + "lang" + File.separator + lang + ".yml");
|
||||||
boolean newLangs = false;
|
boolean newLangs = false;
|
||||||
if (langFile.exists()) {
|
if (langFile.exists()) {
|
||||||
LinkedHashMap<String, String> tempMap = new LinkedHashMap<String, String>();
|
LinkedHashMap<String, String> tempMap = new LinkedHashMap<String, String>();
|
||||||
@ -1010,7 +1014,7 @@ public class Lang {
|
|||||||
}
|
}
|
||||||
langMap.putAll(toPut);
|
langMap.putAll(toPut);
|
||||||
if (newLangs) {
|
if (newLangs) {
|
||||||
File file = new File(plugin.getDataFolder(), "/lang/" + lang + "_new.yml");
|
File file = new File(plugin.getDataFolder(), File.separator + "lang" + File.separator + lang + "_new.yml");
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
file.delete();
|
file.delete();
|
||||||
}
|
}
|
||||||
@ -1036,6 +1040,30 @@ public class Lang {
|
|||||||
plugin.getLogger().severe("Attempted to load language file: /lang/" + lang + ".yml but the file was not found. Using default language EN");
|
plugin.getLogger().severe("Attempted to load language file: /lang/" + lang + ".yml but the file was not found. Using default language EN");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load YAML file using UTF8 format to allow extended characters
|
||||||
|
* @param file
|
||||||
|
* @return yaml
|
||||||
|
* @throws InvalidConfigurationException
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static YamlConfiguration loadYamlUTF8(File file) throws InvalidConfigurationException, IOException {
|
||||||
|
StringBuilder sb = new StringBuilder((int) file.length());
|
||||||
|
|
||||||
|
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
|
||||||
|
char[] buf = new char[1024];
|
||||||
|
int l;
|
||||||
|
while ((l = in.read(buf, 0, buf.length)) > -1) {
|
||||||
|
sb = sb.append(buf, 0, l);
|
||||||
|
}
|
||||||
|
in.close();
|
||||||
|
|
||||||
|
YamlConfiguration yaml = new YamlConfiguration();
|
||||||
|
yaml.loadFromString(sb.toString());
|
||||||
|
|
||||||
|
return yaml;
|
||||||
|
}
|
||||||
|
|
||||||
private static class LangToken {
|
private static class LangToken {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user