cleanup Settings

This commit is contained in:
DNx5 2015-09-14 18:58:37 +07:00
parent 550cffcc42
commit 0768642e85
4 changed files with 63 additions and 87 deletions

View File

@ -5,6 +5,7 @@ import com.google.gson.*;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.Utils; import fr.xephi.authme.Utils;
import fr.xephi.authme.settings.Settings;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -28,7 +29,7 @@ public class JsonCache {
public JsonCache(AuthMe plugin) { public JsonCache(AuthMe plugin) {
this.plugin = plugin; this.plugin = plugin;
cacheDir = new File(plugin.getDataFolder(), "cache"); cacheDir = Settings.CACHE_FOLDER;
if (!cacheDir.exists() && !cacheDir.isDirectory() && !cacheDir.mkdir()) { if (!cacheDir.exists() && !cacheDir.isDirectory() && !cacheDir.mkdir()) {
ConsoleLogger.showError("Failed to create cache directory."); ConsoleLogger.showError("Failed to create cache directory.");
} }

View File

@ -517,11 +517,7 @@ public class AdminCommand implements CommandExecutor {
if (Settings.applyBlindEffect) if (Settings.applyBlindEffect)
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2)); target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2));
m.send(target, "unregistered"); m.send(target, "unregistered");
} else {
// Player isn't online, do nothing else
} }
} else {
// Player does not exist, do nothing else
} }
m.send(sender, "unregistered"); m.send(sender, "unregistered");
ConsoleLogger.info(args[1] + " unregistered"); ConsoleLogger.info(args[1] + " unregistered");

View File

@ -104,13 +104,13 @@ public class Messages extends CustomConfiguration {
public static Messages getInstance() { public static Messages getInstance() {
if (singleton == null) { if (singleton == null) {
singleton = new Messages(new File(Settings.MESSAGE_DIR, "messages_" + Settings.messagesLanguage + ".yml"), Settings.messagesLanguage); singleton = new Messages(Settings.messageFile, Settings.messagesLanguage);
} }
return singleton; return singleton;
} }
public void reloadMessages() { public void reloadMessages() {
singleton = new Messages(new File(Settings.MESSAGE_DIR, "messages_" + Settings.messagesLanguage + ".yml"), Settings.messagesLanguage); singleton = new Messages(Settings.messageFile, Settings.messagesLanguage);
} }
} }

View File

@ -5,7 +5,6 @@ import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.datasource.DataSource.DataSourceType; import fr.xephi.authme.datasource.DataSource.DataSourceType;
import fr.xephi.authme.security.HashAlgorithm; import fr.xephi.authme.security.HashAlgorithm;
import org.bukkit.configuration.MemoryConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import java.io.*; import java.io.*;
@ -15,14 +14,16 @@ import java.util.List;
public final class Settings extends YamlConfiguration { public final class Settings extends YamlConfiguration {
private AuthMe plugin;
// This is not an option! // This is not an option!
public static Boolean antiBotInAction = false; public static Boolean antiBotInAction = false;
public static final File PLUGIN_FOLDER = AuthMe.getInstance().getDataFolder(); public static final File PLUGIN_FOLDER;
public static final File CACHE_FOLDER = new File(PLUGIN_FOLDER, "cache"); public static final File CACHE_FOLDER;
public static final File AUTH_FILE = new File(PLUGIN_FOLDER, "auths.db"); public static final File AUTH_FILE;
public static final File MESSAGE_DIR = new File(PLUGIN_FOLDER, "messages"); public static final File SETTINGS_FILE;
public static final File SETTINGS_FILE = new File(PLUGIN_FOLDER, "config.yml"); public static File messageFile;
public static List<String> allowCommands = null; public static List<String> allowCommands = null;
public static List<String> getJoinPermissions = null; public static List<String> getJoinPermissions = null;
public static List<String> getUnrestrictedName = null; public static List<String> getUnrestrictedName = null;
@ -35,7 +36,6 @@ public final class Settings extends YamlConfiguration {
public static List<String> forceCommandsAsConsole = null; public static List<String> forceCommandsAsConsole = null;
public static List<String> forceRegisterCommands = null; public static List<String> forceRegisterCommands = null;
public static List<String> forceRegisterCommandsAsConsole = null; public static List<String> forceRegisterCommandsAsConsole = null;
private AuthMe plugin;
public static DataSourceType getDataSource; public static DataSourceType getDataSource;
public static HashAlgorithm getPasswordHash; public static HashAlgorithm getPasswordHash;
public static Boolean useLogging = false; public static Boolean useLogging = false;
@ -71,7 +71,7 @@ public final class Settings extends YamlConfiguration {
getMySQLTablename, getMySQLColumnName, getMySQLColumnPassword, getMySQLTablename, getMySQLColumnName, getMySQLColumnPassword,
getMySQLColumnIp, getMySQLColumnLastLogin, getMySQLColumnSalt, getMySQLColumnIp, getMySQLColumnLastLogin, getMySQLColumnSalt,
getMySQLColumnGroup, getMySQLColumnEmail, unRegisteredGroup, getMySQLColumnGroup, getMySQLColumnEmail, unRegisteredGroup,
backupWindowsPath, getcUnrestrictedName, getRegisteredGroup, backupWindowsPath, getRegisteredGroup,
messagesLanguage, getMySQLlastlocX, getMySQLlastlocY, messagesLanguage, getMySQLlastlocX, getMySQLlastlocY,
getMySQLlastlocZ, rakamakUsers, rakamakUsersIp, getmailAccount, getMySQLlastlocZ, rakamakUsers, rakamakUsersIp, getmailAccount,
getmailPassword, getmailSMTP, getMySQLColumnId, getmailSenderName, getmailPassword, getmailSMTP, getMySQLColumnId, getmailSenderName,
@ -91,17 +91,23 @@ public final class Settings extends YamlConfiguration {
protected static YamlConfiguration configFile; protected static YamlConfiguration configFile;
static {
PLUGIN_FOLDER = AuthMe.getInstance().getDataFolder();
CACHE_FOLDER = new File(PLUGIN_FOLDER, "cache");
AUTH_FILE = new File(PLUGIN_FOLDER, "auths.db");
SETTINGS_FILE = new File(PLUGIN_FOLDER, "config.yml");
}
public Settings(AuthMe plugin) { public Settings(AuthMe plugin) {
configFile = (YamlConfiguration) plugin.getConfig(); configFile = (YamlConfiguration) plugin.getConfig();
this.plugin = plugin; this.plugin = plugin;
boolean exist = exists(); boolean exist = exists();
if (exist) { if (!exist) {
load();
} else {
plugin.saveDefaultConfig(); plugin.saveDefaultConfig();
load();
} }
load();
loadConfigOptions(exist); loadConfigOptions(exist);
messageFile = new File(PLUGIN_FOLDER, "messages" + File.separator + "messages_" + messagesLanguage + ".yml");
} }
public void loadConfigOptions(boolean exist) { public void loadConfigOptions(boolean exist) {
@ -277,133 +283,127 @@ public final class Settings extends YamlConfiguration {
} }
public static void reloadConfigOptions(YamlConfiguration newConfig) {
configFile = newConfig;
loadVariables();
}
public void mergeConfig() { public void mergeConfig() {
boolean changes = false; int changes = 0;
if (contains("Xenoforo.predefinedSalt")) if (contains("Xenoforo.predefinedSalt"))
set("Xenoforo.predefinedSalt", null); set("Xenoforo.predefinedSalt", null);
if (configFile.getString("settings.security.passwordHash", "SHA256").toUpperCase().equals("XFSHA1") || configFile.getString("settings.security.passwordHash", "SHA256").toUpperCase().equals("XFSHA256")) if (configFile.getString("settings.security.passwordHash", "SHA256").toUpperCase().equals("XFSHA1") || configFile.getString("settings.security.passwordHash", "SHA256").toUpperCase().equals("XFSHA256"))
set("settings.security.passwordHash", "XENFORO"); set("settings.security.passwordHash", "XENFORO");
if (!contains("Protection.enableProtection")) { if (!contains("Protection.enableProtection")) {
set("Protection.enableProtection", false); set("Protection.enableProtection", false);
changes = true; changes++;
} }
if (!contains("Protection.countries")) { if (!contains("Protection.countries")) {
countries = new ArrayList<String>(); countries = new ArrayList<>();
countries.add("US"); countries.add("US");
countries.add("GB"); countries.add("GB");
set("Protection.countries", countries); set("Protection.countries", countries);
changes = true; changes++;
} }
if (!contains("Protection.enableAntiBot")) { if (!contains("Protection.enableAntiBot")) {
set("Protection.enableAntiBot", false); set("Protection.enableAntiBot", false);
changes = true; changes++;
} }
if (!contains("Protection.antiBotSensibility")) { if (!contains("Protection.antiBotSensibility")) {
set("Protection.antiBotSensibility", 5); set("Protection.antiBotSensibility", 5);
changes = true; changes++;
} }
if (!contains("Protection.antiBotDuration")) { if (!contains("Protection.antiBotDuration")) {
set("Protection.antiBotDuration", 10); set("Protection.antiBotDuration", 10);
changes = true; changes++;
} }
if (!contains("settings.forceCommands")) { if (!contains("settings.forceCommands")) {
set("settings.forceCommands", new ArrayList<String>()); set("settings.forceCommands", new ArrayList<String>());
changes = true; changes++;
} }
if (!contains("settings.forceCommandsAsConsole")) { if (!contains("settings.forceCommandsAsConsole")) {
set("settings.forceCommandsAsConsole", new ArrayList<String>()); set("settings.forceCommandsAsConsole", new ArrayList<String>());
changes = true; changes++;
} }
if (!contains("Email.recallPlayers")) { if (!contains("Email.recallPlayers")) {
set("Email.recallPlayers", false); set("Email.recallPlayers", false);
changes = true; changes++;
} }
if (!contains("Email.delayRecall")) { if (!contains("Email.delayRecall")) {
set("Email.delayRecall", 5); set("Email.delayRecall", 5);
changes = true; changes++;
} }
if (!contains("settings.useWelcomeMessage")) { if (!contains("settings.useWelcomeMessage")) {
set("settings.useWelcomeMessage", true); set("settings.useWelcomeMessage", true);
changes = true; changes++;
} }
if (!contains("settings.security.unsafePasswords")) { if (!contains("settings.security.unsafePasswords")) {
List<String> str = new ArrayList<String>(); List<String> str = new ArrayList<>();
str.add("123456"); str.add("123456");
str.add("password"); str.add("password");
set("settings.security.unsafePasswords", str); set("settings.security.unsafePasswords", str);
changes = true; changes++;
} }
if (!contains("Protection.countriesBlacklist")) { if (!contains("Protection.countriesBlacklist")) {
countriesBlacklist = new ArrayList<String>(); countriesBlacklist = new ArrayList<>();
countriesBlacklist.add("A1"); countriesBlacklist.add("A1");
set("Protection.countriesBlacklist", countriesBlacklist); set("Protection.countriesBlacklist", countriesBlacklist);
changes = true; changes++;
} }
if (!contains("settings.broadcastWelcomeMessage")) { if (!contains("settings.broadcastWelcomeMessage")) {
set("settings.broadcastWelcomeMessage", false); set("settings.broadcastWelcomeMessage", false);
changes = true; changes++;
} }
if (!contains("settings.registration.forceKickAfterRegister")) { if (!contains("settings.registration.forceKickAfterRegister")) {
set("settings.registration.forceKickAfterRegister", false); set("settings.registration.forceKickAfterRegister", false);
changes = true; changes++;
} }
if (!contains("settings.registration.forceLoginAfterRegister")) { if (!contains("settings.registration.forceLoginAfterRegister")) {
set("settings.registration.forceLoginAfterRegister", false); set("settings.registration.forceLoginAfterRegister", false);
changes = true; changes++;
} }
if (!contains("DataSource.mySQLColumnLogged")) { if (!contains("DataSource.mySQLColumnLogged")) {
set("DataSource.mySQLColumnLogged", "isLogged"); set("DataSource.mySQLColumnLogged", "isLogged");
changes = true; changes++;
} }
if (!contains("settings.restrictions.spawnPriority")) { if (!contains("settings.restrictions.spawnPriority")) {
set("settings.restrictions.spawnPriority", "authme,essentials,multiverse,default"); set("settings.restrictions.spawnPriority", "authme,essentials,multiverse,default");
changes = true; changes++;
} }
if (!contains("settings.restrictions.maxLoginPerIp")) { if (!contains("settings.restrictions.maxLoginPerIp")) {
set("settings.restrictions.maxLoginPerIp", 0); set("settings.restrictions.maxLoginPerIp", 0);
changes = true; changes++;
} }
if (!contains("settings.restrictions.maxJoinPerIp")) { if (!contains("settings.restrictions.maxJoinPerIp")) {
set("settings.restrictions.maxJoinPerIp", 0); set("settings.restrictions.maxJoinPerIp", 0);
changes = true; changes++;
} }
if (!contains("VeryGames.enableIpCheck")) { if (!contains("VeryGames.enableIpCheck")) {
set("VeryGames.enableIpCheck", false); set("VeryGames.enableIpCheck", false);
changes = true; changes++;
} }
if (getString("settings.restrictions.allowedNicknameCharacters").equals("[a-zA-Z0-9_?]*")) if (getString("settings.restrictions.allowedNicknameCharacters").equals("[a-zA-Z0-9_?]*"))
set("settings.restrictions.allowedNicknameCharacters", "[a-zA-Z0-9_]*"); set("settings.restrictions.allowedNicknameCharacters", "[a-zA-Z0-9_]*");
if (!contains("settings.delayJoinMessage")) { if (!contains("settings.delayJoinMessage")) {
set("settings.delayJoinMessage", false); set("settings.delayJoinMessage", false);
changes = true; changes++;
} }
if (!contains("settings.restrictions.noTeleport")) { if (!contains("settings.restrictions.noTeleport")) {
set("settings.restrictions.noTeleport", false); set("settings.restrictions.noTeleport", false);
changes = true; changes++;
} }
if (contains("Converter.Rakamak.newPasswordHash")) if (contains("Converter.Rakamak.newPasswordHash"))
set("Converter.Rakamak.newPasswordHash", null); set("Converter.Rakamak.newPasswordHash", null);
if (!contains("Converter.CrazyLogin.fileName")) { if (!contains("Converter.CrazyLogin.fileName")) {
set("Converter.CrazyLogin.fileName", "accounts.db"); set("Converter.CrazyLogin.fileName", "accounts.db");
changes = true; changes++;
} }
if (!contains("settings.restrictions.allowedPasswordCharacters")) { if (!contains("settings.restrictions.allowedPasswordCharacters")) {
set("settings.restrictions.allowedPasswordCharacters", "[\\x21-\\x7E]*"); set("settings.restrictions.allowedPasswordCharacters", "[\\x21-\\x7E]*");
changes = true; changes++;
} }
if (!contains("settings.applyBlindEffect")) { if (!contains("settings.applyBlindEffect")) {
set("settings.applyBlindEffect", false); set("settings.applyBlindEffect", false);
changes = true; changes++;
} }
if (!contains("Email.emailBlacklisted")) { if (!contains("Email.emailBlacklisted")) {
set("Email.emailBlacklisted", new ArrayList<String>()); set("Email.emailBlacklisted", new ArrayList<String>());
changes = true; changes++;
} }
if (contains("Performances.useMultiThreading")) if (contains("Performances.useMultiThreading"))
set("Performances.useMultiThreading", null); set("Performances.useMultiThreading", null);
@ -419,23 +419,23 @@ public final class Settings extends YamlConfiguration {
if (!contains("Email.emailWhitelisted")) { if (!contains("Email.emailWhitelisted")) {
set("Email.emailWhitelisted", new ArrayList<String>()); set("Email.emailWhitelisted", new ArrayList<String>());
changes = true; changes++;
} }
if (!contains("settings.forceRegisterCommands")) { if (!contains("settings.forceRegisterCommands")) {
set("settings.forceRegisterCommands", new ArrayList<String>()); set("settings.forceRegisterCommands", new ArrayList<String>());
changes = true; changes++;
} }
if (!contains("settings.forceRegisterCommandsAsConsole")) { if (!contains("settings.forceRegisterCommandsAsConsole")) {
set("settings.forceRegisterCommandsAsConsole", new ArrayList<String>()); set("settings.forceRegisterCommandsAsConsole", new ArrayList<String>());
changes = true; changes++;
} }
if (!contains("Hooks.customAttributes")) { if (!contains("Hooks.customAttributes")) {
set("Hooks.customAttributes", false); set("Hooks.customAttributes", false);
changes = true; changes++;
} }
if (!contains("Purge.removePermissions")) { if (!contains("Purge.removePermissions")) {
set("Purge.removePermissions", false); set("Purge.removePermissions", false);
changes = true; changes++;
} }
if (contains("Hooks.notifications")) if (contains("Hooks.notifications"))
set("Hooks.notifications", null); set("Hooks.notifications", null);
@ -447,19 +447,17 @@ public final class Settings extends YamlConfiguration {
set("Hooks.legacyChestshop", useChestShop); set("Hooks.legacyChestshop", useChestShop);
if (!contains("Email.generateImage")) { if (!contains("Email.generateImage")) {
set("Email.generateImage", true); set("Email.generateImage", true);
changes = true; changes++;
} }
if (!contains("DataSource.mySQLRealName")) { if (!contains("DataSource.mySQLRealName")) {
set("DataSource.mySQLRealName", "realname"); set("DataSource.mySQLRealName", "realname");
changes = true; changes++;
} }
if (changes) { if (changes > 0) {
plugin.getLogger().warning("Merge new Config Options - I'm not an error, please don't report me"); plugin.getLogger().warning("Merge " + changes + " new Config Options - I'm not an error, please don't report me");
plugin.getLogger().warning("Please check your config.yml file for new configs!"); plugin.getLogger().warning("Please check your config.yml file for new configs!");
} }
return;
} }
public void setValue(String key, Object value) { public void setValue(String key, Object value) {
@ -506,7 +504,6 @@ public final class Settings extends YamlConfiguration {
if (testip.equalsIgnoreCase(ip)) { if (testip.equalsIgnoreCase(ip)) {
trueonce = true; trueonce = true;
} }
;
} }
} }
if (!namefound) { if (!namefound) {
@ -576,24 +573,8 @@ public final class Settings extends YamlConfiguration {
return success; return success;
} }
/**
* Clears current configuration defaults
*/
public final void clearDefaults() {
setDefaults(new MemoryConfiguration());
}
/**
* Check loaded defaults against current configuration
*
* @return false When all defaults aren't present in config
*/
public boolean checkDefaults() {
return getDefaults() == null || getKeys(true).containsAll(getDefaults().getKeys(true));
}
public static String checkLang(String lang) { public static String checkLang(String lang) {
if (new File(MESSAGE_DIR, "messages_" + lang + ".yml").exists()) { if (new File(PLUGIN_FOLDER, "messages" + File.separator + "messages_" + lang + ".yml").exists()) {
ConsoleLogger.info("Set Language to: " + lang); ConsoleLogger.info("Set Language to: " + lang);
return lang; return lang;
} }
@ -636,13 +617,11 @@ public final class Settings extends YamlConfiguration {
try { try {
FileReader fr = new FileReader(plugin.getDataFolder() + File.separator + "welcome.txt"); FileReader fr = new FileReader(plugin.getDataFolder() + File.separator + "welcome.txt");
BufferedReader br = new BufferedReader(fr); BufferedReader br = new BufferedReader(fr);
String line = ""; String line;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
welcomeMsg.add(line); welcomeMsg.add(line);
} }
br.close(); br.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }