Use Guava's Files.toString API to read the email file.

This commit is contained in:
DNx5 2016-01-02 06:23:38 +07:00
parent 266c979319
commit 6cae520604

View File

@ -1,32 +1,27 @@
package fr.xephi.authme.settings; package fr.xephi.authme.settings;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.datasource.DataSource.DataSourceType;
import fr.xephi.authme.security.HashAlgorithm;
import fr.xephi.authme.util.Wrapper;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.bukkit.configuration.file.YamlConfiguration;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.datasource.DataSource.DataSourceType;
import fr.xephi.authme.security.HashAlgorithm;
import fr.xephi.authme.util.Wrapper;
/** /**
*/ */
public final class Settings { public final class Settings {
@ -313,21 +308,17 @@ public final class Settings {
if (!EMAIL_FILE.exists()) { if (!EMAIL_FILE.exists()) {
plugin.saveResource("email.html", false); plugin.saveResource("email.html", false);
} }
StringBuilder str = new StringBuilder();
try { try {
BufferedReader in = new BufferedReader(new FileReader(EMAIL_FILE)); return Files.toString(EMAIL_FILE, Charsets.UTF_8);
String s; } catch (IOException e) {
while ((s = in.readLine()) != null) ConsoleLogger.showError(e.getMessage());
str.append(s); ConsoleLogger.writeStackTrace(e);
in.close(); return "";
} catch (IOException ignored) {
} }
return str.toString();
} }
/** /**
* * @param key the key to set
* @param key the key to set
* @param value the value to set * @param value the value to set
*/ */
public static void setValue(String key, Object value) { public static void setValue(String key, Object value) {
@ -370,8 +361,8 @@ public final class Settings {
* return false if ip and name doesn't match with player that join the * return false if ip and name doesn't match with player that join the
* server, so player has a restricted access * server, so player has a restricted access
* *
* @param name String * @param name String
* @param ip String * @param ip String
* @param domain String * @param domain String
* *
* @return boolean * @return boolean
@ -387,14 +378,12 @@ public final class Settings {
String testIp = args[1]; String testIp = args[1];
if (testName.equalsIgnoreCase(name)) { if (testName.equalsIgnoreCase(name)) {
nameFound = true; nameFound = true;
if (ip != null) if (ip != null) {
{
if (testIp.equalsIgnoreCase(ip)) { if (testIp.equalsIgnoreCase(ip)) {
trueOnce = true; trueOnce = true;
} }
} }
if (domain != null) if (domain != null) {
{
if (testIp.equalsIgnoreCase(domain)) { if (testIp.equalsIgnoreCase(domain)) {
trueOnce = true; trueOnce = true;
} }
@ -728,10 +717,9 @@ public final class Settings {
changes = true; changes = true;
} }
if (!contains("settings.preventOtherCase")) if (!contains("settings.preventOtherCase")) {
{ set("settings.preventOtherCase", false);
set("settings.preventOtherCase", false); changes = true;
changes = true;
} }
if (contains("Email.mailText")) { if (contains("Email.mailText")) {
@ -740,15 +728,14 @@ public final class Settings {
} }
if (!contains("Security.stop.kickPlayersBeforeStopping")) { if (!contains("Security.stop.kickPlayersBeforeStopping")) {
set("Security.stop.kickPlayersBeforeStopping", true); set("Security.stop.kickPlayersBeforeStopping", true);
changes = true; changes = true;
} }
if (!contains("Email.emailOauth2Token")) if (!contains("Email.emailOauth2Token"))
set("Email.emailOauth2Token", ""); set("Email.emailOauth2Token", "");
if (!contains("Hook.sendPlayerTo")) if (!contains("Hook.sendPlayerTo")) {
{
set("Hooks.sendPlayerTo", ""); set("Hooks.sendPlayerTo", "");
changes = true; changes = true;
} }
@ -760,8 +747,8 @@ public final class Settings {
} }
/** /**
*
* @param path * @param path
*
* @return * @return
*/ */
private static boolean contains(String path) { private static boolean contains(String path) {
@ -769,9 +756,9 @@ public final class Settings {
} }
// public because it's used in AuthMe at one place // public because it's used in AuthMe at one place
/** /**
* * @param path String
* @param path String
* @param value String * @param value String
*/ */
public void set(String path, Object value) { public void set(String path, Object value) {