diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java index b15f4043..d0b36840 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java @@ -196,7 +196,7 @@ public class AuthMePlayerListener implements Listener { } if (Settings.removeJoinMessage) { - event.setJoinMessage((String)null); + event.setJoinMessage(null); return; } if (!Settings.delayJoinMessage) { @@ -210,7 +210,7 @@ public class AuthMePlayerListener implements Listener { if (joinMsg == null) { return; } - event.setJoinMessage((String)null); + event.setJoinMessage(null); joinMessage.put(name, joinMsg); } @@ -366,7 +366,7 @@ public class AuthMePlayerListener implements Listener { } if (Settings.removeLeaveMessage) { - event.setQuitMessage((String)null); + event.setQuitMessage(null); } plugin.getManagement().performQuit(player, false); @@ -391,7 +391,7 @@ public class AuthMePlayerListener implements Listener { /* * <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - * TODO #360: npc status can be used to bypass security!!! + * Note #360: npc status can be used to bypass security!!! * <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */ diff --git a/src/main/java/fr/xephi/authme/settings/Settings.java b/src/main/java/fr/xephi/authme/settings/Settings.java index c4c8adc5..262838dc 100644 --- a/src/main/java/fr/xephi/authme/settings/Settings.java +++ b/src/main/java/fr/xephi/authme/settings/Settings.java @@ -1,15 +1,18 @@ package fr.xephi.authme.settings; 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.settings.domain.Property; +import fr.xephi.authme.settings.properties.DatabaseSettings; +import fr.xephi.authme.settings.properties.PluginSettings; +import fr.xephi.authme.settings.properties.RegistrationSettings; +import fr.xephi.authme.settings.properties.RestrictionSettings; +import fr.xephi.authme.settings.properties.SecuritySettings; import fr.xephi.authme.util.Wrapper; import org.bukkit.configuration.file.FileConfiguration; import java.io.File; -import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -23,8 +26,6 @@ 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 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 List allowCommands; @@ -105,7 +106,7 @@ public final class Settings { } public static void loadVariables() { - isPermissionCheckEnabled = configFile.getBoolean("permission.EnablePermissionCheck", false); + isPermissionCheckEnabled = load(PluginSettings.ENABLE_PERMISSION_CHECK); isForcedRegistrationEnabled = configFile.getBoolean("settings.registration.force", true); isRegistrationEnabled = configFile.getBoolean("settings.registration.enabled", true); isTeleportToSpawnEnabled = configFile.getBoolean("settings.restrictions.teleportUnAuthedToSpawn", false); @@ -132,16 +133,16 @@ public final class Settings { isSaveQuitLocationEnabled = configFile.getBoolean("settings.restrictions.SaveQuitLocation", false); isForceSurvivalModeEnabled = configFile.getBoolean("settings.GameMode.ForceSurvivalMode", false); getmaxRegPerIp = configFile.getInt("settings.restrictions.maxRegPerIp", 1); - getPasswordHash = getPasswordHash(); - getUnloggedinGroup = configFile.getString("settings.security.unLoggedinGroup", "unLoggedInGroup"); - getDataSource = getDataSource(); - isCachingEnabled = configFile.getBoolean("DataSource.caching", true); - getMySQLHost = configFile.getString("DataSource.mySQLHost", "127.0.0.1"); - getMySQLPort = configFile.getString("DataSource.mySQLPort", "3306"); - getMySQLUsername = configFile.getString("DataSource.mySQLUsername", "authme"); - getMySQLPassword = configFile.getString("DataSource.mySQLPassword", "12345"); - getMySQLDatabase = configFile.getString("DataSource.mySQLDatabase", "authme"); - getMySQLTablename = configFile.getString("DataSource.mySQLTablename", "authme"); + getPasswordHash = load(SecuritySettings.PASSWORD_HASH); + getUnloggedinGroup = load(SecuritySettings.UNLOGGEDIN_GROUP); + getDataSource = load(DatabaseSettings.BACKEND); + isCachingEnabled = load(DatabaseSettings.USE_CACHING); + getMySQLHost = load(DatabaseSettings.MYSQL_HOST); + getMySQLPort = load(DatabaseSettings.MYSQL_PORT); + getMySQLUsername = load(DatabaseSettings.MYSQL_USERNAME); + getMySQLPassword = load(DatabaseSettings.MYSQL_PASSWORD); + getMySQLDatabase = load(DatabaseSettings.MYSQL_DATABASE); + getMySQLTablename = load(DatabaseSettings.MYSQL_TABLE); getMySQLColumnEmail = configFile.getString("DataSource.mySQLColumnEmail", "email"); getMySQLColumnName = configFile.getString("DataSource.mySQLColumnName", "username"); getMySQLColumnPassword = configFile.getString("DataSource.mySQLColumnPassword", "password"); @@ -163,15 +164,15 @@ public final class Settings { } getRegisteredGroup = configFile.getString("GroupOptions.RegisteredPlayerGroup", ""); - enablePasswordConfirmation = configFile.getBoolean("settings.restrictions.enablePasswordConfirmation", true); + enablePasswordConfirmation = load(RestrictionSettings.ENABLE_PASSWORD_CONFIRMATION); - protectInventoryBeforeLogInEnabled = configFile.getBoolean("settings.restrictions.ProtectInventoryBeforeLogIn", true); - denyTabcompleteBeforeLogin = configFile.getBoolean("settings.restrictions.DenyTabcompleteBeforeLogin", true); - hideTablistBeforeLogin = configFile.getBoolean("settings.restrictions.DenyTabcompleteBeforeLogin", true); + protectInventoryBeforeLogInEnabled = load(RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN); + denyTabcompleteBeforeLogin = load(RestrictionSettings.DENY_TABCOMPLETE_BEFORE_LOGIN); + hideTablistBeforeLogin = load(RestrictionSettings.HIDE_TABLIST_BEFORE_LOGIN); plugin.checkProtocolLib(); - passwordMaxLength = configFile.getInt("settings.security.passwordMaxLength", 20); + passwordMaxLength = load(SecuritySettings.MAX_PASSWORD_LENGTH); backupWindowsPath = configFile.getString("BackupSystem.MysqlWindowsPath", "C:\\Program Files\\MySQL\\MySQL Server 5.1\\"); isStopEnabled = configFile.getBoolean("Security.SQLProblem.stopServer", true); reloadSupport = configFile.getBoolean("Security.ReloadCommand.useReloadCommandSupport", true); @@ -245,9 +246,9 @@ public final class Settings { getMaxLoginPerIp = configFile.getInt("settings.restrictions.maxLoginPerIp", 0); getMaxJoinPerIp = configFile.getInt("settings.restrictions.maxJoinPerIp", 0); checkVeryGames = configFile.getBoolean("VeryGames.enableIpCheck", false); - removeJoinMessage = configFile.getBoolean("settings.removeJoineMessage", false); - removeLeaveMessage = configFile.getBoolean("settings.removeLeaveMessage", false); - delayJoinMessage = configFile.getBoolean("settings.delayJoineMessage", false); + removeJoinMessage = load(RegistrationSettings.REMOVE_JOIN_MESSAGE); + removeLeaveMessage = load(RegistrationSettings.REMOVE_LEAVE_MESSAGE); + delayJoinMessage = load(RegistrationSettings.DELAY_JOIN_MESSAGE); noTeleport = configFile.getBoolean("settings.restrictions.noTeleport", false); crazyloginFileName = configFile.getString("Converter.CrazyLogin.fileName", "accounts.db"); getPassRegex = configFile.getString("settings.restrictions.allowedPasswordCharacters", "[\\x21-\\x7E]*"); @@ -264,70 +265,6 @@ public final class Settings { } - /** - * Method getPasswordHash. - * - * @return HashAlgorithm - */ - private static HashAlgorithm getPasswordHash() { - String key = "settings.security.passwordHash"; - try { - return HashAlgorithm.valueOf(configFile.getString(key, "SHA256").toUpperCase()); - } catch (IllegalArgumentException ex) { - ConsoleLogger.showError("Unknown Hash Algorithm; defaulting to SHA256"); - return HashAlgorithm.SHA256; - } - } - - /** - * Method getDataSource. - * - * @return DataSourceType - */ - private static DataSourceType getDataSource() { - String key = "DataSource.backend"; - try { - return DataSource.DataSourceType.valueOf(configFile.getString(key, "sqlite").toUpperCase()); - } catch (IllegalArgumentException ex) { - ConsoleLogger.showError("Unknown database backend; defaulting to SQLite database"); - return DataSource.DataSourceType.SQLITE; - } - } - - /** - * Saves the configuration to disk - * - * @return True if saved successfully - */ - private static boolean save() { - try { - configFile.save(SETTINGS_FILE); - return true; - } catch (IOException ex) { - return false; - } - } - - /** - * Method checkLang. - * - * @param lang String - * - * @return String - */ - private static String checkLang(String lang) { - if (new File(PLUGIN_FOLDER, "messages" + File.separator + "messages_" + lang + ".yml").exists()) { - ConsoleLogger.info("Set Language to: " + lang); - return lang; - } - if (AuthMe.class.getResourceAsStream("/messages/messages_" + lang + ".yml") != null) { - ConsoleLogger.info("Set Language to: " + lang); - return lang; - } - ConsoleLogger.info("Language file not found for " + lang + ", set to default language: en !"); - return "en"; - } - /** * Method switchAntiBotMod. * @@ -344,20 +281,13 @@ public final class Settings { } /** - * Saves current configuration (plus defaults) to disk. - *

- * If defaults and configuration are empty, saves blank file. + * Load the value via the new Property setup for temporary support within this old settings manager. * - * @return True if saved successfully + * @param property The property to load + * @param The property type + * @return The config value of the property */ - private boolean saveDefaults() { - configFile.options() - .copyDefaults(true) - .copyHeader(true); - boolean success = save(); - configFile.options() - .copyDefaults(false) - .copyHeader(false); - return success; + private static T load(Property property) { + return property.getFromFile(configFile); } } diff --git a/src/main/java/fr/xephi/authme/settings/SettingsMigrationService.java b/src/main/java/fr/xephi/authme/settings/SettingsMigrationService.java index 0a41301c..5bb15690 100644 --- a/src/main/java/fr/xephi/authme/settings/SettingsMigrationService.java +++ b/src/main/java/fr/xephi/authme/settings/SettingsMigrationService.java @@ -13,6 +13,9 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; +import static fr.xephi.authme.settings.properties.RegistrationSettings.DELAY_JOIN_MESSAGE; +import static fr.xephi.authme.settings.properties.RegistrationSettings.REMOVE_JOIN_MESSAGE; +import static fr.xephi.authme.settings.properties.RegistrationSettings.REMOVE_LEAVE_MESSAGE; import static fr.xephi.authme.settings.properties.RestrictionSettings.ALLOWED_NICKNAME_CHARACTERS; import static java.lang.String.format; @@ -43,7 +46,8 @@ public final class SettingsMigrationService { configuration.set(ALLOWED_NICKNAME_CHARACTERS.getPath(), "[a-zA-Z0-9_]*"); changes = true; } - changes = changes || performMailTextToFileMigration(configuration, pluginFolder); + changes = changes || performMailTextToFileMigration(configuration, pluginFolder) + || migrateJoinLeaveMessages(configuration); return changes; } @@ -104,6 +108,33 @@ public final class SettingsMigrationService { return true; } + /** + * Detected deprecated {@code settings.delayJoinLeaveMessages} and inform user of new "remove join messages" + * and "remove leave messages" settings. + * + * @param configuration The file configuration + * @return True if the configuration has changed, false otherwise + */ + private static boolean migrateJoinLeaveMessages(FileConfiguration configuration) { + final String oldDelayJoinPath = "settings.delayJoinLeaveMessages"; + if (configuration.contains(oldDelayJoinPath)) { + ConsoleLogger.info("Detected deprecated property " + oldDelayJoinPath); + ConsoleLogger.info(String.format("Note that we now also have the settings %s and %s", + REMOVE_JOIN_MESSAGE.getPath(), REMOVE_LEAVE_MESSAGE.getPath())); + if (!configuration.contains(DELAY_JOIN_MESSAGE.getPath())) { + configuration.set(DELAY_JOIN_MESSAGE.getPath(), true); + ConsoleLogger.info("Renamed " + oldDelayJoinPath + " to " + DELAY_JOIN_MESSAGE.getPath()); + } + return true; + } + return false; + } + + + // ------- + // Utilities + // ------- + /** * Copy a resource file (from the JAR) to the given file if it doesn't exist. * diff --git a/src/main/java/fr/xephi/authme/settings/properties/RegistrationSettings.java b/src/main/java/fr/xephi/authme/settings/properties/RegistrationSettings.java index fe41709e..0be9f67a 100644 --- a/src/main/java/fr/xephi/authme/settings/properties/RegistrationSettings.java +++ b/src/main/java/fr/xephi/authme/settings/properties/RegistrationSettings.java @@ -80,16 +80,17 @@ public class RegistrationSettings implements SettingsClass { public static final Property BROADCAST_WELCOME_MESSAGE = newProperty("settings.broadcastWelcomeMessage", false); - @Comment("Do we need to delay the join/leave message to be displayed only when the player is authenticated?") + @Comment("Should we delay the join message and display it once the player has logged in?") public static final Property DELAY_JOIN_MESSAGE = newProperty("settings.delayJoinMessage", false); - // TODO: comments! + @Comment("Should we remove join messages altogether?") public static final Property REMOVE_JOIN_MESSAGE = - newProperty("settings.removeJoinMessage", false); + newProperty("settings.removeJoinMessage", false); + @Comment("Should we remove leave messages?") public static final Property REMOVE_LEAVE_MESSAGE = - newProperty("settings.removeLeaveMessage", false); + newProperty("settings.removeLeaveMessage", false); @Comment("Do we need to add potion effect Blinding before login/reigster?") public static final Property APPLY_BLIND_EFFECT = diff --git a/src/main/java/fr/xephi/authme/settings/properties/RestrictionSettings.java b/src/main/java/fr/xephi/authme/settings/properties/RestrictionSettings.java index c140a67a..4025c0be 100644 --- a/src/main/java/fr/xephi/authme/settings/properties/RestrictionSettings.java +++ b/src/main/java/fr/xephi/authme/settings/properties/RestrictionSettings.java @@ -132,7 +132,7 @@ public class RestrictionSettings implements SettingsClass { @Comment("Should we deny the tabcomplete feature before logging in? Requires ProtocolLib.") public static final Property DENY_TABCOMPLETE_BEFORE_LOGIN = - newProperty("settings.restrictions.DenyTabcompleteBeforeLogin", true); + newProperty("settings.restrictions.DenyTabCompleteBeforeLogin", true); @Comment("Should we hide the tablist before logging in? Requires ProtocolLib.") public static final Property HIDE_TABLIST_BEFORE_LOGIN = diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index cfa7cb01..dc52379a 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -135,9 +135,9 @@ settings: # Should we protect the player inventory before logging in? Requires ProtocolLib. ProtectInventoryBeforeLogIn: true # Should we deny the tabcomplete feature before logging in? Requires ProtocolLib. - DenyTabcompleteBeforeLogIn: true + DenyTabCompleteBeforeLogin: true # Should we hide the tablist before logging in? Requires ProtocolLib. - HideTablistBeforeLogIn: true + HideTablistBeforeLogin: true # Should we display all other accounts from a player when he joins? # permission: /authme.admin.accounts displayOtherAccounts: true @@ -256,8 +256,12 @@ settings: useWelcomeMessage: true # Do we need to broadcast the welcome message to all server or only to the player? set true for server or false for player broadcastWelcomeMessage: false - # Do we need to delay the join/leave message to be displayed only when the player is authenticated ? - delayJoinLeaveMessages: true + # Should we delay the join message and display it once the player has logged in? + delayJoinMessage: true + # Should we remove join messages altogether? + removeJoinMessage: true + # Should we remove leave messages? + removeLeaveMessage: true # Do we need to add potion effect Blinding before login/register? applyBlindEffect: false # Do we need to prevent people to login with another case?