From fb6cff2e073a043ea06bb3219f8c9e1dd83ab81e Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sun, 17 Jan 2016 09:23:01 +0100 Subject: [PATCH] #347 Add remaining missing properties --- .../settings/custom/BackupSettings.java | 29 +++++ .../settings/custom/DatabaseSettings.java | 46 ++++---- .../authme/settings/custom/HooksSettings.java | 30 ++++++ .../settings/custom/PluginSettings.java | 14 +++ .../settings/custom/RegistrationSettings.java | 101 ++++++++++++++++++ .../settings/custom/RestrictionSettings.java | 12 +++ .../custom/SettingsFieldRetriever.java | 7 +- src/main/resources/config.yml | 2 +- .../custom/ConfigFileConsistencyTest.java | 18 +++- .../custom/SettingsClassConsistencyTest.java | 13 +++ 10 files changed, 241 insertions(+), 31 deletions(-) create mode 100644 src/main/java/fr/xephi/authme/settings/custom/BackupSettings.java create mode 100644 src/main/java/fr/xephi/authme/settings/custom/RegistrationSettings.java diff --git a/src/main/java/fr/xephi/authme/settings/custom/BackupSettings.java b/src/main/java/fr/xephi/authme/settings/custom/BackupSettings.java new file mode 100644 index 000000000..f2e78931b --- /dev/null +++ b/src/main/java/fr/xephi/authme/settings/custom/BackupSettings.java @@ -0,0 +1,29 @@ +package fr.xephi.authme.settings.custom; + +import fr.xephi.authme.settings.domain.Comment; +import fr.xephi.authme.settings.domain.Property; +import fr.xephi.authme.settings.domain.SettingsClass; + +import static fr.xephi.authme.settings.domain.Property.newProperty; + +public class BackupSettings implements SettingsClass { + + @Comment("Enable or disable automatic backup") + public static final Property ENABLED = + newProperty("BackupSystem.ActivateBackup", false); + + @Comment("Set backup at every start of server") + public static final Property ON_SERVER_START = + newProperty("BackupSystem.OnServerStart", false); + + @Comment("Set backup at every stop of server") + public static final Property ON_SERVER_STOP = + newProperty("BackupSystem.OnServerStop", true); + + @Comment(" Windows only mysql installation Path") + public static final Property MYSQL_WINDOWS_PATH = + newProperty("BackupSystem.MysqlWindowsPath", "C:\\Program Files\\MySQL\\MySQL Server 5.1\\"); + + private BackupSettings() { + } +} diff --git a/src/main/java/fr/xephi/authme/settings/custom/DatabaseSettings.java b/src/main/java/fr/xephi/authme/settings/custom/DatabaseSettings.java index 582e5d6eb..84f0b7085 100644 --- a/src/main/java/fr/xephi/authme/settings/custom/DatabaseSettings.java +++ b/src/main/java/fr/xephi/authme/settings/custom/DatabaseSettings.java @@ -6,8 +6,6 @@ import fr.xephi.authme.settings.domain.Property; import fr.xephi.authme.settings.domain.SettingsClass; import static fr.xephi.authme.settings.domain.Property.newProperty; -import static fr.xephi.authme.settings.domain.PropertyType.BOOLEAN; -import static fr.xephi.authme.settings.domain.PropertyType.STRING; public class DatabaseSettings implements SettingsClass { @@ -18,91 +16,91 @@ public class DatabaseSettings implements SettingsClass { @Comment("Enable database caching, should improve database performance") public static final Property USE_CACHING = - newProperty(BOOLEAN, "DataSource.caching", true); + newProperty("DataSource.caching", true); @Comment("Database host address") public static final Property MYSQL_HOST = - newProperty(STRING, "DataSource.mySQLHost", "127.0.0.1"); + newProperty("DataSource.mySQLHost", "127.0.0.1"); @Comment("Database port") public static final Property MYSQL_PORT = - newProperty(STRING, "DataSource.mySQLPort", "3306"); + newProperty("DataSource.mySQLPort", "3306"); @Comment("Username about Database Connection Infos") public static final Property MYSQL_USERNAME = - newProperty(STRING, "DataSource.mySQLUsername", "authme"); + newProperty("DataSource.mySQLUsername", "authme"); @Comment("Password about Database Connection Infos") public static final Property MYSQL_PASSWORD = - newProperty(STRING, "DataSource.mySQLPassword", "123456"); + newProperty("DataSource.mySQLPassword", "123456"); @Comment("Database Name, use with converters or as SQLITE database name") public static final Property MYSQL_DATABASE = - newProperty(STRING, "DataSource.mySQLDatabase", "authme"); + newProperty("DataSource.mySQLDatabase", "authme"); @Comment("Table of the database") public static final Property MYSQL_TABLE = - newProperty(STRING, "DataSource.mySQLTablename", "authme"); + newProperty("DataSource.mySQLTablename", "authme"); @Comment("Column of IDs to sort data") public static final Property MYSQL_COL_ID = - newProperty(STRING, "DataSource.mySQLColumnId", "id"); + newProperty("DataSource.mySQLColumnId", "id"); @Comment("Column for storing or checking players nickname") public static final Property MYSQL_COL_NAME = - newProperty(STRING, "DataSource.mySQLColumnName", "username"); + newProperty("DataSource.mySQLColumnName", "username"); @Comment("Column for storing or checking players RealName ") public static final Property MYSQL_COL_REALNAME = - newProperty(STRING, "DataSource.mySQLRealName", "realname"); + newProperty("DataSource.mySQLRealName", "realname"); @Comment("Column for storing players passwords") public static final Property MYSQL_COL_PASSWORD = - newProperty(STRING, "DataSource.mySQLColumnPassword", "password"); + newProperty("DataSource.mySQLColumnPassword", "password"); @Comment("Column for storing players passwords salts") public static final Property MYSQL_COL_SALT = - newProperty(STRING, "ExternalBoardOptions.mySQLColumnSalt", ""); + newProperty("ExternalBoardOptions.mySQLColumnSalt", ""); @Comment("Column for storing players emails") public static final Property MYSQL_COL_EMAIL = - newProperty(STRING, "DataSource.mySQLColumnEmail", "email"); + newProperty("DataSource.mySQLColumnEmail", "email"); @Comment("Column for storing if a player is logged in or not") public static final Property MYSQL_COL_ISLOGGED = - newProperty(STRING, "DataSource.mySQLColumnLogged", "isLogged"); + newProperty("DataSource.mySQLColumnLogged", "isLogged"); @Comment("Column for storing players ips") public static final Property MYSQL_COL_IP = - newProperty(STRING, "DataSource.mySQLColumnIp", "ip"); + newProperty("DataSource.mySQLColumnIp", "ip"); @Comment("Column for storing players lastlogins") public static final Property MYSQL_COL_LASTLOGIN = - newProperty(STRING, "DataSource.mySQLColumnLastLogin", "lastlogin"); + newProperty("DataSource.mySQLColumnLastLogin", "lastlogin"); @Comment("Column for storing player LastLocation - X") public static final Property MYSQL_COL_LASTLOC_X = - newProperty(STRING, "DataSource.mySQLlastlocX", "x"); + newProperty("DataSource.mySQLlastlocX", "x"); @Comment("Column for storing player LastLocation - Y") public static final Property MYSQL_COL_LASTLOC_Y = - newProperty(STRING, "DataSource.mySQLlastlocY", "y"); + newProperty("DataSource.mySQLlastlocY", "y"); @Comment("Column for storing player LastLocation - Z") public static final Property MYSQL_COL_LASTLOC_Z = - newProperty(STRING, "DataSource.mySQLlastlocZ", "z"); + newProperty("DataSource.mySQLlastlocZ", "z"); @Comment("Column for storing player LastLocation - World Name") public static final Property MYSQL_COL_LASTLOC_WORLD = - newProperty(STRING, "DataSource.mySQLlastlocWorld", "world"); + newProperty("DataSource.mySQLlastlocWorld", "world"); @Comment("Column for storing players groups") public static final Property MYSQL_COL_GROUP = - newProperty(STRING, "ExternalBoardOptions.mySQLColumnGroup", ""); + newProperty("ExternalBoardOptions.mySQLColumnGroup", ""); @Comment("Enable this when you allow registration through a website") public static final Property MYSQL_WEBSITE = - newProperty(BOOLEAN, "DataSource.mySQLWebsite", false); + newProperty("DataSource.mySQLWebsite", false); private DatabaseSettings() { } diff --git a/src/main/java/fr/xephi/authme/settings/custom/HooksSettings.java b/src/main/java/fr/xephi/authme/settings/custom/HooksSettings.java index f13e66055..af0458ac4 100644 --- a/src/main/java/fr/xephi/authme/settings/custom/HooksSettings.java +++ b/src/main/java/fr/xephi/authme/settings/custom/HooksSettings.java @@ -2,8 +2,11 @@ package fr.xephi.authme.settings.custom; import fr.xephi.authme.settings.domain.Comment; import fr.xephi.authme.settings.domain.Property; +import fr.xephi.authme.settings.domain.PropertyType; import fr.xephi.authme.settings.domain.SettingsClass; +import java.util.List; + import static fr.xephi.authme.settings.domain.Property.newProperty; public class HooksSettings implements SettingsClass { @@ -36,6 +39,33 @@ public class HooksSettings implements SettingsClass { public static final Property ENABLE_VERYGAMES_IP_CHECK = newProperty("VeryGames.enableIpCheck", false); + @Comment({ + "-1 means disabled. If you want that only activated players", + "can log into your server, you can set here the group number", + "of unactivated users, needed for some forum/CMS support"}) + public static final Property NON_ACTIVATED_USERS_GROUP = + newProperty("ExternalBoardOptions.nonActivedUserGroup", -1); + + @Comment("Other MySQL columns where we need to put the username (case-sensitive)") + public static final Property> MYSQL_OTHER_USERNAME_COLS = + newProperty(PropertyType.STRING_LIST, "ExternalBoardOptions.mySQLOtherUsernameColumns"); + + @Comment("How much log2 rounds needed in BCrypt (do not change if you do not know what it does)") + public static final Property BCRYPT_LOG2_ROUND = + newProperty("ExternalBoardOptions.bCryptLog2Round", 10); + + @Comment("phpBB table prefix defined during the phpBB installation process") + public static final Property PHPBB_TABLE_PREFIX = + newProperty("ExternalBoardOptions.phpbbTablePrefix", "phpbb_"); + + @Comment("phpBB activated group ID; 2 is the default registered group defined by phpBB") + public static final Property PHPBB_ACTIVATED_GROUP_ID = + newProperty("ExternalBoardOptions.phpbbActivatedGroupId", 2); + + @Comment("Wordpress prefix defined during WordPress installation") + public static final Property WORDPRESS_TABLE_PREFIX = + newProperty("ExternalBoardOptions.wordpressTablePrefix", "wp_"); + private HooksSettings() { } diff --git a/src/main/java/fr/xephi/authme/settings/custom/PluginSettings.java b/src/main/java/fr/xephi/authme/settings/custom/PluginSettings.java index 9778d04e4..e35076db2 100644 --- a/src/main/java/fr/xephi/authme/settings/custom/PluginSettings.java +++ b/src/main/java/fr/xephi/authme/settings/custom/PluginSettings.java @@ -40,6 +40,20 @@ public class PluginSettings implements SettingsClass { public static final Property SESSIONS_EXPIRE_ON_IP_CHANGE = newProperty("settings.sessions.sessionExpireOnIpChange", true); + @Comment("Message language, available: en, de, br, cz, pl, fr, ru, hu, sk, es, zhtw, fi, zhcn, lt, it, ko, pt") + public static final Property MESSAGES_LANGUAGE = + newProperty("settings.messagesLanguage", "en"); + + @Comment({ + "Take care with this option; if you don't want", + "to use Vault and group switching of AuthMe", + "for unloggedIn players, set this setting to true.", + "Default is false." + }) + public static final Property ENABLE_PERMISSION_CHECK = + newProperty("permission.EnablePermissionCheck", false); + + private PluginSettings() { } diff --git a/src/main/java/fr/xephi/authme/settings/custom/RegistrationSettings.java b/src/main/java/fr/xephi/authme/settings/custom/RegistrationSettings.java new file mode 100644 index 000000000..7e8301456 --- /dev/null +++ b/src/main/java/fr/xephi/authme/settings/custom/RegistrationSettings.java @@ -0,0 +1,101 @@ +package fr.xephi.authme.settings.custom; + +import fr.xephi.authme.settings.domain.Comment; +import fr.xephi.authme.settings.domain.Property; +import fr.xephi.authme.settings.domain.PropertyType; +import fr.xephi.authme.settings.domain.SettingsClass; + +import java.util.List; + +import static fr.xephi.authme.settings.domain.Property.newProperty; + +public class RegistrationSettings implements SettingsClass { + + @Comment("Enable registration on the server?") + public static final Property IS_ENABLED = + newProperty("settings.registration.enabled", true); + + @Comment({ + "Send every X seconds a message to a player to", + "remind him that he has to login/register"}) + public static final Property MESSAGE_INTERVAL = + newProperty("settings.registration.messageInterval", 5); + + @Comment({ + "Only registered and logged in players can play.", + "See restrictions for exceptions"}) + public static final Property FORCE = + newProperty("settings.registration.force", true); + + @Comment("Do we replace password registration by an email registration method?") + public static final Property USE_EMAIL_REGISTRATION = + newProperty("settings.registration.enableEmailRegistrationSystem", false); + + @Comment({ + "Enable double check of email when you register", + "when it's true, registration requires that kind of command:", + "/register "}) + public static final Property ENABLE_CONFIRM_EMAIL = + newProperty("settings.registration.doubleEmailCheck", false); + + @Comment({ + "Do we force kicking player after a successful registration?", + "Do not use with login feature below"}) + public static final Property FORCE_KICK_AFTER_REGISTER = + newProperty("settings.registration.forceKickAfterRegister", false); + + @Comment("Does AuthMe need to enforce a /login after a successful registration?") + public static final Property FORCE_LOGIN_AFTER_REGISTER = + newProperty("settings.registration.forceLoginAfterRegister", false); + + @Comment("Force these commands after /login, without any '/', use %p to replace with player name") + public static final Property> FORCE_COMMANDS = + newProperty(PropertyType.STRING_LIST, "settings.forceCommands"); + + @Comment("Force these commands after /login as service console, without any '/'. " + + "Use %p to replace with player name") + public static final Property> FORCE_COMMANDS_AS_CONSOLE = + newProperty(PropertyType.STRING_LIST, "settings.forceCommandsAsConsole"); + + @Comment("Force these commands after /register, without any '/', use %p to replace with player name") + public static final Property> FORCE_REGISTER_COMMANDS = + newProperty(PropertyType.STRING_LIST, "settings.forceRegisterCommands"); + + @Comment("Force these commands after /register as a server console, without any '/'. " + + "Use %p to replace with player name") + public static final Property> FORCE_REGISTER_COMMANDS_AS_CONSOLE = + newProperty(PropertyType.STRING_LIST, "settings.forceRegisterCommandsAsConsole"); + + @Comment({ + "Enable to display the welcome message (welcome.txt) after a registration or a login", + "You can use colors in this welcome.txt + some replaced strings:", + "{PLAYER}: player name, {ONLINE}: display number of online players, {MAXPLAYERS}: display server slots,", + "{IP}: player ip, {LOGINS}: number of players logged, {WORLD}: player current world, {SERVER}: server name", + "{VERSION}: get current bukkit version, {COUNTRY}: player country"}) + public static final Property USE_WELCOME_MESSAGE = + newProperty("settings.useWelcomeMessage", true); + + @Comment("Do we need to broadcast the welcome message to all server or only to the player? set true for " + + "server or false for player") + 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?") + public static final Property DELAY_JOIN_LEAVE_MESSAGES = + newProperty("settings.delayJoinLeaveMessages", true); + + @Comment("Do we need to add potion effect Blinding before login/reigster?") + public static final Property APPLY_BLIND_EFFECT = + newProperty("settings.applyBlindEffect", false); + + @Comment({ + "Do we need to prevent people to login with another case?", + "If Xephi is registered, then Xephi can login, but not XEPHI/xephi/XePhI"}) + public static final Property PREVENT_OTHER_CASE = + newProperty("settings.preventOtherCase", false); + + + private RegistrationSettings() { + } + +} diff --git a/src/main/java/fr/xephi/authme/settings/custom/RestrictionSettings.java b/src/main/java/fr/xephi/authme/settings/custom/RestrictionSettings.java index e34a2c2fe..651c7833d 100644 --- a/src/main/java/fr/xephi/authme/settings/custom/RestrictionSettings.java +++ b/src/main/java/fr/xephi/authme/settings/custom/RestrictionSettings.java @@ -165,6 +165,18 @@ public class RestrictionSettings implements SettingsClass { public static final Property FORCE_SURVIVAL_MODE = newProperty("settings.GameMode.ForceSurvivalMode", false); + @Comment({ + "Below you can list all account names that", + "AuthMe will ignore for registration or login, configure it", + "at your own risk!! Remember that if you are going to add", + "nickname with [], you have to delimit name with ' '.", + "this option add compatibility with BuildCraft and some", + "other mods.", + "It is case-sensitive!" + }) + public static final Property> UNRESTRICTED_NAMES = + newProperty(PropertyType.STRING_LIST, "settings.unrestrictions.UnrestrictedName"); + private RestrictionSettings() { } diff --git a/src/main/java/fr/xephi/authme/settings/custom/SettingsFieldRetriever.java b/src/main/java/fr/xephi/authme/settings/custom/SettingsFieldRetriever.java index f5c7f23d8..74b722e8f 100644 --- a/src/main/java/fr/xephi/authme/settings/custom/SettingsFieldRetriever.java +++ b/src/main/java/fr/xephi/authme/settings/custom/SettingsFieldRetriever.java @@ -18,9 +18,10 @@ final class SettingsFieldRetriever { /** The classes to scan for properties. */ private static final List> CONFIGURATION_CLASSES = Arrays.asList( - ConverterSettings.class, PluginSettings.class, RestrictionSettings.class, - DatabaseSettings.class, EmailSettings.class, HooksSettings.class, - ProtectionSettings.class, PurgeSettings.class, SecuritySettings.class); + ConverterSettings.class, PluginSettings.class, RestrictionSettings.class, + DatabaseSettings.class, EmailSettings.class, HooksSettings.class, + ProtectionSettings.class, PurgeSettings.class, SecuritySettings.class, + RegistrationSettings.class, BackupSettings.class); private SettingsFieldRetriever() { } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 960cfc6ee..22dd7431c 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -209,7 +209,7 @@ settings: # Only registered and logged in players can play. # See restrictions for exceptions force: true - # Does we replace password registration by an Email registration method? + # Do we replace password registration by an email registration method? enableEmailRegistrationSystem: false # Enable double check of email when you register # when it's true, registration require that kind of command: diff --git a/src/test/java/fr/xephi/authme/settings/custom/ConfigFileConsistencyTest.java b/src/test/java/fr/xephi/authme/settings/custom/ConfigFileConsistencyTest.java index eb12ab030..d012a50a4 100644 --- a/src/test/java/fr/xephi/authme/settings/custom/ConfigFileConsistencyTest.java +++ b/src/test/java/fr/xephi/authme/settings/custom/ConfigFileConsistencyTest.java @@ -1,9 +1,11 @@ package fr.xephi.authme.settings.custom; +import fr.xephi.authme.ReflectionTestUtils; import fr.xephi.authme.settings.domain.Property; import fr.xephi.authme.settings.propertymap.PropertyMap; import fr.xephi.authme.util.StringUtils; import org.bukkit.configuration.MemorySection; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.junit.Test; @@ -16,8 +18,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; /** @@ -40,7 +40,19 @@ public class ConfigFileConsistencyTest { boolean result = settings.containsAllSettings(SettingsFieldRetriever.getAllPropertyFields()); // then - assertThat(result, equalTo(true)); + if (!result) { + FileConfiguration configuration = + (FileConfiguration) ReflectionTestUtils.getFieldValue(NewSetting.class, settings, "configuration"); + + Set knownProperties = getAllKnownPropertyPaths(); + List missingProperties = new ArrayList<>(); + for (String path : knownProperties) { + if (!configuration.contains(path)) { + missingProperties.add(path); + } + } + fail("Found missing properties!\n-" + StringUtils.join("\n-", missingProperties)); + } } @Test diff --git a/src/test/java/fr/xephi/authme/settings/custom/SettingsClassConsistencyTest.java b/src/test/java/fr/xephi/authme/settings/custom/SettingsClassConsistencyTest.java index 6dab6bdfc..a6b67763a 100644 --- a/src/test/java/fr/xephi/authme/settings/custom/SettingsClassConsistencyTest.java +++ b/src/test/java/fr/xephi/authme/settings/custom/SettingsClassConsistencyTest.java @@ -7,6 +7,7 @@ import org.junit.BeforeClass; import org.junit.Test; import java.io.File; +import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.ArrayList; @@ -14,6 +15,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import static org.hamcrest.Matchers.arrayWithSize; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; @@ -82,6 +84,17 @@ public class SettingsClassConsistencyTest { } } + @Test + public void shouldHaveHiddenDefaultConstructorOnly() { + for (Class clazz : classes) { + Constructor[] constructors = clazz.getDeclaredConstructors(); + assertThat(clazz + " should only have one constructor", + constructors, arrayWithSize(1)); + assertThat("Constructor of " + clazz + " is private", + Modifier.isPrivate(constructors[0].getModifiers()), equalTo(true)); + } + } + private static boolean isValidConstantField(Field field) { int modifiers = field.getModifiers(); return Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers);