Fix charset issues with locale file reading

This commit is contained in:
Esophose 2019-12-13 07:02:05 -07:00
parent 2d7c78a06c
commit a6c6b9d8ac
7 changed files with 18 additions and 15 deletions

View file

@ -25,7 +25,7 @@ dependencies {
compile 'org.slf4j:slf4j-nop:1.7.25'
compile 'com.zaxxer:HikariCP:3.2.0'
compile 'com.googlecode.json-simple:json-simple:1.1.1'
compile 'me.clip:placeholderapi:2.10.4'
shadow 'me.clip:placeholderapi:2.10.4'
shadow 'org.xerial:sqlite-jdbc:3.23.1'
shadow 'org.spigotmc:spigot-api:1.15-R0.1-SNAPSHOT'
}

View file

@ -1,15 +1,16 @@
package dev.esophose.playerparticles.config;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.Charset;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
@ -66,7 +67,7 @@ public class CommentedFileConfigurationHelper {
String pluginName = this.getPluginName();
StringBuilder whole = new StringBuilder();
BufferedReader reader = new BufferedReader(new FileReader(file));
BufferedReader reader = Files.newBufferedReader(Paths.get(file.getAbsolutePath()), StandardCharsets.UTF_8);
String currentLine;
while ((currentLine = reader.readLine()) != null) {
@ -81,7 +82,7 @@ public class CommentedFileConfigurationHelper {
}
String config = whole.toString();
Reader configStream = new InputStreamReader(new ByteArrayInputStream(config.getBytes(StandardCharsets.UTF_8)));
Reader configStream = new StringReader(config);
reader.close();
return configStream;
@ -105,7 +106,7 @@ public class CommentedFileConfigurationHelper {
int comments = 0;
String currentLine;
BufferedReader reader = new BufferedReader(new FileReader(file));
BufferedReader reader = Files.newBufferedReader(Paths.get(file.getAbsolutePath()), StandardCharsets.UTF_8);
while ((currentLine = reader.readLine()) != null)
if (currentLine.trim().startsWith("#"))
@ -210,7 +211,7 @@ public class CommentedFileConfigurationHelper {
}
}
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(file.getAbsolutePath()))) {
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(file.getAbsolutePath()), StandardCharsets.UTF_8)) {
writer.write(stringBuilder.toString());
writer.flush();
} catch (IOException e) {

View file

@ -43,7 +43,7 @@ public class GuiInventoryLoadPresetGroups extends GuiInventory {
particles.sort(Comparator.comparingInt(ParticlePair::getId));
String[] lore = new String[particles.size() + 1];
lore[0] = localeManager.getLocaleMessage("gui-color-subtext") + localeManager.getLocaleMessage("gui-click-to-load", StringPlaceholders.single("id", particles.size()));
lore[0] = localeManager.getLocaleMessage("gui-color-subtext") + localeManager.getLocaleMessage("gui-click-to-load", StringPlaceholders.single("amount", particles.size()));
int i = 1;
for (ParticlePair particle : particles) {
StringPlaceholders stringPlaceholders = StringPlaceholders.builder("id", particle.getId())

View file

@ -304,7 +304,7 @@ public class FrenchLocale implements Locale {
this.put("gui-select-data-description", "Mets les paramètres de la particule à &b%data%");
this.put("gui-select-data-note", "note #%note%");
this.put("#38", "GUI Color Name Messages");
this.put("gui-edit-data-color-red", "&crouge");
this.put("gui-edit-data-color-orange", "&6orange");
this.put("gui-edit-data-color-yellow", "&ejaune");

View file

@ -303,7 +303,7 @@ public class GermanLocale implements Locale {
this.put("gui-select-data-description", "Setzt die Partikeldaten auf &b%data%");
this.put("gui-select-data-note", "Hinweis #%note%");
this.put("#38", "GUI Color Name Messages");
this.put("gui-edit-data-color-red", "Rot");
this.put("gui-edit-data-color-orange", "Orange");
this.put("gui-edit-data-color-yellow", "Gelb");

View file

@ -304,7 +304,7 @@ public class VietnameseLocale implements Locale {
this.put("gui-select-data-description", "Thiết lập DỮ liệu của Hạt thành &b%data%");
this.put("gui-select-data-note", "note #%note%");
this.put("#38", "GUI Color Name Messages");
this.put("gui-edit-data-color-red", "&cĐỏ mạnh mẽ");
this.put("gui-edit-data-color-orange", "&6Cam dịu dàng");
this.put("gui-edit-data-color-yellow", "&eVàng yêu thương");

View file

@ -61,6 +61,9 @@ public class LocaleManager extends Manager {
} else {
Map<String, String> defaultLocaleStrings = locale.getDefaultLocaleStrings();
for (String key : defaultLocaleStrings.keySet()) {
if (key.startsWith("#"))
continue;
String value = defaultLocaleStrings.get(key);
if (!configuration.contains(key))
configuration.set(key, value);
@ -103,7 +106,6 @@ public class LocaleManager extends Manager {
public String getLocaleMessage(String messageKey, StringPlaceholders stringPlaceholders) {
String message = this.locale.getString(messageKey);
System.out.println("Message: " + messageKey + " = " + message);
if (message == null)
return "null";
return ChatColor.translateAlternateColorCodes('&', stringPlaceholders.apply(message));
@ -138,7 +140,7 @@ public class LocaleManager extends Manager {
* @param messageKey The message key of the Locale to send
*/
public void sendMessage(CommandSender sender, String messageKey) {
this.sendMessage(sender, messageKey, new StringPlaceholders());
this.sendMessage(sender, messageKey, StringPlaceholders.empty());
}
/**
@ -148,7 +150,7 @@ public class LocaleManager extends Manager {
* @param messageKey The message key of the Locale to send
*/
public void sendMessage(PPlayer pplayer, String messageKey) {
this.sendMessage(pplayer, messageKey);
this.sendMessage(pplayer, messageKey, StringPlaceholders.empty());
}
/**