#450 Move Settings#loadEmailText and #getWelcomeMessage
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package fr.xephi.authme.settings;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.io.Files;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.settings.domain.Property;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.SettingsFieldRetriever;
|
||||
import fr.xephi.authme.settings.propertymap.PropertyMap;
|
||||
import fr.xephi.authme.util.CollectionUtils;
|
||||
@@ -16,6 +18,7 @@ import org.yaml.snakeyaml.Yaml;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -31,7 +34,10 @@ public class NewSetting {
|
||||
private final File pluginFolder;
|
||||
private final File configFile;
|
||||
private FileConfiguration configuration;
|
||||
/** The file with the localized messages based on {@link PluginSettings#MESSAGES_LANGUAGE}. */
|
||||
private File messagesFile;
|
||||
private List<String> welcomeMessage;
|
||||
private String emailMessage;
|
||||
|
||||
/**
|
||||
* Constructor. Checks the given {@link FileConfiguration} object for completeness.
|
||||
@@ -45,6 +51,8 @@ public class NewSetting {
|
||||
this.configFile = configFile;
|
||||
this.pluginFolder = pluginFolder;
|
||||
messagesFile = buildMessagesFile();
|
||||
welcomeMessage = readWelcomeMessage();
|
||||
emailMessage = readEmailMessage();
|
||||
|
||||
PropertyMap propertyMap = SettingsFieldRetriever.getAllPropertyFields();
|
||||
if (SettingsMigrationService.checkAndMigrate(configuration, propertyMap, pluginFolder)) {
|
||||
@@ -110,6 +118,14 @@ public class NewSetting {
|
||||
return messagesFile;
|
||||
}
|
||||
|
||||
public String getEmailMessage() {
|
||||
return emailMessage;
|
||||
}
|
||||
|
||||
public List<String> getWelcomeMessage() {
|
||||
return welcomeMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload the configuration.
|
||||
*/
|
||||
@@ -189,6 +205,54 @@ public class NewSetting {
|
||||
makePath("messages", "messages_" + language + ".yml"));
|
||||
}
|
||||
|
||||
private List<String> readWelcomeMessage() {
|
||||
if (getProperty(RegistrationSettings.USE_WELCOME_MESSAGE)) {
|
||||
final File welcomeFile = new File(pluginFolder, "welcome.txt");
|
||||
final Charset charset = Charset.forName("UTF-8");
|
||||
if (!welcomeFile.exists()) {
|
||||
try {
|
||||
Files.write(
|
||||
"Welcome {PLAYER} to {SERVER} server\n\nThis server uses AuthMe protection!",
|
||||
welcomeFile, charset);
|
||||
} catch (IOException e) {
|
||||
ConsoleLogger.showError("Failed to create file '" + welcomeFile.getPath() + "': "
|
||||
+ StringUtils.formatException(e));
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
return Files.readLines(welcomeFile, charset);
|
||||
} catch (IOException e) {
|
||||
ConsoleLogger.showError("Failed to read file '" + welcomeFile.getPath() + "': " +
|
||||
StringUtils.formatException(e));
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
}
|
||||
}
|
||||
return new ArrayList<>(0);
|
||||
}
|
||||
|
||||
private String readEmailMessage() {
|
||||
final File emailFile = new File(pluginFolder, "email.txt");
|
||||
final Charset charset = Charset.forName("UTF-8");
|
||||
if (!emailFile.exists()) {
|
||||
try {
|
||||
Files.write("", emailFile, charset);
|
||||
} catch (IOException e) {
|
||||
ConsoleLogger.showError("Failed to create file '" + emailFile.getPath() + "': "
|
||||
+ StringUtils.formatException(e));
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
return StringUtils.join("", Files.readLines(emailFile, charset));
|
||||
} catch (IOException e) {
|
||||
ConsoleLogger.showError("Failed to read file '" + emailFile.getPath() + "': " +
|
||||
StringUtils.formatException(e));
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private static Yaml newYaml(boolean useSingleQuotes) {
|
||||
DumperOptions options = new DumperOptions();
|
||||
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
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.StringUtils;
|
||||
import fr.xephi.authme.util.Wrapper;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
@@ -30,12 +27,10 @@ public final class Settings {
|
||||
public static final File PLUGIN_FOLDER = Wrapper.getInstance().getDataFolder();
|
||||
public static final File MODULE_FOLDER = new File(PLUGIN_FOLDER, "modules");
|
||||
public static final File CACHE_FOLDER = new File(PLUGIN_FOLDER, "cache");
|
||||
private static final File EMAIL_FILE = new File(PLUGIN_FOLDER, "email.html");
|
||||
private static final File SETTINGS_FILE = new File(PLUGIN_FOLDER, "config.yml");
|
||||
public static final File LOG_FILE = new File(PLUGIN_FOLDER, "authme.log");
|
||||
// This is not an option!
|
||||
public static boolean antiBotInAction = false;
|
||||
public static File messageFile;
|
||||
public static List<String> allowCommands;
|
||||
public static List<String> getJoinPermissions;
|
||||
public static List<String> getUnrestrictedName;
|
||||
@@ -48,7 +43,6 @@ public final class Settings {
|
||||
public static List<String> forceCommandsAsConsole;
|
||||
public static List<String> forceRegisterCommands;
|
||||
public static List<String> forceRegisterCommandsAsConsole;
|
||||
public static List<String> welcomeMsg;
|
||||
public static List<String> unsafePasswords;
|
||||
public static List<String> emailBlacklist;
|
||||
public static List<String> emailWhitelist;
|
||||
@@ -85,11 +79,10 @@ public final class Settings {
|
||||
backupWindowsPath, getRegisteredGroup,
|
||||
messagesLanguage, getMySQLlastlocX, getMySQLlastlocY,
|
||||
getMySQLlastlocZ, rakamakUsers, rakamakUsersIp, getmailAccount,
|
||||
getmailPassword, getmailSMTP, getMySQLColumnId, getmailSenderName,
|
||||
getMailSubject, getMailText, getMySQLlastlocWorld, defaultWorld,
|
||||
getMySQLColumnId, getMySQLlastlocWorld, defaultWorld,
|
||||
getPhpbbPrefix, getWordPressPrefix, getMySQLColumnLogged,
|
||||
spawnPriority, crazyloginFileName, getPassRegex,
|
||||
getMySQLColumnRealName, emailOauth2Token, sendPlayerTo;
|
||||
getMySQLColumnRealName, sendPlayerTo;
|
||||
public static int getWarnMessageInterval, getSessionTimeout,
|
||||
getRegistrationTimeout, getMaxNickLength, getMinNickLength,
|
||||
getPasswordMinLen, getMovementRadius, getmaxRegPerIp,
|
||||
@@ -129,7 +122,6 @@ public final class Settings {
|
||||
if (exist) {
|
||||
instance.saveDefaults();
|
||||
}
|
||||
messageFile = new File(PLUGIN_FOLDER, "messages" + File.separator + "messages_" + messagesLanguage + ".yml");
|
||||
}
|
||||
|
||||
public static void loadVariables() {
|
||||
@@ -217,19 +209,14 @@ public final class Settings {
|
||||
noConsoleSpam = configFile.getBoolean("Security.console.noConsoleSpam", false);
|
||||
removePassword = configFile.getBoolean("Security.console.removePassword", true);
|
||||
getmailAccount = configFile.getString("Email.mailAccount", "");
|
||||
getmailPassword = configFile.getString("Email.mailPassword", "");
|
||||
getmailSMTP = configFile.getString("Email.mailSMTP", "smtp.gmail.com");
|
||||
getMailPort = configFile.getInt("Email.mailPort", 465);
|
||||
getRecoveryPassLength = configFile.getInt("Email.RecoveryPasswordLength", 8);
|
||||
getMySQLOtherUsernameColumn = configFile.getStringList("ExternalBoardOptions.mySQLOtherUsernameColumns");
|
||||
displayOtherAccounts = configFile.getBoolean("settings.restrictions.displayOtherAccounts", true);
|
||||
getMySQLColumnId = configFile.getString("DataSource.mySQLColumnId", "id");
|
||||
getmailSenderName = configFile.getString("Email.mailSenderName", "");
|
||||
useCaptcha = configFile.getBoolean("Security.captcha.useCaptcha", false);
|
||||
maxLoginTry = configFile.getInt("Security.captcha.maxLoginTry", 5);
|
||||
captchaLength = configFile.getInt("Security.captcha.captchaLength", 5);
|
||||
getMailSubject = configFile.getString("Email.mailSubject", "Your new AuthMe Password");
|
||||
getMailText = loadEmailText();
|
||||
emailRegistration = configFile.getBoolean("settings.registration.enableEmailRegistrationSystem", false);
|
||||
saltLength = configFile.getInt("settings.security.doubleMD5SaltLength", 8);
|
||||
getmaxRegPerEmail = configFile.getInt("Email.maxRegPerEmail", 1);
|
||||
@@ -288,25 +275,8 @@ public final class Settings {
|
||||
generateImage = configFile.getBoolean("Email.generateImage", false);
|
||||
preventOtherCase = configFile.getBoolean("settings.preventOtherCase", false);
|
||||
kickPlayersBeforeStopping = configFile.getBoolean("Security.stop.kickPlayersBeforeStopping", true);
|
||||
emailOauth2Token = configFile.getString("Email.emailOauth2Token", "");
|
||||
sendPlayerTo = configFile.getString("Hooks.sendPlayerTo", "");
|
||||
|
||||
// Load the welcome message
|
||||
getWelcomeMessage();
|
||||
|
||||
}
|
||||
|
||||
private static String loadEmailText() {
|
||||
if (!EMAIL_FILE.exists()) {
|
||||
plugin.saveResource("email.html", false);
|
||||
}
|
||||
try {
|
||||
return Files.toString(EMAIL_FILE, Charsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
ConsoleLogger.showError("Error loading email text: " + StringUtils.formatException(e));
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -388,37 +358,6 @@ public final class Settings {
|
||||
}
|
||||
}
|
||||
|
||||
private static void getWelcomeMessage() {
|
||||
AuthMe plugin = AuthMe.getInstance();
|
||||
welcomeMsg = new ArrayList<>();
|
||||
if (!useWelcomeMessage) {
|
||||
return;
|
||||
}
|
||||
if (!(new File(plugin.getDataFolder() + File.separator + "welcome.txt").exists())) {
|
||||
try {
|
||||
FileWriter fw = new FileWriter(plugin.getDataFolder() + File.separator + "welcome.txt", true);
|
||||
BufferedWriter w = new BufferedWriter(fw);
|
||||
w.write("Welcome {PLAYER} on {SERVER} server");
|
||||
w.newLine();
|
||||
w.write("This server uses " + AuthMe.getPluginName() + " protection!");
|
||||
w.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
try {
|
||||
FileReader fr = new FileReader(plugin.getDataFolder() + File.separator + "welcome.txt");
|
||||
BufferedReader br = new BufferedReader(fr);
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
welcomeMsg.add(line);
|
||||
}
|
||||
br.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves current configuration (plus defaults) to disk.
|
||||
* <p>
|
||||
|
||||
Reference in New Issue
Block a user