Permalink
Browse files

v1.6.2_2

言語ファイルの文字コード問題の修正
  • Loading branch information...
hide92795 committed Aug 29, 2013
1 parent 8646eb7 commit f366cdc5519567a4f653a13fb4083bd8152fb8c8
Binary file not shown.
@@ -0,0 +1,90 @@
package hide92795.bukkit.plugin.corelib;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.util.logging.Level;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import com.google.common.io.Files;
public class LanguageConfiguration extends YamlConfiguration {
@Override
public void load(InputStream stream) throws IOException, InvalidConfigurationException {
Validate.notNull(stream, "Stream cannot be null");
InputStreamReader reader = new InputStreamReader(stream, Charset.forName("UTF-8"));
StringBuilder builder = new StringBuilder();
BufferedReader input = new BufferedReader(reader);
try {
String line;
while ((line = input.readLine()) != null) {
builder.append(line);
builder.append('\n');
}
} finally {
input.close();
}
loadFromString(builder.toString());
}
@Override
public void save(File file) throws IOException {
Validate.notNull(file, "File cannot be null");
Files.createParentDirs(file);
String data = saveToString();
try (OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8"))) {
osw.write(data);
osw.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
public static LanguageConfiguration loadConfiguration(File file) {
Validate.notNull(file, "File cannot be null");
LanguageConfiguration config = new LanguageConfiguration();
try {
config.load(file);
} catch (FileNotFoundException ex) {
} catch (IOException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex);
} catch (InvalidConfigurationException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex);
}
return config;
}
public static LanguageConfiguration loadConfiguration(InputStream stream) {
Validate.notNull(stream, "Stream cannot be null");
LanguageConfiguration config = new LanguageConfiguration();
try {
config.load(stream);
} catch (IOException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Cannot load language configuration from stream", ex);
} catch (InvalidConfigurationException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Cannot load language configuration from stream", ex);
}
return config;
}
}
@@ -3,7 +3,6 @@
import java.io.File;
import java.io.InputStream;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
public class Localize {
@@ -18,12 +17,12 @@ public Localize(JavaPlugin plugin) {
public void reload(String lang) throws Exception {
configFile = new File(plugin.getDataFolder(), lang + ".yml");
config = YamlConfiguration.loadConfiguration(configFile);
config = LanguageConfiguration.loadConfiguration(configFile);
config.options().copyDefaults(true);
InputStream defConfigStream = plugin.getResource("jp.yml");
if (defConfigStream != null) {
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
LanguageConfiguration defConfig = LanguageConfiguration.loadConfiguration(defConfigStream);
config.setDefaults(defConfig);
}
@@ -1,5 +1,5 @@
name: hide92795CoreLib
main: hide92795.bukkit.plugin.corelib.CoreLib
version: 1.6.2_1
version: 1.6.2_2
description: Core Liblary for my plugins.
author: hide92795

0 comments on commit f366cdc

Please sign in to comment.