From 06d61db7f016e41180c75072d977e302b4cd635b Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sat, 1 Oct 2016 14:47:31 +0200 Subject: [PATCH 01/18] #822 Minor - fix Essentials userdata folder in config comment --- .../java/fr/xephi/authme/settings/properties/PurgeSettings.java | 2 +- src/main/resources/config.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/xephi/authme/settings/properties/PurgeSettings.java b/src/main/java/fr/xephi/authme/settings/properties/PurgeSettings.java index 013163745..f23a3eb12 100644 --- a/src/main/java/fr/xephi/authme/settings/properties/PurgeSettings.java +++ b/src/main/java/fr/xephi/authme/settings/properties/PurgeSettings.java @@ -20,7 +20,7 @@ public class PurgeSettings implements SettingsHolder { public static final Property REMOVE_PLAYER_DAT = newProperty("Purge.removePlayerDat", false); - @Comment("Do we need to remove the Essentials/users/player.yml file during purge process?") + @Comment("Do we need to remove the Essentials/userdata/player.yml file during purge process?") public static final Property REMOVE_ESSENTIALS_FILES = newProperty("Purge.removeEssentialsFile", false); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 211328fe1..7516890af 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -405,7 +405,7 @@ Purge: daysBeforeRemovePlayer: 60 # Do we need to remove the player.dat file during purge process? removePlayerDat: false - # Do we need to remove the Essentials/users/player.yml file during purge process? + # Do we need to remove the Essentials/userdata/player.yml file during purge process? removeEssentialsFile: false # World where are players.dat stores defaultWorld: 'world' From 62b8af6a37e2a918edfa5c8666c3406330a3c8cb Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Sat, 1 Oct 2016 23:09:39 +0200 Subject: [PATCH 02/18] Fix #904 (Ljacqu, pls fix me :P) --- src/main/java/fr/xephi/authme/AntiBot.java | 8 ++++++-- .../java/fr/xephi/authme/permission/AdminPermission.java | 5 +++++ src/main/java/fr/xephi/authme/util/BukkitService.java | 1 + src/test/java/fr/xephi/authme/AntiBotTest.java | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AntiBot.java b/src/main/java/fr/xephi/authme/AntiBot.java index 81fd11b07..cfbc1f9de 100644 --- a/src/main/java/fr/xephi/authme/AntiBot.java +++ b/src/main/java/fr/xephi/authme/AntiBot.java @@ -2,6 +2,7 @@ package fr.xephi.authme; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.Messages; +import fr.xephi.authme.permission.AdminPermission; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerStatePermission; import fr.xephi.authme.settings.Settings; @@ -66,8 +67,11 @@ public class AntiBot { public void activateAntiBot() { antiBotStatus = AntiBotStatus.ACTIVE; - for (String s : messages.retrieve(MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE)) { - bukkitService.broadcastMessage(s); + for(Player player : bukkitService.getOnlinePlayers()) { + if(!permissionsManager.hasPermission(player, AdminPermission.ANTIBOT_MESSAGES)) { + continue; + } + messages.send(player, MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE); } final int duration = settings.getProperty(ProtectionSettings.ANTIBOT_DURATION); diff --git a/src/main/java/fr/xephi/authme/permission/AdminPermission.java b/src/main/java/fr/xephi/authme/permission/AdminPermission.java index 043ba6dc2..b34291282 100644 --- a/src/main/java/fr/xephi/authme/permission/AdminPermission.java +++ b/src/main/java/fr/xephi/authme/permission/AdminPermission.java @@ -100,6 +100,11 @@ public enum AdminPermission implements PermissionNode { */ RELOAD("authme.admin.reload", DefaultPermission.OP_ONLY), + /** + * Administrator command to reload the plugin configuration. + */ + ANTIBOT_MESSAGES("authme.admin.antibotmessages", DefaultPermission.OP_ONLY), + /** * Permission to see the other accounts of the players that log in. */ diff --git a/src/main/java/fr/xephi/authme/util/BukkitService.java b/src/main/java/fr/xephi/authme/util/BukkitService.java index 72bdacf7a..4931689ff 100644 --- a/src/main/java/fr/xephi/authme/util/BukkitService.java +++ b/src/main/java/fr/xephi/authme/util/BukkitService.java @@ -3,6 +3,7 @@ package fr.xephi.authme.util; import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.initialization.SettingsDependent; +import fr.xephi.authme.permission.PermissionNode; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.PluginSettings; import org.bukkit.BanEntry; diff --git a/src/test/java/fr/xephi/authme/AntiBotTest.java b/src/test/java/fr/xephi/authme/AntiBotTest.java index 2aee0c66e..d00bca63d 100644 --- a/src/test/java/fr/xephi/authme/AntiBotTest.java +++ b/src/test/java/fr/xephi/authme/AntiBotTest.java @@ -127,7 +127,7 @@ public class AntiBotTest { // then assertThat(antiBot.getAntiBotStatus(), equalTo(AntiBot.AntiBotStatus.ACTIVE)); ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); - verify(bukkitService, times(2)).broadcastMessage(captor.capture()); + verify(messages, times(2)).send(captor.capture()); assertThat(captor.getAllValues(), contains("Test line #1", "Test line #2")); long expectedTicks = duration * TICKS_PER_MINUTE; verify(bukkitService).scheduleSyncDelayedTask(any(Runnable.class), eq(expectedTicks)); From 74a61188f597b5877bfa17452f9fa358164706eb Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sat, 1 Oct 2016 23:43:37 +0200 Subject: [PATCH 03/18] Update docs / fix hash algorithms task / fix unit tests - From a common session wit sgdc3 --- docs/commands.md | 8 ++++---- docs/hash_algorithms.md | 6 +++--- docs/permission_nodes.md | 5 +++-- src/test/java/fr/xephi/authme/AntiBotTest.java | 17 ++++++++++++----- .../EncryptionMethodInfoGatherer.java | 2 +- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/docs/commands.md b/docs/commands.md index edb4a3b94..00f4f8c61 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -1,5 +1,5 @@ - + ## AuthMe Commands You can use the following commands to use the features of AuthMe. Mandatory arguments are marked with `< >` @@ -32,7 +32,7 @@ brackets; optional arguments are enclosed in square brackets (`[ ]`).
Requires `authme.admin.firstspawn` - **/authme setfirstspawn**: Change the first player's spawn to your current position.
Requires `authme.admin.setfirstspawn` -- **/authme purge** <days>: Purge old AuthMeReloaded data longer than the specified amount of days ago. +- **/authme purge** <days> [all]: Purge old AuthMeReloaded data longer than the specified amount of days ago.
Requires `authme.admin.purge` - **/authme resetpos** <player/*>: Purge the last know position of the specified player or all of them.
Requires `authme.admin.purgelastpos` @@ -66,7 +66,7 @@ brackets; optional arguments are enclosed in square brackets (`[ ]`).
Requires `authme.player.email.add` - **/email change** <oldEmail> <newEmail>: Change an email address of your account.
Requires `authme.player.email.change` -- **/email recover** <email>: Recover your account using an Email address by sending a mail containing a new password. +- **/email recover** <email> [code]: Recover your account using an Email address by sending a mail containing a new password.
Requires `authme.player.email.recover` - **/email help** [query]: View detailed help for /email commands. - **/captcha** <captcha>: Captcha command for AuthMeReloaded. @@ -76,4 +76,4 @@ brackets; optional arguments are enclosed in square brackets (`[ ]`). --- -This page was automatically generated on the [AuthMe-Team/AuthMeReloaded repository](https://github.com/AuthMe-Team/AuthMeReloaded/tree/master/docs/) on Wed Jun 22 17:39:14 EDT 2016 +This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Sat Oct 01 23:33:39 CEST 2016 diff --git a/docs/hash_algorithms.md b/docs/hash_algorithms.md index 8c141a27e..e7fd0ae36 100644 --- a/docs/hash_algorithms.md +++ b/docs/hash_algorithms.md @@ -1,5 +1,5 @@ - + ## Hash Algorithms AuthMe supports the following hash algorithms for storing your passwords safely. @@ -17,7 +17,7 @@ JOOMLA | Recommended | 65 | | | Text | 32 | MD5 | Do not use | 32 | | | None | | MD5VB | Acceptable | 56 | | | Text | 16 | MYBB | Acceptable | 32 | | | Text | 8 | Y -PBKDF2 | Does not work | 328 | | | Text | 12 | +PBKDF2 | Does not work | 332 | | | Text | 12 | PBKDF2DJANGO | Acceptable | 77 | Y | | Text | 12 | PHPBB | Acceptable | 34 | | | Text | 16 | PHPFUSION | Do not use | 64 | Y | | | | Y @@ -82,4 +82,4 @@ or bad. --- -This page was automatically generated on the [AuthMe-Team/AuthMeReloaded repository](https://github.com/AuthMe-Team/AuthMeReloaded/tree/master/docs/) on Wed Jun 22 17:39:16 EDT 2016 +This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Sat Oct 01 23:42:20 CEST 2016 diff --git a/docs/permission_nodes.md b/docs/permission_nodes.md index e501736cd..9acaa7131 100644 --- a/docs/permission_nodes.md +++ b/docs/permission_nodes.md @@ -1,11 +1,12 @@ - + ## AuthMe Permission Nodes The following are the permission nodes that are currently supported by the latest dev builds. - **authme.admin.*** – Give access to all admin commands. - **authme.admin.accounts** – Administrator command to see all accounts associated with a user. +- **authme.admin.antibotmessages** – Administrator command to reload the plugin configuration. - **authme.admin.changemail** – Administrator command to set or change the email address of a user. - **authme.admin.changepassword** – Administrator command to change the password of a user. - **authme.admin.converter** – Administrator command to convert old or other data to AuthMe data. @@ -46,4 +47,4 @@ The following are the permission nodes that are currently supported by the lates --- -This page was automatically generated on the [AuthMe-Team/AuthMeReloaded repository](https://github.com/AuthMe-Team/AuthMeReloaded/tree/master/docs/) on Wed Jun 22 17:39:29 EDT 2016 +This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Sat Oct 01 23:34:27 CEST 2016 diff --git a/src/test/java/fr/xephi/authme/AntiBotTest.java b/src/test/java/fr/xephi/authme/AntiBotTest.java index d00bca63d..2b46bab10 100644 --- a/src/test/java/fr/xephi/authme/AntiBotTest.java +++ b/src/test/java/fr/xephi/authme/AntiBotTest.java @@ -2,6 +2,7 @@ package fr.xephi.authme; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.Messages; +import fr.xephi.authme.permission.AdminPermission; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerStatePermission; import fr.xephi.authme.settings.Settings; @@ -15,6 +16,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import java.util.Arrays; import java.util.List; import static fr.xephi.authme.util.BukkitService.TICKS_PER_MINUTE; @@ -115,20 +117,25 @@ public class AntiBotTest { @Test public void shouldActivateAntiBot() { // given - given(messages.retrieve(MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE)) - .willReturn(new String[]{"Test line #1", "Test line #2"}); int duration = 300; given(settings.getProperty(ProtectionSettings.ANTIBOT_DURATION)).willReturn(duration); AntiBot antiBot = createListeningAntiBot(); + List onlinePlayers = Arrays.asList(mock(Player.class), mock(Player.class), mock(Player.class)); + given(bukkitService.getOnlinePlayers()).willReturn((List) onlinePlayers); + given(permissionsManager.hasPermission(onlinePlayers.get(0), AdminPermission.ANTIBOT_MESSAGES)).willReturn(true); + given(permissionsManager.hasPermission(onlinePlayers.get(1), AdminPermission.ANTIBOT_MESSAGES)).willReturn(false); + given(permissionsManager.hasPermission(onlinePlayers.get(2), AdminPermission.ANTIBOT_MESSAGES)).willReturn(true); // when antiBot.activateAntiBot(); // then assertThat(antiBot.getAntiBotStatus(), equalTo(AntiBot.AntiBotStatus.ACTIVE)); - ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); - verify(messages, times(2)).send(captor.capture()); - assertThat(captor.getAllValues(), contains("Test line #1", "Test line #2")); + verify(bukkitService).getOnlinePlayers(); + verify(permissionsManager, times(3)).hasPermission(any(Player.class), eq(AdminPermission.ANTIBOT_MESSAGES)); + verify(messages).send(onlinePlayers.get(0), MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE); + verify(messages, never()).send(onlinePlayers.get(1), MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE); + verify(messages).send(onlinePlayers.get(2), MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE); long expectedTicks = duration * TICKS_PER_MINUTE; verify(bukkitService).scheduleSyncDelayedTask(any(Runnable.class), eq(expectedTicks)); } diff --git a/src/test/java/tools/hashmethods/EncryptionMethodInfoGatherer.java b/src/test/java/tools/hashmethods/EncryptionMethodInfoGatherer.java index 23fa6d6b2..057f14bbb 100644 --- a/src/test/java/tools/hashmethods/EncryptionMethodInfoGatherer.java +++ b/src/test/java/tools/hashmethods/EncryptionMethodInfoGatherer.java @@ -152,7 +152,7 @@ public class EncryptionMethodInfoGatherer { // By passing some bogus "package" to the constructor, the injector will throw if it needs to // instantiate any dependency other than what we provide. - Injector injector = new InjectorBuilder().addDefaultHandlers("!!No package!!").create(); + Injector injector = new InjectorBuilder().addDefaultHandlers("fr.xephi.authme.security.crypts").create(); injector.register(Settings.class, settings); return injector; } From 6f4a5fee07874bcea4dbc1356619e908e050f70a Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sun, 2 Oct 2016 10:48:26 +0200 Subject: [PATCH 04/18] Add missing permission to plugin.yml, fix description --- docs/permission_nodes.md | 6 +++--- src/main/java/fr/xephi/authme/AntiBot.java | 7 +++---- .../java/fr/xephi/authme/permission/AdminPermission.java | 2 +- src/main/java/fr/xephi/authme/util/BukkitService.java | 1 - src/main/resources/plugin.yml | 3 +++ 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/permission_nodes.md b/docs/permission_nodes.md index 9acaa7131..61f61c3e1 100644 --- a/docs/permission_nodes.md +++ b/docs/permission_nodes.md @@ -1,12 +1,12 @@ - + ## AuthMe Permission Nodes The following are the permission nodes that are currently supported by the latest dev builds. - **authme.admin.*** – Give access to all admin commands. - **authme.admin.accounts** – Administrator command to see all accounts associated with a user. -- **authme.admin.antibotmessages** – Administrator command to reload the plugin configuration. +- **authme.admin.antibotmessages** – Permission to see Antibot messages. - **authme.admin.changemail** – Administrator command to set or change the email address of a user. - **authme.admin.changepassword** – Administrator command to change the password of a user. - **authme.admin.converter** – Administrator command to convert old or other data to AuthMe data. @@ -47,4 +47,4 @@ The following are the permission nodes that are currently supported by the lates --- -This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Sat Oct 01 23:34:27 CEST 2016 +This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Sun Oct 02 10:47:16 CEST 2016 diff --git a/src/main/java/fr/xephi/authme/AntiBot.java b/src/main/java/fr/xephi/authme/AntiBot.java index cfbc1f9de..53ced436e 100644 --- a/src/main/java/fr/xephi/authme/AntiBot.java +++ b/src/main/java/fr/xephi/authme/AntiBot.java @@ -67,11 +67,10 @@ public class AntiBot { public void activateAntiBot() { antiBotStatus = AntiBotStatus.ACTIVE; - for(Player player : bukkitService.getOnlinePlayers()) { - if(!permissionsManager.hasPermission(player, AdminPermission.ANTIBOT_MESSAGES)) { - continue; + for (Player player : bukkitService.getOnlinePlayers()) { + if (permissionsManager.hasPermission(player, AdminPermission.ANTIBOT_MESSAGES)) { + messages.send(player, MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE); } - messages.send(player, MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE); } final int duration = settings.getProperty(ProtectionSettings.ANTIBOT_DURATION); diff --git a/src/main/java/fr/xephi/authme/permission/AdminPermission.java b/src/main/java/fr/xephi/authme/permission/AdminPermission.java index b34291282..ed5ab9f4c 100644 --- a/src/main/java/fr/xephi/authme/permission/AdminPermission.java +++ b/src/main/java/fr/xephi/authme/permission/AdminPermission.java @@ -101,7 +101,7 @@ public enum AdminPermission implements PermissionNode { RELOAD("authme.admin.reload", DefaultPermission.OP_ONLY), /** - * Administrator command to reload the plugin configuration. + * Permission to see Antibot messages. */ ANTIBOT_MESSAGES("authme.admin.antibotmessages", DefaultPermission.OP_ONLY), diff --git a/src/main/java/fr/xephi/authme/util/BukkitService.java b/src/main/java/fr/xephi/authme/util/BukkitService.java index 4931689ff..72bdacf7a 100644 --- a/src/main/java/fr/xephi/authme/util/BukkitService.java +++ b/src/main/java/fr/xephi/authme/util/BukkitService.java @@ -3,7 +3,6 @@ package fr.xephi.authme.util; import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.initialization.SettingsDependent; -import fr.xephi.authme.permission.PermissionNode; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.PluginSettings; import org.bukkit.BanEntry; diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index f6af6d4c7..2b950e3a7 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -126,6 +126,9 @@ permissions: authme.admin.reload: description: Administrator command to reload the plugin configuration. default: op + authme.admin.antibotmessages: + description: Permission to see Antibot messages + default: op authme.player.*: description: Permission to use all player (non-admin) commands. children: From e07c685d2a420d48764266110db3b1b0b646d2ff Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sun, 2 Oct 2016 10:55:02 +0200 Subject: [PATCH 05/18] Minor tool task improvements - List tasks alphabetically in tools runner - Remove redundant space before CUSTOM entry in hash algorithms table --- src/test/java/tools/ToolsRunner.java | 4 ++-- .../java/tools/hashmethods/HashAlgorithmsDescriptionTask.java | 2 +- src/test/java/tools/hashmethods/hash_algorithms.tpl.md | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/test/java/tools/ToolsRunner.java b/src/test/java/tools/ToolsRunner.java index 240b0681a..3dfbd36b7 100644 --- a/src/test/java/tools/ToolsRunner.java +++ b/src/test/java/tools/ToolsRunner.java @@ -5,9 +5,9 @@ import fr.xephi.authme.TestHelper; import tools.utils.AutoToolTask; import tools.utils.ToolTask; -import java.util.HashMap; import java.util.Map; import java.util.Scanner; +import java.util.TreeMap; /** * Runner for executing tool tasks. @@ -29,7 +29,7 @@ public final class ToolsRunner { // Note ljacqu 20151212: If the tools folder becomes a lot bigger, it will make sense to restrict the depth // of this recursive collector ClassCollector collector = new ClassCollector(TestHelper.TEST_SOURCES_FOLDER, "tools"); - Map tasks = new HashMap<>(); + Map tasks = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); for (ToolTask task : collector.getInstancesOfType(ToolTask.class)) { tasks.put(task.getTaskName(), task); } diff --git a/src/test/java/tools/hashmethods/HashAlgorithmsDescriptionTask.java b/src/test/java/tools/hashmethods/HashAlgorithmsDescriptionTask.java index edbf54307..9f0a7b366 100644 --- a/src/test/java/tools/hashmethods/HashAlgorithmsDescriptionTask.java +++ b/src/test/java/tools/hashmethods/HashAlgorithmsDescriptionTask.java @@ -13,7 +13,7 @@ import java.util.Scanner; /** * Task for generating the markdown page describing the AuthMe hash algorithms. * - * @see {@link fr.xephi.authme.security.HashAlgorithm} + * @see fr.xephi.authme.security.HashAlgorithm */ public class HashAlgorithmsDescriptionTask implements AutoToolTask { diff --git a/src/test/java/tools/hashmethods/hash_algorithms.tpl.md b/src/test/java/tools/hashmethods/hash_algorithms.tpl.md index 73e85ba00..17431eb5b 100644 --- a/src/test/java/tools/hashmethods/hash_algorithms.tpl.md +++ b/src/test/java/tools/hashmethods/hash_algorithms.tpl.md @@ -9,8 +9,7 @@ Algorithm | Recommendation | Hash length | ASCII | | Salt type | Length | Se --------- | -------------- | ----------- | ----- | --- | --------- | ------ | --------- [#algorithms] {name} | {recommendation} | {hash_length} | {ascii_restricted} | | {salt_type} | {salt_length} | {separate_salt} -[/#algorithms] -CUSTOM | | | | | | | | +[/#algorithms]CUSTOM | | | | | | | | From 71ac86ff02d5a2a83187f572b45d25370d668ebd Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sun, 2 Oct 2016 12:44:10 +0200 Subject: [PATCH 06/18] Remove StringUtils#join in favor of String#join (Java 8) --- .../java/fr/xephi/authme/PerformBackup.java | 3 +- .../fr/xephi/authme/command/CommandUtils.java | 13 ----- .../executable/authme/AccountsCommand.java | 3 +- .../authme/command/help/HelpProvider.java | 2 +- .../AbstractDataSourceConverter.java | 3 +- .../listener/FailedVerificationException.java | 5 +- .../process/register/AsyncRegister.java | 2 +- .../fr/xephi/authme/util/StringUtils.java | 41 +--------------- .../fr/xephi/authme/ConsoleLoggerTest.java | 3 +- .../command/CommandInitializerTest.java | 11 ++--- .../authme/command/CommandUtilsTest.java | 40 ---------------- .../authme/listener/OnJoinVerifierTest.java | 3 +- .../output/MessagesFileConsistencyTest.java | 4 +- .../output/MessagesFileYamlCheckerTest.java | 2 +- .../permission/PermissionConsistencyTest.java | 7 ++- .../settings/ConfigFileConsistencyTest.java | 5 +- .../fr/xephi/authme/util/StringUtilsTest.java | 47 ------------------- .../tools/checktestmocks/CheckTestMocks.java | 10 ++-- .../messages/translation/MessageExport.java | 4 +- 19 files changed, 27 insertions(+), 181 deletions(-) diff --git a/src/main/java/fr/xephi/authme/PerformBackup.java b/src/main/java/fr/xephi/authme/PerformBackup.java index 79f1bf9f5..ab2d72db9 100644 --- a/src/main/java/fr/xephi/authme/PerformBackup.java +++ b/src/main/java/fr/xephi/authme/PerformBackup.java @@ -4,7 +4,6 @@ import fr.xephi.authme.datasource.DataSourceType; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.BackupSettings; import fr.xephi.authme.settings.properties.DatabaseSettings; -import fr.xephi.authme.util.StringUtils; import java.io.File; import java.io.FileInputStream; @@ -47,7 +46,7 @@ public class PerformBackup { this.tblname = settings.getProperty(DatabaseSettings.MYSQL_TABLE); String dateString = DATE_FORMAT.format(new Date()); - this.path = StringUtils.join(File.separator, + this.path = String.join(File.separator, instance.getDataFolder().getPath(), "backups", "backup" + dateString); } diff --git a/src/main/java/fr/xephi/authme/command/CommandUtils.java b/src/main/java/fr/xephi/authme/command/CommandUtils.java index 016cbce13..9ea1f5c55 100644 --- a/src/main/java/fr/xephi/authme/command/CommandUtils.java +++ b/src/main/java/fr/xephi/authme/command/CommandUtils.java @@ -1,7 +1,6 @@ package fr.xephi.authme.command; import com.google.common.collect.Lists; -import fr.xephi.authme.util.StringUtils; import java.util.ArrayList; import java.util.List; @@ -25,18 +24,6 @@ public final class CommandUtils { return command.getArguments().size(); } - /** - * Provide a textual representation of a list of labels to show it as a command. For example, a list containing - * the items ["authme", "register", "player"] will return "authme register player". - * - * @param labels The labels to format - * - * @return The space-separated labels - */ - public static String labelsToString(Iterable labels) { - return StringUtils.join(" ", labels); - } - public static String constructCommandPath(CommandDescription command) { StringBuilder sb = new StringBuilder(); String prefix = "/"; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java index 3b446a7fb..f8d39d054 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java @@ -6,7 +6,6 @@ import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.util.BukkitService; -import fr.xephi.authme.util.StringUtils; import org.bukkit.command.CommandSender; import javax.inject.Inject; @@ -70,7 +69,7 @@ public class AccountsCommand implements ExecutableCommand { private static void outputAccountsList(CommandSender sender, String playerName, List accountList) { sender.sendMessage("[AuthMe] " + playerName + " has " + accountList.size() + " accounts."); - String message = "[AuthMe] " + StringUtils.join(", ", accountList) + "."; + String message = "[AuthMe] " + String.join(", ", accountList) + "."; sender.sendMessage(message); } } diff --git a/src/main/java/fr/xephi/authme/command/help/HelpProvider.java b/src/main/java/fr/xephi/authme/command/help/HelpProvider.java index ebe8c0cb0..cb9793d2e 100644 --- a/src/main/java/fr/xephi/authme/command/help/HelpProvider.java +++ b/src/main/java/fr/xephi/authme/command/help/HelpProvider.java @@ -187,7 +187,7 @@ public class HelpProvider implements SettingsDependent { } lines.add(ChatColor.GOLD + "Commands:"); - String parentCommandPath = CommandUtils.labelsToString(parentLabels); + String parentCommandPath = String.join(" ", parentLabels); for (CommandDescription child : command.getChildren()) { lines.add(" /" + parentCommandPath + " " + child.getLabels().get(0) + ChatColor.GRAY + ChatColor.ITALIC + ": " + child.getDescription()); diff --git a/src/main/java/fr/xephi/authme/converter/AbstractDataSourceConverter.java b/src/main/java/fr/xephi/authme/converter/AbstractDataSourceConverter.java index 19be41c33..083cfe2cb 100644 --- a/src/main/java/fr/xephi/authme/converter/AbstractDataSourceConverter.java +++ b/src/main/java/fr/xephi/authme/converter/AbstractDataSourceConverter.java @@ -4,7 +4,6 @@ import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSourceType; -import fr.xephi.authme.util.StringUtils; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; @@ -67,7 +66,7 @@ public abstract class AbstractDataSourceConverter implemen if (!skippedPlayers.isEmpty()) { logAndSendMessage(sender, "Skipped conversion for players which were already in " - + destinationType + ": " + StringUtils.join(", ", skippedPlayers)); + + destinationType + ": " + String.join(", ", skippedPlayers)); } logAndSendMessage(sender, "Database successfully converted from " + source.getType() + " to " + destinationType); diff --git a/src/main/java/fr/xephi/authme/listener/FailedVerificationException.java b/src/main/java/fr/xephi/authme/listener/FailedVerificationException.java index b189fd071..fcbaa1b6a 100644 --- a/src/main/java/fr/xephi/authme/listener/FailedVerificationException.java +++ b/src/main/java/fr/xephi/authme/listener/FailedVerificationException.java @@ -1,7 +1,6 @@ package fr.xephi.authme.listener; import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.util.StringUtils; /** * Exception thrown when a verification has failed. @@ -27,7 +26,7 @@ public class FailedVerificationException extends Exception { @Override public String toString() { - return getClass().getSimpleName() + ": reason=" + (reason == null ? "null" : reason) - + ";args=" + (args == null ? "null" : StringUtils.join(", ", args)); + return getClass().getSimpleName() + ": reason=" + reason + + ";args=" + (args == null ? "null" : String.join(", ", args)); } } diff --git a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java index 8be5b5404..21eae43dc 100644 --- a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java @@ -102,7 +102,7 @@ public class AsyncRegister implements AsynchronousProcess { List otherAccounts = database.getAllAuthsByIp(ip); if (otherAccounts.size() >= maxRegPerIp) { service.send(player, MessageKey.MAX_REGISTER_EXCEEDED, Integer.toString(maxRegPerIp), - Integer.toString(otherAccounts.size()), StringUtils.join(", ", otherAccounts)); + Integer.toString(otherAccounts.size()), String.join(", ", otherAccounts)); return false; } } diff --git a/src/main/java/fr/xephi/authme/util/StringUtils.java b/src/main/java/fr/xephi/authme/util/StringUtils.java index 377dd9f75..a02418ca9 100644 --- a/src/main/java/fr/xephi/authme/util/StringUtils.java +++ b/src/main/java/fr/xephi/authme/util/StringUtils.java @@ -5,7 +5,6 @@ import net.ricecode.similarity.StringSimilarityService; import net.ricecode.similarity.StringSimilarityServiceImpl; import java.io.File; -import java.util.Arrays; /** * Utility class for String operations. @@ -69,44 +68,6 @@ public final class StringUtils { return str == null || str.trim().isEmpty(); } - /** - * Join a list of elements into a single string with the specified delimiter. - * - * @param delimiter The delimiter to use - * @param elements The elements to join - * - * @return A new String that is composed of the elements separated by the delimiter - */ - public static String join(String delimiter, Iterable elements) { - if (delimiter == null) { - delimiter = ""; - } - StringBuilder sb = new StringBuilder(); - for (String element : elements) { - if (!isEmpty(element)) { - // Add the separator if it isn't the first element - if (sb.length() > 0) { - sb.append(delimiter); - } - sb.append(element); - } - } - - return sb.toString(); - } - - /** - * Join a list of elements into a single string with the specified delimiter. - * - * @param delimiter The delimiter to use - * @param elements The elements to join - * - * @return A new String that is composed of the elements separated by the delimiter - */ - public static String join(String delimiter, String... elements) { - return join(delimiter, Arrays.asList(elements)); - } - /** * Format the information from a Throwable as string, retaining the type and its message. * @@ -126,7 +87,7 @@ public final class StringUtils { * @return The created path */ public static String makePath(String... elements) { - return join(File.separator, elements); + return String.join(File.separator, elements); } } diff --git a/src/test/java/fr/xephi/authme/ConsoleLoggerTest.java b/src/test/java/fr/xephi/authme/ConsoleLoggerTest.java index 8d331f9cf..6ae87df63 100644 --- a/src/test/java/fr/xephi/authme/ConsoleLoggerTest.java +++ b/src/test/java/fr/xephi/authme/ConsoleLoggerTest.java @@ -4,7 +4,6 @@ import fr.xephi.authme.output.LogLevel; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.PluginSettings; import fr.xephi.authme.settings.properties.SecuritySettings; -import fr.xephi.authme.util.StringUtils; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -135,7 +134,7 @@ public class ConsoleLoggerTest { assertThat(loggedLines.get(1), containsString("[WARN] Exception occurred: [IllegalStateException]: Test exception message")); // Check that we have this class' full name somewhere in the file -> stacktrace of Exception e - assertThat(StringUtils.join("", loggedLines), containsString(getClass().getCanonicalName())); + assertThat(String.join("", loggedLines), containsString(getClass().getCanonicalName())); } @Test diff --git a/src/test/java/fr/xephi/authme/command/CommandInitializerTest.java b/src/test/java/fr/xephi/authme/command/CommandInitializerTest.java index d5db0c550..944424f52 100644 --- a/src/test/java/fr/xephi/authme/command/CommandInitializerTest.java +++ b/src/test/java/fr/xephi/authme/command/CommandInitializerTest.java @@ -296,17 +296,12 @@ public class CommandInitializerTest { * @return List of all bindings that lead to the command */ private static List getAbsoluteLabels(CommandDescription command) { - String parentPath = ""; - CommandDescription elem = command.getParent(); - while (elem != null) { - parentPath = elem.getLabels().get(0) + " " + parentPath; - elem = elem.getParent(); - } - parentPath = parentPath.trim(); + CommandDescription parent = command.getParent(); + String parentPath = (parent == null) ? "" : parent.getLabels().get(0) + " "; List bindings = new ArrayList<>(command.getLabels().size()); for (String label : command.getLabels()) { - bindings.add(StringUtils.join(" ", parentPath, label)); + bindings.add(parentPath + label); } return bindings; } diff --git a/src/test/java/fr/xephi/authme/command/CommandUtilsTest.java b/src/test/java/fr/xephi/authme/command/CommandUtilsTest.java index bdff3c251..2d73549d8 100644 --- a/src/test/java/fr/xephi/authme/command/CommandUtilsTest.java +++ b/src/test/java/fr/xephi/authme/command/CommandUtilsTest.java @@ -3,10 +3,6 @@ package fr.xephi.authme.command; import fr.xephi.authme.TestHelper; import org.junit.Test; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; @@ -15,42 +11,6 @@ import static org.junit.Assert.assertThat; */ public class CommandUtilsTest { - @Test - public void shouldPrintPartsForStringRepresentation() { - // given - Iterable parts = Arrays.asList("some", "parts", "for", "test"); - - // when - String str = CommandUtils.labelsToString(parts); - - // then - assertThat(str, equalTo("some parts for test")); - } - - @Test - public void shouldPrintEmptyStringForNoArguments() { - // given - List parts = Collections.emptyList(); - - // when - String str = CommandUtils.labelsToString(parts); - - // then - assertThat(str, equalTo("")); - } - - @Test - public void shouldPrintLabels() { - // given - List labels = Arrays.asList("authme", "help", "reload"); - - // when - String result = CommandUtils.labelsToString(labels); - - // then - assertThat(result, equalTo("authme help reload")); - } - @Test public void shouldReturnCommandPath() { // given diff --git a/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java b/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java index 19685ff8c..c77b5724e 100644 --- a/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java +++ b/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java @@ -13,7 +13,6 @@ import fr.xephi.authme.settings.properties.ProtectionSettings; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.util.BukkitService; -import fr.xephi.authme.util.StringUtils; import fr.xephi.authme.util.ValidationService; import org.bukkit.Server; import org.bukkit.entity.Player; @@ -511,7 +510,7 @@ public class OnJoinVerifierTest { @Override public void describeTo(Description description) { description.appendValue("VerificationFailedException: reason=" + messageKey + ";args=" - + (args == null ? "null" : StringUtils.join(", ", args))); + + (args == null ? "null" : String.join(", ", args))); } }; } diff --git a/src/test/java/fr/xephi/authme/output/MessagesFileConsistencyTest.java b/src/test/java/fr/xephi/authme/output/MessagesFileConsistencyTest.java index 607560d64..5cbf36a74 100644 --- a/src/test/java/fr/xephi/authme/output/MessagesFileConsistencyTest.java +++ b/src/test/java/fr/xephi/authme/output/MessagesFileConsistencyTest.java @@ -32,7 +32,7 @@ public class MessagesFileConsistencyTest { if (!errors.isEmpty()) { fail("Validation errors in " + MESSAGES_FILE + ":\n- " - + StringUtils.join("\n- ", errors)); + + String.join("\n- ", errors)); } } @@ -55,7 +55,7 @@ public class MessagesFileConsistencyTest { if (!missingTags.isEmpty()) { String pluralS = missingTags.size() > 1 ? "s" : ""; errors.add(String.format("Message with key '%s' missing tag%s: %s", key, pluralS, - StringUtils.join(", ", missingTags))); + String.join(", ", missingTags))); } } } diff --git a/src/test/java/fr/xephi/authme/output/MessagesFileYamlCheckerTest.java b/src/test/java/fr/xephi/authme/output/MessagesFileYamlCheckerTest.java index fc7b74e5e..4f76882fa 100644 --- a/src/test/java/fr/xephi/authme/output/MessagesFileYamlCheckerTest.java +++ b/src/test/java/fr/xephi/authme/output/MessagesFileYamlCheckerTest.java @@ -48,7 +48,7 @@ public class MessagesFileYamlCheckerTest { // then if (!errors.isEmpty()) { - fail("Errors during verification of message files:\n-" + StringUtils.join("\n-", errors)); + fail("Errors during verification of message files:\n-" + String.join("\n-", errors)); } } diff --git a/src/test/java/fr/xephi/authme/permission/PermissionConsistencyTest.java b/src/test/java/fr/xephi/authme/permission/PermissionConsistencyTest.java index 55c22eb85..bd18df8ad 100644 --- a/src/test/java/fr/xephi/authme/permission/PermissionConsistencyTest.java +++ b/src/test/java/fr/xephi/authme/permission/PermissionConsistencyTest.java @@ -2,7 +2,6 @@ package fr.xephi.authme.permission; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import fr.xephi.authme.util.StringUtils; import org.bukkit.configuration.MemorySection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -65,7 +64,7 @@ public class PermissionConsistencyTest { // then if (!errors.isEmpty()) { - fail("Found consistency issues!\n" + StringUtils.join("\n", errors)); + fail("Found consistency issues!\n" + String.join("\n", errors)); } } @@ -90,7 +89,7 @@ public class PermissionConsistencyTest { // then if (!errors.isEmpty()) { - fail("Found consistency issues!\n" + StringUtils.join("\n", errors)); + fail("Found consistency issues!\n" + String.join("\n", errors)); } } @@ -172,7 +171,7 @@ public class PermissionConsistencyTest { } if (!badChildren.isEmpty()) { errorList.add("Permission '" + definition.node + "' has children that are not logically below it: " - + StringUtils.join(", ", badChildren)); + + String.join(", ", badChildren)); } } diff --git a/src/test/java/fr/xephi/authme/settings/ConfigFileConsistencyTest.java b/src/test/java/fr/xephi/authme/settings/ConfigFileConsistencyTest.java index a495254aa..768dd98ed 100644 --- a/src/test/java/fr/xephi/authme/settings/ConfigFileConsistencyTest.java +++ b/src/test/java/fr/xephi/authme/settings/ConfigFileConsistencyTest.java @@ -8,7 +8,6 @@ import com.github.authme.configme.resource.PropertyResource; import com.github.authme.configme.resource.YamlFileResource; import fr.xephi.authme.TestHelper; import fr.xephi.authme.settings.properties.AuthMeSettingsRetriever; -import fr.xephi.authme.util.StringUtils; import org.bukkit.configuration.MemorySection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -54,7 +53,7 @@ public class ConfigFileConsistencyTest { missingProperties.add(path); } } - fail("Found missing properties!\n-" + StringUtils.join("\n-", missingProperties)); + fail("Found missing properties!\n-" + String.join("\n-", missingProperties)); } } @@ -78,7 +77,7 @@ public class ConfigFileConsistencyTest { // then if (!unknownPaths.isEmpty()) { fail("Found " + unknownPaths.size() + " unknown property paths in the project's config.yml: \n- " - + StringUtils.join("\n- ", unknownPaths)); + + String.join("\n- ", unknownPaths)); } } diff --git a/src/test/java/fr/xephi/authme/util/StringUtilsTest.java b/src/test/java/fr/xephi/authme/util/StringUtilsTest.java index a09ac87ce..72826b4cf 100644 --- a/src/test/java/fr/xephi/authme/util/StringUtilsTest.java +++ b/src/test/java/fr/xephi/authme/util/StringUtilsTest.java @@ -5,8 +5,6 @@ import org.junit.Test; import java.io.File; import java.net.MalformedURLException; -import java.util.Arrays; -import java.util.List; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; @@ -65,51 +63,6 @@ public class StringUtilsTest { assertFalse(StringUtils.isEmpty(" test")); } - @Test - public void shouldJoinStrings() { - // given - List elements = Arrays.asList("test", "for", null, "join", "StringUtils"); - - // when - String result = StringUtils.join(", ", elements); - - // then - assertThat(result, equalTo("test, for, join, StringUtils")); - } - - @Test - public void shouldJoinStringArray() { - // given - String[] elements = {"A", "test", "sentence", "for", "the join", null, "method"}; - - // when - String result = StringUtils.join("_", elements); - - // then - assertThat(result, equalTo("A_test_sentence_for_the join_method")); - } - - @Test - public void shouldNotHaveDelimiter() { - // given - List elements = Arrays.asList(" ", null, "\t", "hello", null); - - // when - String result = StringUtils.join("-", elements); - - // then - assertThat(result, equalTo("hello")); - } - - @Test - public void shouldJoinWithNullDelimiter() { - // given/when - String result = StringUtils.join(null, "A", "Few", "Words", "\n", "To", "Join"); - - // then - assertThat(result, equalTo("AFewWordsToJoin")); - } - @Test public void shouldFormatException() { // given diff --git a/src/test/java/tools/checktestmocks/CheckTestMocks.java b/src/test/java/tools/checktestmocks/CheckTestMocks.java index 8e3011349..b6d79c07a 100644 --- a/src/test/java/tools/checktestmocks/CheckTestMocks.java +++ b/src/test/java/tools/checktestmocks/CheckTestMocks.java @@ -1,10 +1,8 @@ package tools.checktestmocks; -import com.google.common.collect.Collections2; import com.google.common.collect.Sets; import fr.xephi.authme.ClassCollector; import fr.xephi.authme.TestHelper; -import fr.xephi.authme.util.StringUtils; import org.mockito.Mock; import tools.utils.AutoToolTask; import tools.utils.InjectorUtils; @@ -16,6 +14,7 @@ import java.util.HashSet; import java.util.List; import java.util.Scanner; import java.util.Set; +import java.util.stream.Collectors; /** * Task checking if all tests' {@code @Mock} fields have a corresponding @@ -41,7 +40,7 @@ public class CheckTestMocks implements AutoToolTask { for (Class clazz : collector.collectClasses(c -> isTestClassWithMocks(c))) { checkClass(clazz); } - System.out.println(StringUtils.join("\n", errors)); + System.out.println(String.join("\n", errors)); } /** @@ -112,8 +111,9 @@ public class CheckTestMocks implements AutoToolTask { } private static String formatClassList(Collection> coll) { - Collection classNames = Collections2.transform(coll, Class::getSimpleName); - return StringUtils.join(", ", classNames); + return coll.stream() + .map(Class::getSimpleName) + .collect(Collectors.joining(", ")); } } diff --git a/src/test/java/tools/messages/translation/MessageExport.java b/src/test/java/tools/messages/translation/MessageExport.java index 270c460db..1b37347c8 100644 --- a/src/test/java/tools/messages/translation/MessageExport.java +++ b/src/test/java/tools/messages/translation/MessageExport.java @@ -1,7 +1,5 @@ package tools.messages.translation; -import fr.xephi.authme.util.StringUtils; - /** * Container class for one translatable message. */ @@ -14,7 +12,7 @@ public class MessageExport { public MessageExport(String key, String[] tags, String defaultMessage, String translatedMessage) { this.key = key; - this.tags = StringUtils.join(",", tags); + this.tags = String.join(",", tags); this.defaultMessage = defaultMessage; this.translatedMessage = translatedMessage; } From c8cbd4e8536f7173d7ba1d568a358d1769f0049b Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Sun, 2 Oct 2016 17:19:50 +0200 Subject: [PATCH 07/18] Update dependencies --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index a399f16a8..101ec1198 100644 --- a/pom.xml +++ b/pom.xml @@ -367,7 +367,7 @@ org.eluder.coveralls coveralls-maven-plugin - 4.2.0 + 4.3.0 false @@ -505,7 +505,7 @@ com.zaxxer HikariCP - 2.5.1-SNAPSHOT + 2.5.1 compile From 88ce493438247b9aaa68673c1fffc8d021f63bf1 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Sun, 2 Oct 2016 19:41:14 +0200 Subject: [PATCH 08/18] AntiBot cleanup + moved to services Some test needs to be fixed/added --- src/main/java/fr/xephi/authme/AntiBot.java | 145 ------------ .../authme/SwitchAntiBotCommand.java | 10 +- .../xephi/authme/listener/OnJoinVerifier.java | 24 +- .../xephi/authme/listener/PlayerListener.java | 16 +- .../xephi/authme/service/AntiBotService.java | 207 ++++++++++++++++++ .../authme/SwitchAntiBotCommandTest.java | 6 +- .../authme/listener/OnJoinVerifierTest.java | 39 +--- .../authme/listener/PlayerListenerTest.java | 18 +- .../authme/{ => service}/AntiBotTest.java | 90 ++------ 9 files changed, 282 insertions(+), 273 deletions(-) delete mode 100644 src/main/java/fr/xephi/authme/AntiBot.java create mode 100644 src/main/java/fr/xephi/authme/service/AntiBotService.java rename src/test/java/fr/xephi/authme/{ => service}/AntiBotTest.java (61%) diff --git a/src/main/java/fr/xephi/authme/AntiBot.java b/src/main/java/fr/xephi/authme/AntiBot.java deleted file mode 100644 index 53ced436e..000000000 --- a/src/main/java/fr/xephi/authme/AntiBot.java +++ /dev/null @@ -1,145 +0,0 @@ -package fr.xephi.authme; - -import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.output.Messages; -import fr.xephi.authme.permission.AdminPermission; -import fr.xephi.authme.permission.PermissionsManager; -import fr.xephi.authme.permission.PlayerStatePermission; -import fr.xephi.authme.settings.Settings; -import fr.xephi.authme.settings.properties.ProtectionSettings; -import fr.xephi.authme.util.BukkitService; -import org.bukkit.entity.Player; - -import javax.inject.Inject; -import java.util.concurrent.CopyOnWriteArrayList; - -import static fr.xephi.authme.util.BukkitService.TICKS_PER_MINUTE; -import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND; - -/** - * The AntiBot Service Management class. - */ -public class AntiBot { - - private final Settings settings; - private final Messages messages; - private final PermissionsManager permissionsManager; - private final BukkitService bukkitService; - private final CopyOnWriteArrayList antibotKicked = new CopyOnWriteArrayList(); - private final CopyOnWriteArrayList antibotPlayers = new CopyOnWriteArrayList(); - private AntiBotStatus antiBotStatus = AntiBotStatus.DISABLED; - - @Inject - AntiBot(Settings settings, Messages messages, PermissionsManager permissionsManager, - BukkitService bukkitService) { - this.settings = settings; - this.messages = messages; - this.permissionsManager = permissionsManager; - this.bukkitService = bukkitService; - - setupAntiBotService(); - } - - private void setupAntiBotService() { - if (settings.getProperty(ProtectionSettings.ENABLE_ANTIBOT)) { - bukkitService.scheduleSyncDelayedTask(new Runnable() { - @Override - public void run() { - antiBotStatus = AntiBotStatus.LISTENING; - } - }, 2 * TICKS_PER_MINUTE); - } - } - - public void overrideAntiBotStatus(boolean activated) { - if (antiBotStatus != AntiBotStatus.DISABLED) { - if (activated) { - antiBotStatus = AntiBotStatus.ACTIVE; - } else { - antiBotStatus = AntiBotStatus.LISTENING; - } - } - } - - public AntiBotStatus getAntiBotStatus() { - return antiBotStatus; - } - - public void activateAntiBot() { - antiBotStatus = AntiBotStatus.ACTIVE; - for (Player player : bukkitService.getOnlinePlayers()) { - if (permissionsManager.hasPermission(player, AdminPermission.ANTIBOT_MESSAGES)) { - messages.send(player, MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE); - } - } - - final int duration = settings.getProperty(ProtectionSettings.ANTIBOT_DURATION); - bukkitService.scheduleSyncDelayedTask(new Runnable() { - @Override - public void run() { - if (antiBotStatus == AntiBotStatus.ACTIVE) { - antiBotStatus = AntiBotStatus.LISTENING; - antibotPlayers.clear(); - antibotKicked.clear(); - for (String s : messages.retrieve(MessageKey.ANTIBOT_AUTO_DISABLED_MESSAGE)) { - bukkitService.broadcastMessage(s.replace("%m", Integer.toString(duration))); - } - } - } - }, duration * TICKS_PER_MINUTE); - } - - /** - * Handles a player joining the server and checks if AntiBot needs to be activated. - * - * @param player the player who joined the server - */ - public void handlePlayerJoin(final Player player) { - if (antiBotStatus == AntiBotStatus.ACTIVE || antiBotStatus == AntiBotStatus.DISABLED) { - return; - } - if (permissionsManager.hasPermission(player, PlayerStatePermission.BYPASS_ANTIBOT)) { - return; - } - - antibotPlayers.add(player.getName().toLowerCase()); - if (antibotPlayers.size() > settings.getProperty(ProtectionSettings.ANTIBOT_SENSIBILITY)) { - activateAntiBot(); - return; - } - bukkitService.scheduleSyncDelayedTask(new Runnable() { - @Override - public void run() { - antibotPlayers.remove(player.getName().toLowerCase()); - } - }, 15 * TICKS_PER_SECOND); - } - - /** - * Returns whether the player was kicked because of activated antibot. The list is reset - * when antibot is deactivated. - * - * @param name the name to check - * @return true if the given name has been kicked because of Antibot - */ - public boolean wasPlayerKicked(String name) { - return antibotKicked.contains(name.toLowerCase()); - } - - /** - * Adds a name to the list of players kicked by antibot. Should only be used when a player - * is determined to be kicked because of failed antibot verification. - * - * @param name the name to add - */ - public void addPlayerKick(String name) { - antibotKicked.addIfAbsent(name.toLowerCase()); - } - - public enum AntiBotStatus { - LISTENING, - DISABLED, - ACTIVE - } - -} diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/SwitchAntiBotCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/SwitchAntiBotCommand.java index 64a7241f2..44c303843 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/SwitchAntiBotCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/SwitchAntiBotCommand.java @@ -1,6 +1,6 @@ package fr.xephi.authme.command.executable.authme; -import fr.xephi.authme.AntiBot; +import fr.xephi.authme.service.AntiBotService; import fr.xephi.authme.command.CommandMapper; import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.FoundCommandResult; @@ -18,7 +18,7 @@ import java.util.List; public class SwitchAntiBotCommand implements ExecutableCommand { @Inject - private AntiBot antiBot; + private AntiBotService antiBotService; @Inject private CommandMapper commandMapper; @@ -29,7 +29,7 @@ public class SwitchAntiBotCommand implements ExecutableCommand { @Override public void executeCommand(final CommandSender sender, List arguments) { if (arguments.isEmpty()) { - sender.sendMessage("[AuthMe] AntiBot status: " + antiBot.getAntiBotStatus().name()); + sender.sendMessage("[AuthMe] AntiBot status: " + antiBotService.getAntiBotStatus().name()); return; } @@ -37,10 +37,10 @@ public class SwitchAntiBotCommand implements ExecutableCommand { // Enable or disable the mod if ("ON".equalsIgnoreCase(newState)) { - antiBot.overrideAntiBotStatus(true); + antiBotService.overrideAntiBotStatus(true); sender.sendMessage("[AuthMe] AntiBot Manual Override: enabled!"); } else if ("OFF".equalsIgnoreCase(newState)) { - antiBot.overrideAntiBotStatus(false); + antiBotService.overrideAntiBotStatus(false); sender.sendMessage("[AuthMe] AntiBot Manual Override: disabled!"); } else { sender.sendMessage(ChatColor.DARK_RED + "Invalid AntiBot mode!"); diff --git a/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java b/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java index 745a1908c..1767e0e0b 100644 --- a/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java +++ b/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java @@ -1,6 +1,5 @@ package fr.xephi.authme.listener; -import fr.xephi.authme.AntiBot; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.datasource.DataSource; @@ -9,6 +8,7 @@ import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.Messages; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerStatePermission; +import fr.xephi.authme.service.AntiBotService; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.ProtectionSettings; import fr.xephi.authme.settings.properties.RegistrationSettings; @@ -40,7 +40,7 @@ class OnJoinVerifier implements Reloadable { @Inject private PermissionsManager permissionsManager; @Inject - private AntiBot antiBot; + private AntiBotService antiBotService; @Inject private ValidationService validationService; @Inject @@ -50,7 +50,8 @@ class OnJoinVerifier implements Reloadable { private Pattern nicknamePattern; - OnJoinVerifier() { } + OnJoinVerifier() { + } @PostConstruct @@ -63,12 +64,15 @@ class OnJoinVerifier implements Reloadable { /** * Checks if Antibot is enabled. * - * @param playerName the name of the player (lowercase) + * @param player the player * @param isAuthAvailable whether or not the player is registered */ - public void checkAntibot(String playerName, boolean isAuthAvailable) throws FailedVerificationException { - if (antiBot.getAntiBotStatus() == AntiBot.AntiBotStatus.ACTIVE && !isAuthAvailable) { - antiBot.addPlayerKick(playerName); + public void checkAntibot(Player player, boolean isAuthAvailable) throws FailedVerificationException { + if (permissionsManager.hasPermission(player, PlayerStatePermission.BYPASS_ANTIBOT)) { + return; + } + if (antiBotService.shouldKick(isAuthAvailable)) { + antiBotService.addPlayerKick(player.getName()); throw new FailedVerificationException(MessageKey.KICK_ANTIBOT); } } @@ -105,6 +109,7 @@ class OnJoinVerifier implements Reloadable { * joining player is a VIP. * * @param event the login event to verify + * * @return true if the player's connection should be refused (i.e. the event does not need to be processed * further), false if the player is not refused */ @@ -141,7 +146,7 @@ class OnJoinVerifier implements Reloadable { * Checks that the casing in the username corresponds to the one in the database, if so configured. * * @param player the player to verify - * @param auth the auth object associated with the player + * @param auth the auth object associated with the player */ public void checkNameCasing(Player player, PlayerAuth auth) throws FailedVerificationException { if (auth != null && settings.getProperty(RegistrationSettings.PREVENT_OTHER_CASE)) { @@ -160,7 +165,7 @@ class OnJoinVerifier implements Reloadable { * Checks that the player's country is admitted. * * @param isAuthAvailable whether or not the user is registered - * @param playerIp the ip address of the player + * @param playerIp the ip address of the player */ public void checkPlayerCountry(boolean isAuthAvailable, String playerIp) throws FailedVerificationException { @@ -193,6 +198,7 @@ class OnJoinVerifier implements Reloadable { * Selects a non-VIP player to kick when a VIP player joins the server when full. * * @param onlinePlayers list of online players + * * @return the player to kick, or null if none applicable */ private Player generateKickPlayer(Collection onlinePlayers) { diff --git a/src/main/java/fr/xephi/authme/listener/PlayerListener.java b/src/main/java/fr/xephi/authme/listener/PlayerListener.java index c498e6ecc..63a7ec961 100644 --- a/src/main/java/fr/xephi/authme/listener/PlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/PlayerListener.java @@ -1,11 +1,11 @@ package fr.xephi.authme.listener; -import fr.xephi.authme.AntiBot; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.Messages; import fr.xephi.authme.process.Management; +import fr.xephi.authme.service.AntiBotService; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.SpawnLoader; import fr.xephi.authme.settings.properties.HooksSettings; @@ -62,7 +62,7 @@ public class PlayerListener implements Listener { @Inject private DataSource dataSource; @Inject - private AntiBot antiBot; + private AntiBotService antiBotService; @Inject private Management management; @Inject @@ -218,13 +218,13 @@ public class PlayerListener implements Listener { // Fast stuff onJoinVerifier.checkSingleSession(name); onJoinVerifier.checkIsValidName(name); - + // Get the auth later as this may cause the single session check to fail // Slow stuff final PlayerAuth auth = dataSource.getAuth(name); final boolean isAuthAvailable = (auth != null); final String lowerName = name.toLowerCase(); - onJoinVerifier.checkAntibot(lowerName, isAuthAvailable); + onJoinVerifier.checkAntibot(player, isAuthAvailable); onJoinVerifier.checkKickNonRegistered(isAuthAvailable); onJoinVerifier.checkNameCasing(player, auth); onJoinVerifier.checkPlayerCountry(isAuthAvailable, event.getAddress().getHostAddress()); @@ -234,7 +234,7 @@ public class PlayerListener implements Listener { return; } - antiBot.handlePlayerJoin(player); + antiBotService.handlePlayerJoin(); teleportationService.teleportOnJoin(player); } @@ -245,12 +245,12 @@ public class PlayerListener implements Listener { if (settings.getProperty(RegistrationSettings.REMOVE_LEAVE_MESSAGE)) { event.setQuitMessage(null); } else if (settings.getProperty(RegistrationSettings.REMOVE_UNLOGGED_LEAVE_MESSAGE)) { - if(listenerService.shouldCancelEvent(event)) { + if (listenerService.shouldCancelEvent(event)) { event.setQuitMessage(null); } } - if (antiBot.wasPlayerKicked(player.getName())) { + if (antiBotService.wasPlayerKicked(player.getName())) { return; } @@ -268,7 +268,7 @@ public class PlayerListener implements Listener { } final Player player = event.getPlayer(); - if (!antiBot.wasPlayerKicked(player.getName())) { + if (!antiBotService.wasPlayerKicked(player.getName())) { management.performQuit(player); } } diff --git a/src/main/java/fr/xephi/authme/service/AntiBotService.java b/src/main/java/fr/xephi/authme/service/AntiBotService.java new file mode 100644 index 000000000..12d1bf94c --- /dev/null +++ b/src/main/java/fr/xephi/authme/service/AntiBotService.java @@ -0,0 +1,207 @@ +package fr.xephi.authme.service; + +import fr.xephi.authme.initialization.SettingsDependent; +import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.output.Messages; +import fr.xephi.authme.permission.AdminPermission; +import fr.xephi.authme.permission.PermissionsManager; +import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.settings.properties.ProtectionSettings; +import fr.xephi.authme.util.BukkitService; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitTask; + +import javax.inject.Inject; +import java.util.concurrent.CopyOnWriteArrayList; + +import static fr.xephi.authme.util.BukkitService.TICKS_PER_MINUTE; +import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND; + +/** + * The AntiBot Service Management class. + */ +public class AntiBotService implements SettingsDependent { + + // Instances + private final Messages messages; + private final PermissionsManager permissionsManager; + private final BukkitService bukkitService; + + // Settings + private int duration; + private int sensibility; + + // Service status + private AntiBotStatus antiBotStatus; + private BukkitTask disableTask; + private int antibotPlayers; + private final CopyOnWriteArrayList antibotKicked = new CopyOnWriteArrayList(); + + @Inject + AntiBotService(Settings settings, Messages messages, PermissionsManager permissionsManager, BukkitService bukkitService) { + // Instances + this.messages = messages; + this.permissionsManager = permissionsManager; + this.bukkitService = bukkitService; + // Initial status + disableTask = null; + antibotPlayers = 0; + antiBotStatus = AntiBotStatus.DISABLED; + // Load settings and start if required + reload(settings); + } + + @Override + public void reload(Settings settings) { + // Load settings + duration = settings.getProperty(ProtectionSettings.ANTIBOT_DURATION); + sensibility = settings.getProperty(ProtectionSettings.ANTIBOT_SENSIBILITY); + + // Stop existing protection + stopProtection(); + antiBotStatus = AntiBotStatus.DISABLED; + + // If antibot is disabled, just stop + if (!settings.getProperty(ProtectionSettings.ENABLE_ANTIBOT)) { + return; + } + + // Schedule the bot activation + bukkitService.scheduleSyncDelayedTask(new Runnable() { + @Override + public void run() { + antiBotStatus = AntiBotStatus.LISTENING; + } + }, 90 * TICKS_PER_SECOND); + } + + protected void startProtection() { + // Disable existing antibot session + stopProtection(); + // Enable the new session + antiBotStatus = AntiBotStatus.ACTIVE; + + // Inform admins + for (Player player : bukkitService.getOnlinePlayers()) { + if (permissionsManager.hasPermission(player, AdminPermission.ANTIBOT_MESSAGES)) { + messages.send(player, MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE); + } + } + + // Schedule auto-disable + disableTask = bukkitService.runTaskLater(new Runnable() { + @Override + public void run() { + stopProtection(); + } + }, duration * TICKS_PER_MINUTE); + } + + private void stopProtection() { + if(antiBotStatus != AntiBotStatus.ACTIVE) { + return; + } + + // Change status + antiBotStatus = AntiBotStatus.LISTENING; + antibotPlayers = 0; + antibotKicked.clear(); + + // Cancel auto-disable task + disableTask.cancel(); + disableTask = null; + + // Inform admins + for (Player player : bukkitService.getOnlinePlayers()) { + if (permissionsManager.hasPermission(player, AdminPermission.ANTIBOT_MESSAGES)) { + messages.send(player, MessageKey.ANTIBOT_AUTO_DISABLED_MESSAGE, Integer.toString(duration)); + } + } + } + + /** + * Returns the status of the AntiBot service. + * + * @return status of the antibot service + */ + public AntiBotStatus getAntiBotStatus() { + return antiBotStatus; + } + + /** + * Allows to override the status of the protection. + * + * @param started the new protection status + */ + public void overrideAntiBotStatus(boolean started) { + if (antiBotStatus == AntiBotStatus.DISABLED) { + return; + } + if (started) { + startProtection(); + } else { + stopProtection(); + } + } + + /** + * Handles a player joining the server and checks if AntiBot needs to be activated. + */ + public void handlePlayerJoin() { + if (antiBotStatus != AntiBotStatus.LISTENING) { + return; + } + + antibotPlayers++; + if (antibotPlayers > sensibility) { + startProtection(); + return; + } + + bukkitService.scheduleSyncDelayedTask(new Runnable() { + @Override + public void run() { + antibotPlayers--; + } + }, 15 * TICKS_PER_SECOND); + } + + /** + * Returns if a player should be kicked due to antibot service. + * + * @param isAuthAvailable if the player is registered + * @return if the player should be kicked + */ + public boolean shouldKick(boolean isAuthAvailable) { + return !isAuthAvailable && (antiBotStatus == AntiBotStatus.ACTIVE); + } + + /** + * Returns whether the player was kicked because of activated antibot. The list is reset + * when antibot is deactivated. + * + * @param name the name to check + * + * @return true if the given name has been kicked because of Antibot + */ + public boolean wasPlayerKicked(String name) { + return antibotKicked.contains(name.toLowerCase()); + } + + /** + * Adds a name to the list of players kicked by antibot. Should only be used when a player + * is determined to be kicked because of failed antibot verification. + * + * @param name the name to add + */ + public void addPlayerKick(String name) { + antibotKicked.addIfAbsent(name.toLowerCase()); + } + + public enum AntiBotStatus { + LISTENING, + DISABLED, + ACTIVE + } + +} diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/SwitchAntiBotCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/SwitchAntiBotCommandTest.java index 9b380411c..239ba33d2 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/SwitchAntiBotCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/SwitchAntiBotCommandTest.java @@ -1,6 +1,6 @@ package fr.xephi.authme.command.executable.authme; -import fr.xephi.authme.AntiBot; +import fr.xephi.authme.service.AntiBotService; import fr.xephi.authme.command.CommandMapper; import fr.xephi.authme.command.FoundCommandResult; import fr.xephi.authme.command.help.HelpProvider; @@ -32,7 +32,7 @@ public class SwitchAntiBotCommandTest { private SwitchAntiBotCommand command; @Mock - private AntiBot antiBot; + private AntiBotService antiBot; @Mock private CommandMapper commandMapper; @@ -43,7 +43,7 @@ public class SwitchAntiBotCommandTest { @Test public void shouldReturnAntiBotState() { // given - given(antiBot.getAntiBotStatus()).willReturn(AntiBot.AntiBotStatus.ACTIVE); + given(antiBot.getAntiBotStatus()).willReturn(AntiBotService.AntiBotStatus.ACTIVE); CommandSender sender = mock(CommandSender.class); // when diff --git a/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java b/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java index c77b5724e..32ee61715 100644 --- a/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java +++ b/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java @@ -1,6 +1,6 @@ package fr.xephi.authme.listener; -import fr.xephi.authme.AntiBot; +import fr.xephi.authme.service.AntiBotService; import fr.xephi.authme.TestHelper; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.datasource.DataSource; @@ -61,7 +61,7 @@ public class OnJoinVerifierTest { @Mock private PermissionsManager permissionsManager; @Mock - private AntiBot antiBot; + private AntiBotService antiBotService; @Mock private ValidationService validationService; @Mock @@ -378,46 +378,31 @@ public class OnJoinVerifierTest { @Test public void shouldCheckAntiBot() throws FailedVerificationException { // given - String name = "user123"; + Player player = newPlayerWithName("test123"); boolean hasAuth = false; - given(antiBot.getAntiBotStatus()).willReturn(AntiBot.AntiBotStatus.LISTENING); + given(permissionsManager.hasPermission(player, PlayerStatePermission.BYPASS_ANTIBOT)).willReturn(false); + given(antiBotService.getAntiBotStatus()).willReturn(AntiBotService.AntiBotStatus.LISTENING); // when - onJoinVerifier.checkAntibot(name, hasAuth); + onJoinVerifier.checkAntibot(player, hasAuth); // then - verify(antiBot).getAntiBotStatus(); + verify(antiBotService).shouldKick(hasAuth); } @Test public void shouldAllowUserWithAuth() throws FailedVerificationException { // given - String name = "Bobby"; + Player player = newPlayerWithName("Bobby"); boolean hasAuth = true; - given(antiBot.getAntiBotStatus()).willReturn(AntiBot.AntiBotStatus.ACTIVE); + given(permissionsManager.hasPermission(player, PlayerStatePermission.BYPASS_ANTIBOT)).willReturn(false); + given(antiBotService.getAntiBotStatus()).willReturn(AntiBotService.AntiBotStatus.ACTIVE); // when - onJoinVerifier.checkAntibot(name, hasAuth); + onJoinVerifier.checkAntibot(player, hasAuth); // then - verify(antiBot).getAntiBotStatus(); - } - - @Test - public void shouldThrowForActiveAntiBot() { - // given - String name = "Bobby"; - boolean hasAuth = false; - given(antiBot.getAntiBotStatus()).willReturn(AntiBot.AntiBotStatus.ACTIVE); - - // when / then - try { - onJoinVerifier.checkAntibot(name, hasAuth); - fail("Expected exception to be thrown"); - } catch (FailedVerificationException e) { - assertThat(e, exceptionWithData(MessageKey.KICK_ANTIBOT)); - verify(antiBot).addPlayerKick(name); - } + verify(antiBotService).shouldKick(hasAuth); } /** diff --git a/src/test/java/fr/xephi/authme/listener/PlayerListenerTest.java b/src/test/java/fr/xephi/authme/listener/PlayerListenerTest.java index 35179e6e7..f9efc830a 100644 --- a/src/test/java/fr/xephi/authme/listener/PlayerListenerTest.java +++ b/src/test/java/fr/xephi/authme/listener/PlayerListenerTest.java @@ -1,6 +1,6 @@ package fr.xephi.authme.listener; -import fr.xephi.authme.AntiBot; +import fr.xephi.authme.service.AntiBotService; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.output.MessageKey; @@ -80,7 +80,7 @@ public class PlayerListenerTest { @Mock private DataSource dataSource; @Mock - private AntiBot antiBot; + private AntiBotService antiBotService; @Mock private Management management; @Mock @@ -112,7 +112,7 @@ public class PlayerListenerTest { // then assertThat(event.isCancelled(), equalTo(true)); - verifyZeroInteractions(player, management, antiBot); + verifyZeroInteractions(player, management, antiBotService); } @Test @@ -122,14 +122,14 @@ public class PlayerListenerTest { String name = "Bobby"; Player player = mockPlayerWithName(name); PlayerKickEvent event = new PlayerKickEvent(player, "You logged in from another location", ""); - given(antiBot.wasPlayerKicked(name)).willReturn(false); + given(antiBotService.wasPlayerKicked(name)).willReturn(false); // when listener.onPlayerKick(event); // then assertThat(event.isCancelled(), equalTo(false)); - verify(antiBot).wasPlayerKicked(name); + verify(antiBotService).wasPlayerKicked(name); verify(management).performQuit(player); } @@ -140,14 +140,14 @@ public class PlayerListenerTest { String name = "Bobby"; Player player = mockPlayerWithName(name); PlayerKickEvent event = new PlayerKickEvent(player, "No longer desired here!", ""); - given(antiBot.wasPlayerKicked(name)).willReturn(true); + given(antiBotService.wasPlayerKicked(name)).willReturn(true); // when listener.onPlayerKick(event); // then assertThat(event.isCancelled(), equalTo(false)); - verify(antiBot).wasPlayerKicked(name); + verify(antiBotService).wasPlayerKicked(name); verifyZeroInteractions(management); } @@ -560,11 +560,11 @@ public class PlayerListenerTest { verify(onJoinVerifier).refusePlayerForFullServer(event); verify(onJoinVerifier).checkSingleSession(name); verify(onJoinVerifier).checkIsValidName(name); - verify(onJoinVerifier).checkAntibot(name, true); + verify(onJoinVerifier).checkAntibot(player, true); verify(onJoinVerifier).checkKickNonRegistered(true); verify(onJoinVerifier).checkNameCasing(player, auth); verify(onJoinVerifier).checkPlayerCountry(true, ip); - verify(antiBot).handlePlayerJoin(player); + verify(antiBotService).handlePlayerJoin(); verify(teleportationService).teleportOnJoin(player); verifyNoModifyingCalls(event); } diff --git a/src/test/java/fr/xephi/authme/AntiBotTest.java b/src/test/java/fr/xephi/authme/service/AntiBotTest.java similarity index 61% rename from src/test/java/fr/xephi/authme/AntiBotTest.java rename to src/test/java/fr/xephi/authme/service/AntiBotTest.java index 2b46bab10..0ec5089ed 100644 --- a/src/test/java/fr/xephi/authme/AntiBotTest.java +++ b/src/test/java/fr/xephi/authme/service/AntiBotTest.java @@ -1,10 +1,13 @@ -package fr.xephi.authme; +package fr.xephi.authme.service; +import fr.xephi.authme.ReflectionTestUtils; +import fr.xephi.authme.TestHelper; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.Messages; import fr.xephi.authme.permission.AdminPermission; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerStatePermission; +import fr.xephi.authme.service.AntiBotService; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.ProtectionSettings; import fr.xephi.authme.util.BukkitService; @@ -37,7 +40,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; /** - * Test for {@link AntiBot}. + * Test for {@link AntiBotService}. */ @RunWith(MockitoJUnitRunner.class) public class AntiBotTest { @@ -60,58 +63,58 @@ public class AntiBotTest { public void shouldKeepAntiBotDisabled() { // given / when given(settings.getProperty(ProtectionSettings.ENABLE_ANTIBOT)).willReturn(false); - AntiBot antiBot = new AntiBot(settings, messages, permissionsManager, bukkitService); + AntiBotService antiBot = new AntiBotService(settings, messages, permissionsManager, bukkitService); // then verify(bukkitService, never()).scheduleSyncDelayedTask(any(Runnable.class), anyLong()); - assertThat(antiBot.getAntiBotStatus(), equalTo(AntiBot.AntiBotStatus.DISABLED)); + assertThat(antiBot.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.DISABLED)); } @Test public void shouldTransitionToListening() { // given / when - AntiBot antiBot = new AntiBot(settings, messages, permissionsManager, bukkitService); + AntiBotService antiBot = new AntiBotService(settings, messages, permissionsManager, bukkitService); TestHelper.runSyncDelayedTaskWithDelay(bukkitService); // then - assertThat(antiBot.getAntiBotStatus(), equalTo(AntiBot.AntiBotStatus.LISTENING)); + assertThat(antiBot.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.LISTENING)); } @Test public void shouldSetStatusToActive() { // given - AntiBot antiBot = createListeningAntiBot(); + AntiBotService antiBot = createListeningAntiBot(); // when antiBot.overrideAntiBotStatus(true); // then - assertThat(antiBot.getAntiBotStatus(), equalTo(AntiBot.AntiBotStatus.ACTIVE)); + assertThat(antiBot.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.ACTIVE)); } @Test public void shouldSetStatusToListening() { // given - AntiBot antiBot = createListeningAntiBot(); + AntiBotService antiBot = createListeningAntiBot(); // when antiBot.overrideAntiBotStatus(false); // then - assertThat(antiBot.getAntiBotStatus(), equalTo(AntiBot.AntiBotStatus.LISTENING)); + assertThat(antiBot.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.LISTENING)); } @Test public void shouldRemainDisabled() { // given given(settings.getProperty(ProtectionSettings.ENABLE_ANTIBOT)).willReturn(false); - AntiBot antiBot = new AntiBot(settings, messages, permissionsManager, bukkitService); + AntiBotService antiBot = new AntiBotService(settings, messages, permissionsManager, bukkitService); // when antiBot.overrideAntiBotStatus(true); // then - assertThat(antiBot.getAntiBotStatus(), equalTo(AntiBot.AntiBotStatus.DISABLED)); + assertThat(antiBot.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.DISABLED)); } @Test @@ -119,7 +122,7 @@ public class AntiBotTest { // given int duration = 300; given(settings.getProperty(ProtectionSettings.ANTIBOT_DURATION)).willReturn(duration); - AntiBot antiBot = createListeningAntiBot(); + AntiBotService antiBot = createListeningAntiBot(); List onlinePlayers = Arrays.asList(mock(Player.class), mock(Player.class), mock(Player.class)); given(bukkitService.getOnlinePlayers()).willReturn((List) onlinePlayers); given(permissionsManager.hasPermission(onlinePlayers.get(0), AdminPermission.ANTIBOT_MESSAGES)).willReturn(true); @@ -127,10 +130,10 @@ public class AntiBotTest { given(permissionsManager.hasPermission(onlinePlayers.get(2), AdminPermission.ANTIBOT_MESSAGES)).willReturn(true); // when - antiBot.activateAntiBot(); + antiBot.startProtection(); // then - assertThat(antiBot.getAntiBotStatus(), equalTo(AntiBot.AntiBotStatus.ACTIVE)); + assertThat(antiBot.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.ACTIVE)); verify(bukkitService).getOnlinePlayers(); verify(permissionsManager, times(3)).hasPermission(any(Player.class), eq(AdminPermission.ANTIBOT_MESSAGES)); verify(messages).send(onlinePlayers.get(0), MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE); @@ -147,69 +150,22 @@ public class AntiBotTest { given(messages.retrieve(MessageKey.ANTIBOT_AUTO_DISABLED_MESSAGE)) .willReturn(new String[]{"Disabled...", "Placeholder: %m."}); given(settings.getProperty(ProtectionSettings.ANTIBOT_DURATION)).willReturn(4); - AntiBot antiBot = createListeningAntiBot(); + AntiBotService antiBot = createListeningAntiBot(); // when - antiBot.activateAntiBot(); + antiBot.startProtection(); TestHelper.runSyncDelayedTaskWithDelay(bukkitService); // then - assertThat(antiBot.getAntiBotStatus(), equalTo(AntiBot.AntiBotStatus.LISTENING)); + assertThat(antiBot.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.LISTENING)); verify(bukkitService).scheduleSyncDelayedTask(any(Runnable.class), eq((long) 4800)); ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); verify(bukkitService, times(2)).broadcastMessage(captor.capture()); assertThat(captor.getAllValues(), contains("Disabled...", "Placeholder: 4.")); } - @Test - public void shouldCheckPlayerAndRemoveHimLater() { - // given - Player player = mock(Player.class); - given(player.getName()).willReturn("Plaer"); - given(permissionsManager.hasPermission(player, PlayerStatePermission.BYPASS_ANTIBOT)).willReturn(false); - given(settings.getProperty(ProtectionSettings.ANTIBOT_SENSIBILITY)).willReturn(10); - AntiBot antiBot = createListeningAntiBot(); - - // when - antiBot.handlePlayerJoin(player); - - // then - List playerList = ReflectionTestUtils - .getFieldValue(AntiBot.class, antiBot, "antibotPlayers"); - assertThat(playerList, hasSize(1)); - verify(bukkitService).scheduleSyncDelayedTask(any(Runnable.class), eq((long) 15 * TICKS_PER_SECOND)); - - // Follow-up: Check that player will be removed from list again by running the Runnable - // given (2) - // Add another player to the list - playerList.add("other_player"); - - // when (2) - TestHelper.runSyncDelayedTaskWithDelay(bukkitService); - - // then (2) - assertThat(playerList, contains("other_player")); - } - - @Test - public void shouldNotUpdateListForPlayerWithByPassPermission() { - // given - Player player = mock(Player.class); - given(permissionsManager.hasPermission(player, PlayerStatePermission.BYPASS_ANTIBOT)).willReturn(true); - given(settings.getProperty(ProtectionSettings.ANTIBOT_SENSIBILITY)).willReturn(3); - AntiBot antiBot = createListeningAntiBot(); - - // when - antiBot.handlePlayerJoin(player); - - // then - List playerList = ReflectionTestUtils.getFieldValue(AntiBot.class, antiBot, "antibotPlayers"); - assertThat(playerList, empty()); - verify(bukkitService, never()).scheduleSyncDelayedTask(any(Runnable.class), anyLong()); - } - - private AntiBot createListeningAntiBot() { - AntiBot antiBot = new AntiBot(settings, messages, permissionsManager, bukkitService); + private AntiBotService createListeningAntiBot() { + AntiBotService antiBot = new AntiBotService(settings, messages, permissionsManager, bukkitService); TestHelper.runSyncDelayedTaskWithDelay(bukkitService); // Make BukkitService forget about all interactions up to here reset(bukkitService); From 5c2d7139bc6e70e4f1db8c5d77279129d7fd66b2 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Mon, 3 Oct 2016 21:55:04 +0200 Subject: [PATCH 09/18] Create unit tests for antibot refactoring --- .../xephi/authme/listener/PlayerListener.java | 1 - .../xephi/authme/service/AntiBotService.java | 22 +- .../authme/listener/OnJoinVerifierTest.java | 50 +++-- .../authme/service/AntiBotServiceTest.java | 211 ++++++++++++++++++ .../fr/xephi/authme/service/AntiBotTest.java | 175 --------------- 5 files changed, 257 insertions(+), 202 deletions(-) create mode 100644 src/test/java/fr/xephi/authme/service/AntiBotServiceTest.java delete mode 100644 src/test/java/fr/xephi/authme/service/AntiBotTest.java diff --git a/src/main/java/fr/xephi/authme/listener/PlayerListener.java b/src/main/java/fr/xephi/authme/listener/PlayerListener.java index 63a7ec961..1a5f8a287 100644 --- a/src/main/java/fr/xephi/authme/listener/PlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/PlayerListener.java @@ -223,7 +223,6 @@ public class PlayerListener implements Listener { // Slow stuff final PlayerAuth auth = dataSource.getAuth(name); final boolean isAuthAvailable = (auth != null); - final String lowerName = name.toLowerCase(); onJoinVerifier.checkAntibot(player, isAuthAvailable); onJoinVerifier.checkKickNonRegistered(isAuthAvailable); onJoinVerifier.checkNameCasing(player, auth); diff --git a/src/main/java/fr/xephi/authme/service/AntiBotService.java b/src/main/java/fr/xephi/authme/service/AntiBotService.java index 12d1bf94c..6fd3d8fa8 100644 --- a/src/main/java/fr/xephi/authme/service/AntiBotService.java +++ b/src/main/java/fr/xephi/authme/service/AntiBotService.java @@ -35,10 +35,11 @@ public class AntiBotService implements SettingsDependent { private AntiBotStatus antiBotStatus; private BukkitTask disableTask; private int antibotPlayers; - private final CopyOnWriteArrayList antibotKicked = new CopyOnWriteArrayList(); + private final CopyOnWriteArrayList antibotKicked = new CopyOnWriteArrayList<>(); @Inject - AntiBotService(Settings settings, Messages messages, PermissionsManager permissionsManager, BukkitService bukkitService) { + AntiBotService(Settings settings, Messages messages, PermissionsManager permissionsManager, + BukkitService bukkitService) { // Instances this.messages = messages; this.permissionsManager = permissionsManager; @@ -75,7 +76,7 @@ public class AntiBotService implements SettingsDependent { }, 90 * TICKS_PER_SECOND); } - protected void startProtection() { + private void startProtection() { // Disable existing antibot session stopProtection(); // Enable the new session @@ -98,7 +99,7 @@ public class AntiBotService implements SettingsDependent { } private void stopProtection() { - if(antiBotStatus != AntiBotStatus.ACTIVE) { + if (antiBotStatus != AntiBotStatus.ACTIVE) { return; } @@ -134,13 +135,12 @@ public class AntiBotService implements SettingsDependent { * @param started the new protection status */ public void overrideAntiBotStatus(boolean started) { - if (antiBotStatus == AntiBotStatus.DISABLED) { - return; - } - if (started) { - startProtection(); - } else { - stopProtection(); + if (antiBotStatus != AntiBotStatus.DISABLED) { + if (started) { + startProtection(); + } else { + stopProtection(); + } } } diff --git a/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java b/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java index 32ee61715..66ddb673b 100644 --- a/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java +++ b/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java @@ -1,6 +1,5 @@ package fr.xephi.authme.listener; -import fr.xephi.authme.service.AntiBotService; import fr.xephi.authme.TestHelper; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.datasource.DataSource; @@ -8,6 +7,7 @@ import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.Messages; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerStatePermission; +import fr.xephi.authme.service.AntiBotService; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.ProtectionSettings; import fr.xephi.authme.settings.properties.RegistrationSettings; @@ -376,33 +376,53 @@ public class OnJoinVerifierTest { } @Test - public void shouldCheckAntiBot() throws FailedVerificationException { + public void shouldAllowUser() throws FailedVerificationException { // given - Player player = newPlayerWithName("test123"); - boolean hasAuth = false; + Player player = newPlayerWithName("Bobby"); + boolean isAuthAvailable = false; given(permissionsManager.hasPermission(player, PlayerStatePermission.BYPASS_ANTIBOT)).willReturn(false); - given(antiBotService.getAntiBotStatus()).willReturn(AntiBotService.AntiBotStatus.LISTENING); + given(antiBotService.shouldKick(isAuthAvailable)).willReturn(false); // when - onJoinVerifier.checkAntibot(player, hasAuth); + onJoinVerifier.checkAntibot(player, isAuthAvailable); // then - verify(antiBotService).shouldKick(hasAuth); + verify(permissionsManager).hasPermission(player, PlayerStatePermission.BYPASS_ANTIBOT); + verify(antiBotService).shouldKick(isAuthAvailable); } @Test - public void shouldAllowUserWithAuth() throws FailedVerificationException { + public void shouldAllowUserWithBypassPermission() throws FailedVerificationException { // given - Player player = newPlayerWithName("Bobby"); - boolean hasAuth = true; - given(permissionsManager.hasPermission(player, PlayerStatePermission.BYPASS_ANTIBOT)).willReturn(false); - given(antiBotService.getAntiBotStatus()).willReturn(AntiBotService.AntiBotStatus.ACTIVE); + Player player = newPlayerWithName("Steward"); + boolean isAuthAvailable = false; + given(permissionsManager.hasPermission(player, PlayerStatePermission.BYPASS_ANTIBOT)).willReturn(true); + given(antiBotService.shouldKick(isAuthAvailable)).willReturn(true); // when - onJoinVerifier.checkAntibot(player, hasAuth); + onJoinVerifier.checkAntibot(player, isAuthAvailable); // then - verify(antiBotService).shouldKick(hasAuth); + verify(permissionsManager).hasPermission(player, PlayerStatePermission.BYPASS_ANTIBOT); + } + + @Test + public void shouldKickUserForFailedAntibotCheck() throws FailedVerificationException { + // given + Player player = newPlayerWithName("D3"); + boolean isAuthAvailable = false; + given(permissionsManager.hasPermission(player, PlayerStatePermission.BYPASS_ANTIBOT)).willReturn(false); + given(antiBotService.shouldKick(isAuthAvailable)).willReturn(true); + + // when / then + try { + onJoinVerifier.checkAntibot(player, isAuthAvailable); + fail("Expected exception to be thrown"); + } catch (FailedVerificationException e) { + verify(permissionsManager).hasPermission(player, PlayerStatePermission.BYPASS_ANTIBOT); + verify(antiBotService).shouldKick(isAuthAvailable); + } + } /** @@ -473,7 +493,7 @@ public class OnJoinVerifierTest { return player; } - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings("unchecked") private void returnOnlineListFromBukkitServer(Collection onlineList) { // Note ljacqu 20160529: The compiler gets lost in generics because Collection is returned // from getOnlinePlayers(). We need to uncheck onlineList to a simple Collection or it will refuse to compile. diff --git a/src/test/java/fr/xephi/authme/service/AntiBotServiceTest.java b/src/test/java/fr/xephi/authme/service/AntiBotServiceTest.java new file mode 100644 index 000000000..b401a895f --- /dev/null +++ b/src/test/java/fr/xephi/authme/service/AntiBotServiceTest.java @@ -0,0 +1,211 @@ +package fr.xephi.authme.service; + +import ch.jalu.injector.testing.BeforeInjecting; +import ch.jalu.injector.testing.DelayedInjectionRunner; +import ch.jalu.injector.testing.InjectDelayed; +import fr.xephi.authme.ReflectionTestUtils; +import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.output.Messages; +import fr.xephi.authme.permission.AdminPermission; +import fr.xephi.authme.permission.PermissionsManager; +import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.settings.properties.ProtectionSettings; +import fr.xephi.authme.util.BukkitService; +import org.bukkit.entity.Player; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; + +import java.util.Arrays; +import java.util.List; + +import static fr.xephi.authme.TestHelper.runSyncDelayedTaskWithDelay; +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.only; +import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; + +/** + * Test for {@link AntiBotService}. + */ +@RunWith(DelayedInjectionRunner.class) +public class AntiBotServiceTest { + + @InjectDelayed + private AntiBotService antiBotService; + + @Mock + private Settings settings; + @Mock + private Messages messages; + @Mock + private PermissionsManager permissionsManager; + @Mock + private BukkitService bukkitService; + + @BeforeInjecting + public void initSettings() { + given(settings.getProperty(ProtectionSettings.ANTIBOT_DURATION)).willReturn(10); + given(settings.getProperty(ProtectionSettings.ANTIBOT_SENSIBILITY)).willReturn(5); + given(settings.getProperty(ProtectionSettings.ENABLE_ANTIBOT)).willReturn(true); + } + + @Test + public void shouldStartListenerOnStartup() { + // given / when + runSyncDelayedTaskWithDelay(bukkitService); + + // then + assertThat(antiBotService.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.LISTENING)); + } + + @Test + public void shouldNotListenForDisabledSetting() { + // given + reset(bukkitService); + given(settings.getProperty(ProtectionSettings.ENABLE_ANTIBOT)).willReturn(false); + + // when + AntiBotService antiBotService = new AntiBotService(settings, messages, permissionsManager, bukkitService); + + // then + assertThat(antiBotService.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.DISABLED)); + verifyZeroInteractions(bukkitService); + } + + @Test + public void shouldActivateAntibot() { + // given - listening antibot + runSyncDelayedTaskWithDelay(bukkitService); + + // when + antiBotService.overrideAntiBotStatus(true); + + // then + assertThat(antiBotService.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.ACTIVE)); + // Check that a task is scheduled to disable again + runSyncDelayedTaskWithDelay(bukkitService); + assertThat(antiBotService.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.LISTENING)); + } + + @Test + public void shouldNotActivateAntibotForDisabledSetting() { + // given - disabled antibot + reset(bukkitService); + assertThat(antiBotService.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.DISABLED)); + given(settings.getProperty(ProtectionSettings.ENABLE_ANTIBOT)).willReturn(false); + + // when + antiBotService.overrideAntiBotStatus(true); + + // then + assertThat(antiBotService.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.DISABLED)); + verifyZeroInteractions(bukkitService); + } + + @Test + public void shouldKeepTrackOfKickedPlayers() { + // given + String name = "eratic"; + antiBotService.addPlayerKick(name); + + // when + boolean result1 = antiBotService.wasPlayerKicked(name); + boolean result2 = antiBotService.wasPlayerKicked("other"); + + // then + assertThat(result1, equalTo(true)); + assertThat(result2, equalTo(false)); + } + + @Test + public void shouldAcceptPlayerToJoin() { + // given - listening antibot + runSyncDelayedTaskWithDelay(bukkitService); + + // when + boolean result = antiBotService.shouldKick(false); + + // then + assertThat(result, equalTo(false)); + } + + @Test + public void shouldRejectPlayerWithoutAuth() { + // given - active antibot + runSyncDelayedTaskWithDelay(bukkitService); + antiBotService.overrideAntiBotStatus(true); + + // when + boolean kickWithoutAuth = antiBotService.shouldKick(false); + boolean kickWithAuth = antiBotService.shouldKick(true); + + // then + assertThat(kickWithoutAuth, equalTo(true)); + assertThat(kickWithAuth, equalTo(false)); + } + + @Test + public void shouldIncreaseCountAndDecreaseAfterDelay() { + // given - listening antibot + runSyncDelayedTaskWithDelay(bukkitService); + reset(bukkitService); + assertThat(getAntiBotCount(antiBotService), equalTo(0)); + + // when + antiBotService.handlePlayerJoin(); + + // then + assertThat(getAntiBotCount(antiBotService), equalTo(1)); + runSyncDelayedTaskWithDelay(bukkitService); + assertThat(getAntiBotCount(antiBotService), equalTo(0)); + } + + @Test + public void shouldActivateAntibotAfterThreshold() { + // given + int sensitivity = 10; + given(settings.getProperty(ProtectionSettings.ANTIBOT_SENSIBILITY)).willReturn(sensitivity); + reset(bukkitService); + AntiBotService antiBotService = new AntiBotService(settings, messages, permissionsManager, bukkitService); + runSyncDelayedTaskWithDelay(bukkitService); + + for (int i = 0; i < sensitivity; ++i) { + antiBotService.handlePlayerJoin(); + } + assertThat(antiBotService.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.LISTENING)); + + // when + antiBotService.handlePlayerJoin(); + + // then + assertThat(antiBotService.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.ACTIVE)); + } + + @Test + @SuppressWarnings("unchecked") + public void shouldInformPlayersOnActivation() { + // given - listening antibot + runSyncDelayedTaskWithDelay(bukkitService); + List players = Arrays.asList(mock(Player.class), mock(Player.class)); + given(bukkitService.getOnlinePlayers()).willReturn((List) players); + given(permissionsManager.hasPermission(players.get(0), AdminPermission.ANTIBOT_MESSAGES)).willReturn(false); + given(permissionsManager.hasPermission(players.get(1), AdminPermission.ANTIBOT_MESSAGES)).willReturn(true); + + // when + antiBotService.overrideAntiBotStatus(true); + + // then + verify(permissionsManager).hasPermission(players.get(0), AdminPermission.ANTIBOT_MESSAGES); + verify(permissionsManager).hasPermission(players.get(1), AdminPermission.ANTIBOT_MESSAGES); + verify(messages, only()).send(players.get(1), MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE); + } + + private static int getAntiBotCount(AntiBotService antiBotService) { + return ReflectionTestUtils.getFieldValue(AntiBotService.class, antiBotService, "antibotPlayers"); + } +} diff --git a/src/test/java/fr/xephi/authme/service/AntiBotTest.java b/src/test/java/fr/xephi/authme/service/AntiBotTest.java deleted file mode 100644 index 0ec5089ed..000000000 --- a/src/test/java/fr/xephi/authme/service/AntiBotTest.java +++ /dev/null @@ -1,175 +0,0 @@ -package fr.xephi.authme.service; - -import fr.xephi.authme.ReflectionTestUtils; -import fr.xephi.authme.TestHelper; -import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.output.Messages; -import fr.xephi.authme.permission.AdminPermission; -import fr.xephi.authme.permission.PermissionsManager; -import fr.xephi.authme.permission.PlayerStatePermission; -import fr.xephi.authme.service.AntiBotService; -import fr.xephi.authme.settings.Settings; -import fr.xephi.authme.settings.properties.ProtectionSettings; -import fr.xephi.authme.util.BukkitService; -import org.bukkit.entity.Player; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; - -import java.util.Arrays; -import java.util.List; - -import static fr.xephi.authme.util.BukkitService.TICKS_PER_MINUTE; -import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasSize; -import static org.junit.Assert.assertThat; -import static org.mockito.BDDMockito.given; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.reset; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -/** - * Test for {@link AntiBotService}. - */ -@RunWith(MockitoJUnitRunner.class) -public class AntiBotTest { - - @Mock - private Settings settings; - @Mock - private Messages messages; - @Mock - private PermissionsManager permissionsManager; - @Mock - private BukkitService bukkitService; - - @Before - public void setDefaultSettingValues() { - given(settings.getProperty(ProtectionSettings.ENABLE_ANTIBOT)).willReturn(true); - } - - @Test - public void shouldKeepAntiBotDisabled() { - // given / when - given(settings.getProperty(ProtectionSettings.ENABLE_ANTIBOT)).willReturn(false); - AntiBotService antiBot = new AntiBotService(settings, messages, permissionsManager, bukkitService); - - // then - verify(bukkitService, never()).scheduleSyncDelayedTask(any(Runnable.class), anyLong()); - assertThat(antiBot.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.DISABLED)); - } - - @Test - public void shouldTransitionToListening() { - // given / when - AntiBotService antiBot = new AntiBotService(settings, messages, permissionsManager, bukkitService); - TestHelper.runSyncDelayedTaskWithDelay(bukkitService); - - // then - assertThat(antiBot.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.LISTENING)); - } - - @Test - public void shouldSetStatusToActive() { - // given - AntiBotService antiBot = createListeningAntiBot(); - - // when - antiBot.overrideAntiBotStatus(true); - - // then - assertThat(antiBot.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.ACTIVE)); - } - - @Test - public void shouldSetStatusToListening() { - // given - AntiBotService antiBot = createListeningAntiBot(); - - // when - antiBot.overrideAntiBotStatus(false); - - // then - assertThat(antiBot.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.LISTENING)); - } - - @Test - public void shouldRemainDisabled() { - // given - given(settings.getProperty(ProtectionSettings.ENABLE_ANTIBOT)).willReturn(false); - AntiBotService antiBot = new AntiBotService(settings, messages, permissionsManager, bukkitService); - - // when - antiBot.overrideAntiBotStatus(true); - - // then - assertThat(antiBot.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.DISABLED)); - } - - @Test - public void shouldActivateAntiBot() { - // given - int duration = 300; - given(settings.getProperty(ProtectionSettings.ANTIBOT_DURATION)).willReturn(duration); - AntiBotService antiBot = createListeningAntiBot(); - List onlinePlayers = Arrays.asList(mock(Player.class), mock(Player.class), mock(Player.class)); - given(bukkitService.getOnlinePlayers()).willReturn((List) onlinePlayers); - given(permissionsManager.hasPermission(onlinePlayers.get(0), AdminPermission.ANTIBOT_MESSAGES)).willReturn(true); - given(permissionsManager.hasPermission(onlinePlayers.get(1), AdminPermission.ANTIBOT_MESSAGES)).willReturn(false); - given(permissionsManager.hasPermission(onlinePlayers.get(2), AdminPermission.ANTIBOT_MESSAGES)).willReturn(true); - - // when - antiBot.startProtection(); - - // then - assertThat(antiBot.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.ACTIVE)); - verify(bukkitService).getOnlinePlayers(); - verify(permissionsManager, times(3)).hasPermission(any(Player.class), eq(AdminPermission.ANTIBOT_MESSAGES)); - verify(messages).send(onlinePlayers.get(0), MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE); - verify(messages, never()).send(onlinePlayers.get(1), MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE); - verify(messages).send(onlinePlayers.get(2), MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE); - long expectedTicks = duration * TICKS_PER_MINUTE; - verify(bukkitService).scheduleSyncDelayedTask(any(Runnable.class), eq(expectedTicks)); - } - - @Test - public void shouldDisableAntiBotAfterSetDuration() { - // given - given(messages.retrieve(MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE)).willReturn(new String[0]); - given(messages.retrieve(MessageKey.ANTIBOT_AUTO_DISABLED_MESSAGE)) - .willReturn(new String[]{"Disabled...", "Placeholder: %m."}); - given(settings.getProperty(ProtectionSettings.ANTIBOT_DURATION)).willReturn(4); - AntiBotService antiBot = createListeningAntiBot(); - - // when - antiBot.startProtection(); - TestHelper.runSyncDelayedTaskWithDelay(bukkitService); - - // then - assertThat(antiBot.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.LISTENING)); - verify(bukkitService).scheduleSyncDelayedTask(any(Runnable.class), eq((long) 4800)); - ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); - verify(bukkitService, times(2)).broadcastMessage(captor.capture()); - assertThat(captor.getAllValues(), contains("Disabled...", "Placeholder: 4.")); - } - - private AntiBotService createListeningAntiBot() { - AntiBotService antiBot = new AntiBotService(settings, messages, permissionsManager, bukkitService); - TestHelper.runSyncDelayedTaskWithDelay(bukkitService); - // Make BukkitService forget about all interactions up to here - reset(bukkitService); - return antiBot; - } - -} From 42dbb2772805d4707f363c725302f71db792c253 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Tue, 4 Oct 2016 19:08:18 +0200 Subject: [PATCH 10/18] Service cleanup --- src/main/java/fr/xephi/authme/AuthMe.java | 17 ++--- src/main/java/fr/xephi/authme/api/API.java | 2 +- src/main/java/fr/xephi/authme/api/NewAPI.java | 2 +- .../fr/xephi/authme/cache/TempbanManager.java | 6 +- .../cache/backup/PlayerDataStorage.java | 12 ++-- .../xephi/authme/command/CommandService.java | 2 +- .../executable/authme/AccountsCommand.java | 2 +- .../authme/ChangePasswordAdminCommand.java | 6 +- .../executable/authme/ConverterCommand.java | 2 +- .../executable/authme/ForceLoginCommand.java | 2 +- .../executable/authme/GetIpCommand.java | 2 +- .../authme/PurgeBannedPlayersCommand.java | 2 +- .../authme/RegisterAdminCommand.java | 6 +- .../executable/authme/SetEmailCommand.java | 2 +- .../authme/UnregisterAdminCommand.java | 2 +- .../executable/authme/VersionCommand.java | 2 +- .../changepassword/ChangePasswordCommand.java | 4 +- .../executable/email/RecoverEmailCommand.java | 12 ++-- .../authme/{util => geoip}/GeoLiteAPI.java | 3 +- .../authme/initialization/Initializer.java | 6 +- .../initialization/OnShutdownPlayerSaver.java | 4 +- .../authme/listener/ListenerService.java | 2 +- .../xephi/authme/listener/OnJoinVerifier.java | 4 +- .../xephi/authme/listener/PlayerListener.java | 6 +- .../protocollib/ProtocolLibService.java | 2 +- .../fr/xephi/authme/mail/SendMailSSL.java | 2 +- .../fr/xephi/authme/process/Management.java | 2 +- .../xephi/authme/process/ProcessService.java | 2 +- .../authme/process/SyncProcessManager.java | 2 +- .../authme/process/join/AsynchronousJoin.java | 10 +-- .../process/login/AsynchronousLogin.java | 12 ++-- .../process/login/ProcessSyncPlayerLogin.java | 4 +- .../ProcessSynchronousPlayerLogout.java | 6 +- .../authme/process/quit/AsynchronousQuit.java | 6 +- .../process/register/AsyncRegister.java | 14 ++-- .../register/ProcessSyncEmailRegister.java | 4 +- .../register/ProcessSyncPasswordRegister.java | 4 +- .../unregister/AsynchronousUnregister.java | 6 +- .../xephi/authme/service/AntiBotService.java | 5 +- .../BackupService.java} | 8 ++- .../{util => service}/BukkitService.java | 2 +- .../{util => service}/MigrationService.java | 2 +- ...eManager.java => RecoveryCodeService.java} | 4 +- .../TeleportationService.java | 2 +- .../{util => service}/ValidationService.java | 5 +- .../fr/xephi/authme/task/MessageTask.java | 4 +- .../authme/task/PlayerDataTaskManager.java | 4 +- .../authme/task/purge/PurgeExecutor.java | 8 +-- .../xephi/authme/task/purge/PurgeService.java | 2 +- .../fr/xephi/authme/util/CollectionUtils.java | 1 + .../java/fr/xephi/authme/util/FileUtils.java | 1 + .../fr/xephi/authme/util/PlayerUtils.java | 42 +++++++++++ .../fr/xephi/authme/util/RuntimeUtils.java | 13 ++++ .../fr/xephi/authme/util/StringUtils.java | 2 +- src/main/java/fr/xephi/authme/util/Utils.java | 29 +------- .../authme/AuthMeInitializationTest.java | 2 +- src/test/java/fr/xephi/authme/TestHelper.java | 2 +- .../java/fr/xephi/authme/api/NewAPITest.java | 2 +- .../authme/cache/TempbanManagerTest.java | 2 +- .../cache/backup/PlayerDataStorageTest.java | 2 +- .../authme/command/CommandServiceTest.java | 2 +- .../authme/AccountsCommandTest.java | 2 +- .../ChangePasswordAdminCommandTest.java | 6 +- .../authme/ConverterCommandTest.java | 2 +- .../authme/ForceLoginCommandTest.java | 2 +- .../executable/authme/GetIpCommandTest.java | 2 +- .../authme/PurgeBannedPlayersCommandTest.java | 2 +- .../authme/RegisterAdminCommandTest.java | 6 +- .../authme/SetEmailCommandTest.java | 2 +- .../authme/UnregisterAdminCommandTest.java | 2 +- .../ChangePasswordCommandTest.java | 4 +- .../email/RecoverEmailCommandTest.java | 22 +++--- .../GeoIpManagerTest.java} | 5 +- .../authme/listener/ListenerServiceTest.java | 2 +- .../authme/listener/OnJoinVerifierTest.java | 4 +- .../authme/listener/PlayerListenerTest.java | 6 +- .../authme/process/ProcessServiceTest.java | 2 +- .../process/login/AsynchronousLoginTest.java | 2 +- .../AsynchronousUnregisterTest.java | 4 +- .../authme/service/AntiBotServiceTest.java | 1 - .../{util => service}/BukkitServiceTest.java | 2 +- .../MigrationServiceTest.java | 3 +- ...Test.java => RecoveryCodeServiceTest.java} | 30 ++++---- .../TeleportationServiceTest.java | 4 +- .../ValidationServiceTest.java | 6 +- .../task/PlayerDataTaskManagerTest.java | 2 +- .../authme/task/purge/PurgeServiceTest.java | 2 +- .../fr/xephi/authme/util/PlayerUtilsTest.java | 69 +++++++++++++++++++ .../java/fr/xephi/authme/util/UtilsTest.java | 48 ------------- 89 files changed, 319 insertions(+), 257 deletions(-) rename src/main/java/fr/xephi/authme/{util => geoip}/GeoLiteAPI.java (98%) rename src/main/java/fr/xephi/authme/{PerformBackup.java => service/BackupService.java} (97%) rename src/main/java/fr/xephi/authme/{util => service}/BukkitService.java (99%) rename src/main/java/fr/xephi/authme/{util => service}/MigrationService.java (99%) rename src/main/java/fr/xephi/authme/service/{RecoveryCodeManager.java => RecoveryCodeService.java} (96%) rename src/main/java/fr/xephi/authme/{util => service}/TeleportationService.java (99%) rename src/main/java/fr/xephi/authme/{util => service}/ValidationService.java (98%) create mode 100644 src/main/java/fr/xephi/authme/util/PlayerUtils.java rename src/test/java/fr/xephi/authme/{util/GeoLiteAPITest.java => geoip/GeoIpManagerTest.java} (96%) rename src/test/java/fr/xephi/authme/{util => service}/BukkitServiceTest.java (98%) rename src/test/java/fr/xephi/authme/{util => service}/MigrationServiceTest.java (98%) rename src/test/java/fr/xephi/authme/service/{RecoveryCodeManagerTest.java => RecoveryCodeServiceTest.java} (73%) rename src/test/java/fr/xephi/authme/{util => service}/TeleportationServiceTest.java (99%) rename src/test/java/fr/xephi/authme/{util => service}/ValidationServiceTest.java (98%) create mode 100644 src/test/java/fr/xephi/authme/util/PlayerUtilsTest.java diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index b80130576..9c94bc8ea 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -25,16 +25,17 @@ import fr.xephi.authme.output.Messages; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PermissionsSystemType; import fr.xephi.authme.security.crypts.SHA256; +import fr.xephi.authme.service.BackupService; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.PluginSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.settings.properties.SecuritySettings; import fr.xephi.authme.task.CleanupTask; import fr.xephi.authme.task.purge.PurgeService; -import fr.xephi.authme.util.BukkitService; -import fr.xephi.authme.util.GeoLiteAPI; -import fr.xephi.authme.util.MigrationService; -import fr.xephi.authme.util.Utils; +import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.geoip.GeoLiteAPI; +import fr.xephi.authme.service.MigrationService; +import fr.xephi.authme.util.PlayerUtils; import org.bukkit.Server; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -48,7 +49,7 @@ import org.bukkit.scheduler.BukkitScheduler; import java.io.File; import java.util.Date; -import static fr.xephi.authme.util.BukkitService.TICKS_PER_MINUTE; +import static fr.xephi.authme.service.BukkitService.TICKS_PER_MINUTE; import static fr.xephi.authme.util.Utils.isClassLoaded; /** @@ -150,7 +151,7 @@ public class AuthMe extends JavaPlugin { } // Do a backup on start - new PerformBackup(this, settings).doBackup(PerformBackup.BackupCause.START); + new BackupService(this, settings).doBackup(BackupService.BackupCause.START); // Set up Metrics MetricsManager.sendMetrics(this, settings); @@ -344,7 +345,7 @@ public class AuthMe extends JavaPlugin { // Do backup on stop if enabled if (settings != null) { - new PerformBackup(this, settings).doBackup(PerformBackup.BackupCause.STOP); + new BackupService(this, settings).doBackup(BackupService.BackupCause.STOP); } // Wait for tasks and close data source @@ -360,7 +361,7 @@ public class AuthMe extends JavaPlugin { public String replaceAllInfo(String message, Player player) { String playersOnline = Integer.toString(bukkitService.getOnlinePlayers().size()); - String ipAddress = Utils.getPlayerIp(player); + String ipAddress = PlayerUtils.getPlayerIp(player); Server server = getServer(); return message .replace("&", "\u00a7") diff --git a/src/main/java/fr/xephi/authme/api/API.java b/src/main/java/fr/xephi/authme/api/API.java index 0eafe3dac..8e16bd608 100644 --- a/src/main/java/fr/xephi/authme/api/API.java +++ b/src/main/java/fr/xephi/authme/api/API.java @@ -8,7 +8,7 @@ import fr.xephi.authme.hooks.PluginHooks; import fr.xephi.authme.process.Management; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.crypts.HashedPassword; -import fr.xephi.authme.util.ValidationService; +import fr.xephi.authme.service.ValidationService; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; diff --git a/src/main/java/fr/xephi/authme/api/NewAPI.java b/src/main/java/fr/xephi/authme/api/NewAPI.java index 68f973a82..5cee36e04 100644 --- a/src/main/java/fr/xephi/authme/api/NewAPI.java +++ b/src/main/java/fr/xephi/authme/api/NewAPI.java @@ -8,7 +8,7 @@ import fr.xephi.authme.hooks.PluginHooks; import fr.xephi.authme.process.Management; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.crypts.HashedPassword; -import fr.xephi.authme.util.ValidationService; +import fr.xephi.authme.service.ValidationService; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; diff --git a/src/main/java/fr/xephi/authme/cache/TempbanManager.java b/src/main/java/fr/xephi/authme/cache/TempbanManager.java index 832c650d1..c0cb39200 100644 --- a/src/main/java/fr/xephi/authme/cache/TempbanManager.java +++ b/src/main/java/fr/xephi/authme/cache/TempbanManager.java @@ -7,8 +7,8 @@ import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.SecuritySettings; -import fr.xephi.authme.util.BukkitService; -import fr.xephi.authme.util.Utils; +import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.util.PlayerUtils; import org.bukkit.entity.Player; import javax.inject.Inject; @@ -108,7 +108,7 @@ public class TempbanManager implements SettingsDependent, HasCleanup { */ public void tempbanPlayer(final Player player) { if (isEnabled) { - final String ip = Utils.getPlayerIp(player); + final String ip = PlayerUtils.getPlayerIp(player); final String reason = messages.retrieveSingle(MessageKey.TEMPBAN_MAX_LOGINS); final Date expires = new Date(); diff --git a/src/main/java/fr/xephi/authme/cache/backup/PlayerDataStorage.java b/src/main/java/fr/xephi/authme/cache/backup/PlayerDataStorage.java index e10e88efa..04015d844 100644 --- a/src/main/java/fr/xephi/authme/cache/backup/PlayerDataStorage.java +++ b/src/main/java/fr/xephi/authme/cache/backup/PlayerDataStorage.java @@ -14,9 +14,9 @@ import fr.xephi.authme.cache.limbo.PlayerData; import fr.xephi.authme.initialization.DataFolder; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.settings.SpawnLoader; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.util.FileUtils; -import fr.xephi.authme.util.Utils; +import fr.xephi.authme.util.PlayerUtils; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; @@ -64,7 +64,7 @@ public class PlayerDataStorage { * @return PlayerData object if the data is exist, null otherwise. */ public PlayerData readData(Player player) { - String id = Utils.getUUIDorName(player); + String id = PlayerUtils.getUUIDorName(player); File file = new File(cacheDir, id + File.separator + "data.json"); if (!file.exists()) { return null; @@ -85,7 +85,7 @@ public class PlayerDataStorage { * @param player player to save */ public void saveData(Player player) { - String id = Utils.getUUIDorName(player); + String id = PlayerUtils.getUUIDorName(player); Location location = spawnLoader.getPlayerLocationOrSpawn(player); String group = ""; if (permissionsManager.hasGroupSupport()) { @@ -113,7 +113,7 @@ public class PlayerDataStorage { * @param player player to remove */ public void removeData(Player player) { - String id = Utils.getUUIDorName(player); + String id = PlayerUtils.getUUIDorName(player); File file = new File(cacheDir, id); if (file.exists()) { FileUtils.purgeDirectory(file); @@ -131,7 +131,7 @@ public class PlayerDataStorage { * @return true if data exist, false otherwise. */ public boolean hasData(Player player) { - String id = Utils.getUUIDorName(player); + String id = PlayerUtils.getUUIDorName(player); File file = new File(cacheDir, id + File.separator + "data.json"); return file.exists(); } diff --git a/src/main/java/fr/xephi/authme/command/CommandService.java b/src/main/java/fr/xephi/authme/command/CommandService.java index 95965fac9..a01edfaeb 100644 --- a/src/main/java/fr/xephi/authme/command/CommandService.java +++ b/src/main/java/fr/xephi/authme/command/CommandService.java @@ -4,7 +4,7 @@ import com.github.authme.configme.properties.Property; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; -import fr.xephi.authme.util.ValidationService; +import fr.xephi.authme.service.ValidationService; import org.bukkit.command.CommandSender; import javax.inject.Inject; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java index f8d39d054..5951bd808 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java @@ -5,7 +5,7 @@ import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import org.bukkit.command.CommandSender; import javax.inject.Inject; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/ChangePasswordAdminCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/ChangePasswordAdminCommand.java index 9dcd04797..3c0b2323a 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/ChangePasswordAdminCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/ChangePasswordAdminCommand.java @@ -9,9 +9,9 @@ import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.crypts.HashedPassword; -import fr.xephi.authme.util.BukkitService; -import fr.xephi.authme.util.ValidationService; -import fr.xephi.authme.util.ValidationService.ValidationResult; +import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.service.ValidationService; +import fr.xephi.authme.service.ValidationService.ValidationResult; import org.bukkit.command.CommandSender; import javax.inject.Inject; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/ConverterCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/ConverterCommand.java index a615f3ec9..73a21a047 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/ConverterCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/ConverterCommand.java @@ -15,7 +15,7 @@ import fr.xephi.authme.converter.SqliteToSql; import fr.xephi.authme.converter.vAuthConverter; import fr.xephi.authme.converter.xAuthConverter; import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import org.bukkit.command.CommandSender; import javax.inject.Inject; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/ForceLoginCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/ForceLoginCommand.java index 9928f56f6..3adcad45e 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/ForceLoginCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/ForceLoginCommand.java @@ -3,7 +3,7 @@ package fr.xephi.authme.command.executable.authme; import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.process.Management; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/GetIpCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/GetIpCommand.java index 773f01b40..332c0c8dd 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/GetIpCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/GetIpCommand.java @@ -1,7 +1,7 @@ package fr.xephi.authme.command.executable.authme; import fr.xephi.authme.command.ExecutableCommand; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/PurgeBannedPlayersCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeBannedPlayersCommand.java index b4e9e545e..ff41ddbac 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/PurgeBannedPlayersCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeBannedPlayersCommand.java @@ -2,7 +2,7 @@ package fr.xephi.authme.command.executable.authme; import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.task.purge.PurgeService; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java index f4ca7cb04..166d2d808 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java @@ -9,9 +9,9 @@ import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.crypts.HashedPassword; -import fr.xephi.authme.util.BukkitService; -import fr.xephi.authme.util.ValidationService; -import fr.xephi.authme.util.ValidationService.ValidationResult; +import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.service.ValidationService; +import fr.xephi.authme.service.ValidationService.ValidationResult; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/SetEmailCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/SetEmailCommand.java index ebce774cf..d3d6ea78d 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/SetEmailCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/SetEmailCommand.java @@ -6,7 +6,7 @@ import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import org.bukkit.command.CommandSender; import javax.inject.Inject; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/UnregisterAdminCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/UnregisterAdminCommand.java index eaf14b6b7..51e7c4d43 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/UnregisterAdminCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/UnregisterAdminCommand.java @@ -5,7 +5,7 @@ import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.process.Management; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/VersionCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/VersionCommand.java index 86437dd77..4169940bb 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/VersionCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/VersionCommand.java @@ -3,7 +3,7 @@ package fr.xephi.authme.command.executable.authme; import fr.xephi.authme.AuthMe; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.ExecutableCommand; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommand.java b/src/main/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommand.java index 0fdbf6072..2d7c12046 100644 --- a/src/main/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommand.java @@ -5,8 +5,8 @@ import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.PlayerCommand; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.process.Management; -import fr.xephi.authme.util.ValidationService; -import fr.xephi.authme.util.ValidationService.ValidationResult; +import fr.xephi.authme.service.ValidationService; +import fr.xephi.authme.service.ValidationService.ValidationResult; import org.bukkit.entity.Player; import javax.inject.Inject; diff --git a/src/main/java/fr/xephi/authme/command/executable/email/RecoverEmailCommand.java b/src/main/java/fr/xephi/authme/command/executable/email/RecoverEmailCommand.java index 26b0e2f9c..ccff7b1be 100644 --- a/src/main/java/fr/xephi/authme/command/executable/email/RecoverEmailCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/email/RecoverEmailCommand.java @@ -11,7 +11,7 @@ import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.RandomString; import fr.xephi.authme.security.crypts.HashedPassword; -import fr.xephi.authme.service.RecoveryCodeManager; +import fr.xephi.authme.service.RecoveryCodeService; import org.bukkit.entity.Player; import javax.inject.Inject; @@ -40,7 +40,7 @@ public class RecoverEmailCommand extends PlayerCommand { private SendMailSSL sendMailSsl; @Inject - private RecoveryCodeManager recoveryCodeManager; + private RecoveryCodeService recoveryCodeService; @Override public void runCommand(Player player, List arguments) { @@ -69,7 +69,7 @@ public class RecoverEmailCommand extends PlayerCommand { return; } - if (recoveryCodeManager.isRecoveryCodeNeeded()) { + if (recoveryCodeService.isRecoveryCodeNeeded()) { // Process /email recovery addr@example.com if (arguments.size() == 1) { createAndSendRecoveryCode(player, email); @@ -83,20 +83,20 @@ public class RecoverEmailCommand extends PlayerCommand { } private void createAndSendRecoveryCode(Player player, String email) { - String recoveryCode = recoveryCodeManager.generateCode(player.getName()); + String recoveryCode = recoveryCodeService.generateCode(player.getName()); sendMailSsl.sendRecoveryCode(player.getName(), email, recoveryCode); commandService.send(player, MessageKey.RECOVERY_CODE_SENT); } private void processRecoveryCode(Player player, String code, String email) { final String name = player.getName(); - if (!recoveryCodeManager.isCodeValid(name, code)) { + if (!recoveryCodeService.isCodeValid(name, code)) { commandService.send(player, MessageKey.INCORRECT_RECOVERY_CODE); return; } generateAndSendNewPassword(player, email); - recoveryCodeManager.removeCode(name); + recoveryCodeService.removeCode(name); } private void generateAndSendNewPassword(Player player, String email) { diff --git a/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java b/src/main/java/fr/xephi/authme/geoip/GeoLiteAPI.java similarity index 98% rename from src/main/java/fr/xephi/authme/util/GeoLiteAPI.java rename to src/main/java/fr/xephi/authme/geoip/GeoLiteAPI.java index 050c37300..11f5e4f01 100644 --- a/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java +++ b/src/main/java/fr/xephi/authme/geoip/GeoLiteAPI.java @@ -1,9 +1,10 @@ -package fr.xephi.authme.util; +package fr.xephi.authme.geoip; import com.google.common.annotations.VisibleForTesting; import com.maxmind.geoip.LookupService; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.initialization.DataFolder; +import fr.xephi.authme.util.FileUtils; import javax.inject.Inject; import java.io.File; diff --git a/src/main/java/fr/xephi/authme/initialization/Initializer.java b/src/main/java/fr/xephi/authme/initialization/Initializer.java index 9aaba7990..5a048678d 100644 --- a/src/main/java/fr/xephi/authme/initialization/Initializer.java +++ b/src/main/java/fr/xephi/authme/initialization/Initializer.java @@ -22,9 +22,9 @@ import fr.xephi.authme.settings.properties.AuthMeSettingsRetriever; import fr.xephi.authme.settings.properties.DatabaseSettings; import fr.xephi.authme.settings.properties.EmailSettings; import fr.xephi.authme.settings.properties.SecuritySettings; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.util.FileUtils; -import fr.xephi.authme.util.MigrationService; +import fr.xephi.authme.service.MigrationService; import fr.xephi.authme.util.StringUtils; import org.apache.logging.log4j.LogManager; import org.bukkit.Bukkit; @@ -37,7 +37,7 @@ import java.util.List; import java.util.logging.Logger; import static fr.xephi.authme.settings.properties.EmailSettings.RECALL_PLAYERS; -import static fr.xephi.authme.util.BukkitService.TICKS_PER_MINUTE; +import static fr.xephi.authme.service.BukkitService.TICKS_PER_MINUTE; /** * Initializes various services. diff --git a/src/main/java/fr/xephi/authme/initialization/OnShutdownPlayerSaver.java b/src/main/java/fr/xephi/authme/initialization/OnShutdownPlayerSaver.java index 852f5380d..28a1134f6 100644 --- a/src/main/java/fr/xephi/authme/initialization/OnShutdownPlayerSaver.java +++ b/src/main/java/fr/xephi/authme/initialization/OnShutdownPlayerSaver.java @@ -9,8 +9,8 @@ import fr.xephi.authme.hooks.PluginHooks; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.SpawnLoader; import fr.xephi.authme.settings.properties.RestrictionSettings; -import fr.xephi.authme.util.BukkitService; -import fr.xephi.authme.util.ValidationService; +import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.service.ValidationService; import org.bukkit.Location; import org.bukkit.entity.Player; diff --git a/src/main/java/fr/xephi/authme/listener/ListenerService.java b/src/main/java/fr/xephi/authme/listener/ListenerService.java index 6c09bd2e5..4db65530a 100644 --- a/src/main/java/fr/xephi/authme/listener/ListenerService.java +++ b/src/main/java/fr/xephi/authme/listener/ListenerService.java @@ -6,7 +6,7 @@ import fr.xephi.authme.hooks.PluginHooks; import fr.xephi.authme.initialization.SettingsDependent; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.RegistrationSettings; -import fr.xephi.authme.util.ValidationService; +import fr.xephi.authme.service.ValidationService; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityEvent; diff --git a/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java b/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java index 1767e0e0b..b58f9bc99 100644 --- a/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java +++ b/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java @@ -13,10 +13,10 @@ import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.ProtectionSettings; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.util.StringUtils; import fr.xephi.authme.util.Utils; -import fr.xephi.authme.util.ValidationService; +import fr.xephi.authme.service.ValidationService; import org.bukkit.Server; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerLoginEvent; diff --git a/src/main/java/fr/xephi/authme/listener/PlayerListener.java b/src/main/java/fr/xephi/authme/listener/PlayerListener.java index 1a5f8a287..20f33f09e 100644 --- a/src/main/java/fr/xephi/authme/listener/PlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/PlayerListener.java @@ -11,9 +11,9 @@ import fr.xephi.authme.settings.SpawnLoader; import fr.xephi.authme.settings.properties.HooksSettings; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; -import fr.xephi.authme.util.BukkitService; -import fr.xephi.authme.util.TeleportationService; -import fr.xephi.authme.util.ValidationService; +import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.service.TeleportationService; +import fr.xephi.authme.service.ValidationService; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; diff --git a/src/main/java/fr/xephi/authme/listener/protocollib/ProtocolLibService.java b/src/main/java/fr/xephi/authme/listener/protocollib/ProtocolLibService.java index ae373bb08..3e10cde0d 100644 --- a/src/main/java/fr/xephi/authme/listener/protocollib/ProtocolLibService.java +++ b/src/main/java/fr/xephi/authme/listener/protocollib/ProtocolLibService.java @@ -7,7 +7,7 @@ import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.initialization.SettingsDependent; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.RestrictionSettings; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import org.bukkit.entity.Player; import javax.inject.Inject; diff --git a/src/main/java/fr/xephi/authme/mail/SendMailSSL.java b/src/main/java/fr/xephi/authme/mail/SendMailSSL.java index 3bd5be44d..e629402f1 100644 --- a/src/main/java/fr/xephi/authme/mail/SendMailSSL.java +++ b/src/main/java/fr/xephi/authme/mail/SendMailSSL.java @@ -5,7 +5,7 @@ import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.EmailSettings; import fr.xephi.authme.settings.properties.SecuritySettings; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.util.FileUtils; import fr.xephi.authme.util.StringUtils; import org.apache.commons.mail.EmailConstants; diff --git a/src/main/java/fr/xephi/authme/process/Management.java b/src/main/java/fr/xephi/authme/process/Management.java index 9efb5e6d2..be32e99e8 100644 --- a/src/main/java/fr/xephi/authme/process/Management.java +++ b/src/main/java/fr/xephi/authme/process/Management.java @@ -9,7 +9,7 @@ import fr.xephi.authme.process.logout.AsynchronousLogout; import fr.xephi.authme.process.quit.AsynchronousQuit; import fr.xephi.authme.process.register.AsyncRegister; import fr.xephi.authme.process.unregister.AsynchronousUnregister; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/fr/xephi/authme/process/ProcessService.java b/src/main/java/fr/xephi/authme/process/ProcessService.java index 33f3eed78..239c73fd1 100644 --- a/src/main/java/fr/xephi/authme/process/ProcessService.java +++ b/src/main/java/fr/xephi/authme/process/ProcessService.java @@ -8,7 +8,7 @@ import fr.xephi.authme.permission.AuthGroupType; import fr.xephi.authme.permission.PermissionNode; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.settings.Settings; -import fr.xephi.authme.util.ValidationService; +import fr.xephi.authme.service.ValidationService; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/fr/xephi/authme/process/SyncProcessManager.java b/src/main/java/fr/xephi/authme/process/SyncProcessManager.java index 777a957dd..b8c344bfe 100644 --- a/src/main/java/fr/xephi/authme/process/SyncProcessManager.java +++ b/src/main/java/fr/xephi/authme/process/SyncProcessManager.java @@ -5,7 +5,7 @@ import fr.xephi.authme.process.logout.ProcessSynchronousPlayerLogout; import fr.xephi.authme.process.quit.ProcessSyncronousPlayerQuit; import fr.xephi.authme.process.register.ProcessSyncEmailRegister; import fr.xephi.authme.process.register.ProcessSyncPasswordRegister; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import org.bukkit.entity.Player; import javax.inject.Inject; diff --git a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java index dcd7599d3..b8dd5af00 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java @@ -20,8 +20,8 @@ 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.task.PlayerDataTaskManager; -import fr.xephi.authme.util.BukkitService; -import fr.xephi.authme.util.Utils; +import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.util.PlayerUtils; import org.apache.commons.lang.reflect.MethodUtils; import org.bukkit.GameMode; import org.bukkit.entity.LivingEntity; @@ -32,7 +32,7 @@ import org.bukkit.potion.PotionEffectType; import javax.inject.Inject; import static fr.xephi.authme.settings.properties.RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN; -import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND; +import static fr.xephi.authme.service.BukkitService.TICKS_PER_SECOND; /** * Asynchronous process for when a player joins. @@ -78,7 +78,7 @@ public class AsynchronousJoin implements AsynchronousProcess { public void processJoin(final Player player) { final String name = player.getName().toLowerCase(); - final String ip = Utils.getPlayerIp(player); + final String ip = PlayerUtils.getPlayerIp(player); if (isPlayerUnrestricted(name)) { return; @@ -249,7 +249,7 @@ public class AsynchronousJoin implements AsynchronousProcess { private int countOnlinePlayersByIp(String ip) { int count = 0; for (Player player : bukkitService.getOnlinePlayers()) { - if (ip.equalsIgnoreCase(Utils.getPlayerIp(player))) { + if (ip.equalsIgnoreCase(PlayerUtils.getPlayerIp(player))) { ++count; } } diff --git a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java index b63c6ccd5..3a8b7fc38 100644 --- a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java @@ -25,9 +25,9 @@ import fr.xephi.authme.settings.properties.HooksSettings; import fr.xephi.authme.settings.properties.PluginSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.task.PlayerDataTaskManager; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.util.PlayerUtils; import fr.xephi.authme.util.StringUtils; -import fr.xephi.authme.util.Utils; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -130,7 +130,7 @@ public class AsynchronousLogin implements AsynchronousProcess { return null; } - final String ip = Utils.getPlayerIp(player); + final String ip = PlayerUtils.getPlayerIp(player); if (hasReachedMaxLoggedInPlayersForIp(player, ip)) { service.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR); return null; @@ -163,7 +163,7 @@ public class AsynchronousLogin implements AsynchronousProcess { return false; } - final String ip = Utils.getPlayerIp(player); + final String ip = PlayerUtils.getPlayerIp(player); // Increase the counts here before knowing the result of the login. captchaManager.increaseCount(name); @@ -210,7 +210,7 @@ public class AsynchronousLogin implements AsynchronousProcess { private void performLogin(Player player, PlayerAuth auth) { if (player.isOnline()) { // Update auth to reflect this new login - final String ip = Utils.getPlayerIp(player); + final String ip = PlayerUtils.getPlayerIp(player); auth.setRealName(player.getName()); auth.setLastLogin(System.currentTimeMillis()); auth.setIp(ip); @@ -311,7 +311,7 @@ public class AsynchronousLogin implements AsynchronousProcess { final String name = player.getName(); int count = 0; for (Player onlinePlayer : bukkitService.getOnlinePlayers()) { - if (ip.equalsIgnoreCase(Utils.getPlayerIp(onlinePlayer)) + if (ip.equalsIgnoreCase(PlayerUtils.getPlayerIp(onlinePlayer)) && !onlinePlayer.getName().equals(name) && dataSource.isLogged(onlinePlayer.getName().toLowerCase())) { ++count; diff --git a/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java b/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java index acc235dbb..4735ab579 100644 --- a/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java @@ -12,8 +12,8 @@ import fr.xephi.authme.process.ProcessService; import fr.xephi.authme.process.SynchronousProcess; import fr.xephi.authme.service.BungeeService; import fr.xephi.authme.settings.properties.RegistrationSettings; -import fr.xephi.authme.util.BukkitService; -import fr.xephi.authme.util.TeleportationService; +import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.service.TeleportationService; import org.apache.commons.lang.reflect.MethodUtils; import org.bukkit.Bukkit; import org.bukkit.entity.LivingEntity; diff --git a/src/main/java/fr/xephi/authme/process/logout/ProcessSynchronousPlayerLogout.java b/src/main/java/fr/xephi/authme/process/logout/ProcessSynchronousPlayerLogout.java index 6b61b9258..cb3723cbe 100644 --- a/src/main/java/fr/xephi/authme/process/logout/ProcessSynchronousPlayerLogout.java +++ b/src/main/java/fr/xephi/authme/process/logout/ProcessSynchronousPlayerLogout.java @@ -11,15 +11,15 @@ import fr.xephi.authme.process.SynchronousProcess; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.task.PlayerDataTaskManager; -import fr.xephi.authme.util.BukkitService; -import fr.xephi.authme.util.TeleportationService; +import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.service.TeleportationService; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import javax.inject.Inject; -import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND; +import static fr.xephi.authme.service.BukkitService.TICKS_PER_SECOND; public class ProcessSynchronousPlayerLogout implements SynchronousProcess { diff --git a/src/main/java/fr/xephi/authme/process/quit/AsynchronousQuit.java b/src/main/java/fr/xephi/authme/process/quit/AsynchronousQuit.java index cc7eb60fc..ce3af43aa 100644 --- a/src/main/java/fr/xephi/authme/process/quit/AsynchronousQuit.java +++ b/src/main/java/fr/xephi/authme/process/quit/AsynchronousQuit.java @@ -11,8 +11,8 @@ import fr.xephi.authme.process.ProcessService; import fr.xephi.authme.process.SyncProcessManager; import fr.xephi.authme.settings.SpawnLoader; import fr.xephi.authme.settings.properties.RestrictionSettings; -import fr.xephi.authme.util.Utils; -import fr.xephi.authme.util.ValidationService; +import fr.xephi.authme.util.PlayerUtils; +import fr.xephi.authme.service.ValidationService; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -63,7 +63,7 @@ public class AsynchronousQuit implements AsynchronousProcess { database.updateQuitLoc(auth); } - final String ip = Utils.getPlayerIp(player); + final String ip = PlayerUtils.getPlayerIp(player); PlayerAuth auth = PlayerAuth.builder() .name(name) .realName(player.getName()) diff --git a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java index 21eae43dc..41b1d9992 100644 --- a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java @@ -19,11 +19,11 @@ 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.BukkitService; +import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.util.PlayerUtils; import fr.xephi.authme.util.StringUtils; -import fr.xephi.authme.util.Utils; -import fr.xephi.authme.util.ValidationService; -import fr.xephi.authme.util.ValidationService.ValidationResult; +import fr.xephi.authme.service.ValidationService; +import fr.xephi.authme.service.ValidationService.ValidationResult; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -94,7 +94,7 @@ public class AsyncRegister implements AsynchronousProcess { } final int maxRegPerIp = service.getProperty(RestrictionSettings.MAX_REGISTRATION_PER_IP); - final String ip = Utils.getPlayerIp(player); + final String ip = PlayerUtils.getPlayerIp(player); if (maxRegPerIp > 0 && !"127.0.0.1".equalsIgnoreCase(ip) && !"localhost".equalsIgnoreCase(ip) @@ -132,7 +132,7 @@ public class AsyncRegister implements AsynchronousProcess { } final HashedPassword hashedPassword = passwordSecurity.computeHash(password, name); - final String ip = Utils.getPlayerIp(player); + final String ip = PlayerUtils.getPlayerIp(player); PlayerAuth auth = PlayerAuth.builder() .name(name) .realName(player.getName()) @@ -154,7 +154,7 @@ public class AsyncRegister implements AsynchronousProcess { private void passwordRegister(final Player player, String password, boolean autoLogin) { final String name = player.getName().toLowerCase(); - final String ip = Utils.getPlayerIp(player); + final String ip = PlayerUtils.getPlayerIp(player); final HashedPassword hashedPassword = passwordSecurity.computeHash(password, name); PlayerAuth auth = PlayerAuth.builder() .name(name) diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java index cd10a69b5..67e1478a9 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java @@ -7,7 +7,7 @@ import fr.xephi.authme.process.ProcessService; import fr.xephi.authme.process.SynchronousProcess; import fr.xephi.authme.settings.properties.HooksSettings; import fr.xephi.authme.task.PlayerDataTaskManager; -import fr.xephi.authme.util.Utils; +import fr.xephi.authme.util.PlayerUtils; import org.bukkit.entity.Player; import javax.inject.Inject; @@ -35,7 +35,7 @@ public class ProcessSyncEmailRegister implements SynchronousProcess { playerDataTaskManager.registerMessageTask(name, true); player.saveData(); - ConsoleLogger.fine(player.getName() + " registered " + Utils.getPlayerIp(player)); + ConsoleLogger.fine(player.getName() + " registered " + PlayerUtils.getPlayerIp(player)); } } diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java index 2770b96ee..cbc37cbd4 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java @@ -11,7 +11,7 @@ import fr.xephi.authme.settings.properties.EmailSettings; import fr.xephi.authme.settings.properties.HooksSettings; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.task.PlayerDataTaskManager; -import fr.xephi.authme.util.Utils; +import fr.xephi.authme.util.PlayerUtils; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -74,7 +74,7 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess { } player.saveData(); - ConsoleLogger.fine(player.getName() + " registered " + Utils.getPlayerIp(player)); + ConsoleLogger.fine(player.getName() + " registered " + PlayerUtils.getPlayerIp(player)); // Kick Player after Registration is enabled, kick the player if (service.getProperty(RegistrationSettings.FORCE_KICK_AFTER_REGISTER)) { diff --git a/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java b/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java index 5d9a0fca1..de859e9a7 100644 --- a/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java +++ b/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java @@ -14,8 +14,8 @@ import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.task.PlayerDataTaskManager; -import fr.xephi.authme.util.BukkitService; -import fr.xephi.authme.util.TeleportationService; +import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.service.TeleportationService; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; @@ -23,7 +23,7 @@ import org.bukkit.potion.PotionEffectType; import javax.inject.Inject; -import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND; +import static fr.xephi.authme.service.BukkitService.TICKS_PER_SECOND; public class AsynchronousUnregister implements AsynchronousProcess { diff --git a/src/main/java/fr/xephi/authme/service/AntiBotService.java b/src/main/java/fr/xephi/authme/service/AntiBotService.java index 6fd3d8fa8..a1ecf71fc 100644 --- a/src/main/java/fr/xephi/authme/service/AntiBotService.java +++ b/src/main/java/fr/xephi/authme/service/AntiBotService.java @@ -7,15 +7,14 @@ import fr.xephi.authme.permission.AdminPermission; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.ProtectionSettings; -import fr.xephi.authme.util.BukkitService; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; import javax.inject.Inject; import java.util.concurrent.CopyOnWriteArrayList; -import static fr.xephi.authme.util.BukkitService.TICKS_PER_MINUTE; -import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND; +import static fr.xephi.authme.service.BukkitService.TICKS_PER_MINUTE; +import static fr.xephi.authme.service.BukkitService.TICKS_PER_SECOND; /** * The AntiBot Service Management class. diff --git a/src/main/java/fr/xephi/authme/PerformBackup.java b/src/main/java/fr/xephi/authme/service/BackupService.java similarity index 97% rename from src/main/java/fr/xephi/authme/PerformBackup.java rename to src/main/java/fr/xephi/authme/service/BackupService.java index ab2d72db9..b5dfa06d3 100644 --- a/src/main/java/fr/xephi/authme/PerformBackup.java +++ b/src/main/java/fr/xephi/authme/service/BackupService.java @@ -1,5 +1,7 @@ -package fr.xephi.authme; +package fr.xephi.authme.service; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.datasource.DataSourceType; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.BackupSettings; @@ -19,7 +21,7 @@ import java.util.Date; * * @author stefano */ -public class PerformBackup { +public class BackupService { private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd_HH-mm"); @@ -37,7 +39,7 @@ public class PerformBackup { * @param instance AuthMe * @param settings The plugin settings */ - public PerformBackup(AuthMe instance, Settings settings) { + public BackupService(AuthMe instance, Settings settings) { this.dataFolder = instance.getDataFolder(); this.settings = settings; this.dbName = settings.getProperty(DatabaseSettings.MYSQL_DATABASE); diff --git a/src/main/java/fr/xephi/authme/util/BukkitService.java b/src/main/java/fr/xephi/authme/service/BukkitService.java similarity index 99% rename from src/main/java/fr/xephi/authme/util/BukkitService.java rename to src/main/java/fr/xephi/authme/service/BukkitService.java index 72bdacf7a..cd5595fff 100644 --- a/src/main/java/fr/xephi/authme/util/BukkitService.java +++ b/src/main/java/fr/xephi/authme/service/BukkitService.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.util; +package fr.xephi.authme.service; import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; diff --git a/src/main/java/fr/xephi/authme/util/MigrationService.java b/src/main/java/fr/xephi/authme/service/MigrationService.java similarity index 99% rename from src/main/java/fr/xephi/authme/util/MigrationService.java rename to src/main/java/fr/xephi/authme/service/MigrationService.java index 7b0a32d0a..f21bb8539 100644 --- a/src/main/java/fr/xephi/authme/util/MigrationService.java +++ b/src/main/java/fr/xephi/authme/service/MigrationService.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.util; +package fr.xephi.authme.service; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.cache.auth.PlayerAuth; diff --git a/src/main/java/fr/xephi/authme/service/RecoveryCodeManager.java b/src/main/java/fr/xephi/authme/service/RecoveryCodeService.java similarity index 96% rename from src/main/java/fr/xephi/authme/service/RecoveryCodeManager.java rename to src/main/java/fr/xephi/authme/service/RecoveryCodeService.java index e37d22733..5f5dd746b 100644 --- a/src/main/java/fr/xephi/authme/service/RecoveryCodeManager.java +++ b/src/main/java/fr/xephi/authme/service/RecoveryCodeService.java @@ -16,7 +16,7 @@ import static fr.xephi.authme.util.Utils.MILLIS_PER_HOUR; /** * Manager for recovery codes. */ -public class RecoveryCodeManager implements SettingsDependent { +public class RecoveryCodeService implements SettingsDependent { private Map recoveryCodes = new ConcurrentHashMap<>(); @@ -24,7 +24,7 @@ public class RecoveryCodeManager implements SettingsDependent { private long recoveryCodeExpirationMillis; @Inject - RecoveryCodeManager(Settings settings) { + RecoveryCodeService(Settings settings) { reload(settings); } diff --git a/src/main/java/fr/xephi/authme/util/TeleportationService.java b/src/main/java/fr/xephi/authme/service/TeleportationService.java similarity index 99% rename from src/main/java/fr/xephi/authme/util/TeleportationService.java rename to src/main/java/fr/xephi/authme/service/TeleportationService.java index b35535158..92f1c93a3 100644 --- a/src/main/java/fr/xephi/authme/util/TeleportationService.java +++ b/src/main/java/fr/xephi/authme/service/TeleportationService.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.util; +package fr.xephi.authme.service; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerCache; diff --git a/src/main/java/fr/xephi/authme/util/ValidationService.java b/src/main/java/fr/xephi/authme/service/ValidationService.java similarity index 98% rename from src/main/java/fr/xephi/authme/util/ValidationService.java rename to src/main/java/fr/xephi/authme/service/ValidationService.java index 7225c1e09..63227823d 100644 --- a/src/main/java/fr/xephi/authme/util/ValidationService.java +++ b/src/main/java/fr/xephi/authme/service/ValidationService.java @@ -1,7 +1,8 @@ -package fr.xephi.authme.util; +package fr.xephi.authme.service; import com.github.authme.configme.properties.Property; import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.geoip.GeoLiteAPI; import fr.xephi.authme.initialization.Reloadable; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.permission.PermissionsManager; @@ -11,6 +12,8 @@ import fr.xephi.authme.settings.properties.EmailSettings; import fr.xephi.authme.settings.properties.ProtectionSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.settings.properties.SecuritySettings; +import fr.xephi.authme.util.CollectionUtils; +import fr.xephi.authme.util.Utils; import org.bukkit.command.CommandSender; import javax.annotation.PostConstruct; diff --git a/src/main/java/fr/xephi/authme/task/MessageTask.java b/src/main/java/fr/xephi/authme/task/MessageTask.java index 7282bc659..1ae0aaed2 100644 --- a/src/main/java/fr/xephi/authme/task/MessageTask.java +++ b/src/main/java/fr/xephi/authme/task/MessageTask.java @@ -2,11 +2,11 @@ package fr.xephi.authme.task; import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.limbo.LimboCache; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; -import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND; +import static fr.xephi.authme.service.BukkitService.TICKS_PER_SECOND; /** * Message shown to a player in a regular interval as long as he is not logged in. diff --git a/src/main/java/fr/xephi/authme/task/PlayerDataTaskManager.java b/src/main/java/fr/xephi/authme/task/PlayerDataTaskManager.java index b4e1846d2..b57141457 100644 --- a/src/main/java/fr/xephi/authme/task/PlayerDataTaskManager.java +++ b/src/main/java/fr/xephi/authme/task/PlayerDataTaskManager.java @@ -9,13 +9,13 @@ import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; import javax.inject.Inject; -import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND; +import static fr.xephi.authme.service.BukkitService.TICKS_PER_SECOND; /** * Registers tasks associated with a PlayerData. diff --git a/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java b/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java index 2fb65fdd2..dcadc49b8 100644 --- a/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java +++ b/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java @@ -6,8 +6,8 @@ import fr.xephi.authme.hooks.PluginHooks; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.PurgeSettings; -import fr.xephi.authme.util.BukkitService; -import fr.xephi.authme.util.Utils; +import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.util.PlayerUtils; import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer; import org.bukkit.Server; @@ -152,7 +152,7 @@ class PurgeExecutor { , makePath(settings.getProperty(PurgeSettings.DEFAULT_WORLD), "players")); for (OfflinePlayer offlinePlayer : cleared) { - File playerFile = new File(dataFolder, Utils.getUUIDorName(offlinePlayer) + ".dat"); + File playerFile = new File(dataFolder, PlayerUtils.getUUIDorName(offlinePlayer) + ".dat"); if (playerFile.delete()) { i++; } @@ -184,7 +184,7 @@ class PurgeExecutor { } for (OfflinePlayer offlinePlayer : cleared) { - File playerFile = new File(userDataFolder, Utils.getUUIDorName(offlinePlayer) + ".yml"); + File playerFile = new File(userDataFolder, PlayerUtils.getUUIDorName(offlinePlayer) + ".yml"); if (playerFile.exists() && playerFile.delete()) { i++; } diff --git a/src/main/java/fr/xephi/authme/task/purge/PurgeService.java b/src/main/java/fr/xephi/authme/task/purge/PurgeService.java index ee4370f88..040d2a893 100644 --- a/src/main/java/fr/xephi/authme/task/purge/PurgeService.java +++ b/src/main/java/fr/xephi/authme/task/purge/PurgeService.java @@ -5,7 +5,7 @@ import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.PurgeSettings; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.util.CollectionUtils; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; diff --git a/src/main/java/fr/xephi/authme/util/CollectionUtils.java b/src/main/java/fr/xephi/authme/util/CollectionUtils.java index 9644c6cdc..2388fc608 100644 --- a/src/main/java/fr/xephi/authme/util/CollectionUtils.java +++ b/src/main/java/fr/xephi/authme/util/CollectionUtils.java @@ -9,6 +9,7 @@ import java.util.List; */ public final class CollectionUtils { + // Utility class private CollectionUtils() { } diff --git a/src/main/java/fr/xephi/authme/util/FileUtils.java b/src/main/java/fr/xephi/authme/util/FileUtils.java index d420ef0d5..faf557f47 100644 --- a/src/main/java/fr/xephi/authme/util/FileUtils.java +++ b/src/main/java/fr/xephi/authme/util/FileUtils.java @@ -15,6 +15,7 @@ import static java.lang.String.format; */ public final class FileUtils { + // Utility class private FileUtils() { } diff --git a/src/main/java/fr/xephi/authme/util/PlayerUtils.java b/src/main/java/fr/xephi/authme/util/PlayerUtils.java new file mode 100644 index 000000000..7c7302eb8 --- /dev/null +++ b/src/main/java/fr/xephi/authme/util/PlayerUtils.java @@ -0,0 +1,42 @@ +package fr.xephi.authme.util; + +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +/** + * Player utilities. + */ +public class PlayerUtils { + + // Utility class + private PlayerUtils() { + } + + /** + * Get player's UUID if can, name otherwise. + * + * @param player Player to retrieve + * + * @return player's UUID or Name in String. + */ + public static String getUUIDorName(OfflinePlayer player) { + // We may made this configurable in future + // so we can have uuid support. + try { + return player.getUniqueId().toString(); + } catch (NoSuchMethodError ignore) { + return player.getName(); + } + } + + /** + * Returns the IP of the given player. + * + * @param p The player to return the IP address for + * + * @return The player's IP address + */ + public static String getPlayerIp(Player p) { + return p.getAddress().getAddress().getHostAddress(); + } +} diff --git a/src/main/java/fr/xephi/authme/util/RuntimeUtils.java b/src/main/java/fr/xephi/authme/util/RuntimeUtils.java index af7fa3a34..6af0c4576 100644 --- a/src/main/java/fr/xephi/authme/util/RuntimeUtils.java +++ b/src/main/java/fr/xephi/authme/util/RuntimeUtils.java @@ -1,6 +1,19 @@ package fr.xephi.authme.util; +/** + * Runtime utilities. + */ public class RuntimeUtils { + + // Utility class + private RuntimeUtils() { + } + + /** + * Return the available core count of the JVM. + * + * @return the core count + */ public static int getCoreCount() { return Runtime.getRuntime().availableProcessors(); } diff --git a/src/main/java/fr/xephi/authme/util/StringUtils.java b/src/main/java/fr/xephi/authme/util/StringUtils.java index a02418ca9..d26a281fb 100644 --- a/src/main/java/fr/xephi/authme/util/StringUtils.java +++ b/src/main/java/fr/xephi/authme/util/StringUtils.java @@ -11,8 +11,8 @@ import java.io.File; */ public final class StringUtils { + // Utility class private StringUtils() { - // Utility class } /** diff --git a/src/main/java/fr/xephi/authme/util/Utils.java b/src/main/java/fr/xephi/authme/util/Utils.java index 3a7040d17..f15d77c8e 100644 --- a/src/main/java/fr/xephi/authme/util/Utils.java +++ b/src/main/java/fr/xephi/authme/util/Utils.java @@ -16,26 +16,10 @@ public final class Utils { /** Number of milliseconds in an hour. */ public static final long MILLIS_PER_HOUR = 60 * MILLIS_PER_MINUTE; + // Utility class private Utils() { } - /** - * Get player's UUID if can, name otherwise. - * - * @param player Player to retrieve - * - * @return player's UUID or Name in String. - */ - public static String getUUIDorName(OfflinePlayer player) { - // We may made this configurable in future - // so we can have uuid support. - try { - return player.getUniqueId().toString(); - } catch (NoSuchMethodError ignore) { - return player.getName(); - } - } - /** * Compile Pattern sneaky without throwing Exception. * @@ -52,17 +36,6 @@ public final class Utils { } } - /** - * Returns the IP of the given player. - * - * @param p The player to return the IP address for - * - * @return The player's IP address - */ - public static String getPlayerIp(Player p) { - return p.getAddress().getAddress().getHostAddress(); - } - /** * Returns whether the class exists in the current class loader. * diff --git a/src/test/java/fr/xephi/authme/AuthMeInitializationTest.java b/src/test/java/fr/xephi/authme/AuthMeInitializationTest.java index d20424a06..fc504f439 100644 --- a/src/test/java/fr/xephi/authme/AuthMeInitializationTest.java +++ b/src/test/java/fr/xephi/authme/AuthMeInitializationTest.java @@ -15,7 +15,7 @@ import fr.xephi.authme.process.login.ProcessSyncPlayerLogin; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.task.purge.PurgeService; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.plugin.PluginDescriptionFile; diff --git a/src/test/java/fr/xephi/authme/TestHelper.java b/src/test/java/fr/xephi/authme/TestHelper.java index c8d4803ec..d16bd31f7 100644 --- a/src/test/java/fr/xephi/authme/TestHelper.java +++ b/src/test/java/fr/xephi/authme/TestHelper.java @@ -1,6 +1,6 @@ package fr.xephi.authme; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import org.bukkit.entity.Player; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; diff --git a/src/test/java/fr/xephi/authme/api/NewAPITest.java b/src/test/java/fr/xephi/authme/api/NewAPITest.java index 5ec009c02..7d915018b 100644 --- a/src/test/java/fr/xephi/authme/api/NewAPITest.java +++ b/src/test/java/fr/xephi/authme/api/NewAPITest.java @@ -8,7 +8,7 @@ import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.hooks.PluginHooks; import fr.xephi.authme.process.Management; import fr.xephi.authme.security.PasswordSecurity; -import fr.xephi.authme.util.ValidationService; +import fr.xephi.authme.service.ValidationService; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Server; diff --git a/src/test/java/fr/xephi/authme/cache/TempbanManagerTest.java b/src/test/java/fr/xephi/authme/cache/TempbanManagerTest.java index f487a97f6..bd4cfc04c 100644 --- a/src/test/java/fr/xephi/authme/cache/TempbanManagerTest.java +++ b/src/test/java/fr/xephi/authme/cache/TempbanManagerTest.java @@ -7,7 +7,7 @@ import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.SecuritySettings; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import org.bukkit.entity.Player; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/src/test/java/fr/xephi/authme/cache/backup/PlayerDataStorageTest.java b/src/test/java/fr/xephi/authme/cache/backup/PlayerDataStorageTest.java index 3480b7d52..288f47710 100644 --- a/src/test/java/fr/xephi/authme/cache/backup/PlayerDataStorageTest.java +++ b/src/test/java/fr/xephi/authme/cache/backup/PlayerDataStorageTest.java @@ -8,7 +8,7 @@ import fr.xephi.authme.cache.limbo.PlayerData; import fr.xephi.authme.initialization.DataFolder; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.settings.SpawnLoader; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.util.StringUtils; import org.bukkit.Location; import org.bukkit.World; diff --git a/src/test/java/fr/xephi/authme/command/CommandServiceTest.java b/src/test/java/fr/xephi/authme/command/CommandServiceTest.java index 07c8a2898..cbdfc8f02 100644 --- a/src/test/java/fr/xephi/authme/command/CommandServiceTest.java +++ b/src/test/java/fr/xephi/authme/command/CommandServiceTest.java @@ -5,7 +5,7 @@ import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.SecuritySettings; -import fr.xephi.authme.util.ValidationService; +import fr.xephi.authme.service.ValidationService; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.junit.Test; diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/AccountsCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/AccountsCommandTest.java index 096157516..09405e079 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/AccountsCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/AccountsCommandTest.java @@ -4,7 +4,7 @@ import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import org.bukkit.command.CommandSender; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/ChangePasswordAdminCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/ChangePasswordAdminCommandTest.java index a44cd6bc9..14df46d9e 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/ChangePasswordAdminCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/ChangePasswordAdminCommandTest.java @@ -8,9 +8,9 @@ import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.crypts.HashedPassword; -import fr.xephi.authme.util.BukkitService; -import fr.xephi.authme.util.ValidationService; -import fr.xephi.authme.util.ValidationService.ValidationResult; +import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.service.ValidationService; +import fr.xephi.authme.service.ValidationService.ValidationResult; import org.bukkit.command.CommandSender; import org.junit.BeforeClass; import org.junit.Test; diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/ConverterCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/ConverterCommandTest.java index a978833a4..e5035c450 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/ConverterCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/ConverterCommandTest.java @@ -5,7 +5,7 @@ import fr.xephi.authme.TestHelper; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.converter.Converter; import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.util.StringUtils; import org.bukkit.command.CommandSender; import org.junit.BeforeClass; diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/ForceLoginCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/ForceLoginCommandTest.java index bc7fdec0f..fc2602bb4 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/ForceLoginCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/ForceLoginCommandTest.java @@ -3,7 +3,7 @@ package fr.xephi.authme.command.executable.authme; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerPermission; import fr.xephi.authme.process.Management; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.junit.Test; diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/GetIpCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/GetIpCommandTest.java index 65ed998a7..75d8953a0 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/GetIpCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/GetIpCommandTest.java @@ -1,7 +1,7 @@ package fr.xephi.authme.command.executable.authme; import fr.xephi.authme.TestHelper; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.junit.Test; diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/PurgeBannedPlayersCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/PurgeBannedPlayersCommandTest.java index 01d9c89d9..1927854ec 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/PurgeBannedPlayersCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/PurgeBannedPlayersCommandTest.java @@ -1,7 +1,7 @@ package fr.xephi.authme.command.executable.authme; import fr.xephi.authme.task.purge.PurgeService; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; import org.junit.Test; diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommandTest.java index c71572296..49ea28ac8 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommandTest.java @@ -8,9 +8,9 @@ import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.crypts.HashedPassword; -import fr.xephi.authme.util.BukkitService; -import fr.xephi.authme.util.ValidationService; -import fr.xephi.authme.util.ValidationService.ValidationResult; +import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.service.ValidationService; +import fr.xephi.authme.service.ValidationService.ValidationResult; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.junit.BeforeClass; diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/SetEmailCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/SetEmailCommandTest.java index 7a07d8c8a..705302829 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/SetEmailCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/SetEmailCommandTest.java @@ -5,7 +5,7 @@ import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import org.bukkit.command.CommandSender; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/UnregisterAdminCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/UnregisterAdminCommandTest.java index aea73ed71..e9cfbbabd 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/UnregisterAdminCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/UnregisterAdminCommandTest.java @@ -4,7 +4,7 @@ import fr.xephi.authme.command.CommandService; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.process.Management; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.junit.Test; diff --git a/src/test/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommandTest.java index 3a67bd77e..a3d5a8ae0 100644 --- a/src/test/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommandTest.java @@ -6,8 +6,8 @@ import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.process.Management; import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.settings.properties.SecuritySettings; -import fr.xephi.authme.util.ValidationService; -import fr.xephi.authme.util.ValidationService.ValidationResult; +import fr.xephi.authme.service.ValidationService; +import fr.xephi.authme.service.ValidationService.ValidationResult; import org.bukkit.command.BlockCommandSender; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/test/java/fr/xephi/authme/command/executable/email/RecoverEmailCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/email/RecoverEmailCommandTest.java index 14d2cc62b..cb615d913 100644 --- a/src/test/java/fr/xephi/authme/command/executable/email/RecoverEmailCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/email/RecoverEmailCommandTest.java @@ -9,7 +9,7 @@ import fr.xephi.authme.mail.SendMailSSL; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.crypts.HashedPassword; -import fr.xephi.authme.service.RecoveryCodeManager; +import fr.xephi.authme.service.RecoveryCodeService; import fr.xephi.authme.settings.properties.EmailSettings; import fr.xephi.authme.settings.properties.SecuritySettings; import org.bukkit.entity.Player; @@ -63,7 +63,7 @@ public class RecoverEmailCommandTest { private SendMailSSL sendMailSsl; @Mock - private RecoveryCodeManager recoveryCodeManager; + private RecoveryCodeService recoveryCodeService; @BeforeClass public static void initLogger() { @@ -177,8 +177,8 @@ public class RecoverEmailCommandTest { int hoursValid = 12; given(commandService.getProperty(SecuritySettings.RECOVERY_CODE_HOURS_VALID)).willReturn(hoursValid); String code = "a94f37"; - given(recoveryCodeManager.isRecoveryCodeNeeded()).willReturn(true); - given(recoveryCodeManager.generateCode(name)).willReturn(code); + given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(true); + given(recoveryCodeService.generateCode(name)).willReturn(code); // when command.executeCommand(sender, Collections.singletonList(email.toUpperCase())); @@ -186,7 +186,7 @@ public class RecoverEmailCommandTest { // then verify(sendMailSsl).hasAllInformation(); verify(dataSource).getAuth(name); - verify(recoveryCodeManager).generateCode(name); + verify(recoveryCodeService).generateCode(name); verify(commandService).send(sender, MessageKey.RECOVERY_CODE_SENT); verify(sendMailSsl).sendRecoveryCode(name, email, code); } @@ -203,8 +203,8 @@ public class RecoverEmailCommandTest { PlayerAuth auth = newAuthWithEmail(email); given(dataSource.getAuth(name)).willReturn(auth); given(commandService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH)).willReturn(20); - given(recoveryCodeManager.isRecoveryCodeNeeded()).willReturn(true); - given(recoveryCodeManager.isCodeValid(name, "bogus")).willReturn(false); + given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(true); + given(recoveryCodeService.isCodeValid(name, "bogus")).willReturn(false); // when command.executeCommand(sender, Arrays.asList(email, "bogus")); @@ -231,8 +231,8 @@ public class RecoverEmailCommandTest { given(commandService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH)).willReturn(20); given(passwordSecurity.computeHash(anyString(), eq(name))) .willAnswer(invocation -> new HashedPassword((String) invocation.getArguments()[0])); - given(recoveryCodeManager.isRecoveryCodeNeeded()).willReturn(true); - given(recoveryCodeManager.isCodeValid(name, code)).willReturn(true); + given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(true); + given(recoveryCodeService.isCodeValid(name, code)).willReturn(true); // when command.executeCommand(sender, Arrays.asList(email, code)); @@ -245,7 +245,7 @@ public class RecoverEmailCommandTest { String generatedPassword = passwordCaptor.getValue(); assertThat(generatedPassword, stringWithLength(20)); verify(dataSource).updatePassword(eq(name), any(HashedPassword.class)); - verify(recoveryCodeManager).removeCode(name); + verify(recoveryCodeService).removeCode(name); verify(sendMailSsl).sendPasswordMail(name, email, generatedPassword); verify(commandService).send(sender, MessageKey.RECOVERY_EMAIL_SENT_MESSAGE); } @@ -264,7 +264,7 @@ public class RecoverEmailCommandTest { given(commandService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH)).willReturn(20); given(passwordSecurity.computeHash(anyString(), eq(name))) .willAnswer(invocation -> new HashedPassword((String) invocation.getArguments()[0])); - given(recoveryCodeManager.isRecoveryCodeNeeded()).willReturn(false); + given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(false); // when command.executeCommand(sender, Collections.singletonList(email)); diff --git a/src/test/java/fr/xephi/authme/util/GeoLiteAPITest.java b/src/test/java/fr/xephi/authme/geoip/GeoIpManagerTest.java similarity index 96% rename from src/test/java/fr/xephi/authme/util/GeoLiteAPITest.java rename to src/test/java/fr/xephi/authme/geoip/GeoIpManagerTest.java index c932ddbb8..547cf3e70 100644 --- a/src/test/java/fr/xephi/authme/util/GeoLiteAPITest.java +++ b/src/test/java/fr/xephi/authme/geoip/GeoIpManagerTest.java @@ -1,7 +1,8 @@ -package fr.xephi.authme.util; +package fr.xephi.authme.geoip; import com.maxmind.geoip.Country; import com.maxmind.geoip.LookupService; +import fr.xephi.authme.geoip.GeoLiteAPI; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -25,7 +26,7 @@ import static org.mockito.Mockito.verify; * Test for {@link GeoLiteAPI}. */ @RunWith(MockitoJUnitRunner.class) -public class GeoLiteAPITest { +public class GeoIpManagerTest { private GeoLiteAPI geoLiteApi; private File dataFolder; diff --git a/src/test/java/fr/xephi/authme/listener/ListenerServiceTest.java b/src/test/java/fr/xephi/authme/listener/ListenerServiceTest.java index bc78db2f3..7ff0202f1 100644 --- a/src/test/java/fr/xephi/authme/listener/ListenerServiceTest.java +++ b/src/test/java/fr/xephi/authme/listener/ListenerServiceTest.java @@ -8,7 +8,7 @@ import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.hooks.PluginHooks; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.RegistrationSettings; -import fr.xephi.authme.util.ValidationService; +import fr.xephi.authme.service.ValidationService; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; diff --git a/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java b/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java index 66ddb673b..db6da711e 100644 --- a/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java +++ b/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java @@ -12,8 +12,8 @@ import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.ProtectionSettings; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; -import fr.xephi.authme.util.BukkitService; -import fr.xephi.authme.util.ValidationService; +import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.service.ValidationService; import org.bukkit.Server; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerLoginEvent; diff --git a/src/test/java/fr/xephi/authme/listener/PlayerListenerTest.java b/src/test/java/fr/xephi/authme/listener/PlayerListenerTest.java index f9efc830a..d269726c8 100644 --- a/src/test/java/fr/xephi/authme/listener/PlayerListenerTest.java +++ b/src/test/java/fr/xephi/authme/listener/PlayerListenerTest.java @@ -10,9 +10,9 @@ import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.SpawnLoader; import fr.xephi.authme.settings.properties.HooksSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; -import fr.xephi.authme.util.BukkitService; -import fr.xephi.authme.util.TeleportationService; -import fr.xephi.authme.util.ValidationService; +import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.service.TeleportationService; +import fr.xephi.authme.service.ValidationService; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.World; diff --git a/src/test/java/fr/xephi/authme/process/ProcessServiceTest.java b/src/test/java/fr/xephi/authme/process/ProcessServiceTest.java index a1196c4d2..3e6ed8520 100644 --- a/src/test/java/fr/xephi/authme/process/ProcessServiceTest.java +++ b/src/test/java/fr/xephi/authme/process/ProcessServiceTest.java @@ -9,7 +9,7 @@ import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerPermission; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.SecuritySettings; -import fr.xephi.authme.util.ValidationService; +import fr.xephi.authme.service.ValidationService; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.junit.Test; diff --git a/src/test/java/fr/xephi/authme/process/login/AsynchronousLoginTest.java b/src/test/java/fr/xephi/authme/process/login/AsynchronousLoginTest.java index 2171bef20..b3dd38cf1 100644 --- a/src/test/java/fr/xephi/authme/process/login/AsynchronousLoginTest.java +++ b/src/test/java/fr/xephi/authme/process/login/AsynchronousLoginTest.java @@ -14,7 +14,7 @@ import fr.xephi.authme.settings.properties.HooksSettings; import fr.xephi.authme.settings.properties.PluginSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.task.PlayerDataTaskManager; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import org.bukkit.entity.Player; import org.junit.BeforeClass; import org.junit.Test; diff --git a/src/test/java/fr/xephi/authme/process/unregister/AsynchronousUnregisterTest.java b/src/test/java/fr/xephi/authme/process/unregister/AsynchronousUnregisterTest.java index c77d4d3cf..24724768f 100644 --- a/src/test/java/fr/xephi/authme/process/unregister/AsynchronousUnregisterTest.java +++ b/src/test/java/fr/xephi/authme/process/unregister/AsynchronousUnregisterTest.java @@ -14,8 +14,8 @@ import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.task.PlayerDataTaskManager; -import fr.xephi.authme.util.BukkitService; -import fr.xephi.authme.util.TeleportationService; +import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.service.TeleportationService; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.junit.BeforeClass; diff --git a/src/test/java/fr/xephi/authme/service/AntiBotServiceTest.java b/src/test/java/fr/xephi/authme/service/AntiBotServiceTest.java index b401a895f..ffe06b82a 100644 --- a/src/test/java/fr/xephi/authme/service/AntiBotServiceTest.java +++ b/src/test/java/fr/xephi/authme/service/AntiBotServiceTest.java @@ -10,7 +10,6 @@ import fr.xephi.authme.permission.AdminPermission; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.ProtectionSettings; -import fr.xephi.authme.util.BukkitService; import org.bukkit.entity.Player; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/src/test/java/fr/xephi/authme/util/BukkitServiceTest.java b/src/test/java/fr/xephi/authme/service/BukkitServiceTest.java similarity index 98% rename from src/test/java/fr/xephi/authme/util/BukkitServiceTest.java rename to src/test/java/fr/xephi/authme/service/BukkitServiceTest.java index 37922e929..d43f3c530 100644 --- a/src/test/java/fr/xephi/authme/util/BukkitServiceTest.java +++ b/src/test/java/fr/xephi/authme/service/BukkitServiceTest.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.util; +package fr.xephi.authme.service; import fr.xephi.authme.AuthMe; import fr.xephi.authme.ReflectionTestUtils; diff --git a/src/test/java/fr/xephi/authme/util/MigrationServiceTest.java b/src/test/java/fr/xephi/authme/service/MigrationServiceTest.java similarity index 98% rename from src/test/java/fr/xephi/authme/util/MigrationServiceTest.java rename to src/test/java/fr/xephi/authme/service/MigrationServiceTest.java index 5a3f19ee0..aad9343d4 100644 --- a/src/test/java/fr/xephi/authme/util/MigrationServiceTest.java +++ b/src/test/java/fr/xephi/authme/service/MigrationServiceTest.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.util; +package fr.xephi.authme.service; import fr.xephi.authme.TestHelper; import fr.xephi.authme.cache.auth.PlayerAuth; @@ -6,6 +6,7 @@ import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.security.HashAlgorithm; import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.security.crypts.SHA256; +import fr.xephi.authme.service.MigrationService; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.SecuritySettings; import org.junit.BeforeClass; diff --git a/src/test/java/fr/xephi/authme/service/RecoveryCodeManagerTest.java b/src/test/java/fr/xephi/authme/service/RecoveryCodeServiceTest.java similarity index 73% rename from src/test/java/fr/xephi/authme/service/RecoveryCodeManagerTest.java rename to src/test/java/fr/xephi/authme/service/RecoveryCodeServiceTest.java index c606a743a..b06a01f82 100644 --- a/src/test/java/fr/xephi/authme/service/RecoveryCodeManagerTest.java +++ b/src/test/java/fr/xephi/authme/service/RecoveryCodeServiceTest.java @@ -4,7 +4,7 @@ import ch.jalu.injector.testing.BeforeInjecting; import ch.jalu.injector.testing.DelayedInjectionRunner; import ch.jalu.injector.testing.InjectDelayed; import fr.xephi.authme.ReflectionTestUtils; -import fr.xephi.authme.service.RecoveryCodeManager.ExpiringEntry; +import fr.xephi.authme.service.RecoveryCodeService.ExpiringEntry; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.SecuritySettings; import org.junit.Test; @@ -20,13 +20,13 @@ import static org.junit.Assert.assertThat; import static org.mockito.BDDMockito.given; /** - * Test for {@link RecoveryCodeManager}. + * Test for {@link RecoveryCodeService}. */ @RunWith(DelayedInjectionRunner.class) -public class RecoveryCodeManagerTest { +public class RecoveryCodeServiceTest { @InjectDelayed - private RecoveryCodeManager recoveryCodeManager; + private RecoveryCodeService recoveryCodeService; @Mock private Settings settings; @@ -39,16 +39,16 @@ public class RecoveryCodeManagerTest { @Test public void shouldBeDisabledForNonPositiveLength() { - assertThat(recoveryCodeManager.isRecoveryCodeNeeded(), equalTo(true)); + assertThat(recoveryCodeService.isRecoveryCodeNeeded(), equalTo(true)); // given given(settings.getProperty(SecuritySettings.RECOVERY_CODE_LENGTH)).willReturn(0); // when - recoveryCodeManager.reload(settings); + recoveryCodeService.reload(settings); // then - assertThat(recoveryCodeManager.isRecoveryCodeNeeded(), equalTo(false)); + assertThat(recoveryCodeService.isRecoveryCodeNeeded(), equalTo(false)); } @Test @@ -57,7 +57,7 @@ public class RecoveryCodeManagerTest { String name = "Bobbers"; // when - recoveryCodeManager.generateCode(name); + recoveryCodeService.generateCode(name); // then ExpiringEntry entry = getCodeMap().get(name); @@ -72,7 +72,7 @@ public class RecoveryCodeManagerTest { setCodeInMap(player, code, System.currentTimeMillis() - 500); // when - boolean result = recoveryCodeManager.isCodeValid(player, code); + boolean result = recoveryCodeService.isCodeValid(player, code); // then assertThat(result, equalTo(false)); @@ -82,10 +82,10 @@ public class RecoveryCodeManagerTest { public void shouldRecognizeCorrectCode() { // given String player = "dragon"; - String code = recoveryCodeManager.generateCode(player); + String code = recoveryCodeService.generateCode(player); // when - boolean result = recoveryCodeManager.isCodeValid(player, code); + boolean result = recoveryCodeService.isCodeValid(player, code); // then assertThat(result, equalTo(true)); @@ -95,19 +95,19 @@ public class RecoveryCodeManagerTest { public void shouldRemoveCode() { // given String player = "Tester"; - String code = recoveryCodeManager.generateCode(player); + String code = recoveryCodeService.generateCode(player); // when - recoveryCodeManager.removeCode(player); + recoveryCodeService.removeCode(player); // then - assertThat(recoveryCodeManager.isCodeValid(player, code), equalTo(false)); + assertThat(recoveryCodeService.isCodeValid(player, code), equalTo(false)); assertThat(getCodeMap().get(player), nullValue()); } private Map getCodeMap() { - return ReflectionTestUtils.getFieldValue(RecoveryCodeManager.class, recoveryCodeManager, "recoveryCodes"); + return ReflectionTestUtils.getFieldValue(RecoveryCodeService.class, recoveryCodeService, "recoveryCodes"); } private void setCodeInMap(String player, String code, long expiration) { diff --git a/src/test/java/fr/xephi/authme/util/TeleportationServiceTest.java b/src/test/java/fr/xephi/authme/service/TeleportationServiceTest.java similarity index 99% rename from src/test/java/fr/xephi/authme/util/TeleportationServiceTest.java rename to src/test/java/fr/xephi/authme/service/TeleportationServiceTest.java index d3b0973f7..0a218a84d 100644 --- a/src/test/java/fr/xephi/authme/util/TeleportationServiceTest.java +++ b/src/test/java/fr/xephi/authme/service/TeleportationServiceTest.java @@ -1,10 +1,12 @@ -package fr.xephi.authme.util; +package fr.xephi.authme.service; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.limbo.PlayerData; import fr.xephi.authme.events.FirstSpawnTeleportEvent; import fr.xephi.authme.events.SpawnTeleportEvent; +import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.service.TeleportationService; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.SpawnLoader; import fr.xephi.authme.settings.properties.RestrictionSettings; diff --git a/src/test/java/fr/xephi/authme/util/ValidationServiceTest.java b/src/test/java/fr/xephi/authme/service/ValidationServiceTest.java similarity index 98% rename from src/test/java/fr/xephi/authme/util/ValidationServiceTest.java rename to src/test/java/fr/xephi/authme/service/ValidationServiceTest.java index b61f833db..2a85b131a 100644 --- a/src/test/java/fr/xephi/authme/util/ValidationServiceTest.java +++ b/src/test/java/fr/xephi/authme/service/ValidationServiceTest.java @@ -1,19 +1,21 @@ -package fr.xephi.authme.util; +package fr.xephi.authme.service; import ch.jalu.injector.testing.BeforeInjecting; import ch.jalu.injector.testing.DelayedInjectionRunner; import ch.jalu.injector.testing.InjectDelayed; import com.google.common.base.Strings; import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.geoip.GeoLiteAPI; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerStatePermission; +import fr.xephi.authme.service.ValidationService; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.EmailSettings; import fr.xephi.authme.settings.properties.ProtectionSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.settings.properties.SecuritySettings; -import fr.xephi.authme.util.ValidationService.ValidationResult; +import fr.xephi.authme.service.ValidationService.ValidationResult; import org.bukkit.command.CommandSender; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/src/test/java/fr/xephi/authme/task/PlayerDataTaskManagerTest.java b/src/test/java/fr/xephi/authme/task/PlayerDataTaskManagerTest.java index ab4d6ef92..93b552ca1 100644 --- a/src/test/java/fr/xephi/authme/task/PlayerDataTaskManagerTest.java +++ b/src/test/java/fr/xephi/authme/task/PlayerDataTaskManagerTest.java @@ -9,7 +9,7 @@ import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; import org.junit.BeforeClass; diff --git a/src/test/java/fr/xephi/authme/task/purge/PurgeServiceTest.java b/src/test/java/fr/xephi/authme/task/purge/PurgeServiceTest.java index 3f626f4d1..d6fe5b574 100644 --- a/src/test/java/fr/xephi/authme/task/purge/PurgeServiceTest.java +++ b/src/test/java/fr/xephi/authme/task/purge/PurgeServiceTest.java @@ -6,7 +6,7 @@ import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.PurgeSettings; -import fr.xephi.authme.util.BukkitService; +import fr.xephi.authme.service.BukkitService; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/test/java/fr/xephi/authme/util/PlayerUtilsTest.java b/src/test/java/fr/xephi/authme/util/PlayerUtilsTest.java new file mode 100644 index 000000000..444d0c497 --- /dev/null +++ b/src/test/java/fr/xephi/authme/util/PlayerUtilsTest.java @@ -0,0 +1,69 @@ +package fr.xephi.authme.util; + +import fr.xephi.authme.TestHelper; +import org.bukkit.entity.Player; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.UUID; +import java.util.regex.Pattern; + +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; + +/** + * Test for {@link Utils}. + */ +public class PlayerUtilsTest { + + @BeforeClass + public static void setAuthmeInstance() { + TestHelper.setupLogger(); + } + + @Test + public void shouldGetPlayerIp() { + // given + Player player = mock(Player.class); + String ip = "124.86.248.62"; + TestHelper.mockPlayerIp(player, ip); + + // when + String result = PlayerUtils.getPlayerIp(player); + + // then + assertThat(result, equalTo(ip)); + } + + @Test + public void shouldGetUuid() { + // given + UUID uuid = UUID.randomUUID(); + Player player = mock(Player.class); + given(player.getUniqueId()).willReturn(uuid); + + // when + String result = PlayerUtils.getUUIDorName(player); + + // then + assertThat(result, equalTo(uuid.toString())); + } + + @Test + public void shouldFallbackToName() { + // given + Player player = mock(Player.class); + doThrow(NoSuchMethodError.class).when(player).getUniqueId(); + String name = "Bobby12"; + given(player.getName()).willReturn(name); + + // when + String result = PlayerUtils.getUUIDorName(player); + + // then + assertThat(result, equalTo(name)); + } +} diff --git a/src/test/java/fr/xephi/authme/util/UtilsTest.java b/src/test/java/fr/xephi/authme/util/UtilsTest.java index 930a5db8a..458023d6d 100644 --- a/src/test/java/fr/xephi/authme/util/UtilsTest.java +++ b/src/test/java/fr/xephi/authme/util/UtilsTest.java @@ -1,18 +1,13 @@ package fr.xephi.authme.util; import fr.xephi.authme.TestHelper; -import org.bukkit.entity.Player; import org.junit.BeforeClass; import org.junit.Test; -import java.util.UUID; import java.util.regex.Pattern; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; /** * Test for {@link Utils}. @@ -48,49 +43,6 @@ public class UtilsTest { assertThat(result.toString(), equalTo(".*?")); } - @Test - public void shouldGetPlayerIp() { - // given - Player player = mock(Player.class); - String ip = "124.86.248.62"; - TestHelper.mockPlayerIp(player, ip); - - // when - String result = Utils.getPlayerIp(player); - - // then - assertThat(result, equalTo(ip)); - } - - @Test - public void shouldGetUuid() { - // given - UUID uuid = UUID.randomUUID(); - Player player = mock(Player.class); - given(player.getUniqueId()).willReturn(uuid); - - // when - String result = Utils.getUUIDorName(player); - - // then - assertThat(result, equalTo(uuid.toString())); - } - - @Test - public void shouldFallbackToName() { - // given - Player player = mock(Player.class); - doThrow(NoSuchMethodError.class).when(player).getUniqueId(); - String name = "Bobby12"; - given(player.getName()).willReturn(name); - - // when - String result = Utils.getUUIDorName(player); - - // then - assertThat(result, equalTo(name)); - } - @Test public void shouldHavePrivateConstructorOnly() { // given / when / then From f3cd193d47ef03ac3211267af2541d3909809503 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Tue, 4 Oct 2016 19:16:06 +0200 Subject: [PATCH 11/18] Move RandomStringUtils --- .../java/fr/xephi/authme/cache/CaptchaManager.java | 4 ++-- .../executable/email/RecoverEmailCommand.java | 4 ++-- .../executable/register/RegisterCommand.java | 4 ++-- .../authme/security/crypts/HexSaltedMethod.java | 4 ++-- .../java/fr/xephi/authme/security/crypts/IPB3.java | 4 ++-- .../java/fr/xephi/authme/security/crypts/IPB4.java | 4 ++-- .../java/fr/xephi/authme/security/crypts/MYBB.java | 4 ++-- .../fr/xephi/authme/security/crypts/PHPFUSION.java | 4 ++-- .../fr/xephi/authme/security/crypts/SALTED2MD5.java | 4 ++-- .../xephi/authme/security/crypts/SALTEDSHA512.java | 4 ++-- .../java/fr/xephi/authme/security/crypts/WBB3.java | 4 ++-- .../xephi/authme/service/RecoveryCodeService.java | 4 ++-- .../RandomStringUtils.java} | 7 ++++--- ...omStringTest.java => RandomStringUtilsTest.java} | 13 +++++++------ 14 files changed, 35 insertions(+), 33 deletions(-) rename src/main/java/fr/xephi/authme/{security/RandomString.java => util/RandomStringUtils.java} (93%) rename src/test/java/fr/xephi/authme/security/{RandomStringTest.java => RandomStringUtilsTest.java} (84%) diff --git a/src/main/java/fr/xephi/authme/cache/CaptchaManager.java b/src/main/java/fr/xephi/authme/cache/CaptchaManager.java index f37637df0..d46d4891a 100644 --- a/src/main/java/fr/xephi/authme/cache/CaptchaManager.java +++ b/src/main/java/fr/xephi/authme/cache/CaptchaManager.java @@ -1,7 +1,7 @@ package fr.xephi.authme.cache; import fr.xephi.authme.initialization.SettingsDependent; -import fr.xephi.authme.security.RandomString; +import fr.xephi.authme.util.RandomStringUtils; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.SecuritySettings; @@ -86,7 +86,7 @@ public class CaptchaManager implements SettingsDependent { * @return the generated code */ public String generateCode(String name) { - String code = RandomString.generate(captchaLength); + String code = RandomStringUtils.generate(captchaLength); captchaCodes.put(name.toLowerCase(), code); return code; } diff --git a/src/main/java/fr/xephi/authme/command/executable/email/RecoverEmailCommand.java b/src/main/java/fr/xephi/authme/command/executable/email/RecoverEmailCommand.java index ccff7b1be..1aeeb1d8b 100644 --- a/src/main/java/fr/xephi/authme/command/executable/email/RecoverEmailCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/email/RecoverEmailCommand.java @@ -9,7 +9,7 @@ import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.mail.SendMailSSL; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.security.PasswordSecurity; -import fr.xephi.authme.security.RandomString; +import fr.xephi.authme.util.RandomStringUtils; import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.service.RecoveryCodeService; import org.bukkit.entity.Player; @@ -101,7 +101,7 @@ public class RecoverEmailCommand extends PlayerCommand { private void generateAndSendNewPassword(Player player, String email) { String name = player.getName(); - String thePass = RandomString.generate(commandService.getProperty(RECOVERY_PASSWORD_LENGTH)); + String thePass = RandomStringUtils.generate(commandService.getProperty(RECOVERY_PASSWORD_LENGTH)); HashedPassword hashNew = passwordSecurity.computeHash(thePass, name); dataSource.updatePassword(name, hashNew); diff --git a/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java b/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java index 0e3f055b2..fbfcfb5fb 100644 --- a/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java @@ -7,7 +7,7 @@ import fr.xephi.authme.mail.SendMailSSL; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.process.Management; import fr.xephi.authme.security.HashAlgorithm; -import fr.xephi.authme.security.RandomString; +import fr.xephi.authme.util.RandomStringUtils; import fr.xephi.authme.settings.properties.EmailSettings; import fr.xephi.authme.settings.properties.SecuritySettings; import org.bukkit.entity.Player; @@ -80,7 +80,7 @@ public class RegisterCommand extends PlayerCommand { } else if (commandService.getProperty(ENABLE_CONFIRM_EMAIL) && !email.equals(arguments.get(1))) { commandService.send(player, MessageKey.USAGE_REGISTER); } else { - String thePass = RandomString.generate(commandService.getProperty(RECOVERY_PASSWORD_LENGTH)); + String thePass = RandomStringUtils.generate(commandService.getProperty(RECOVERY_PASSWORD_LENGTH)); management.performRegister(player, thePass, email, true); } } diff --git a/src/main/java/fr/xephi/authme/security/crypts/HexSaltedMethod.java b/src/main/java/fr/xephi/authme/security/crypts/HexSaltedMethod.java index 9f76dbbb8..5ac8caf8b 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/HexSaltedMethod.java +++ b/src/main/java/fr/xephi/authme/security/crypts/HexSaltedMethod.java @@ -1,6 +1,6 @@ package fr.xephi.authme.security.crypts; -import fr.xephi.authme.security.RandomString; +import fr.xephi.authme.util.RandomStringUtils; import fr.xephi.authme.security.crypts.description.HasSalt; import fr.xephi.authme.security.crypts.description.Recommendation; import fr.xephi.authme.security.crypts.description.SaltType; @@ -30,7 +30,7 @@ public abstract class HexSaltedMethod implements EncryptionMethod { @Override public String generateSalt() { - return RandomString.generateHex(getSaltLength()); + return RandomStringUtils.generateHex(getSaltLength()); } @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/IPB3.java b/src/main/java/fr/xephi/authme/security/crypts/IPB3.java index 4abfe5d45..a4e62461c 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/IPB3.java +++ b/src/main/java/fr/xephi/authme/security/crypts/IPB3.java @@ -1,6 +1,6 @@ package fr.xephi.authme.security.crypts; -import fr.xephi.authme.security.RandomString; +import fr.xephi.authme.util.RandomStringUtils; import fr.xephi.authme.security.crypts.description.HasSalt; import fr.xephi.authme.security.crypts.description.Recommendation; import fr.xephi.authme.security.crypts.description.SaltType; @@ -19,7 +19,7 @@ public class IPB3 extends SeparateSaltMethod { @Override public String generateSalt() { - return RandomString.generateHex(5); + return RandomStringUtils.generateHex(5); } } diff --git a/src/main/java/fr/xephi/authme/security/crypts/IPB4.java b/src/main/java/fr/xephi/authme/security/crypts/IPB4.java index 0eede2a22..40ea75166 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/IPB4.java +++ b/src/main/java/fr/xephi/authme/security/crypts/IPB4.java @@ -2,7 +2,7 @@ package fr.xephi.authme.security.crypts; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.security.HashUtils; -import fr.xephi.authme.security.RandomString; +import fr.xephi.authme.util.RandomStringUtils; import fr.xephi.authme.security.crypts.description.HasSalt; import fr.xephi.authme.security.crypts.description.Recommendation; import fr.xephi.authme.security.crypts.description.SaltType; @@ -44,7 +44,7 @@ public class IPB4 implements EncryptionMethod { @Override public String generateSalt() { - return RandomString.generateLowerUpper(22); + return RandomStringUtils.generateLowerUpper(22); } @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/MYBB.java b/src/main/java/fr/xephi/authme/security/crypts/MYBB.java index 32ad154a4..b25f47695 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/MYBB.java +++ b/src/main/java/fr/xephi/authme/security/crypts/MYBB.java @@ -1,6 +1,6 @@ package fr.xephi.authme.security.crypts; -import fr.xephi.authme.security.RandomString; +import fr.xephi.authme.util.RandomStringUtils; import fr.xephi.authme.security.crypts.description.HasSalt; import fr.xephi.authme.security.crypts.description.Recommendation; import fr.xephi.authme.security.crypts.description.SaltType; @@ -19,7 +19,7 @@ public class MYBB extends SeparateSaltMethod { @Override public String generateSalt() { - return RandomString.generateLowerUpper(8); + return RandomStringUtils.generateLowerUpper(8); } } diff --git a/src/main/java/fr/xephi/authme/security/crypts/PHPFUSION.java b/src/main/java/fr/xephi/authme/security/crypts/PHPFUSION.java index 2950fe670..905798ec3 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/PHPFUSION.java +++ b/src/main/java/fr/xephi/authme/security/crypts/PHPFUSION.java @@ -1,7 +1,7 @@ package fr.xephi.authme.security.crypts; import fr.xephi.authme.security.HashUtils; -import fr.xephi.authme.security.RandomString; +import fr.xephi.authme.util.RandomStringUtils; import fr.xephi.authme.security.crypts.description.AsciiRestricted; import fr.xephi.authme.security.crypts.description.Recommendation; import fr.xephi.authme.security.crypts.description.Usage; @@ -41,7 +41,7 @@ public class PHPFUSION extends SeparateSaltMethod { @Override public String generateSalt() { - return RandomString.generateHex(12); + return RandomStringUtils.generateHex(12); } diff --git a/src/main/java/fr/xephi/authme/security/crypts/SALTED2MD5.java b/src/main/java/fr/xephi/authme/security/crypts/SALTED2MD5.java index 2b683bb25..b2f22ab9b 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/SALTED2MD5.java +++ b/src/main/java/fr/xephi/authme/security/crypts/SALTED2MD5.java @@ -1,6 +1,6 @@ package fr.xephi.authme.security.crypts; -import fr.xephi.authme.security.RandomString; +import fr.xephi.authme.util.RandomStringUtils; import fr.xephi.authme.security.crypts.description.HasSalt; import fr.xephi.authme.security.crypts.description.Recommendation; import fr.xephi.authme.security.crypts.description.SaltType; @@ -30,7 +30,7 @@ public class SALTED2MD5 extends SeparateSaltMethod { @Override public String generateSalt() { - return RandomString.generateHex(saltLength); + return RandomStringUtils.generateHex(saltLength); } diff --git a/src/main/java/fr/xephi/authme/security/crypts/SALTEDSHA512.java b/src/main/java/fr/xephi/authme/security/crypts/SALTEDSHA512.java index d9952ee48..f0f293439 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/SALTEDSHA512.java +++ b/src/main/java/fr/xephi/authme/security/crypts/SALTEDSHA512.java @@ -1,7 +1,7 @@ package fr.xephi.authme.security.crypts; import fr.xephi.authme.security.HashUtils; -import fr.xephi.authme.security.RandomString; +import fr.xephi.authme.util.RandomStringUtils; import fr.xephi.authme.security.crypts.description.Recommendation; import fr.xephi.authme.security.crypts.description.Usage; @@ -15,6 +15,6 @@ public class SALTEDSHA512 extends SeparateSaltMethod { @Override public String generateSalt() { - return RandomString.generateHex(32); + return RandomStringUtils.generateHex(32); } } diff --git a/src/main/java/fr/xephi/authme/security/crypts/WBB3.java b/src/main/java/fr/xephi/authme/security/crypts/WBB3.java index 28e975856..546c2dc87 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/WBB3.java +++ b/src/main/java/fr/xephi/authme/security/crypts/WBB3.java @@ -1,6 +1,6 @@ package fr.xephi.authme.security.crypts; -import fr.xephi.authme.security.RandomString; +import fr.xephi.authme.util.RandomStringUtils; import fr.xephi.authme.security.crypts.description.HasSalt; import fr.xephi.authme.security.crypts.description.Recommendation; import fr.xephi.authme.security.crypts.description.SaltType; @@ -19,7 +19,7 @@ public class WBB3 extends SeparateSaltMethod { @Override public String generateSalt() { - return RandomString.generateHex(40); + return RandomStringUtils.generateHex(40); } } diff --git a/src/main/java/fr/xephi/authme/service/RecoveryCodeService.java b/src/main/java/fr/xephi/authme/service/RecoveryCodeService.java index 5f5dd746b..e7fa37ad0 100644 --- a/src/main/java/fr/xephi/authme/service/RecoveryCodeService.java +++ b/src/main/java/fr/xephi/authme/service/RecoveryCodeService.java @@ -2,7 +2,7 @@ package fr.xephi.authme.service; import com.google.common.annotations.VisibleForTesting; import fr.xephi.authme.initialization.SettingsDependent; -import fr.xephi.authme.security.RandomString; +import fr.xephi.authme.util.RandomStringUtils; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.SecuritySettings; @@ -42,7 +42,7 @@ public class RecoveryCodeService implements SettingsDependent { * @return the generated code */ public String generateCode(String player) { - String code = RandomString.generateHex(recoveryCodeLength); + String code = RandomStringUtils.generateHex(recoveryCodeLength); recoveryCodes.put(player, new ExpiringEntry(code, System.currentTimeMillis() + recoveryCodeExpirationMillis)); return code; } diff --git a/src/main/java/fr/xephi/authme/security/RandomString.java b/src/main/java/fr/xephi/authme/util/RandomStringUtils.java similarity index 93% rename from src/main/java/fr/xephi/authme/security/RandomString.java rename to src/main/java/fr/xephi/authme/util/RandomStringUtils.java index 10926e114..0ad582abe 100644 --- a/src/main/java/fr/xephi/authme/security/RandomString.java +++ b/src/main/java/fr/xephi/authme/util/RandomStringUtils.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.security; +package fr.xephi.authme.util; import java.security.SecureRandom; import java.util.Random; @@ -6,14 +6,15 @@ import java.util.Random; /** * Utility for generating random strings. */ -public final class RandomString { +public final class RandomStringUtils { private static final String CHARS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; private static final Random RANDOM = new SecureRandom(); private static final int HEX_MAX_INDEX = 16; private static final int LOWER_ALPHANUMERIC_INDEX = 36; - private RandomString() { + // Utility class + private RandomStringUtils() { } /** diff --git a/src/test/java/fr/xephi/authme/security/RandomStringTest.java b/src/test/java/fr/xephi/authme/security/RandomStringUtilsTest.java similarity index 84% rename from src/test/java/fr/xephi/authme/security/RandomStringTest.java rename to src/test/java/fr/xephi/authme/security/RandomStringUtilsTest.java index 3582fb91f..217bc927b 100644 --- a/src/test/java/fr/xephi/authme/security/RandomStringTest.java +++ b/src/test/java/fr/xephi/authme/security/RandomStringUtilsTest.java @@ -1,5 +1,6 @@ package fr.xephi.authme.security; +import fr.xephi.authme.util.RandomStringUtils; import org.junit.Test; import java.util.regex.Pattern; @@ -8,9 +9,9 @@ import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; /** - * Test for {@link RandomString}. + * Test for {@link RandomStringUtils}. */ -public class RandomStringTest { +public class RandomStringUtilsTest { @Test public void shouldGenerateRandomStrings() { @@ -20,7 +21,7 @@ public class RandomStringTest { // when / then for (int length : lengths) { - String result = RandomString.generate(length); + String result = RandomStringUtils.generate(length); assertThat("Result '" + result + "' should have length " + length, result.length(), equalTo(length)); assertThat("Result '" + result + "' should only have characters a-z, 0-9", @@ -36,7 +37,7 @@ public class RandomStringTest { // when / then for (int length : lengths) { - String result = RandomString.generateHex(length); + String result = RandomStringUtils.generateHex(length); assertThat("Result '" + result + "' should have length " + length, result.length(), equalTo(length)); assertThat("Result '" + result + "' should only have characters a-f, 0-9", @@ -52,7 +53,7 @@ public class RandomStringTest { // when / then for (int length : lengths) { - String result = RandomString.generateHex(length); + String result = RandomStringUtils.generateHex(length); assertThat("Result '" + result + "' should have length " + length, result.length(), equalTo(length)); assertThat("Result '" + result + "' should only have characters a-z, A-Z, 0-9", @@ -63,7 +64,7 @@ public class RandomStringTest { @Test(expected = IllegalArgumentException.class) public void shouldThrowForInvalidLength() { // given/when - RandomString.generate(-3); + RandomStringUtils.generate(-3); // then - throw exception } From 7394e004ce3c40da5624f551b2b6390e0ad4fabf Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Tue, 4 Oct 2016 22:10:40 +0200 Subject: [PATCH 12/18] Fix wrong antibot sensibility #896 --- src/main/java/fr/xephi/authme/service/AntiBotService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/xephi/authme/service/AntiBotService.java b/src/main/java/fr/xephi/authme/service/AntiBotService.java index a1ecf71fc..561b57511 100644 --- a/src/main/java/fr/xephi/authme/service/AntiBotService.java +++ b/src/main/java/fr/xephi/authme/service/AntiBotService.java @@ -162,7 +162,7 @@ public class AntiBotService implements SettingsDependent { public void run() { antibotPlayers--; } - }, 15 * TICKS_PER_SECOND); + }, 5 * TICKS_PER_SECOND); } /** From 2d2c14eb0a9006e52cdd116f60093297ea7bc30b Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Tue, 4 Oct 2016 22:30:25 +0200 Subject: [PATCH 13/18] Fix refactor errors --- src/main/java/fr/xephi/authme/AuthMe.java | 8 +++---- .../{GeoLiteAPI.java => GeoIpManager.java} | 6 ++--- .../authme/service/ValidationService.java | 6 ++--- .../xephi/authme/geoip/GeoIpManagerTest.java | 15 ++++++------ .../authme/service/ValidationServiceTest.java | 23 +++++++++---------- .../fr/xephi/authme/util/PlayerUtilsTest.java | 2 +- 6 files changed, 29 insertions(+), 31 deletions(-) rename src/main/java/fr/xephi/authme/geoip/{GeoLiteAPI.java => GeoIpManager.java} (96%) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 9c94bc8ea..e72780aaf 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -33,7 +33,7 @@ import fr.xephi.authme.settings.properties.SecuritySettings; import fr.xephi.authme.task.CleanupTask; import fr.xephi.authme.task.purge.PurgeService; import fr.xephi.authme.service.BukkitService; -import fr.xephi.authme.geoip.GeoLiteAPI; +import fr.xephi.authme.geoip.GeoIpManager; import fr.xephi.authme.service.MigrationService; import fr.xephi.authme.util.PlayerUtils; import org.bukkit.Server; @@ -74,7 +74,7 @@ public class AuthMe extends JavaPlugin { private DataSource database; private BukkitService bukkitService; private Injector injector; - private GeoLiteAPI geoLiteApi; + private GeoIpManager geoIpManager; private PlayerCache playerCache; /** @@ -248,7 +248,7 @@ public class AuthMe extends JavaPlugin { permsMan = injector.getSingleton(PermissionsManager.class); bukkitService = injector.getSingleton(BukkitService.class); commandHandler = injector.getSingleton(CommandHandler.class); - geoLiteApi = injector.getSingleton(GeoLiteAPI.class); + geoIpManager = injector.getSingleton(GeoIpManager.class); // Trigger construction of API classes; they will keep track of the singleton injector.getSingleton(NewAPI.class); @@ -374,7 +374,7 @@ public class AuthMe extends JavaPlugin { .replace("{SERVER}", server.getServerName()) .replace("{VERSION}", server.getBukkitVersion()) // TODO: We should cache info like this, maybe with a class that extends Player? - .replace("{COUNTRY}", geoLiteApi.getCountryName(ipAddress)); + .replace("{COUNTRY}", geoIpManager.getCountryName(ipAddress)); } diff --git a/src/main/java/fr/xephi/authme/geoip/GeoLiteAPI.java b/src/main/java/fr/xephi/authme/geoip/GeoIpManager.java similarity index 96% rename from src/main/java/fr/xephi/authme/geoip/GeoLiteAPI.java rename to src/main/java/fr/xephi/authme/geoip/GeoIpManager.java index 11f5e4f01..bd397a97c 100644 --- a/src/main/java/fr/xephi/authme/geoip/GeoLiteAPI.java +++ b/src/main/java/fr/xephi/authme/geoip/GeoIpManager.java @@ -17,7 +17,7 @@ import java.net.URLConnection; import java.util.concurrent.TimeUnit; import java.util.zip.GZIPInputStream; -public class GeoLiteAPI { +public class GeoIpManager { private static final String LICENSE = "[LICENSE] This product uses data from the GeoLite API created by MaxMind, available at http://www.maxmind.com"; private static final String GEOIP_URL = @@ -28,14 +28,14 @@ public class GeoLiteAPI { private final File dataFile; @Inject - GeoLiteAPI(@DataFolder File dataFolder) { + GeoIpManager(@DataFolder File dataFolder) { this.dataFile = new File(dataFolder, "GeoIP.dat"); // Fires download of recent data or the initialization of the look up service isDataAvailable(); } @VisibleForTesting - GeoLiteAPI(@DataFolder File dataFolder, LookupService lookupService) { + GeoIpManager(@DataFolder File dataFolder, LookupService lookupService) { this.dataFile = dataFolder; this.lookupService = lookupService; } diff --git a/src/main/java/fr/xephi/authme/service/ValidationService.java b/src/main/java/fr/xephi/authme/service/ValidationService.java index 63227823d..258ac149b 100644 --- a/src/main/java/fr/xephi/authme/service/ValidationService.java +++ b/src/main/java/fr/xephi/authme/service/ValidationService.java @@ -2,7 +2,7 @@ package fr.xephi.authme.service; import com.github.authme.configme.properties.Property; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.geoip.GeoLiteAPI; +import fr.xephi.authme.geoip.GeoIpManager; import fr.xephi.authme.initialization.Reloadable; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.permission.PermissionsManager; @@ -36,7 +36,7 @@ public class ValidationService implements Reloadable { @Inject private PermissionsManager permissionsManager; @Inject - private GeoLiteAPI geoLiteApi; + private GeoIpManager geoIpManager; private Pattern passwordRegex; private Set unrestrictedNames; @@ -115,7 +115,7 @@ public class ValidationService implements Reloadable { return true; } - String countryCode = geoLiteApi.getCountryCode(hostAddress); + String countryCode = geoIpManager.getCountryCode(hostAddress); return validateWhitelistAndBlacklist(countryCode, ProtectionSettings.COUNTRIES_WHITELIST, ProtectionSettings.COUNTRIES_BLACKLIST); diff --git a/src/test/java/fr/xephi/authme/geoip/GeoIpManagerTest.java b/src/test/java/fr/xephi/authme/geoip/GeoIpManagerTest.java index 547cf3e70..a4d459ca5 100644 --- a/src/test/java/fr/xephi/authme/geoip/GeoIpManagerTest.java +++ b/src/test/java/fr/xephi/authme/geoip/GeoIpManagerTest.java @@ -2,7 +2,6 @@ package fr.xephi.authme.geoip; import com.maxmind.geoip.Country; import com.maxmind.geoip.LookupService; -import fr.xephi.authme.geoip.GeoLiteAPI; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -23,12 +22,12 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; /** - * Test for {@link GeoLiteAPI}. + * Test for {@link GeoIpManager}. */ @RunWith(MockitoJUnitRunner.class) public class GeoIpManagerTest { - private GeoLiteAPI geoLiteApi; + private GeoIpManager geoIpManager; private File dataFolder; @Mock private LookupService lookupService; @@ -39,7 +38,7 @@ public class GeoIpManagerTest { @Before public void initializeGeoLiteApi() throws IOException { dataFolder = temporaryFolder.newFolder(); - geoLiteApi = new GeoLiteAPI(dataFolder, lookupService); + geoIpManager = new GeoIpManager(dataFolder, lookupService); } @Test @@ -52,7 +51,7 @@ public class GeoIpManagerTest { given(lookupService.getCountry(ip)).willReturn(country); // when - String result = geoLiteApi.getCountryCode(ip); + String result = geoIpManager.getCountryCode(ip); // then assertThat(result, equalTo(countryCode)); @@ -65,7 +64,7 @@ public class GeoIpManagerTest { String ip = "127.0.0.1"; // when - String result = geoLiteApi.getCountryCode(ip); + String result = geoIpManager.getCountryCode(ip); // then assertThat(result, equalTo("--")); @@ -82,7 +81,7 @@ public class GeoIpManagerTest { given(lookupService.getCountry(ip)).willReturn(country); // when - String result = geoLiteApi.getCountryName(ip); + String result = geoIpManager.getCountryName(ip); // then assertThat(result, equalTo(countryName)); @@ -95,7 +94,7 @@ public class GeoIpManagerTest { String ip = "127.0.0.1"; // when - String result = geoLiteApi.getCountryName(ip); + String result = geoIpManager.getCountryName(ip); // then assertThat(result, equalTo("N/A")); diff --git a/src/test/java/fr/xephi/authme/service/ValidationServiceTest.java b/src/test/java/fr/xephi/authme/service/ValidationServiceTest.java index 2a85b131a..b3c3db22b 100644 --- a/src/test/java/fr/xephi/authme/service/ValidationServiceTest.java +++ b/src/test/java/fr/xephi/authme/service/ValidationServiceTest.java @@ -5,11 +5,10 @@ import ch.jalu.injector.testing.DelayedInjectionRunner; import ch.jalu.injector.testing.InjectDelayed; import com.google.common.base.Strings; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.geoip.GeoLiteAPI; +import fr.xephi.authme.geoip.GeoIpManager; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerStatePermission; -import fr.xephi.authme.service.ValidationService; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.EmailSettings; import fr.xephi.authme.settings.properties.ProtectionSettings; @@ -46,7 +45,7 @@ public class ValidationServiceTest { @Mock private PermissionsManager permissionsManager; @Mock - private GeoLiteAPI geoLiteApi; + private GeoIpManager geoIpManager; @BeforeInjecting public void createService() { @@ -267,7 +266,7 @@ public class ValidationServiceTest { // then assertThat(result, equalTo(true)); - verifyZeroInteractions(geoLiteApi); + verifyZeroInteractions(geoIpManager); } @Test @@ -276,14 +275,14 @@ public class ValidationServiceTest { given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(asList("ch", "it")); given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(Collections.emptyList()); String ip = "127.0.0.1"; - given(geoLiteApi.getCountryCode(ip)).willReturn("CH"); + given(geoIpManager.getCountryCode(ip)).willReturn("CH"); // when boolean result = validationService.isCountryAdmitted(ip); // then assertThat(result, equalTo(true)); - verify(geoLiteApi).getCountryCode(ip); + verify(geoIpManager).getCountryCode(ip); } @Test @@ -292,14 +291,14 @@ public class ValidationServiceTest { given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(asList("ch", "it")); given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(Collections.emptyList()); String ip = "123.45.67.89"; - given(geoLiteApi.getCountryCode(ip)).willReturn("BR"); + given(geoIpManager.getCountryCode(ip)).willReturn("BR"); // when boolean result = validationService.isCountryAdmitted(ip); // then assertThat(result, equalTo(false)); - verify(geoLiteApi).getCountryCode(ip); + verify(geoIpManager).getCountryCode(ip); } @Test @@ -308,14 +307,14 @@ public class ValidationServiceTest { given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(Collections.emptyList()); given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(asList("ch", "it")); String ip = "127.0.0.1"; - given(geoLiteApi.getCountryCode(ip)).willReturn("BR"); + given(geoIpManager.getCountryCode(ip)).willReturn("BR"); // when boolean result = validationService.isCountryAdmitted(ip); // then assertThat(result, equalTo(true)); - verify(geoLiteApi).getCountryCode(ip); + verify(geoIpManager).getCountryCode(ip); } @Test @@ -324,14 +323,14 @@ public class ValidationServiceTest { given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(Collections.emptyList()); given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(asList("ch", "it")); String ip = "123.45.67.89"; - given(geoLiteApi.getCountryCode(ip)).willReturn("IT"); + given(geoIpManager.getCountryCode(ip)).willReturn("IT"); // when boolean result = validationService.isCountryAdmitted(ip); // then assertThat(result, equalTo(false)); - verify(geoLiteApi).getCountryCode(ip); + verify(geoIpManager).getCountryCode(ip); } private static void assertErrorEquals(ValidationResult validationResult, MessageKey messageKey, String... args) { diff --git a/src/test/java/fr/xephi/authme/util/PlayerUtilsTest.java b/src/test/java/fr/xephi/authme/util/PlayerUtilsTest.java index 444d0c497..14933a04a 100644 --- a/src/test/java/fr/xephi/authme/util/PlayerUtilsTest.java +++ b/src/test/java/fr/xephi/authme/util/PlayerUtilsTest.java @@ -15,7 +15,7 @@ import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; /** - * Test for {@link Utils}. + * Test for {@link PlayerUtils}. */ public class PlayerUtilsTest { From 7e2912cc600ffb9d47bd0d98e99d867b2f65aba5 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Tue, 4 Oct 2016 22:31:37 +0200 Subject: [PATCH 14/18] Revert "Fix refactor errors" This reverts commit 2d2c14eb0a9006e52cdd116f60093297ea7bc30b. --- src/main/java/fr/xephi/authme/AuthMe.java | 8 +++---- .../{GeoIpManager.java => GeoLiteAPI.java} | 6 ++--- .../authme/service/ValidationService.java | 6 ++--- .../xephi/authme/geoip/GeoIpManagerTest.java | 15 ++++++------ .../authme/service/ValidationServiceTest.java | 23 ++++++++++--------- .../fr/xephi/authme/util/PlayerUtilsTest.java | 2 +- 6 files changed, 31 insertions(+), 29 deletions(-) rename src/main/java/fr/xephi/authme/geoip/{GeoIpManager.java => GeoLiteAPI.java} (96%) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index e72780aaf..9c94bc8ea 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -33,7 +33,7 @@ import fr.xephi.authme.settings.properties.SecuritySettings; import fr.xephi.authme.task.CleanupTask; import fr.xephi.authme.task.purge.PurgeService; import fr.xephi.authme.service.BukkitService; -import fr.xephi.authme.geoip.GeoIpManager; +import fr.xephi.authme.geoip.GeoLiteAPI; import fr.xephi.authme.service.MigrationService; import fr.xephi.authme.util.PlayerUtils; import org.bukkit.Server; @@ -74,7 +74,7 @@ public class AuthMe extends JavaPlugin { private DataSource database; private BukkitService bukkitService; private Injector injector; - private GeoIpManager geoIpManager; + private GeoLiteAPI geoLiteApi; private PlayerCache playerCache; /** @@ -248,7 +248,7 @@ public class AuthMe extends JavaPlugin { permsMan = injector.getSingleton(PermissionsManager.class); bukkitService = injector.getSingleton(BukkitService.class); commandHandler = injector.getSingleton(CommandHandler.class); - geoIpManager = injector.getSingleton(GeoIpManager.class); + geoLiteApi = injector.getSingleton(GeoLiteAPI.class); // Trigger construction of API classes; they will keep track of the singleton injector.getSingleton(NewAPI.class); @@ -374,7 +374,7 @@ public class AuthMe extends JavaPlugin { .replace("{SERVER}", server.getServerName()) .replace("{VERSION}", server.getBukkitVersion()) // TODO: We should cache info like this, maybe with a class that extends Player? - .replace("{COUNTRY}", geoIpManager.getCountryName(ipAddress)); + .replace("{COUNTRY}", geoLiteApi.getCountryName(ipAddress)); } diff --git a/src/main/java/fr/xephi/authme/geoip/GeoIpManager.java b/src/main/java/fr/xephi/authme/geoip/GeoLiteAPI.java similarity index 96% rename from src/main/java/fr/xephi/authme/geoip/GeoIpManager.java rename to src/main/java/fr/xephi/authme/geoip/GeoLiteAPI.java index bd397a97c..11f5e4f01 100644 --- a/src/main/java/fr/xephi/authme/geoip/GeoIpManager.java +++ b/src/main/java/fr/xephi/authme/geoip/GeoLiteAPI.java @@ -17,7 +17,7 @@ import java.net.URLConnection; import java.util.concurrent.TimeUnit; import java.util.zip.GZIPInputStream; -public class GeoIpManager { +public class GeoLiteAPI { private static final String LICENSE = "[LICENSE] This product uses data from the GeoLite API created by MaxMind, available at http://www.maxmind.com"; private static final String GEOIP_URL = @@ -28,14 +28,14 @@ public class GeoIpManager { private final File dataFile; @Inject - GeoIpManager(@DataFolder File dataFolder) { + GeoLiteAPI(@DataFolder File dataFolder) { this.dataFile = new File(dataFolder, "GeoIP.dat"); // Fires download of recent data or the initialization of the look up service isDataAvailable(); } @VisibleForTesting - GeoIpManager(@DataFolder File dataFolder, LookupService lookupService) { + GeoLiteAPI(@DataFolder File dataFolder, LookupService lookupService) { this.dataFile = dataFolder; this.lookupService = lookupService; } diff --git a/src/main/java/fr/xephi/authme/service/ValidationService.java b/src/main/java/fr/xephi/authme/service/ValidationService.java index 258ac149b..63227823d 100644 --- a/src/main/java/fr/xephi/authme/service/ValidationService.java +++ b/src/main/java/fr/xephi/authme/service/ValidationService.java @@ -2,7 +2,7 @@ package fr.xephi.authme.service; import com.github.authme.configme.properties.Property; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.geoip.GeoIpManager; +import fr.xephi.authme.geoip.GeoLiteAPI; import fr.xephi.authme.initialization.Reloadable; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.permission.PermissionsManager; @@ -36,7 +36,7 @@ public class ValidationService implements Reloadable { @Inject private PermissionsManager permissionsManager; @Inject - private GeoIpManager geoIpManager; + private GeoLiteAPI geoLiteApi; private Pattern passwordRegex; private Set unrestrictedNames; @@ -115,7 +115,7 @@ public class ValidationService implements Reloadable { return true; } - String countryCode = geoIpManager.getCountryCode(hostAddress); + String countryCode = geoLiteApi.getCountryCode(hostAddress); return validateWhitelistAndBlacklist(countryCode, ProtectionSettings.COUNTRIES_WHITELIST, ProtectionSettings.COUNTRIES_BLACKLIST); diff --git a/src/test/java/fr/xephi/authme/geoip/GeoIpManagerTest.java b/src/test/java/fr/xephi/authme/geoip/GeoIpManagerTest.java index a4d459ca5..547cf3e70 100644 --- a/src/test/java/fr/xephi/authme/geoip/GeoIpManagerTest.java +++ b/src/test/java/fr/xephi/authme/geoip/GeoIpManagerTest.java @@ -2,6 +2,7 @@ package fr.xephi.authme.geoip; import com.maxmind.geoip.Country; import com.maxmind.geoip.LookupService; +import fr.xephi.authme.geoip.GeoLiteAPI; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -22,12 +23,12 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; /** - * Test for {@link GeoIpManager}. + * Test for {@link GeoLiteAPI}. */ @RunWith(MockitoJUnitRunner.class) public class GeoIpManagerTest { - private GeoIpManager geoIpManager; + private GeoLiteAPI geoLiteApi; private File dataFolder; @Mock private LookupService lookupService; @@ -38,7 +39,7 @@ public class GeoIpManagerTest { @Before public void initializeGeoLiteApi() throws IOException { dataFolder = temporaryFolder.newFolder(); - geoIpManager = new GeoIpManager(dataFolder, lookupService); + geoLiteApi = new GeoLiteAPI(dataFolder, lookupService); } @Test @@ -51,7 +52,7 @@ public class GeoIpManagerTest { given(lookupService.getCountry(ip)).willReturn(country); // when - String result = geoIpManager.getCountryCode(ip); + String result = geoLiteApi.getCountryCode(ip); // then assertThat(result, equalTo(countryCode)); @@ -64,7 +65,7 @@ public class GeoIpManagerTest { String ip = "127.0.0.1"; // when - String result = geoIpManager.getCountryCode(ip); + String result = geoLiteApi.getCountryCode(ip); // then assertThat(result, equalTo("--")); @@ -81,7 +82,7 @@ public class GeoIpManagerTest { given(lookupService.getCountry(ip)).willReturn(country); // when - String result = geoIpManager.getCountryName(ip); + String result = geoLiteApi.getCountryName(ip); // then assertThat(result, equalTo(countryName)); @@ -94,7 +95,7 @@ public class GeoIpManagerTest { String ip = "127.0.0.1"; // when - String result = geoIpManager.getCountryName(ip); + String result = geoLiteApi.getCountryName(ip); // then assertThat(result, equalTo("N/A")); diff --git a/src/test/java/fr/xephi/authme/service/ValidationServiceTest.java b/src/test/java/fr/xephi/authme/service/ValidationServiceTest.java index b3c3db22b..2a85b131a 100644 --- a/src/test/java/fr/xephi/authme/service/ValidationServiceTest.java +++ b/src/test/java/fr/xephi/authme/service/ValidationServiceTest.java @@ -5,10 +5,11 @@ import ch.jalu.injector.testing.DelayedInjectionRunner; import ch.jalu.injector.testing.InjectDelayed; import com.google.common.base.Strings; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.geoip.GeoIpManager; +import fr.xephi.authme.geoip.GeoLiteAPI; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerStatePermission; +import fr.xephi.authme.service.ValidationService; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.EmailSettings; import fr.xephi.authme.settings.properties.ProtectionSettings; @@ -45,7 +46,7 @@ public class ValidationServiceTest { @Mock private PermissionsManager permissionsManager; @Mock - private GeoIpManager geoIpManager; + private GeoLiteAPI geoLiteApi; @BeforeInjecting public void createService() { @@ -266,7 +267,7 @@ public class ValidationServiceTest { // then assertThat(result, equalTo(true)); - verifyZeroInteractions(geoIpManager); + verifyZeroInteractions(geoLiteApi); } @Test @@ -275,14 +276,14 @@ public class ValidationServiceTest { given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(asList("ch", "it")); given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(Collections.emptyList()); String ip = "127.0.0.1"; - given(geoIpManager.getCountryCode(ip)).willReturn("CH"); + given(geoLiteApi.getCountryCode(ip)).willReturn("CH"); // when boolean result = validationService.isCountryAdmitted(ip); // then assertThat(result, equalTo(true)); - verify(geoIpManager).getCountryCode(ip); + verify(geoLiteApi).getCountryCode(ip); } @Test @@ -291,14 +292,14 @@ public class ValidationServiceTest { given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(asList("ch", "it")); given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(Collections.emptyList()); String ip = "123.45.67.89"; - given(geoIpManager.getCountryCode(ip)).willReturn("BR"); + given(geoLiteApi.getCountryCode(ip)).willReturn("BR"); // when boolean result = validationService.isCountryAdmitted(ip); // then assertThat(result, equalTo(false)); - verify(geoIpManager).getCountryCode(ip); + verify(geoLiteApi).getCountryCode(ip); } @Test @@ -307,14 +308,14 @@ public class ValidationServiceTest { given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(Collections.emptyList()); given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(asList("ch", "it")); String ip = "127.0.0.1"; - given(geoIpManager.getCountryCode(ip)).willReturn("BR"); + given(geoLiteApi.getCountryCode(ip)).willReturn("BR"); // when boolean result = validationService.isCountryAdmitted(ip); // then assertThat(result, equalTo(true)); - verify(geoIpManager).getCountryCode(ip); + verify(geoLiteApi).getCountryCode(ip); } @Test @@ -323,14 +324,14 @@ public class ValidationServiceTest { given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(Collections.emptyList()); given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(asList("ch", "it")); String ip = "123.45.67.89"; - given(geoIpManager.getCountryCode(ip)).willReturn("IT"); + given(geoLiteApi.getCountryCode(ip)).willReturn("IT"); // when boolean result = validationService.isCountryAdmitted(ip); // then assertThat(result, equalTo(false)); - verify(geoIpManager).getCountryCode(ip); + verify(geoLiteApi).getCountryCode(ip); } private static void assertErrorEquals(ValidationResult validationResult, MessageKey messageKey, String... args) { diff --git a/src/test/java/fr/xephi/authme/util/PlayerUtilsTest.java b/src/test/java/fr/xephi/authme/util/PlayerUtilsTest.java index 14933a04a..444d0c497 100644 --- a/src/test/java/fr/xephi/authme/util/PlayerUtilsTest.java +++ b/src/test/java/fr/xephi/authme/util/PlayerUtilsTest.java @@ -15,7 +15,7 @@ import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; /** - * Test for {@link PlayerUtils}. + * Test for {@link Utils}. */ public class PlayerUtilsTest { From 58c42cf3005c7dcf65599bcc09d7b5143f9c6dfc Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Tue, 4 Oct 2016 21:49:14 +0200 Subject: [PATCH 15/18] Package cleanup - authme.cache to authme.data - Rename PlayerData to LimboPlayer to match with LimboCache - Move authme.converter to authme.datasource.converter - Split output package into output and message --- src/main/java/fr/xephi/authme/AuthMe.java | 14 ++-- src/main/java/fr/xephi/authme/api/API.java | 4 +- src/main/java/fr/xephi/authme/api/NewAPI.java | 4 +- .../xephi/authme/command/CommandService.java | 4 +- .../executable/authme/AccountsCommand.java | 4 +- .../authme/ChangePasswordAdminCommand.java | 6 +- .../executable/authme/ConverterCommand.java | 18 ++--- .../executable/authme/GetEmailCommand.java | 4 +- .../executable/authme/LastLoginCommand.java | 4 +- .../authme/PurgeLastPositionCommand.java | 4 +- .../authme/RegisterAdminCommand.java | 6 +- .../executable/authme/ReloadCommand.java | 2 +- .../executable/authme/SetEmailCommand.java | 6 +- .../authme/UnregisterAdminCommand.java | 2 +- .../executable/captcha/CaptchaCommand.java | 6 +- .../changepassword/ChangePasswordCommand.java | 4 +- .../executable/email/AddEmailCommand.java | 2 +- .../executable/email/RecoverEmailCommand.java | 6 +- .../executable/register/RegisterCommand.java | 2 +- .../unregister/UnregisterCommand.java | 4 +- .../{cache => data}/CaptchaManager.java | 2 +- .../{cache => data}/SessionManager.java | 2 +- .../{cache => data}/TempbanManager.java | 6 +- .../{cache => data}/auth/PlayerAuth.java | 2 +- .../{cache => data}/auth/PlayerCache.java | 2 +- .../backup/LimboPlayerStorage.java} | 46 +++++------ .../{cache => data}/limbo/LimboCache.java | 30 ++++---- .../limbo/LimboPlayer.java} | 7 +- .../authme/datasource/CacheDataSource.java | 6 +- .../xephi/authme/datasource/DataSource.java | 2 +- .../authme/datasource/DataSourceType.java | 6 +- .../fr/xephi/authme/datasource/FlatFile.java | 4 +- .../fr/xephi/authme/datasource/MySQL.java | 5 +- .../fr/xephi/authme/datasource/SQLite.java | 5 +- .../AbstractDataSourceConverter.java | 4 +- .../{ => datasource}/converter/Converter.java | 2 +- .../converter/CrazyLoginConverter.java | 4 +- .../converter/ForceFlatToSqlite.java | 2 +- .../converter/MySqlToSqlite.java | 2 +- .../converter/RakamakConverter.java | 4 +- .../converter/RoyalAuthConverter.java | 6 +- .../converter/SqliteToSql.java | 2 +- .../converter/vAuthConverter.java | 6 +- .../converter/xAuthConverter.java | 6 +- .../{GeoLiteAPI.java => GeoIpManager.java} | 6 +- .../authme/initialization/Initializer.java | 6 +- .../initialization/OnShutdownPlayerSaver.java | 14 ++-- .../listener/FailedVerificationException.java | 2 +- .../authme/listener/ListenerService.java | 2 +- .../xephi/authme/listener/OnJoinVerifier.java | 6 +- .../xephi/authme/listener/PlayerListener.java | 6 +- .../protocollib/InventoryPacketAdapter.java | 2 +- .../protocollib/ProtocolLibService.java | 2 +- .../protocollib/TabCompletePacketAdapter.java | 2 +- .../{output => message}/MessageKey.java | 2 +- .../authme/{output => message}/Messages.java | 2 +- .../authme/permission/AuthGroupHandler.java | 6 +- .../xephi/authme/process/ProcessService.java | 4 +- .../changepassword/AsyncChangePassword.java | 6 +- .../authme/process/email/AsyncAddEmail.java | 6 +- .../process/email/AsyncChangeEmail.java | 6 +- .../authme/process/join/AsynchronousJoin.java | 10 +-- .../process/login/AsynchronousLogin.java | 20 ++--- .../process/login/ProcessSyncPlayerLogin.java | 8 +- .../process/logout/AsynchronousLogout.java | 8 +- .../ProcessSynchronousPlayerLogout.java | 4 +- .../authme/process/quit/AsynchronousQuit.java | 6 +- .../quit/ProcessSyncronousPlayerQuit.java | 10 +-- .../process/register/AsyncRegister.java | 6 +- .../register/ProcessSyncEmailRegister.java | 2 +- .../register/ProcessSyncPasswordRegister.java | 4 +- .../unregister/AsynchronousUnregister.java | 8 +- .../xephi/authme/service/AntiBotService.java | 4 +- .../authme/service/MigrationService.java | 4 +- .../authme/service/TeleportationService.java | 8 +- .../authme/service/ValidationService.java | 8 +- .../fr/xephi/authme/settings/Settings.java | 4 +- .../fr/xephi/authme/task/MessageTask.java | 4 +- .../authme/task/PlayerDataTaskManager.java | 26 +++---- .../fr/xephi/authme/task/TimeoutTask.java | 2 +- .../authme/task/purge/PurgeExecutor.java | 2 +- .../xephi/authme/task/purge/PurgeService.java | 2 + .../java/fr/xephi/authme/util/FileUtils.java | 11 +++ .../fr/xephi/authme/util/StringUtils.java | 12 --- .../java/fr/xephi/authme/AuthMeMatchers.java | 2 +- .../java/fr/xephi/authme/api/NewAPITest.java | 4 +- .../authme/command/CommandServiceTest.java | 4 +- .../authme/AccountsCommandTest.java | 4 +- .../ChangePasswordAdminCommandTest.java | 6 +- .../authme/ConverterCommandTest.java | 4 +- .../authme/GetEmailCommandTest.java | 4 +- .../authme/LastLoginCommandTest.java | 4 +- .../authme/PurgeLastPositionCommandTest.java | 4 +- .../authme/RegisterAdminCommandTest.java | 6 +- .../executable/authme/ReloadCommandTest.java | 2 +- .../authme/SetEmailCommandTest.java | 6 +- .../authme/UnregisterAdminCommandTest.java | 2 +- .../captcha/CaptchaCommandTest.java | 6 +- .../ChangePasswordCommandTest.java | 4 +- .../executable/email/AddEmailCommandTest.java | 2 +- .../email/RecoverEmailCommandTest.java | 6 +- .../register/RegisterCommandTest.java | 2 +- .../unregister/UnregisterCommandTest.java | 4 +- .../{cache => data}/CaptchaManagerTest.java | 2 +- .../{cache => data}/SessionManagerTest.java | 2 +- .../{cache => data}/TempbanManagerTest.java | 8 +- .../backup/LimboPlayerStorageTest.java} | 30 ++++---- .../{cache => data}/limbo/LimboCacheTest.java | 76 +++++++++---------- .../AbstractDataSourceIntegrationTest.java | 2 +- .../AbstractResourceClosingTest.java | 2 +- .../datasource/FlatFileIntegrationTest.java | 6 +- .../datasource/MySqlIntegrationTest.java | 3 + .../datasource/MySqlResourceClosingTest.java | 3 + .../datasource/SQLiteIntegrationTest.java | 5 +- .../datasource/SQLiteResourceClosingTest.java | 3 + .../AbstractDataSourceConverterTest.java | 4 +- .../converter/CrazyLoginConverterTest.java | 6 +- .../converter/ForceFlatToSqliteTest.java | 4 +- .../xephi/authme/geoip/GeoIpManagerTest.java | 15 ++-- .../authme/listener/ListenerServiceTest.java | 2 +- .../authme/listener/OnJoinVerifierTest.java | 6 +- .../authme/listener/PlayerListenerTest.java | 6 +- .../{output => message}/MessageKeyTest.java | 2 +- .../MessagesFileConsistencyTest.java | 2 +- .../MessagesFileYamlCheckerTest.java | 2 +- .../MessagesIntegrationTest.java | 8 +- .../authme/process/ProcessServiceTest.java | 4 +- .../process/email/AsyncAddEmailTest.java | 6 +- .../process/email/AsyncChangeEmailTest.java | 6 +- .../process/login/AsynchronousLoginTest.java | 6 +- .../AsynchronousUnregisterTest.java | 8 +- .../authme/service/AntiBotServiceTest.java | 4 +- .../authme/service/MigrationServiceTest.java | 3 +- .../service/TeleportationServiceTest.java | 24 +++--- .../authme/service/ValidationServiceTest.java | 25 +++--- .../xephi/authme/settings/SettingsTest.java | 2 +- ...t.java => LimboPlayerTaskManagerTest.java} | 52 ++++++------- .../fr/xephi/authme/util/FileUtilsTest.java | 9 +++ .../fr/xephi/authme/util/PlayerUtilsTest.java | 2 +- .../fr/xephi/authme/util/StringUtilsTest.java | 10 --- .../tools/dependencygraph/DrawDependency.java | 2 +- .../tools/messages/MessageFileVerifier.java | 2 +- .../translation/ExportMessagesTask.java | 2 +- .../translation/ImportMessagesTask.java | 2 +- .../backup/sample-folder/data.json | 0 .../{ => datasource}/converter/crazylogin.db | 0 .../{output => message}/messages_default.yml | 0 .../{output => message}/messages_test.yml | 0 .../{output => message}/messages_test2.yml | 0 149 files changed, 491 insertions(+), 475 deletions(-) rename src/main/java/fr/xephi/authme/{cache => data}/CaptchaManager.java (99%) rename src/main/java/fr/xephi/authme/{cache => data}/SessionManager.java (98%) rename src/main/java/fr/xephi/authme/{cache => data}/TempbanManager.java (98%) rename src/main/java/fr/xephi/authme/{cache => data}/auth/PlayerAuth.java (99%) rename src/main/java/fr/xephi/authme/{cache => data}/auth/PlayerCache.java (98%) rename src/main/java/fr/xephi/authme/{cache/backup/PlayerDataStorage.java => data/backup/LimboPlayerStorage.java} (80%) rename src/main/java/fr/xephi/authme/{cache => data}/limbo/LimboCache.java (82%) rename src/main/java/fr/xephi/authme/{cache/limbo/PlayerData.java => data/limbo/LimboPlayer.java} (94%) rename src/main/java/fr/xephi/authme/{ => datasource}/converter/AbstractDataSourceConverter.java (97%) rename src/main/java/fr/xephi/authme/{ => datasource}/converter/Converter.java (85%) rename src/main/java/fr/xephi/authme/{ => datasource}/converter/CrazyLoginConverter.java (96%) rename src/main/java/fr/xephi/authme/{ => datasource}/converter/ForceFlatToSqlite.java (93%) rename src/main/java/fr/xephi/authme/{ => datasource}/converter/MySqlToSqlite.java (93%) rename src/main/java/fr/xephi/authme/{ => datasource}/converter/RakamakConverter.java (97%) rename src/main/java/fr/xephi/authme/{ => datasource}/converter/RoyalAuthConverter.java (92%) rename src/main/java/fr/xephi/authme/{ => datasource}/converter/SqliteToSql.java (93%) rename src/main/java/fr/xephi/authme/{ => datasource}/converter/vAuthConverter.java (94%) rename src/main/java/fr/xephi/authme/{ => datasource}/converter/xAuthConverter.java (97%) rename src/main/java/fr/xephi/authme/geoip/{GeoLiteAPI.java => GeoIpManager.java} (96%) rename src/main/java/fr/xephi/authme/{output => message}/MessageKey.java (99%) rename src/main/java/fr/xephi/authme/{output => message}/Messages.java (99%) rename src/test/java/fr/xephi/authme/{cache => data}/CaptchaManagerTest.java (99%) rename src/test/java/fr/xephi/authme/{cache => data}/SessionManagerTest.java (99%) rename src/test/java/fr/xephi/authme/{cache => data}/TempbanManagerTest.java (98%) rename src/test/java/fr/xephi/authme/{cache/backup/PlayerDataStorageTest.java => data/backup/LimboPlayerStorageTest.java} (82%) rename src/test/java/fr/xephi/authme/{cache => data}/limbo/LimboCacheTest.java (72%) rename src/test/java/fr/xephi/authme/{ => datasource}/converter/AbstractDataSourceConverterTest.java (98%) rename src/test/java/fr/xephi/authme/{ => datasource}/converter/CrazyLoginConverterTest.java (96%) rename src/test/java/fr/xephi/authme/{ => datasource}/converter/ForceFlatToSqliteTest.java (96%) rename src/test/java/fr/xephi/authme/{output => message}/MessageKeyTest.java (95%) rename src/test/java/fr/xephi/authme/{output => message}/MessagesFileConsistencyTest.java (98%) rename src/test/java/fr/xephi/authme/{output => message}/MessagesFileYamlCheckerTest.java (98%) rename src/test/java/fr/xephi/authme/{output => message}/MessagesIntegrationTest.java (97%) rename src/test/java/fr/xephi/authme/task/{PlayerDataTaskManagerTest.java => LimboPlayerTaskManagerTest.java} (80%) rename src/test/resources/fr/xephi/authme/{cache => data}/backup/sample-folder/data.json (100%) rename src/test/resources/fr/xephi/authme/{ => datasource}/converter/crazylogin.db (100%) rename src/test/resources/fr/xephi/authme/{output => message}/messages_default.yml (100%) rename src/test/resources/fr/xephi/authme/{output => message}/messages_test.yml (100%) rename src/test/resources/fr/xephi/authme/{output => message}/messages_test2.yml (100%) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 9c94bc8ea..eaee0347d 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -5,8 +5,8 @@ import ch.jalu.injector.InjectorBuilder; import com.google.common.annotations.VisibleForTesting; import fr.xephi.authme.api.API; import fr.xephi.authme.api.NewAPI; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.command.CommandHandler; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.initialization.DataFolder; @@ -21,7 +21,7 @@ import fr.xephi.authme.listener.PlayerListener16; import fr.xephi.authme.listener.PlayerListener18; import fr.xephi.authme.listener.PlayerListener19; import fr.xephi.authme.listener.ServerListener; -import fr.xephi.authme.output.Messages; +import fr.xephi.authme.message.Messages; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PermissionsSystemType; import fr.xephi.authme.security.crypts.SHA256; @@ -33,7 +33,7 @@ import fr.xephi.authme.settings.properties.SecuritySettings; import fr.xephi.authme.task.CleanupTask; import fr.xephi.authme.task.purge.PurgeService; import fr.xephi.authme.service.BukkitService; -import fr.xephi.authme.geoip.GeoLiteAPI; +import fr.xephi.authme.geoip.GeoIpManager; import fr.xephi.authme.service.MigrationService; import fr.xephi.authme.util.PlayerUtils; import org.bukkit.Server; @@ -74,7 +74,7 @@ public class AuthMe extends JavaPlugin { private DataSource database; private BukkitService bukkitService; private Injector injector; - private GeoLiteAPI geoLiteApi; + private GeoIpManager geoIpManager; private PlayerCache playerCache; /** @@ -248,7 +248,7 @@ public class AuthMe extends JavaPlugin { permsMan = injector.getSingleton(PermissionsManager.class); bukkitService = injector.getSingleton(BukkitService.class); commandHandler = injector.getSingleton(CommandHandler.class); - geoLiteApi = injector.getSingleton(GeoLiteAPI.class); + geoIpManager = injector.getSingleton(GeoIpManager.class); // Trigger construction of API classes; they will keep track of the singleton injector.getSingleton(NewAPI.class); @@ -374,7 +374,7 @@ public class AuthMe extends JavaPlugin { .replace("{SERVER}", server.getServerName()) .replace("{VERSION}", server.getBukkitVersion()) // TODO: We should cache info like this, maybe with a class that extends Player? - .replace("{COUNTRY}", geoLiteApi.getCountryName(ipAddress)); + .replace("{COUNTRY}", geoIpManager.getCountryName(ipAddress)); } diff --git a/src/main/java/fr/xephi/authme/api/API.java b/src/main/java/fr/xephi/authme/api/API.java index 8e16bd608..8073cf632 100644 --- a/src/main/java/fr/xephi/authme/api/API.java +++ b/src/main/java/fr/xephi/authme/api/API.java @@ -1,8 +1,8 @@ package fr.xephi.authme.api; import fr.xephi.authme.AuthMe; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.hooks.PluginHooks; import fr.xephi.authme.process.Management; diff --git a/src/main/java/fr/xephi/authme/api/NewAPI.java b/src/main/java/fr/xephi/authme/api/NewAPI.java index 5cee36e04..d42d765d0 100644 --- a/src/main/java/fr/xephi/authme/api/NewAPI.java +++ b/src/main/java/fr/xephi/authme/api/NewAPI.java @@ -1,8 +1,8 @@ package fr.xephi.authme.api; import fr.xephi.authme.AuthMe; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.hooks.PluginHooks; import fr.xephi.authme.process.Management; diff --git a/src/main/java/fr/xephi/authme/command/CommandService.java b/src/main/java/fr/xephi/authme/command/CommandService.java index a01edfaeb..bb8bbeca4 100644 --- a/src/main/java/fr/xephi/authme/command/CommandService.java +++ b/src/main/java/fr/xephi/authme/command/CommandService.java @@ -1,8 +1,8 @@ package fr.xephi.authme.command; import com.github.authme.configme.properties.Property; -import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.output.Messages; +import fr.xephi.authme.message.MessageKey; +import fr.xephi.authme.message.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.service.ValidationService; import org.bukkit.command.CommandSender; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java index 5951bd808..f3248b565 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java @@ -1,10 +1,10 @@ package fr.xephi.authme.command.executable.authme; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.service.BukkitService; import org.bukkit.command.CommandSender; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/ChangePasswordAdminCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/ChangePasswordAdminCommand.java index 3c0b2323a..9842b9f89 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/ChangePasswordAdminCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/ChangePasswordAdminCommand.java @@ -1,12 +1,12 @@ package fr.xephi.authme.command.executable.authme; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.service.BukkitService; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/ConverterCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/ConverterCommand.java index 73a21a047..0cbadf2f0 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/ConverterCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/ConverterCommand.java @@ -6,15 +6,15 @@ import com.google.common.collect.ImmutableMap; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.ExecutableCommand; -import fr.xephi.authme.converter.Converter; -import fr.xephi.authme.converter.CrazyLoginConverter; -import fr.xephi.authme.converter.MySqlToSqlite; -import fr.xephi.authme.converter.RakamakConverter; -import fr.xephi.authme.converter.RoyalAuthConverter; -import fr.xephi.authme.converter.SqliteToSql; -import fr.xephi.authme.converter.vAuthConverter; -import fr.xephi.authme.converter.xAuthConverter; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.datasource.converter.Converter; +import fr.xephi.authme.datasource.converter.CrazyLoginConverter; +import fr.xephi.authme.datasource.converter.MySqlToSqlite; +import fr.xephi.authme.datasource.converter.RakamakConverter; +import fr.xephi.authme.datasource.converter.RoyalAuthConverter; +import fr.xephi.authme.datasource.converter.SqliteToSql; +import fr.xephi.authme.datasource.converter.vAuthConverter; +import fr.xephi.authme.datasource.converter.xAuthConverter; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.service.BukkitService; import org.bukkit.command.CommandSender; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/GetEmailCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/GetEmailCommand.java index 07ee57d3a..57ff497ab 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/GetEmailCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/GetEmailCommand.java @@ -1,10 +1,10 @@ package fr.xephi.authme.command.executable.authme; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import org.bukkit.command.CommandSender; import javax.inject.Inject; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/LastLoginCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/LastLoginCommand.java index 376499fba..3c2b8cd5d 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/LastLoginCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/LastLoginCommand.java @@ -1,10 +1,10 @@ package fr.xephi.authme.command.executable.authme; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import org.bukkit.command.CommandSender; import javax.inject.Inject; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommand.java index ca6a02003..fa45367f9 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommand.java @@ -1,10 +1,10 @@ package fr.xephi.authme.command.executable.authme; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import org.bukkit.command.CommandSender; import javax.inject.Inject; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java index 166d2d808..784e9f4fc 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java @@ -1,12 +1,12 @@ package fr.xephi.authme.command.executable.authme; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.limbo.LimboCache; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.limbo.LimboCache; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.service.BukkitService; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/ReloadCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/ReloadCommand.java index e6b8009fc..dc1ba6389 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/ReloadCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/ReloadCommand.java @@ -8,7 +8,7 @@ import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.initialization.Reloadable; import fr.xephi.authme.initialization.SettingsDependent; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.DatabaseSettings; import org.bukkit.command.CommandSender; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/SetEmailCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/SetEmailCommand.java index d3d6ea78d..18eb29f56 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/SetEmailCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/SetEmailCommand.java @@ -1,11 +1,11 @@ package fr.xephi.authme.command.executable.authme; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.service.BukkitService; import org.bukkit.command.CommandSender; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/UnregisterAdminCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/UnregisterAdminCommand.java index 51e7c4d43..345351d99 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/UnregisterAdminCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/UnregisterAdminCommand.java @@ -3,7 +3,7 @@ package fr.xephi.authme.command.executable.authme; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.process.Management; import fr.xephi.authme.service.BukkitService; import org.bukkit.command.CommandSender; diff --git a/src/main/java/fr/xephi/authme/command/executable/captcha/CaptchaCommand.java b/src/main/java/fr/xephi/authme/command/executable/captcha/CaptchaCommand.java index 1577c7ad7..178c6f056 100644 --- a/src/main/java/fr/xephi/authme/command/executable/captcha/CaptchaCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/captcha/CaptchaCommand.java @@ -1,10 +1,10 @@ package fr.xephi.authme.command.executable.captcha; -import fr.xephi.authme.cache.CaptchaManager; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.CaptchaManager; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.PlayerCommand; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import org.bukkit.entity.Player; import javax.inject.Inject; diff --git a/src/main/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommand.java b/src/main/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommand.java index 2d7c12046..bfcdbe778 100644 --- a/src/main/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommand.java @@ -1,9 +1,9 @@ package fr.xephi.authme.command.executable.changepassword; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.PlayerCommand; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.process.Management; import fr.xephi.authme.service.ValidationService; import fr.xephi.authme.service.ValidationService.ValidationResult; diff --git a/src/main/java/fr/xephi/authme/command/executable/email/AddEmailCommand.java b/src/main/java/fr/xephi/authme/command/executable/email/AddEmailCommand.java index 842d866d4..85baa2d65 100644 --- a/src/main/java/fr/xephi/authme/command/executable/email/AddEmailCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/email/AddEmailCommand.java @@ -2,7 +2,7 @@ package fr.xephi.authme.command.executable.email; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.PlayerCommand; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.process.Management; import org.bukkit.entity.Player; diff --git a/src/main/java/fr/xephi/authme/command/executable/email/RecoverEmailCommand.java b/src/main/java/fr/xephi/authme/command/executable/email/RecoverEmailCommand.java index 1aeeb1d8b..89138b413 100644 --- a/src/main/java/fr/xephi/authme/command/executable/email/RecoverEmailCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/email/RecoverEmailCommand.java @@ -1,13 +1,13 @@ package fr.xephi.authme.command.executable.email; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.PlayerCommand; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.mail.SendMailSSL; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.util.RandomStringUtils; import fr.xephi.authme.security.crypts.HashedPassword; diff --git a/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java b/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java index fbfcfb5fb..f49ec2db2 100644 --- a/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java @@ -4,7 +4,7 @@ import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.PlayerCommand; import fr.xephi.authme.mail.SendMailSSL; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.process.Management; import fr.xephi.authme.security.HashAlgorithm; import fr.xephi.authme.util.RandomStringUtils; diff --git a/src/main/java/fr/xephi/authme/command/executable/unregister/UnregisterCommand.java b/src/main/java/fr/xephi/authme/command/executable/unregister/UnregisterCommand.java index 8526e4a1d..c3aaf58a7 100644 --- a/src/main/java/fr/xephi/authme/command/executable/unregister/UnregisterCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/unregister/UnregisterCommand.java @@ -1,9 +1,9 @@ package fr.xephi.authme.command.executable.unregister; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.PlayerCommand; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.process.Management; import org.bukkit.entity.Player; diff --git a/src/main/java/fr/xephi/authme/cache/CaptchaManager.java b/src/main/java/fr/xephi/authme/data/CaptchaManager.java similarity index 99% rename from src/main/java/fr/xephi/authme/cache/CaptchaManager.java rename to src/main/java/fr/xephi/authme/data/CaptchaManager.java index d46d4891a..36f33a3cb 100644 --- a/src/main/java/fr/xephi/authme/cache/CaptchaManager.java +++ b/src/main/java/fr/xephi/authme/data/CaptchaManager.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.cache; +package fr.xephi.authme.data; import fr.xephi.authme.initialization.SettingsDependent; import fr.xephi.authme.util.RandomStringUtils; diff --git a/src/main/java/fr/xephi/authme/cache/SessionManager.java b/src/main/java/fr/xephi/authme/data/SessionManager.java similarity index 98% rename from src/main/java/fr/xephi/authme/cache/SessionManager.java rename to src/main/java/fr/xephi/authme/data/SessionManager.java index 33d3f9a63..f86f54214 100644 --- a/src/main/java/fr/xephi/authme/cache/SessionManager.java +++ b/src/main/java/fr/xephi/authme/data/SessionManager.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.cache; +package fr.xephi.authme.data; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.initialization.HasCleanup; diff --git a/src/main/java/fr/xephi/authme/cache/TempbanManager.java b/src/main/java/fr/xephi/authme/data/TempbanManager.java similarity index 98% rename from src/main/java/fr/xephi/authme/cache/TempbanManager.java rename to src/main/java/fr/xephi/authme/data/TempbanManager.java index c0cb39200..e5d31ed1a 100644 --- a/src/main/java/fr/xephi/authme/cache/TempbanManager.java +++ b/src/main/java/fr/xephi/authme/data/TempbanManager.java @@ -1,10 +1,10 @@ -package fr.xephi.authme.cache; +package fr.xephi.authme.data; import com.google.common.annotations.VisibleForTesting; import fr.xephi.authme.initialization.HasCleanup; import fr.xephi.authme.initialization.SettingsDependent; -import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.output.Messages; +import fr.xephi.authme.message.MessageKey; +import fr.xephi.authme.message.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.SecuritySettings; import fr.xephi.authme.service.BukkitService; diff --git a/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java b/src/main/java/fr/xephi/authme/data/auth/PlayerAuth.java similarity index 99% rename from src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java rename to src/main/java/fr/xephi/authme/data/auth/PlayerAuth.java index cdbe0c00b..e4fd9230f 100644 --- a/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java +++ b/src/main/java/fr/xephi/authme/data/auth/PlayerAuth.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.cache.auth; +package fr.xephi.authme.data.auth; import fr.xephi.authme.security.crypts.HashedPassword; import org.bukkit.Location; diff --git a/src/main/java/fr/xephi/authme/cache/auth/PlayerCache.java b/src/main/java/fr/xephi/authme/data/auth/PlayerCache.java similarity index 98% rename from src/main/java/fr/xephi/authme/cache/auth/PlayerCache.java rename to src/main/java/fr/xephi/authme/data/auth/PlayerCache.java index b13528332..1ae08f8a9 100644 --- a/src/main/java/fr/xephi/authme/cache/auth/PlayerCache.java +++ b/src/main/java/fr/xephi/authme/data/auth/PlayerCache.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.cache.auth; +package fr.xephi.authme.data.auth; import java.util.concurrent.ConcurrentHashMap; diff --git a/src/main/java/fr/xephi/authme/cache/backup/PlayerDataStorage.java b/src/main/java/fr/xephi/authme/data/backup/LimboPlayerStorage.java similarity index 80% rename from src/main/java/fr/xephi/authme/cache/backup/PlayerDataStorage.java rename to src/main/java/fr/xephi/authme/data/backup/LimboPlayerStorage.java index 04015d844..1b2270285 100644 --- a/src/main/java/fr/xephi/authme/cache/backup/PlayerDataStorage.java +++ b/src/main/java/fr/xephi/authme/data/backup/LimboPlayerStorage.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.cache.backup; +package fr.xephi.authme.data.backup; import com.google.common.io.Files; import com.google.gson.Gson; @@ -10,7 +10,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.limbo.PlayerData; +import fr.xephi.authme.data.limbo.LimboPlayer; import fr.xephi.authme.initialization.DataFolder; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.settings.SpawnLoader; @@ -30,7 +30,7 @@ import java.nio.charset.StandardCharsets; /** * Class used to store player's data (OP, flying, speed, position) to disk. */ -public class PlayerDataStorage { +public class LimboPlayerStorage { private final Gson gson; private final File cacheDir; @@ -39,8 +39,8 @@ public class PlayerDataStorage { private BukkitService bukkitService; @Inject - PlayerDataStorage(@DataFolder File dataFolder, PermissionsManager permsMan, - SpawnLoader spawnLoader, BukkitService bukkitService) { + LimboPlayerStorage(@DataFolder File dataFolder, PermissionsManager permsMan, + SpawnLoader spawnLoader, BukkitService bukkitService) { this.permissionsManager = permsMan; this.spawnLoader = spawnLoader; this.bukkitService = bukkitService; @@ -50,8 +50,8 @@ public class PlayerDataStorage { ConsoleLogger.warning("Failed to create userdata directory."); } gson = new GsonBuilder() - .registerTypeAdapter(PlayerData.class, new PlayerDataSerializer()) - .registerTypeAdapter(PlayerData.class, new PlayerDataDeserializer()) + .registerTypeAdapter(LimboPlayer.class, new LimboPlayerSerializer()) + .registerTypeAdapter(LimboPlayer.class, new LimboPlayerDeserializer()) .setPrettyPrinting() .create(); } @@ -63,7 +63,7 @@ public class PlayerDataStorage { * * @return PlayerData object if the data is exist, null otherwise. */ - public PlayerData readData(Player player) { + public LimboPlayer readData(Player player) { String id = PlayerUtils.getUUIDorName(player); File file = new File(cacheDir, id + File.separator + "data.json"); if (!file.exists()) { @@ -72,7 +72,7 @@ public class PlayerDataStorage { try { String str = Files.toString(file, StandardCharsets.UTF_8); - return gson.fromJson(str, PlayerData.class); + return gson.fromJson(str, LimboPlayer.class); } catch (IOException e) { ConsoleLogger.logException("Could not read player data on disk for '" + player.getName() + "'", e); return null; @@ -95,12 +95,12 @@ public class PlayerDataStorage { boolean canFly = player.getAllowFlight(); float walkSpeed = player.getWalkSpeed(); float flySpeed = player.getFlySpeed(); - PlayerData playerData = new PlayerData(location, operator, group, canFly, walkSpeed, flySpeed); + LimboPlayer limboPlayer = new LimboPlayer(location, operator, group, canFly, walkSpeed, flySpeed); try { File file = new File(cacheDir, id + File.separator + "data.json"); Files.createParentDirs(file); Files.touch(file); - Files.write(gson.toJson(playerData), file, StandardCharsets.UTF_8); + Files.write(gson.toJson(limboPlayer), file, StandardCharsets.UTF_8); } catch (IOException e) { ConsoleLogger.logException("Failed to write " + player.getName() + " data.", e); } @@ -136,10 +136,10 @@ public class PlayerDataStorage { return file.exists(); } - private class PlayerDataDeserializer implements JsonDeserializer { + private class LimboPlayerDeserializer implements JsonDeserializer { @Override - public PlayerData deserialize(JsonElement jsonElement, Type type, - JsonDeserializationContext context) { + public LimboPlayer deserialize(JsonElement jsonElement, Type type, + JsonDeserializationContext context) { JsonObject jsonObject = jsonElement.getAsJsonObject(); if (jsonObject == null) { return null; @@ -181,18 +181,18 @@ public class PlayerDataStorage { flySpeed = e.getAsFloat(); } - return new PlayerData(loc, operator, group, canFly, walkSpeed, flySpeed); + return new LimboPlayer(loc, operator, group, canFly, walkSpeed, flySpeed); } } - private class PlayerDataSerializer implements JsonSerializer { + private class LimboPlayerSerializer implements JsonSerializer { @Override - public JsonElement serialize(PlayerData playerData, Type type, + public JsonElement serialize(LimboPlayer limboPlayer, Type type, JsonSerializationContext context) { JsonObject obj = new JsonObject(); - obj.addProperty("group", playerData.getGroup()); + obj.addProperty("group", limboPlayer.getGroup()); - Location loc = playerData.getLocation(); + Location loc = limboPlayer.getLocation(); JsonObject obj2 = new JsonObject(); obj2.addProperty("world", loc.getWorld().getName()); obj2.addProperty("x", loc.getX()); @@ -202,10 +202,10 @@ public class PlayerDataStorage { obj2.addProperty("pitch", loc.getPitch()); obj.add("location", obj2); - obj.addProperty("operator", playerData.isOperator()); - obj.addProperty("can-fly", playerData.isCanFly()); - obj.addProperty("walk-speed", playerData.getWalkSpeed()); - obj.addProperty("fly-speed", playerData.getFlySpeed()); + obj.addProperty("operator", limboPlayer.isOperator()); + obj.addProperty("can-fly", limboPlayer.isCanFly()); + obj.addProperty("walk-speed", limboPlayer.getWalkSpeed()); + obj.addProperty("fly-speed", limboPlayer.getFlySpeed()); return obj; } } diff --git a/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java b/src/main/java/fr/xephi/authme/data/limbo/LimboCache.java similarity index 82% rename from src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java rename to src/main/java/fr/xephi/authme/data/limbo/LimboCache.java index a49408b05..82e42fba8 100644 --- a/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java +++ b/src/main/java/fr/xephi/authme/data/limbo/LimboCache.java @@ -1,6 +1,6 @@ -package fr.xephi.authme.cache.limbo; +package fr.xephi.authme.data.limbo; -import fr.xephi.authme.cache.backup.PlayerDataStorage; +import fr.xephi.authme.data.backup.LimboPlayerStorage; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.SpawnLoader; @@ -16,24 +16,24 @@ import java.util.concurrent.ConcurrentHashMap; import static com.google.common.base.Preconditions.checkNotNull; /** - * Manages all {@link PlayerData} instances. + * Manages all {@link LimboPlayer} instances. */ public class LimboCache { - private final Map cache = new ConcurrentHashMap<>(); + private final Map cache = new ConcurrentHashMap<>(); - private PlayerDataStorage playerDataStorage; + private LimboPlayerStorage limboPlayerStorage; private Settings settings; private PermissionsManager permissionsManager; private SpawnLoader spawnLoader; @Inject LimboCache(Settings settings, PermissionsManager permissionsManager, - SpawnLoader spawnLoader, PlayerDataStorage playerDataStorage) { + SpawnLoader spawnLoader, LimboPlayerStorage limboPlayerStorage) { this.settings = settings; this.permissionsManager = permissionsManager; this.spawnLoader = spawnLoader; - this.playerDataStorage = playerDataStorage; + this.limboPlayerStorage = limboPlayerStorage; } /** @@ -53,8 +53,8 @@ public class LimboCache { playerGroup = permissionsManager.getPrimaryGroup(player); } - if (playerDataStorage.hasData(player)) { - PlayerData cache = playerDataStorage.readData(player); + if (limboPlayerStorage.hasData(player)) { + LimboPlayer cache = limboPlayerStorage.readData(player); if (cache != null) { location = cache.getLocation(); playerGroup = cache.getGroup(); @@ -64,10 +64,10 @@ public class LimboCache { flySpeed = cache.getFlySpeed(); } } else { - playerDataStorage.saveData(player); + limboPlayerStorage.saveData(player); } - cache.put(name, new PlayerData(location, operator, playerGroup, flyEnabled, walkSpeed, flySpeed)); + cache.put(name, new LimboPlayer(location, operator, playerGroup, flyEnabled, walkSpeed, flySpeed)); } /** @@ -78,7 +78,7 @@ public class LimboCache { public void restoreData(Player player) { String lowerName = player.getName().toLowerCase(); if (cache.containsKey(lowerName)) { - PlayerData data = cache.get(lowerName); + LimboPlayer data = cache.get(lowerName); player.setOp(data.isOperator()); player.setAllowFlight(data.isCanFly()); float walkSpeed = data.getWalkSpeed(); @@ -104,7 +104,7 @@ public class LimboCache { */ public void deletePlayerData(Player player) { removeFromCache(player); - playerDataStorage.removeData(player); + limboPlayerStorage.removeData(player); } /** @@ -114,7 +114,7 @@ public class LimboCache { */ public void removeFromCache(Player player) { String name = player.getName().toLowerCase(); - PlayerData cachedPlayer = cache.remove(name); + LimboPlayer cachedPlayer = cache.remove(name); if (cachedPlayer != null) { cachedPlayer.clearTasks(); } @@ -127,7 +127,7 @@ public class LimboCache { * * @return PlayerData */ - public PlayerData getPlayerData(String name) { + public LimboPlayer getPlayerData(String name) { checkNotNull(name); return cache.get(name.toLowerCase()); } diff --git a/src/main/java/fr/xephi/authme/cache/limbo/PlayerData.java b/src/main/java/fr/xephi/authme/data/limbo/LimboPlayer.java similarity index 94% rename from src/main/java/fr/xephi/authme/cache/limbo/PlayerData.java rename to src/main/java/fr/xephi/authme/data/limbo/LimboPlayer.java index 36e641fd8..d0b761f16 100644 --- a/src/main/java/fr/xephi/authme/cache/limbo/PlayerData.java +++ b/src/main/java/fr/xephi/authme/data/limbo/LimboPlayer.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.cache.limbo; +package fr.xephi.authme.data.limbo; import org.bukkit.Location; import org.bukkit.scheduler.BukkitTask; @@ -7,7 +7,7 @@ import org.bukkit.scheduler.BukkitTask; * Represents a player which is not logged in and keeps track of certain states (like OP status, flying) * which may be revoked from the player until he has logged in or registered. */ -public class PlayerData { +public class LimboPlayer { private final boolean canFly; private final boolean operator; @@ -18,8 +18,7 @@ public class PlayerData { private BukkitTask timeoutTask = null; private BukkitTask messageTask = null; - public PlayerData(Location loc, boolean operator, - String group, boolean fly, float walkSpeed, float flySpeed) { + public LimboPlayer(Location loc, boolean operator, String group, boolean fly, float walkSpeed, float flySpeed) { this.loc = loc; this.operator = operator; this.group = group; diff --git a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java index 7032733d0..ebd9299ef 100644 --- a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java @@ -9,8 +9,10 @@ import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.ThreadFactoryBuilder; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.datasource.DataSourceType; import fr.xephi.authme.security.crypts.HashedPassword; import java.util.ArrayList; diff --git a/src/main/java/fr/xephi/authme/datasource/DataSource.java b/src/main/java/fr/xephi/authme/datasource/DataSource.java index 98e29adab..c1c79a648 100644 --- a/src/main/java/fr/xephi/authme/datasource/DataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/DataSource.java @@ -1,6 +1,6 @@ package fr.xephi.authme.datasource; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.initialization.Reloadable; import fr.xephi.authme.security.crypts.HashedPassword; diff --git a/src/main/java/fr/xephi/authme/datasource/DataSourceType.java b/src/main/java/fr/xephi/authme/datasource/DataSourceType.java index 133b492f8..093e88ed9 100644 --- a/src/main/java/fr/xephi/authme/datasource/DataSourceType.java +++ b/src/main/java/fr/xephi/authme/datasource/DataSourceType.java @@ -7,9 +7,9 @@ public enum DataSourceType { MYSQL, - @Deprecated - FILE, + SQLITE, - SQLITE + @Deprecated + FILE } diff --git a/src/main/java/fr/xephi/authme/datasource/FlatFile.java b/src/main/java/fr/xephi/authme/datasource/FlatFile.java index 779d36407..49b5442d1 100644 --- a/src/main/java/fr/xephi/authme/datasource/FlatFile.java +++ b/src/main/java/fr/xephi/authme/datasource/FlatFile.java @@ -1,8 +1,8 @@ package fr.xephi.authme.datasource; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.security.crypts.HashedPassword; import java.io.BufferedReader; diff --git a/src/main/java/fr/xephi/authme/datasource/MySQL.java b/src/main/java/fr/xephi/authme/datasource/MySQL.java index 05f22d0c9..9c613ec35 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQL.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQL.java @@ -4,7 +4,10 @@ import com.google.common.annotations.VisibleForTesting; import com.zaxxer.hikari.HikariDataSource; import com.zaxxer.hikari.pool.HikariPool.PoolInitializationException; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.datasource.Columns; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.datasource.DataSourceType; import fr.xephi.authme.security.HashAlgorithm; import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.security.crypts.XFBCRYPT; diff --git a/src/main/java/fr/xephi/authme/datasource/SQLite.java b/src/main/java/fr/xephi/authme/datasource/SQLite.java index 1e554671d..d19c4aa22 100644 --- a/src/main/java/fr/xephi/authme/datasource/SQLite.java +++ b/src/main/java/fr/xephi/authme/datasource/SQLite.java @@ -2,7 +2,10 @@ package fr.xephi.authme.datasource; import com.google.common.annotations.VisibleForTesting; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.datasource.Columns; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.datasource.DataSourceType; import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.DatabaseSettings; diff --git a/src/main/java/fr/xephi/authme/converter/AbstractDataSourceConverter.java b/src/main/java/fr/xephi/authme/datasource/converter/AbstractDataSourceConverter.java similarity index 97% rename from src/main/java/fr/xephi/authme/converter/AbstractDataSourceConverter.java rename to src/main/java/fr/xephi/authme/datasource/converter/AbstractDataSourceConverter.java index 083cfe2cb..d2be78047 100644 --- a/src/main/java/fr/xephi/authme/converter/AbstractDataSourceConverter.java +++ b/src/main/java/fr/xephi/authme/datasource/converter/AbstractDataSourceConverter.java @@ -1,7 +1,7 @@ -package fr.xephi.authme.converter; +package fr.xephi.authme.datasource.converter; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSourceType; import org.bukkit.command.CommandSender; diff --git a/src/main/java/fr/xephi/authme/converter/Converter.java b/src/main/java/fr/xephi/authme/datasource/converter/Converter.java similarity index 85% rename from src/main/java/fr/xephi/authme/converter/Converter.java rename to src/main/java/fr/xephi/authme/datasource/converter/Converter.java index 28f18fd98..7549bb481 100644 --- a/src/main/java/fr/xephi/authme/converter/Converter.java +++ b/src/main/java/fr/xephi/authme/datasource/converter/Converter.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.converter; +package fr.xephi.authme.datasource.converter; import org.bukkit.command.CommandSender; diff --git a/src/main/java/fr/xephi/authme/converter/CrazyLoginConverter.java b/src/main/java/fr/xephi/authme/datasource/converter/CrazyLoginConverter.java similarity index 96% rename from src/main/java/fr/xephi/authme/converter/CrazyLoginConverter.java rename to src/main/java/fr/xephi/authme/datasource/converter/CrazyLoginConverter.java index 50cb43c1d..535c0ebab 100644 --- a/src/main/java/fr/xephi/authme/converter/CrazyLoginConverter.java +++ b/src/main/java/fr/xephi/authme/datasource/converter/CrazyLoginConverter.java @@ -1,7 +1,7 @@ -package fr.xephi.authme.converter; +package fr.xephi.authme.datasource.converter; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.initialization.DataFolder; import fr.xephi.authme.settings.Settings; diff --git a/src/main/java/fr/xephi/authme/converter/ForceFlatToSqlite.java b/src/main/java/fr/xephi/authme/datasource/converter/ForceFlatToSqlite.java similarity index 93% rename from src/main/java/fr/xephi/authme/converter/ForceFlatToSqlite.java rename to src/main/java/fr/xephi/authme/datasource/converter/ForceFlatToSqlite.java index 321ef2463..a52b216b6 100644 --- a/src/main/java/fr/xephi/authme/converter/ForceFlatToSqlite.java +++ b/src/main/java/fr/xephi/authme/datasource/converter/ForceFlatToSqlite.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.converter; +package fr.xephi.authme.datasource.converter; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.FlatFile; diff --git a/src/main/java/fr/xephi/authme/converter/MySqlToSqlite.java b/src/main/java/fr/xephi/authme/datasource/converter/MySqlToSqlite.java similarity index 93% rename from src/main/java/fr/xephi/authme/converter/MySqlToSqlite.java rename to src/main/java/fr/xephi/authme/datasource/converter/MySqlToSqlite.java index 76e58f960..7b793e8b0 100644 --- a/src/main/java/fr/xephi/authme/converter/MySqlToSqlite.java +++ b/src/main/java/fr/xephi/authme/datasource/converter/MySqlToSqlite.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.converter; +package fr.xephi.authme.datasource.converter; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSourceType; diff --git a/src/main/java/fr/xephi/authme/converter/RakamakConverter.java b/src/main/java/fr/xephi/authme/datasource/converter/RakamakConverter.java similarity index 97% rename from src/main/java/fr/xephi/authme/converter/RakamakConverter.java rename to src/main/java/fr/xephi/authme/datasource/converter/RakamakConverter.java index 9cf6749fd..eb9d904cd 100644 --- a/src/main/java/fr/xephi/authme/converter/RakamakConverter.java +++ b/src/main/java/fr/xephi/authme/datasource/converter/RakamakConverter.java @@ -1,7 +1,7 @@ -package fr.xephi.authme.converter; +package fr.xephi.authme.datasource.converter; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.initialization.DataFolder; import fr.xephi.authme.security.PasswordSecurity; diff --git a/src/main/java/fr/xephi/authme/converter/RoyalAuthConverter.java b/src/main/java/fr/xephi/authme/datasource/converter/RoyalAuthConverter.java similarity index 92% rename from src/main/java/fr/xephi/authme/converter/RoyalAuthConverter.java rename to src/main/java/fr/xephi/authme/datasource/converter/RoyalAuthConverter.java index 49cde259c..34b0d61c1 100644 --- a/src/main/java/fr/xephi/authme/converter/RoyalAuthConverter.java +++ b/src/main/java/fr/xephi/authme/datasource/converter/RoyalAuthConverter.java @@ -1,8 +1,8 @@ -package fr.xephi.authme.converter; +package fr.xephi.authme.datasource.converter; import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.datasource.DataSource; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; @@ -12,7 +12,7 @@ import org.bukkit.configuration.file.YamlConfiguration; import javax.inject.Inject; import java.io.File; -import static fr.xephi.authme.util.StringUtils.makePath; +import static fr.xephi.authme.util.FileUtils.makePath; public class RoyalAuthConverter implements Converter { diff --git a/src/main/java/fr/xephi/authme/converter/SqliteToSql.java b/src/main/java/fr/xephi/authme/datasource/converter/SqliteToSql.java similarity index 93% rename from src/main/java/fr/xephi/authme/converter/SqliteToSql.java rename to src/main/java/fr/xephi/authme/datasource/converter/SqliteToSql.java index fafa7e27d..ce45efed3 100644 --- a/src/main/java/fr/xephi/authme/converter/SqliteToSql.java +++ b/src/main/java/fr/xephi/authme/datasource/converter/SqliteToSql.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.converter; +package fr.xephi.authme.datasource.converter; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSourceType; diff --git a/src/main/java/fr/xephi/authme/converter/vAuthConverter.java b/src/main/java/fr/xephi/authme/datasource/converter/vAuthConverter.java similarity index 94% rename from src/main/java/fr/xephi/authme/converter/vAuthConverter.java rename to src/main/java/fr/xephi/authme/datasource/converter/vAuthConverter.java index 9c116f02c..6d3de8b7d 100644 --- a/src/main/java/fr/xephi/authme/converter/vAuthConverter.java +++ b/src/main/java/fr/xephi/authme/datasource/converter/vAuthConverter.java @@ -1,7 +1,7 @@ -package fr.xephi.authme.converter; +package fr.xephi.authme.datasource.converter; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.initialization.DataFolder; import org.bukkit.Bukkit; @@ -14,7 +14,7 @@ import java.io.IOException; import java.util.Scanner; import java.util.UUID; -import static fr.xephi.authme.util.StringUtils.makePath; +import static fr.xephi.authme.util.FileUtils.makePath; public class vAuthConverter implements Converter { diff --git a/src/main/java/fr/xephi/authme/converter/xAuthConverter.java b/src/main/java/fr/xephi/authme/datasource/converter/xAuthConverter.java similarity index 97% rename from src/main/java/fr/xephi/authme/converter/xAuthConverter.java rename to src/main/java/fr/xephi/authme/datasource/converter/xAuthConverter.java index 37dfc9fe1..27fa6c2e9 100644 --- a/src/main/java/fr/xephi/authme/converter/xAuthConverter.java +++ b/src/main/java/fr/xephi/authme/datasource/converter/xAuthConverter.java @@ -1,9 +1,9 @@ -package fr.xephi.authme.converter; +package fr.xephi.authme.datasource.converter; import de.luricos.bukkit.xAuth.database.DatabaseTables; import de.luricos.bukkit.xAuth.utils.xAuthLog; import de.luricos.bukkit.xAuth.xAuth; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.initialization.DataFolder; import fr.xephi.authme.util.CollectionUtils; @@ -19,7 +19,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import static fr.xephi.authme.util.StringUtils.makePath; +import static fr.xephi.authme.util.FileUtils.makePath; public class xAuthConverter implements Converter { diff --git a/src/main/java/fr/xephi/authme/geoip/GeoLiteAPI.java b/src/main/java/fr/xephi/authme/geoip/GeoIpManager.java similarity index 96% rename from src/main/java/fr/xephi/authme/geoip/GeoLiteAPI.java rename to src/main/java/fr/xephi/authme/geoip/GeoIpManager.java index 11f5e4f01..bd397a97c 100644 --- a/src/main/java/fr/xephi/authme/geoip/GeoLiteAPI.java +++ b/src/main/java/fr/xephi/authme/geoip/GeoIpManager.java @@ -17,7 +17,7 @@ import java.net.URLConnection; import java.util.concurrent.TimeUnit; import java.util.zip.GZIPInputStream; -public class GeoLiteAPI { +public class GeoIpManager { private static final String LICENSE = "[LICENSE] This product uses data from the GeoLite API created by MaxMind, available at http://www.maxmind.com"; private static final String GEOIP_URL = @@ -28,14 +28,14 @@ public class GeoLiteAPI { private final File dataFile; @Inject - GeoLiteAPI(@DataFolder File dataFolder) { + GeoIpManager(@DataFolder File dataFolder) { this.dataFile = new File(dataFolder, "GeoIP.dat"); // Fires download of recent data or the initialization of the look up service isDataAvailable(); } @VisibleForTesting - GeoLiteAPI(@DataFolder File dataFolder, LookupService lookupService) { + GeoIpManager(@DataFolder File dataFolder, LookupService lookupService) { this.dataFile = dataFolder; this.lookupService = lookupService; } diff --git a/src/main/java/fr/xephi/authme/initialization/Initializer.java b/src/main/java/fr/xephi/authme/initialization/Initializer.java index 5a048678d..a7bb4c28c 100644 --- a/src/main/java/fr/xephi/authme/initialization/Initializer.java +++ b/src/main/java/fr/xephi/authme/initialization/Initializer.java @@ -5,7 +5,7 @@ import com.github.authme.configme.resource.PropertyResource; import com.github.authme.configme.resource.YamlFileResource; import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.datasource.CacheDataSource; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSourceType; @@ -14,8 +14,8 @@ import fr.xephi.authme.datasource.MySQL; import fr.xephi.authme.datasource.SQLite; import fr.xephi.authme.output.ConsoleFilter; import fr.xephi.authme.output.Log4JFilter; -import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.output.Messages; +import fr.xephi.authme.message.MessageKey; +import fr.xephi.authme.message.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.SettingsMigrationService; import fr.xephi.authme.settings.properties.AuthMeSettingsRetriever; diff --git a/src/main/java/fr/xephi/authme/initialization/OnShutdownPlayerSaver.java b/src/main/java/fr/xephi/authme/initialization/OnShutdownPlayerSaver.java index 28a1134f6..079fc76a2 100644 --- a/src/main/java/fr/xephi/authme/initialization/OnShutdownPlayerSaver.java +++ b/src/main/java/fr/xephi/authme/initialization/OnShutdownPlayerSaver.java @@ -1,9 +1,9 @@ package fr.xephi.authme.initialization; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; -import fr.xephi.authme.cache.backup.PlayerDataStorage; -import fr.xephi.authme.cache.limbo.LimboCache; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; +import fr.xephi.authme.data.backup.LimboPlayerStorage; +import fr.xephi.authme.data.limbo.LimboCache; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.hooks.PluginHooks; import fr.xephi.authme.settings.Settings; @@ -32,7 +32,7 @@ public class OnShutdownPlayerSaver { @Inject private DataSource dataSource; @Inject - private PlayerDataStorage playerDataStorage; + private LimboPlayerStorage limboPlayerStorage; @Inject private SpawnLoader spawnLoader; @Inject @@ -77,8 +77,8 @@ public class OnShutdownPlayerSaver { } if (settings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN) && !settings.getProperty(RestrictionSettings.NO_TELEPORT)) { - if (!playerDataStorage.hasData(player)) { - playerDataStorage.saveData(player); + if (!limboPlayerStorage.hasData(player)) { + limboPlayerStorage.saveData(player); } } } diff --git a/src/main/java/fr/xephi/authme/listener/FailedVerificationException.java b/src/main/java/fr/xephi/authme/listener/FailedVerificationException.java index fcbaa1b6a..0b887f92b 100644 --- a/src/main/java/fr/xephi/authme/listener/FailedVerificationException.java +++ b/src/main/java/fr/xephi/authme/listener/FailedVerificationException.java @@ -1,6 +1,6 @@ package fr.xephi.authme.listener; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; /** * Exception thrown when a verification has failed. diff --git a/src/main/java/fr/xephi/authme/listener/ListenerService.java b/src/main/java/fr/xephi/authme/listener/ListenerService.java index 4db65530a..279bfd6c2 100644 --- a/src/main/java/fr/xephi/authme/listener/ListenerService.java +++ b/src/main/java/fr/xephi/authme/listener/ListenerService.java @@ -1,6 +1,6 @@ package fr.xephi.authme.listener; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.hooks.PluginHooks; import fr.xephi.authme.initialization.SettingsDependent; diff --git a/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java b/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java index b58f9bc99..93783346d 100644 --- a/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java +++ b/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java @@ -1,11 +1,11 @@ package fr.xephi.authme.listener; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.initialization.Reloadable; -import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.output.Messages; +import fr.xephi.authme.message.MessageKey; +import fr.xephi.authme.message.Messages; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerStatePermission; import fr.xephi.authme.service.AntiBotService; diff --git a/src/main/java/fr/xephi/authme/listener/PlayerListener.java b/src/main/java/fr/xephi/authme/listener/PlayerListener.java index 20f33f09e..b6484fb35 100644 --- a/src/main/java/fr/xephi/authme/listener/PlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/PlayerListener.java @@ -1,9 +1,9 @@ package fr.xephi.authme.listener; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.output.Messages; +import fr.xephi.authme.message.MessageKey; +import fr.xephi.authme.message.Messages; import fr.xephi.authme.process.Management; import fr.xephi.authme.service.AntiBotService; import fr.xephi.authme.settings.Settings; diff --git a/src/main/java/fr/xephi/authme/listener/protocollib/InventoryPacketAdapter.java b/src/main/java/fr/xephi/authme/listener/protocollib/InventoryPacketAdapter.java index 1813ae1d2..c7abf96e6 100644 --- a/src/main/java/fr/xephi/authme/listener/protocollib/InventoryPacketAdapter.java +++ b/src/main/java/fr/xephi/authme/listener/protocollib/InventoryPacketAdapter.java @@ -23,7 +23,7 @@ import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; import fr.xephi.authme.AuthMe; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerCache; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; diff --git a/src/main/java/fr/xephi/authme/listener/protocollib/ProtocolLibService.java b/src/main/java/fr/xephi/authme/listener/protocollib/ProtocolLibService.java index 3e10cde0d..77a75ac04 100644 --- a/src/main/java/fr/xephi/authme/listener/protocollib/ProtocolLibService.java +++ b/src/main/java/fr/xephi/authme/listener/protocollib/ProtocolLibService.java @@ -3,7 +3,7 @@ package fr.xephi.authme.listener.protocollib; import ch.jalu.injector.annotations.NoFieldScan; import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.initialization.SettingsDependent; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.RestrictionSettings; diff --git a/src/main/java/fr/xephi/authme/listener/protocollib/TabCompletePacketAdapter.java b/src/main/java/fr/xephi/authme/listener/protocollib/TabCompletePacketAdapter.java index 350587313..4476f80ad 100644 --- a/src/main/java/fr/xephi/authme/listener/protocollib/TabCompletePacketAdapter.java +++ b/src/main/java/fr/xephi/authme/listener/protocollib/TabCompletePacketAdapter.java @@ -8,7 +8,7 @@ import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.reflect.FieldAccessException; import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerCache; class TabCompletePacketAdapter extends PacketAdapter { diff --git a/src/main/java/fr/xephi/authme/output/MessageKey.java b/src/main/java/fr/xephi/authme/message/MessageKey.java similarity index 99% rename from src/main/java/fr/xephi/authme/output/MessageKey.java rename to src/main/java/fr/xephi/authme/message/MessageKey.java index c5a7cd368..f05752271 100644 --- a/src/main/java/fr/xephi/authme/output/MessageKey.java +++ b/src/main/java/fr/xephi/authme/message/MessageKey.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.output; +package fr.xephi.authme.message; /** * Keys for translatable messages managed by {@link Messages}. diff --git a/src/main/java/fr/xephi/authme/output/Messages.java b/src/main/java/fr/xephi/authme/message/Messages.java similarity index 99% rename from src/main/java/fr/xephi/authme/output/Messages.java rename to src/main/java/fr/xephi/authme/message/Messages.java index 5c076f1ac..e17ee1a1a 100644 --- a/src/main/java/fr/xephi/authme/output/Messages.java +++ b/src/main/java/fr/xephi/authme/message/Messages.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.output; +package fr.xephi.authme.message; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.initialization.SettingsDependent; diff --git a/src/main/java/fr/xephi/authme/permission/AuthGroupHandler.java b/src/main/java/fr/xephi/authme/permission/AuthGroupHandler.java index 7d2136f00..fb4bff486 100644 --- a/src/main/java/fr/xephi/authme/permission/AuthGroupHandler.java +++ b/src/main/java/fr/xephi/authme/permission/AuthGroupHandler.java @@ -1,8 +1,8 @@ package fr.xephi.authme.permission; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.limbo.LimboCache; -import fr.xephi.authme.cache.limbo.PlayerData; +import fr.xephi.authme.data.limbo.LimboCache; +import fr.xephi.authme.data.limbo.LimboPlayer; import fr.xephi.authme.initialization.Reloadable; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.HooksSettings; @@ -72,7 +72,7 @@ public class AuthGroupHandler implements Reloadable { case LOGGED_IN: // Get the player data - PlayerData data = limboCache.getPlayerData(player.getName().toLowerCase()); + LimboPlayer data = limboCache.getPlayerData(player.getName().toLowerCase()); if (data == null) { return false; } diff --git a/src/main/java/fr/xephi/authme/process/ProcessService.java b/src/main/java/fr/xephi/authme/process/ProcessService.java index 239c73fd1..575b80536 100644 --- a/src/main/java/fr/xephi/authme/process/ProcessService.java +++ b/src/main/java/fr/xephi/authme/process/ProcessService.java @@ -1,8 +1,8 @@ package fr.xephi.authme.process; import com.github.authme.configme.properties.Property; -import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.output.Messages; +import fr.xephi.authme.message.MessageKey; +import fr.xephi.authme.message.Messages; import fr.xephi.authme.permission.AuthGroupHandler; import fr.xephi.authme.permission.AuthGroupType; import fr.xephi.authme.permission.PermissionNode; diff --git a/src/main/java/fr/xephi/authme/process/changepassword/AsyncChangePassword.java b/src/main/java/fr/xephi/authme/process/changepassword/AsyncChangePassword.java index 3274c2f47..12471b0ea 100644 --- a/src/main/java/fr/xephi/authme/process/changepassword/AsyncChangePassword.java +++ b/src/main/java/fr/xephi/authme/process/changepassword/AsyncChangePassword.java @@ -1,10 +1,10 @@ package fr.xephi.authme.process.changepassword; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.process.AsynchronousProcess; import fr.xephi.authme.process.ProcessService; import fr.xephi.authme.security.PasswordSecurity; diff --git a/src/main/java/fr/xephi/authme/process/email/AsyncAddEmail.java b/src/main/java/fr/xephi/authme/process/email/AsyncAddEmail.java index d61d39c28..5a8a8e90c 100644 --- a/src/main/java/fr/xephi/authme/process/email/AsyncAddEmail.java +++ b/src/main/java/fr/xephi/authme/process/email/AsyncAddEmail.java @@ -1,10 +1,10 @@ package fr.xephi.authme.process.email; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.process.AsynchronousProcess; import fr.xephi.authme.process.ProcessService; import fr.xephi.authme.settings.properties.RegistrationSettings; diff --git a/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java b/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java index 3ca6a2462..6bc83106b 100644 --- a/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java +++ b/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java @@ -1,9 +1,9 @@ package fr.xephi.authme.process.email; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.process.AsynchronousProcess; import fr.xephi.authme.process.ProcessService; import fr.xephi.authme.settings.properties.RegistrationSettings; diff --git a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java index b8dd5af00..de2762486 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java @@ -2,14 +2,14 @@ package fr.xephi.authme.process.join; import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.SessionManager; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; -import fr.xephi.authme.cache.limbo.LimboCache; +import fr.xephi.authme.data.SessionManager; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; +import fr.xephi.authme.data.limbo.LimboCache; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.events.ProtectInventoryEvent; import fr.xephi.authme.hooks.PluginHooks; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.permission.AuthGroupType; import fr.xephi.authme.permission.PlayerStatePermission; import fr.xephi.authme.process.AsynchronousProcess; diff --git a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java index 3a8b7fc38..6fe3ac960 100644 --- a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java @@ -2,15 +2,15 @@ package fr.xephi.authme.process.login; import com.google.common.annotations.VisibleForTesting; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.CaptchaManager; -import fr.xephi.authme.cache.TempbanManager; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; -import fr.xephi.authme.cache.limbo.LimboCache; -import fr.xephi.authme.cache.limbo.PlayerData; +import fr.xephi.authme.data.CaptchaManager; +import fr.xephi.authme.data.TempbanManager; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; +import fr.xephi.authme.data.limbo.LimboCache; +import fr.xephi.authme.data.limbo.LimboPlayer; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.events.AuthMeAsyncPreLoginEvent; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.permission.AdminPermission; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerPermission; @@ -241,9 +241,9 @@ public class AsynchronousLogin implements AsynchronousProcess { // task, we schedule it in the end // so that we can be sure, and have not to care if it might be // processed in other order. - PlayerData playerData = limboCache.getPlayerData(name); - if (playerData != null) { - playerData.clearTasks(); + LimboPlayer limboPlayer = limboCache.getPlayerData(name); + if (limboPlayer != null) { + limboPlayer.clearTasks(); } syncProcessManager.processSyncPlayerLogin(player); } else { diff --git a/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java b/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java index 4735ab579..a31f4d28f 100644 --- a/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java @@ -1,9 +1,9 @@ package fr.xephi.authme.process.login; import fr.xephi.authme.AuthMe; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.limbo.LimboCache; -import fr.xephi.authme.cache.limbo.PlayerData; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.limbo.LimboCache; +import fr.xephi.authme.data.limbo.LimboPlayer; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.events.LoginEvent; import fr.xephi.authme.events.RestoreInventoryEvent; @@ -79,7 +79,7 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess { public void processPlayerLogin(Player player) { final String name = player.getName().toLowerCase(); - final PlayerData limbo = limboCache.getPlayerData(name); + final LimboPlayer limbo = limboCache.getPlayerData(name); // Limbo contains the State of the Player before /login if (limbo != null) { limboCache.restoreData(player); diff --git a/src/main/java/fr/xephi/authme/process/logout/AsynchronousLogout.java b/src/main/java/fr/xephi/authme/process/logout/AsynchronousLogout.java index 34a5b4937..7374d7389 100644 --- a/src/main/java/fr/xephi/authme/process/logout/AsynchronousLogout.java +++ b/src/main/java/fr/xephi/authme/process/logout/AsynchronousLogout.java @@ -1,10 +1,10 @@ package fr.xephi.authme.process.logout; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; -import fr.xephi.authme.cache.limbo.LimboCache; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; +import fr.xephi.authme.data.limbo.LimboCache; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.process.AsynchronousProcess; import fr.xephi.authme.process.ProcessService; import fr.xephi.authme.process.SyncProcessManager; diff --git a/src/main/java/fr/xephi/authme/process/logout/ProcessSynchronousPlayerLogout.java b/src/main/java/fr/xephi/authme/process/logout/ProcessSynchronousPlayerLogout.java index cb3723cbe..157e2a44e 100644 --- a/src/main/java/fr/xephi/authme/process/logout/ProcessSynchronousPlayerLogout.java +++ b/src/main/java/fr/xephi/authme/process/logout/ProcessSynchronousPlayerLogout.java @@ -1,10 +1,10 @@ package fr.xephi.authme.process.logout; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.SessionManager; +import fr.xephi.authme.data.SessionManager; import fr.xephi.authme.events.LogoutEvent; import fr.xephi.authme.listener.protocollib.ProtocolLibService; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.permission.AuthGroupType; import fr.xephi.authme.process.ProcessService; import fr.xephi.authme.process.SynchronousProcess; diff --git a/src/main/java/fr/xephi/authme/process/quit/AsynchronousQuit.java b/src/main/java/fr/xephi/authme/process/quit/AsynchronousQuit.java index ce3af43aa..c8f63bbd4 100644 --- a/src/main/java/fr/xephi/authme/process/quit/AsynchronousQuit.java +++ b/src/main/java/fr/xephi/authme/process/quit/AsynchronousQuit.java @@ -1,9 +1,9 @@ package fr.xephi.authme.process.quit; import fr.xephi.authme.AuthMe; -import fr.xephi.authme.cache.SessionManager; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.SessionManager; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.CacheDataSource; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.process.AsynchronousProcess; diff --git a/src/main/java/fr/xephi/authme/process/quit/ProcessSyncronousPlayerQuit.java b/src/main/java/fr/xephi/authme/process/quit/ProcessSyncronousPlayerQuit.java index 27f46071c..73db67f89 100644 --- a/src/main/java/fr/xephi/authme/process/quit/ProcessSyncronousPlayerQuit.java +++ b/src/main/java/fr/xephi/authme/process/quit/ProcessSyncronousPlayerQuit.java @@ -1,7 +1,7 @@ package fr.xephi.authme.process.quit; -import fr.xephi.authme.cache.backup.PlayerDataStorage; -import fr.xephi.authme.cache.limbo.LimboCache; +import fr.xephi.authme.data.backup.LimboPlayerStorage; +import fr.xephi.authme.data.limbo.LimboCache; import fr.xephi.authme.process.SynchronousProcess; import org.bukkit.entity.Player; @@ -11,7 +11,7 @@ import javax.inject.Inject; public class ProcessSyncronousPlayerQuit implements SynchronousProcess { @Inject - private PlayerDataStorage playerDataStorage; + private LimboPlayerStorage limboPlayerStorage; @Inject private LimboCache limboCache; @@ -22,8 +22,8 @@ public class ProcessSyncronousPlayerQuit implements SynchronousProcess { limboCache.removeFromCache(player); } else { // Save player's data, so we could retrieve it later on player next join - if (!playerDataStorage.hasData(player)) { - playerDataStorage.saveData(player); + if (!limboPlayerStorage.hasData(player)) { + limboPlayerStorage.saveData(player); } } diff --git a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java index 41b1d9992..627a993b6 100644 --- a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java @@ -1,10 +1,10 @@ package fr.xephi.authme.process.register; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.mail.SendMailSSL; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.process.AsynchronousProcess; import fr.xephi.authme.process.ProcessService; diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java index 67e1478a9..1ea421148 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java @@ -1,7 +1,7 @@ package fr.xephi.authme.process.register; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.permission.AuthGroupType; import fr.xephi.authme.process.ProcessService; import fr.xephi.authme.process.SynchronousProcess; diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java index cbc37cbd4..eb2e5f5c7 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java @@ -1,8 +1,8 @@ package fr.xephi.authme.process.register; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.limbo.LimboCache; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.data.limbo.LimboCache; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.permission.AuthGroupType; import fr.xephi.authme.process.ProcessService; import fr.xephi.authme.process.SynchronousProcess; diff --git a/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java b/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java index de859e9a7..142ff6064 100644 --- a/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java +++ b/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java @@ -1,11 +1,11 @@ package fr.xephi.authme.process.unregister; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; -import fr.xephi.authme.cache.limbo.LimboCache; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; +import fr.xephi.authme.data.limbo.LimboCache; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.permission.AuthGroupHandler; import fr.xephi.authme.permission.AuthGroupType; import fr.xephi.authme.process.AsynchronousProcess; diff --git a/src/main/java/fr/xephi/authme/service/AntiBotService.java b/src/main/java/fr/xephi/authme/service/AntiBotService.java index 561b57511..be1eb8da8 100644 --- a/src/main/java/fr/xephi/authme/service/AntiBotService.java +++ b/src/main/java/fr/xephi/authme/service/AntiBotService.java @@ -1,8 +1,8 @@ package fr.xephi.authme.service; import fr.xephi.authme.initialization.SettingsDependent; -import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.output.Messages; +import fr.xephi.authme.message.MessageKey; +import fr.xephi.authme.message.Messages; import fr.xephi.authme.permission.AdminPermission; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.settings.Settings; diff --git a/src/main/java/fr/xephi/authme/service/MigrationService.java b/src/main/java/fr/xephi/authme/service/MigrationService.java index f21bb8539..3eaab8875 100644 --- a/src/main/java/fr/xephi/authme/service/MigrationService.java +++ b/src/main/java/fr/xephi/authme/service/MigrationService.java @@ -1,8 +1,8 @@ package fr.xephi.authme.service; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.converter.ForceFlatToSqlite; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.datasource.converter.ForceFlatToSqlite; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSourceType; import fr.xephi.authme.datasource.FlatFile; diff --git a/src/main/java/fr/xephi/authme/service/TeleportationService.java b/src/main/java/fr/xephi/authme/service/TeleportationService.java index 92f1c93a3..9be5012f4 100644 --- a/src/main/java/fr/xephi/authme/service/TeleportationService.java +++ b/src/main/java/fr/xephi/authme/service/TeleportationService.java @@ -1,8 +1,8 @@ package fr.xephi.authme.service; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; -import fr.xephi.authme.cache.limbo.PlayerData; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; +import fr.xephi.authme.data.limbo.LimboPlayer; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.events.AbstractTeleportEvent; import fr.xephi.authme.events.AuthMeTeleportEvent; @@ -101,7 +101,7 @@ public class TeleportationService implements Reloadable { * @param auth corresponding PlayerAuth object * @param limbo corresponding PlayerData object */ - public void teleportOnLogin(final Player player, PlayerAuth auth, PlayerData limbo) { + public void teleportOnLogin(final Player player, PlayerAuth auth, LimboPlayer limbo) { if (settings.getProperty(RestrictionSettings.NO_TELEPORT)) { return; } diff --git a/src/main/java/fr/xephi/authme/service/ValidationService.java b/src/main/java/fr/xephi/authme/service/ValidationService.java index 63227823d..030657ce5 100644 --- a/src/main/java/fr/xephi/authme/service/ValidationService.java +++ b/src/main/java/fr/xephi/authme/service/ValidationService.java @@ -2,9 +2,9 @@ package fr.xephi.authme.service; import com.github.authme.configme.properties.Property; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.geoip.GeoLiteAPI; +import fr.xephi.authme.geoip.GeoIpManager; import fr.xephi.authme.initialization.Reloadable; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerStatePermission; import fr.xephi.authme.settings.Settings; @@ -36,7 +36,7 @@ public class ValidationService implements Reloadable { @Inject private PermissionsManager permissionsManager; @Inject - private GeoLiteAPI geoLiteApi; + private GeoIpManager geoIpManager; private Pattern passwordRegex; private Set unrestrictedNames; @@ -115,7 +115,7 @@ public class ValidationService implements Reloadable { return true; } - String countryCode = geoLiteApi.getCountryCode(hostAddress); + String countryCode = geoIpManager.getCountryCode(hostAddress); return validateWhitelistAndBlacklist(countryCode, ProtectionSettings.COUNTRIES_WHITELIST, ProtectionSettings.COUNTRIES_BLACKLIST); diff --git a/src/main/java/fr/xephi/authme/settings/Settings.java b/src/main/java/fr/xephi/authme/settings/Settings.java index fc3e929cd..2f5a34cc4 100644 --- a/src/main/java/fr/xephi/authme/settings/Settings.java +++ b/src/main/java/fr/xephi/authme/settings/Settings.java @@ -7,7 +7,7 @@ import com.github.authme.configme.resource.PropertyResource; import com.google.common.io.Files; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.settings.properties.PluginSettings; -import fr.xephi.authme.util.StringUtils; +import fr.xephi.authme.util.FileUtils; import java.io.File; import java.io.IOException; @@ -120,7 +120,7 @@ public class Settings extends SettingsManager { } private static String buildMessagesFilePathFromCode(String language) { - return StringUtils.makePath("messages", "messages_" + language + ".yml"); + return FileUtils.makePath("messages", "messages_" + language + ".yml"); } /** diff --git a/src/main/java/fr/xephi/authme/task/MessageTask.java b/src/main/java/fr/xephi/authme/task/MessageTask.java index 1ae0aaed2..7480e526b 100644 --- a/src/main/java/fr/xephi/authme/task/MessageTask.java +++ b/src/main/java/fr/xephi/authme/task/MessageTask.java @@ -1,7 +1,7 @@ package fr.xephi.authme.task; -import fr.xephi.authme.cache.auth.PlayerCache; -import fr.xephi.authme.cache.limbo.LimboCache; +import fr.xephi.authme.data.auth.PlayerCache; +import fr.xephi.authme.data.limbo.LimboCache; import fr.xephi.authme.service.BukkitService; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; diff --git a/src/main/java/fr/xephi/authme/task/PlayerDataTaskManager.java b/src/main/java/fr/xephi/authme/task/PlayerDataTaskManager.java index b57141457..af96adc4d 100644 --- a/src/main/java/fr/xephi/authme/task/PlayerDataTaskManager.java +++ b/src/main/java/fr/xephi/authme/task/PlayerDataTaskManager.java @@ -1,11 +1,11 @@ package fr.xephi.authme.task; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.auth.PlayerCache; -import fr.xephi.authme.cache.limbo.LimboCache; -import fr.xephi.authme.cache.limbo.PlayerData; -import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.output.Messages; +import fr.xephi.authme.data.auth.PlayerCache; +import fr.xephi.authme.data.limbo.LimboCache; +import fr.xephi.authme.data.limbo.LimboPlayer; +import fr.xephi.authme.message.MessageKey; +import fr.xephi.authme.message.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; @@ -52,14 +52,14 @@ public class PlayerDataTaskManager { final int interval = settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL); final MessageKey key = getMessageKey(isRegistered); if (interval > 0) { - final PlayerData playerData = limboCache.getPlayerData(name); - if (playerData == null) { + final LimboPlayer limboPlayer = limboCache.getPlayerData(name); + if (limboPlayer == null) { ConsoleLogger.info("PlayerData for '" + name + "' is not available"); } else { - cancelTask(playerData.getMessageTask()); + cancelTask(limboPlayer.getMessageTask()); BukkitTask messageTask = bukkitService.runTask(new MessageTask(name, messages.retrieve(key), interval, bukkitService, limboCache, playerCache)); - playerData.setMessageTask(messageTask); + limboPlayer.setMessageTask(messageTask); } } } @@ -72,14 +72,14 @@ public class PlayerDataTaskManager { public void registerTimeoutTask(Player player) { final int timeout = settings.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND; if (timeout > 0) { - final PlayerData playerData = limboCache.getPlayerData(player.getName()); - if (playerData == null) { + final LimboPlayer limboPlayer = limboCache.getPlayerData(player.getName()); + if (limboPlayer == null) { ConsoleLogger.info("PlayerData for '" + player.getName() + "' is not available"); } else { - cancelTask(playerData.getTimeoutTask()); + cancelTask(limboPlayer.getTimeoutTask()); String message = messages.retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR); BukkitTask task = bukkitService.runTaskLater(new TimeoutTask(player, message, playerCache), timeout); - playerData.setTimeoutTask(task); + limboPlayer.setTimeoutTask(task); } } } diff --git a/src/main/java/fr/xephi/authme/task/TimeoutTask.java b/src/main/java/fr/xephi/authme/task/TimeoutTask.java index 8aa719cd4..60aac7414 100644 --- a/src/main/java/fr/xephi/authme/task/TimeoutTask.java +++ b/src/main/java/fr/xephi/authme/task/TimeoutTask.java @@ -1,6 +1,6 @@ package fr.xephi.authme.task; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerCache; import org.bukkit.entity.Player; /** diff --git a/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java b/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java index dcadc49b8..43476e750 100644 --- a/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java +++ b/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java @@ -16,7 +16,7 @@ import javax.inject.Inject; import java.io.File; import java.util.Collection; -import static fr.xephi.authme.util.StringUtils.makePath; +import static fr.xephi.authme.util.FileUtils.makePath; /** * Executes the purge operations. diff --git a/src/main/java/fr/xephi/authme/task/purge/PurgeService.java b/src/main/java/fr/xephi/authme/task/purge/PurgeService.java index 040d2a893..7a1d19fa4 100644 --- a/src/main/java/fr/xephi/authme/task/purge/PurgeService.java +++ b/src/main/java/fr/xephi/authme/task/purge/PurgeService.java @@ -16,6 +16,8 @@ import java.util.Calendar; import java.util.Collection; import java.util.Set; +// TODO: move into services. -sgdc3 + /** * Initiates purge tasks. */ diff --git a/src/main/java/fr/xephi/authme/util/FileUtils.java b/src/main/java/fr/xephi/authme/util/FileUtils.java index faf557f47..831beafd6 100644 --- a/src/main/java/fr/xephi/authme/util/FileUtils.java +++ b/src/main/java/fr/xephi/authme/util/FileUtils.java @@ -87,4 +87,15 @@ public final class FileUtils { } } } + + /** + * Construct a file path from the given elements, i.e. separate the given elements by the file separator. + * + * @param elements The elements to create a path with + * + * @return The created path + */ + public static String makePath(String... elements) { + return String.join(File.separator, elements); + } } diff --git a/src/main/java/fr/xephi/authme/util/StringUtils.java b/src/main/java/fr/xephi/authme/util/StringUtils.java index d26a281fb..cc85fe333 100644 --- a/src/main/java/fr/xephi/authme/util/StringUtils.java +++ b/src/main/java/fr/xephi/authme/util/StringUtils.java @@ -78,16 +78,4 @@ public final class StringUtils { public static String formatException(Throwable th) { return "[" + th.getClass().getSimpleName() + "]: " + th.getMessage(); } - - /** - * Construct a file path from the given elements, i.e. separate the given elements by the file separator. - * - * @param elements The elements to create a path with - * - * @return The created path - */ - public static String makePath(String... elements) { - return String.join(File.separator, elements); - } - } diff --git a/src/test/java/fr/xephi/authme/AuthMeMatchers.java b/src/test/java/fr/xephi/authme/AuthMeMatchers.java index cb638222c..c19696fad 100644 --- a/src/test/java/fr/xephi/authme/AuthMeMatchers.java +++ b/src/test/java/fr/xephi/authme/AuthMeMatchers.java @@ -1,6 +1,6 @@ package fr.xephi.authme; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.security.crypts.HashedPassword; import org.hamcrest.Description; import org.hamcrest.Matcher; diff --git a/src/test/java/fr/xephi/authme/api/NewAPITest.java b/src/test/java/fr/xephi/authme/api/NewAPITest.java index 7d915018b..64e4c7c85 100644 --- a/src/test/java/fr/xephi/authme/api/NewAPITest.java +++ b/src/test/java/fr/xephi/authme/api/NewAPITest.java @@ -2,8 +2,8 @@ package fr.xephi.authme.api; import fr.xephi.authme.AuthMe; import fr.xephi.authme.ReflectionTestUtils; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.hooks.PluginHooks; import fr.xephi.authme.process.Management; diff --git a/src/test/java/fr/xephi/authme/command/CommandServiceTest.java b/src/test/java/fr/xephi/authme/command/CommandServiceTest.java index cbdfc8f02..dabc8a09c 100644 --- a/src/test/java/fr/xephi/authme/command/CommandServiceTest.java +++ b/src/test/java/fr/xephi/authme/command/CommandServiceTest.java @@ -1,8 +1,8 @@ package fr.xephi.authme.command; import com.github.authme.configme.properties.Property; -import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.output.Messages; +import fr.xephi.authme.message.MessageKey; +import fr.xephi.authme.message.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.SecuritySettings; import fr.xephi.authme.service.ValidationService; diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/AccountsCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/AccountsCommandTest.java index 09405e079..9c645e4d2 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/AccountsCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/AccountsCommandTest.java @@ -1,9 +1,9 @@ package fr.xephi.authme.command.executable.authme; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.service.BukkitService; import org.bukkit.command.CommandSender; import org.junit.Test; diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/ChangePasswordAdminCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/ChangePasswordAdminCommandTest.java index 14df46d9e..af8f4e96c 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/ChangePasswordAdminCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/ChangePasswordAdminCommandTest.java @@ -1,11 +1,11 @@ package fr.xephi.authme.command.executable.authme; import fr.xephi.authme.TestHelper; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.service.BukkitService; diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/ConverterCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/ConverterCommandTest.java index e5035c450..32cc64897 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/ConverterCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/ConverterCommandTest.java @@ -3,8 +3,8 @@ package fr.xephi.authme.command.executable.authme; import ch.jalu.injector.Injector; import fr.xephi.authme.TestHelper; import fr.xephi.authme.command.CommandService; -import fr.xephi.authme.converter.Converter; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.datasource.converter.Converter; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.util.StringUtils; import org.bukkit.command.CommandSender; diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/GetEmailCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/GetEmailCommandTest.java index 6afdc3295..f7d322605 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/GetEmailCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/GetEmailCommandTest.java @@ -1,9 +1,9 @@ package fr.xephi.authme.command.executable.authme; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import org.bukkit.command.CommandSender; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/LastLoginCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/LastLoginCommandTest.java index d42996eed..8ff1baff9 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/LastLoginCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/LastLoginCommandTest.java @@ -1,9 +1,9 @@ package fr.xephi.authme.command.executable.authme; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import org.bukkit.command.CommandSender; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommandTest.java index e3a79db8e..54a31734d 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommandTest.java @@ -1,9 +1,9 @@ package fr.xephi.authme.command.executable.authme; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import org.bukkit.command.CommandSender; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommandTest.java index 49ea28ac8..508010cf9 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommandTest.java @@ -1,11 +1,11 @@ package fr.xephi.authme.command.executable.authme; import fr.xephi.authme.TestHelper; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.limbo.LimboCache; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.limbo.LimboCache; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.service.BukkitService; diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/ReloadCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/ReloadCommandTest.java index 5eb7dcc6d..07424e159 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/ReloadCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/ReloadCommandTest.java @@ -9,7 +9,7 @@ import fr.xephi.authme.datasource.DataSourceType; import fr.xephi.authme.initialization.Reloadable; import fr.xephi.authme.initialization.SettingsDependent; import fr.xephi.authme.output.LogLevel; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.DatabaseSettings; import fr.xephi.authme.settings.properties.PluginSettings; diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/SetEmailCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/SetEmailCommandTest.java index 705302829..033bd8819 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/SetEmailCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/SetEmailCommandTest.java @@ -1,10 +1,10 @@ package fr.xephi.authme.command.executable.authme; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.service.BukkitService; import org.bukkit.command.CommandSender; import org.junit.Test; diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/UnregisterAdminCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/UnregisterAdminCommandTest.java index e9cfbbabd..fd2e36883 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/UnregisterAdminCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/UnregisterAdminCommandTest.java @@ -2,7 +2,7 @@ package fr.xephi.authme.command.executable.authme; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.process.Management; import fr.xephi.authme.service.BukkitService; import org.bukkit.command.CommandSender; diff --git a/src/test/java/fr/xephi/authme/command/executable/captcha/CaptchaCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/captcha/CaptchaCommandTest.java index 5de45e616..cfdc51dc1 100644 --- a/src/test/java/fr/xephi/authme/command/executable/captcha/CaptchaCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/captcha/CaptchaCommandTest.java @@ -1,9 +1,9 @@ package fr.xephi.authme.command.executable.captcha; -import fr.xephi.authme.cache.CaptchaManager; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.CaptchaManager; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.command.CommandService; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import org.bukkit.entity.Player; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/src/test/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommandTest.java index a3d5a8ae0..7ca0510b5 100644 --- a/src/test/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommandTest.java @@ -1,8 +1,8 @@ package fr.xephi.authme.command.executable.changepassword; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.command.CommandService; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.process.Management; import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.settings.properties.SecuritySettings; diff --git a/src/test/java/fr/xephi/authme/command/executable/email/AddEmailCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/email/AddEmailCommandTest.java index 143ac5fe7..985ce8151 100644 --- a/src/test/java/fr/xephi/authme/command/executable/email/AddEmailCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/email/AddEmailCommandTest.java @@ -1,7 +1,7 @@ package fr.xephi.authme.command.executable.email; import fr.xephi.authme.command.CommandService; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.process.Management; import org.bukkit.command.BlockCommandSender; import org.bukkit.command.CommandSender; diff --git a/src/test/java/fr/xephi/authme/command/executable/email/RecoverEmailCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/email/RecoverEmailCommandTest.java index cb615d913..8a3dfcf48 100644 --- a/src/test/java/fr/xephi/authme/command/executable/email/RecoverEmailCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/email/RecoverEmailCommandTest.java @@ -1,12 +1,12 @@ package fr.xephi.authme.command.executable.email; import fr.xephi.authme.TestHelper; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.mail.SendMailSSL; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.service.RecoveryCodeService; diff --git a/src/test/java/fr/xephi/authme/command/executable/register/RegisterCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/register/RegisterCommandTest.java index ca1a1ae6b..a4dfe8f78 100644 --- a/src/test/java/fr/xephi/authme/command/executable/register/RegisterCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/register/RegisterCommandTest.java @@ -3,7 +3,7 @@ package fr.xephi.authme.command.executable.register; import fr.xephi.authme.TestHelper; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.mail.SendMailSSL; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.process.Management; import fr.xephi.authme.security.HashAlgorithm; import fr.xephi.authme.settings.properties.EmailSettings; diff --git a/src/test/java/fr/xephi/authme/command/executable/unregister/UnregisterCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/unregister/UnregisterCommandTest.java index 33bbf4c68..336b17424 100644 --- a/src/test/java/fr/xephi/authme/command/executable/unregister/UnregisterCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/unregister/UnregisterCommandTest.java @@ -1,8 +1,8 @@ package fr.xephi.authme.command.executable.unregister; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.command.CommandService; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.process.Management; import org.bukkit.entity.Player; import org.junit.Test; diff --git a/src/test/java/fr/xephi/authme/cache/CaptchaManagerTest.java b/src/test/java/fr/xephi/authme/data/CaptchaManagerTest.java similarity index 99% rename from src/test/java/fr/xephi/authme/cache/CaptchaManagerTest.java rename to src/test/java/fr/xephi/authme/data/CaptchaManagerTest.java index bb293ef9f..92be450da 100644 --- a/src/test/java/fr/xephi/authme/cache/CaptchaManagerTest.java +++ b/src/test/java/fr/xephi/authme/data/CaptchaManagerTest.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.cache; +package fr.xephi.authme.data; import fr.xephi.authme.ReflectionTestUtils; import fr.xephi.authme.settings.Settings; diff --git a/src/test/java/fr/xephi/authme/cache/SessionManagerTest.java b/src/test/java/fr/xephi/authme/data/SessionManagerTest.java similarity index 99% rename from src/test/java/fr/xephi/authme/cache/SessionManagerTest.java rename to src/test/java/fr/xephi/authme/data/SessionManagerTest.java index 80f9a4097..f778dd16b 100644 --- a/src/test/java/fr/xephi/authme/cache/SessionManagerTest.java +++ b/src/test/java/fr/xephi/authme/data/SessionManagerTest.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.cache; +package fr.xephi.authme.data; import fr.xephi.authme.ReflectionTestUtils; import fr.xephi.authme.settings.Settings; diff --git a/src/test/java/fr/xephi/authme/cache/TempbanManagerTest.java b/src/test/java/fr/xephi/authme/data/TempbanManagerTest.java similarity index 98% rename from src/test/java/fr/xephi/authme/cache/TempbanManagerTest.java rename to src/test/java/fr/xephi/authme/data/TempbanManagerTest.java index bd4cfc04c..70aa11c76 100644 --- a/src/test/java/fr/xephi/authme/cache/TempbanManagerTest.java +++ b/src/test/java/fr/xephi/authme/data/TempbanManagerTest.java @@ -1,10 +1,10 @@ -package fr.xephi.authme.cache; +package fr.xephi.authme.data; import fr.xephi.authme.ReflectionTestUtils; import fr.xephi.authme.TestHelper; -import fr.xephi.authme.cache.TempbanManager.TimedCounter; -import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.output.Messages; +import fr.xephi.authme.data.TempbanManager.TimedCounter; +import fr.xephi.authme.message.MessageKey; +import fr.xephi.authme.message.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.SecuritySettings; import fr.xephi.authme.service.BukkitService; diff --git a/src/test/java/fr/xephi/authme/cache/backup/PlayerDataStorageTest.java b/src/test/java/fr/xephi/authme/data/backup/LimboPlayerStorageTest.java similarity index 82% rename from src/test/java/fr/xephi/authme/cache/backup/PlayerDataStorageTest.java rename to src/test/java/fr/xephi/authme/data/backup/LimboPlayerStorageTest.java index 288f47710..f9c5880ca 100644 --- a/src/test/java/fr/xephi/authme/cache/backup/PlayerDataStorageTest.java +++ b/src/test/java/fr/xephi/authme/data/backup/LimboPlayerStorageTest.java @@ -1,15 +1,15 @@ -package fr.xephi.authme.cache.backup; +package fr.xephi.authme.data.backup; import ch.jalu.injector.testing.BeforeInjecting; import ch.jalu.injector.testing.DelayedInjectionRunner; import ch.jalu.injector.testing.InjectDelayed; import fr.xephi.authme.TestHelper; -import fr.xephi.authme.cache.limbo.PlayerData; +import fr.xephi.authme.data.limbo.LimboPlayer; import fr.xephi.authme.initialization.DataFolder; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.settings.SpawnLoader; import fr.xephi.authme.service.BukkitService; -import fr.xephi.authme.util.StringUtils; +import fr.xephi.authme.util.FileUtils; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; @@ -32,16 +32,16 @@ import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; /** - * Test for {@link PlayerDataStorage}. + * Test for {@link LimboPlayerStorage}. */ @RunWith(DelayedInjectionRunner.class) -public class PlayerDataStorageTest { +public class LimboPlayerStorageTest { private static final UUID SAMPLE_UUID = UUID.nameUUIDFromBytes("PlayerDataStorageTest".getBytes()); - private static final String SOURCE_FOLDER = TestHelper.PROJECT_ROOT + "cache/backup/"; + private static final String SOURCE_FOLDER = TestHelper.PROJECT_ROOT + "data/backup/"; @InjectDelayed - private PlayerDataStorage playerDataStorage; + private LimboPlayerStorage limboPlayerStorage; @Mock private SpawnLoader spawnLoader; @@ -61,11 +61,11 @@ public class PlayerDataStorageTest { @BeforeInjecting public void copyTestFiles() throws IOException { dataFolder = temporaryFolder.newFolder(); - File playerFolder = new File(dataFolder, StringUtils.makePath("playerdata", SAMPLE_UUID.toString())); + File playerFolder = new File(dataFolder, FileUtils.makePath("playerdata", SAMPLE_UUID.toString())); if (!playerFolder.mkdirs()) { throw new IllegalStateException("Cannot create '" + playerFolder.getAbsolutePath() + "'"); } - Files.copy(TestHelper.getJarPath(StringUtils.makePath(SOURCE_FOLDER, "sample-folder", "data.json")), + Files.copy(TestHelper.getJarPath(FileUtils.makePath(SOURCE_FOLDER, "sample-folder", "data.json")), new File(playerFolder, "data.json").toPath()); } @@ -78,7 +78,7 @@ public class PlayerDataStorageTest { given(bukkitService.getWorld("nether")).willReturn(world); // when - PlayerData data = playerDataStorage.readData(player); + LimboPlayer data = limboPlayerStorage.readData(player); // then assertThat(data, not(nullValue())); @@ -103,7 +103,7 @@ public class PlayerDataStorageTest { given(player.getUniqueId()).willReturn(UUID.nameUUIDFromBytes("other-player".getBytes())); // when - PlayerData data = playerDataStorage.readData(player); + LimboPlayer data = limboPlayerStorage.readData(player); // then assertThat(data, nullValue()); @@ -118,8 +118,8 @@ public class PlayerDataStorageTest { given(player2.getUniqueId()).willReturn(UUID.nameUUIDFromBytes("not-stored".getBytes())); // when / then - assertThat(playerDataStorage.hasData(player1), equalTo(true)); - assertThat(playerDataStorage.hasData(player2), equalTo(false)); + assertThat(limboPlayerStorage.hasData(player1), equalTo(true)); + assertThat(limboPlayerStorage.hasData(player2), equalTo(false)); } @Test @@ -140,10 +140,10 @@ public class PlayerDataStorageTest { given(spawnLoader.getPlayerLocationOrSpawn(player)).willReturn(location); // when - playerDataStorage.saveData(player); + limboPlayerStorage.saveData(player); // then - File playerFile = new File(dataFolder, StringUtils.makePath("playerdata", uuid.toString(), "data.json")); + File playerFile = new File(dataFolder, FileUtils.makePath("playerdata", uuid.toString(), "data.json")); assertThat(playerFile.exists(), equalTo(true)); // TODO ljacqu 20160711: Check contents of file } diff --git a/src/test/java/fr/xephi/authme/cache/limbo/LimboCacheTest.java b/src/test/java/fr/xephi/authme/data/limbo/LimboCacheTest.java similarity index 72% rename from src/test/java/fr/xephi/authme/cache/limbo/LimboCacheTest.java rename to src/test/java/fr/xephi/authme/data/limbo/LimboCacheTest.java index 600596309..54f408654 100644 --- a/src/test/java/fr/xephi/authme/cache/limbo/LimboCacheTest.java +++ b/src/test/java/fr/xephi/authme/data/limbo/LimboCacheTest.java @@ -1,7 +1,7 @@ -package fr.xephi.authme.cache.limbo; +package fr.xephi.authme.data.limbo; import fr.xephi.authme.ReflectionTestUtils; -import fr.xephi.authme.cache.backup.PlayerDataStorage; +import fr.xephi.authme.data.backup.LimboPlayerStorage; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.SpawnLoader; @@ -44,7 +44,7 @@ public class LimboCacheTest { private SpawnLoader spawnLoader; @Mock - private PlayerDataStorage playerDataStorage; + private LimboPlayerStorage limboPlayerStorage; @Test public void shouldAddPlayerData() { @@ -63,13 +63,13 @@ public class LimboCacheTest { given(permissionsManager.hasGroupSupport()).willReturn(true); String group = "test-group"; given(permissionsManager.getPrimaryGroup(player)).willReturn(group); - given(playerDataStorage.hasData(player)).willReturn(false); + given(limboPlayerStorage.hasData(player)).willReturn(false); // when limboCache.addPlayerData(player); // then - PlayerData limboPlayer = limboCache.getPlayerData(name); + LimboPlayer limboPlayer = limboCache.getPlayerData(name); assertThat(limboPlayer.getLocation(), equalTo(location)); assertThat(limboPlayer.isOperator(), equalTo(true)); assertThat(limboPlayer.getWalkSpeed(), equalTo(walkSpeed)); @@ -84,22 +84,22 @@ public class LimboCacheTest { String name = "player01"; Player player = mock(Player.class); given(player.getName()).willReturn(name); - given(playerDataStorage.hasData(player)).willReturn(true); - PlayerData playerData = mock(PlayerData.class); - given(playerDataStorage.readData(player)).willReturn(playerData); + given(limboPlayerStorage.hasData(player)).willReturn(true); + LimboPlayer limboPlayer = mock(LimboPlayer.class); + given(limboPlayerStorage.readData(player)).willReturn(limboPlayer); float walkSpeed = 2.4f; - given(playerData.getWalkSpeed()).willReturn(walkSpeed); - given(playerData.isCanFly()).willReturn(true); + given(limboPlayer.getWalkSpeed()).willReturn(walkSpeed); + given(limboPlayer.isCanFly()).willReturn(true); float flySpeed = 1.0f; - given(playerData.getFlySpeed()).willReturn(flySpeed); + given(limboPlayer.getFlySpeed()).willReturn(flySpeed); String group = "primary-group"; - given(playerData.getGroup()).willReturn(group); + given(limboPlayer.getGroup()).willReturn(group); // when limboCache.addPlayerData(player); // then - PlayerData result = limboCache.getPlayerData(name); + LimboPlayer result = limboCache.getPlayerData(name); assertThat(result.getWalkSpeed(), equalTo(walkSpeed)); assertThat(result.isCanFly(), equalTo(true)); assertThat(result.getFlySpeed(), equalTo(flySpeed)); @@ -112,16 +112,16 @@ public class LimboCacheTest { String name = "Champ"; Player player = mock(Player.class); given(player.getName()).willReturn(name); - PlayerData playerData = mock(PlayerData.class); - given(playerData.isOperator()).willReturn(true); + LimboPlayer limboPlayer = mock(LimboPlayer.class); + given(limboPlayer.isOperator()).willReturn(true); float walkSpeed = 2.4f; - given(playerData.getWalkSpeed()).willReturn(walkSpeed); - given(playerData.isCanFly()).willReturn(true); + given(limboPlayer.getWalkSpeed()).willReturn(walkSpeed); + given(limboPlayer.isCanFly()).willReturn(true); float flySpeed = 1.0f; - given(playerData.getFlySpeed()).willReturn(flySpeed); + given(limboPlayer.getFlySpeed()).willReturn(flySpeed); String group = "primary-group"; - given(playerData.getGroup()).willReturn(group); - getCache().put(name.toLowerCase(), playerData); + given(limboPlayer.getGroup()).willReturn(group); + getCache().put(name.toLowerCase(), limboPlayer); given(settings.getProperty(PluginSettings.ENABLE_PERMISSION_CHECK)).willReturn(true); given(permissionsManager.hasGroupSupport()).willReturn(true); @@ -134,7 +134,7 @@ public class LimboCacheTest { verify(player).setAllowFlight(true); verify(player).setFlySpeed(flySpeed); verify(permissionsManager).setGroup(player, group); - verify(playerData).clearTasks(); + verify(limboPlayer).clearTasks(); } @Test @@ -143,14 +143,14 @@ public class LimboCacheTest { String name = "Champ"; Player player = mock(Player.class); given(player.getName()).willReturn(name); - PlayerData playerData = mock(PlayerData.class); - given(playerData.isOperator()).willReturn(true); - given(playerData.getWalkSpeed()).willReturn(0f); - given(playerData.isCanFly()).willReturn(true); - given(playerData.getFlySpeed()).willReturn(0f); + LimboPlayer limboPlayer = mock(LimboPlayer.class); + given(limboPlayer.isOperator()).willReturn(true); + given(limboPlayer.getWalkSpeed()).willReturn(0f); + given(limboPlayer.isCanFly()).willReturn(true); + given(limboPlayer.getFlySpeed()).willReturn(0f); String group = "primary-group"; - given(playerData.getGroup()).willReturn(group); - getCache().put(name.toLowerCase(), playerData); + given(limboPlayer.getGroup()).willReturn(group); + getCache().put(name.toLowerCase(), limboPlayer); given(settings.getProperty(PluginSettings.ENABLE_PERMISSION_CHECK)).willReturn(true); given(permissionsManager.hasGroupSupport()).willReturn(true); @@ -180,9 +180,9 @@ public class LimboCacheTest { @Test public void shouldRemoveAndClearTasks() { // given - PlayerData playerData = mock(PlayerData.class); + LimboPlayer limboPlayer = mock(LimboPlayer.class); String name = "abcdef"; - getCache().put(name, playerData); + getCache().put(name, limboPlayer); Player player = mock(Player.class); given(player.getName()).willReturn(name); @@ -191,16 +191,16 @@ public class LimboCacheTest { // then assertThat(getCache(), anEmptyMap()); - verify(playerData).clearTasks(); + verify(limboPlayer).clearTasks(); } @Test public void shouldDeleteFromCacheAndStorage() { // given - PlayerData playerData = mock(PlayerData.class); + LimboPlayer limboPlayer = mock(LimboPlayer.class); String name = "SomeName"; - getCache().put(name.toLowerCase(), playerData); - getCache().put("othername", mock(PlayerData.class)); + getCache().put(name.toLowerCase(), limboPlayer); + getCache().put("othername", mock(LimboPlayer.class)); Player player = mock(Player.class); given(player.getName()).willReturn(name); @@ -209,22 +209,22 @@ public class LimboCacheTest { // then assertThat(getCache(), aMapWithSize(1)); - verify(playerData).clearTasks(); - verify(playerDataStorage).removeData(player); + verify(limboPlayer).clearTasks(); + verify(limboPlayerStorage).removeData(player); } @Test public void shouldReturnIfHasData() { // given String name = "tester"; - getCache().put(name, mock(PlayerData.class)); + getCache().put(name, mock(LimboPlayer.class)); // when / then assertThat(limboCache.hasPlayerData(name), equalTo(true)); assertThat(limboCache.hasPlayerData("someone_else"), equalTo(false)); } - private Map getCache() { + private Map getCache() { return ReflectionTestUtils.getFieldValue(LimboCache.class, limboCache, "cache"); } } diff --git a/src/test/java/fr/xephi/authme/datasource/AbstractDataSourceIntegrationTest.java b/src/test/java/fr/xephi/authme/datasource/AbstractDataSourceIntegrationTest.java index 6399221c2..3c8523bb3 100644 --- a/src/test/java/fr/xephi/authme/datasource/AbstractDataSourceIntegrationTest.java +++ b/src/test/java/fr/xephi/authme/datasource/AbstractDataSourceIntegrationTest.java @@ -1,6 +1,6 @@ package fr.xephi.authme.datasource; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.security.crypts.HashedPassword; import org.junit.Test; diff --git a/src/test/java/fr/xephi/authme/datasource/AbstractResourceClosingTest.java b/src/test/java/fr/xephi/authme/datasource/AbstractResourceClosingTest.java index ee6bdd048..c8aeb7966 100644 --- a/src/test/java/fr/xephi/authme/datasource/AbstractResourceClosingTest.java +++ b/src/test/java/fr/xephi/authme/datasource/AbstractResourceClosingTest.java @@ -6,7 +6,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import fr.xephi.authme.TestHelper; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.security.HashAlgorithm; import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.settings.Settings; diff --git a/src/test/java/fr/xephi/authme/datasource/FlatFileIntegrationTest.java b/src/test/java/fr/xephi/authme/datasource/FlatFileIntegrationTest.java index 853cbd78c..7ce72f153 100644 --- a/src/test/java/fr/xephi/authme/datasource/FlatFileIntegrationTest.java +++ b/src/test/java/fr/xephi/authme/datasource/FlatFileIntegrationTest.java @@ -2,7 +2,9 @@ package fr.xephi.authme.datasource; import com.google.common.io.Files; import fr.xephi.authme.TestHelper; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.datasource.FlatFile; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -23,7 +25,7 @@ import static org.junit.Assert.assertThat; /** * Integration test for the deprecated {@link FlatFile} datasource. The flatfile datasource is no longer used. - * Essentially, the only time we use it is in {@link fr.xephi.authme.converter.ForceFlatToSqlite}, + * Essentially, the only time we use it is in {@link fr.xephi.authme.datasource.converter.ForceFlatToSqlite}, * which requires {@link FlatFile#getAllAuths()}. */ public class FlatFileIntegrationTest { diff --git a/src/test/java/fr/xephi/authme/datasource/MySqlIntegrationTest.java b/src/test/java/fr/xephi/authme/datasource/MySqlIntegrationTest.java index 93d8a3998..5484bd5e0 100644 --- a/src/test/java/fr/xephi/authme/datasource/MySqlIntegrationTest.java +++ b/src/test/java/fr/xephi/authme/datasource/MySqlIntegrationTest.java @@ -4,6 +4,9 @@ import com.github.authme.configme.properties.Property; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; import fr.xephi.authme.TestHelper; +import fr.xephi.authme.datasource.AbstractDataSourceIntegrationTest; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.datasource.MySQL; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.DatabaseSettings; import org.junit.After; diff --git a/src/test/java/fr/xephi/authme/datasource/MySqlResourceClosingTest.java b/src/test/java/fr/xephi/authme/datasource/MySqlResourceClosingTest.java index 7dccb08b0..f943cac49 100644 --- a/src/test/java/fr/xephi/authme/datasource/MySqlResourceClosingTest.java +++ b/src/test/java/fr/xephi/authme/datasource/MySqlResourceClosingTest.java @@ -1,6 +1,9 @@ package fr.xephi.authme.datasource; import com.zaxxer.hikari.HikariDataSource; +import fr.xephi.authme.datasource.AbstractResourceClosingTest; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.datasource.MySQL; import fr.xephi.authme.security.HashAlgorithm; import fr.xephi.authme.settings.Settings; diff --git a/src/test/java/fr/xephi/authme/datasource/SQLiteIntegrationTest.java b/src/test/java/fr/xephi/authme/datasource/SQLiteIntegrationTest.java index 4836b198d..9398e4ed9 100644 --- a/src/test/java/fr/xephi/authme/datasource/SQLiteIntegrationTest.java +++ b/src/test/java/fr/xephi/authme/datasource/SQLiteIntegrationTest.java @@ -2,7 +2,10 @@ package fr.xephi.authme.datasource; import com.github.authme.configme.properties.Property; import fr.xephi.authme.TestHelper; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.datasource.AbstractDataSourceIntegrationTest; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.datasource.SQLite; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.DatabaseSettings; import org.junit.After; diff --git a/src/test/java/fr/xephi/authme/datasource/SQLiteResourceClosingTest.java b/src/test/java/fr/xephi/authme/datasource/SQLiteResourceClosingTest.java index 9eac94630..efc6dbefb 100644 --- a/src/test/java/fr/xephi/authme/datasource/SQLiteResourceClosingTest.java +++ b/src/test/java/fr/xephi/authme/datasource/SQLiteResourceClosingTest.java @@ -1,5 +1,8 @@ package fr.xephi.authme.datasource; +import fr.xephi.authme.datasource.AbstractResourceClosingTest; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.datasource.SQLite; import fr.xephi.authme.security.HashAlgorithm; import fr.xephi.authme.settings.Settings; diff --git a/src/test/java/fr/xephi/authme/converter/AbstractDataSourceConverterTest.java b/src/test/java/fr/xephi/authme/datasource/converter/AbstractDataSourceConverterTest.java similarity index 98% rename from src/test/java/fr/xephi/authme/converter/AbstractDataSourceConverterTest.java rename to src/test/java/fr/xephi/authme/datasource/converter/AbstractDataSourceConverterTest.java index b8378c1ee..897f36e93 100644 --- a/src/test/java/fr/xephi/authme/converter/AbstractDataSourceConverterTest.java +++ b/src/test/java/fr/xephi/authme/datasource/converter/AbstractDataSourceConverterTest.java @@ -1,7 +1,7 @@ -package fr.xephi.authme.converter; +package fr.xephi.authme.datasource.converter; import fr.xephi.authme.TestHelper; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSourceType; import org.bukkit.command.CommandSender; diff --git a/src/test/java/fr/xephi/authme/converter/CrazyLoginConverterTest.java b/src/test/java/fr/xephi/authme/datasource/converter/CrazyLoginConverterTest.java similarity index 96% rename from src/test/java/fr/xephi/authme/converter/CrazyLoginConverterTest.java rename to src/test/java/fr/xephi/authme/datasource/converter/CrazyLoginConverterTest.java index 0049a0286..e24953b96 100644 --- a/src/test/java/fr/xephi/authme/converter/CrazyLoginConverterTest.java +++ b/src/test/java/fr/xephi/authme/datasource/converter/CrazyLoginConverterTest.java @@ -1,9 +1,9 @@ -package fr.xephi.authme.converter; +package fr.xephi.authme.datasource.converter; import ch.jalu.injector.testing.DelayedInjectionRunner; import ch.jalu.injector.testing.InjectDelayed; import fr.xephi.authme.TestHelper; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.initialization.DataFolder; import fr.xephi.authme.settings.Settings; @@ -45,7 +45,7 @@ public class CrazyLoginConverterTest { private Settings settings; @DataFolder - private File dataFolder = TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "converter/"); + private File dataFolder = TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "/datasource/converter/"); @BeforeClass public static void initializeLogger() { diff --git a/src/test/java/fr/xephi/authme/converter/ForceFlatToSqliteTest.java b/src/test/java/fr/xephi/authme/datasource/converter/ForceFlatToSqliteTest.java similarity index 96% rename from src/test/java/fr/xephi/authme/converter/ForceFlatToSqliteTest.java rename to src/test/java/fr/xephi/authme/datasource/converter/ForceFlatToSqliteTest.java index 273d5530f..3ec28a7b6 100644 --- a/src/test/java/fr/xephi/authme/converter/ForceFlatToSqliteTest.java +++ b/src/test/java/fr/xephi/authme/datasource/converter/ForceFlatToSqliteTest.java @@ -1,8 +1,8 @@ -package fr.xephi.authme.converter; +package fr.xephi.authme.datasource.converter; import com.google.common.io.Files; import fr.xephi.authme.TestHelper; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSourceType; import fr.xephi.authme.datasource.FlatFile; diff --git a/src/test/java/fr/xephi/authme/geoip/GeoIpManagerTest.java b/src/test/java/fr/xephi/authme/geoip/GeoIpManagerTest.java index 547cf3e70..a4d459ca5 100644 --- a/src/test/java/fr/xephi/authme/geoip/GeoIpManagerTest.java +++ b/src/test/java/fr/xephi/authme/geoip/GeoIpManagerTest.java @@ -2,7 +2,6 @@ package fr.xephi.authme.geoip; import com.maxmind.geoip.Country; import com.maxmind.geoip.LookupService; -import fr.xephi.authme.geoip.GeoLiteAPI; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -23,12 +22,12 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; /** - * Test for {@link GeoLiteAPI}. + * Test for {@link GeoIpManager}. */ @RunWith(MockitoJUnitRunner.class) public class GeoIpManagerTest { - private GeoLiteAPI geoLiteApi; + private GeoIpManager geoIpManager; private File dataFolder; @Mock private LookupService lookupService; @@ -39,7 +38,7 @@ public class GeoIpManagerTest { @Before public void initializeGeoLiteApi() throws IOException { dataFolder = temporaryFolder.newFolder(); - geoLiteApi = new GeoLiteAPI(dataFolder, lookupService); + geoIpManager = new GeoIpManager(dataFolder, lookupService); } @Test @@ -52,7 +51,7 @@ public class GeoIpManagerTest { given(lookupService.getCountry(ip)).willReturn(country); // when - String result = geoLiteApi.getCountryCode(ip); + String result = geoIpManager.getCountryCode(ip); // then assertThat(result, equalTo(countryCode)); @@ -65,7 +64,7 @@ public class GeoIpManagerTest { String ip = "127.0.0.1"; // when - String result = geoLiteApi.getCountryCode(ip); + String result = geoIpManager.getCountryCode(ip); // then assertThat(result, equalTo("--")); @@ -82,7 +81,7 @@ public class GeoIpManagerTest { given(lookupService.getCountry(ip)).willReturn(country); // when - String result = geoLiteApi.getCountryName(ip); + String result = geoIpManager.getCountryName(ip); // then assertThat(result, equalTo(countryName)); @@ -95,7 +94,7 @@ public class GeoIpManagerTest { String ip = "127.0.0.1"; // when - String result = geoLiteApi.getCountryName(ip); + String result = geoIpManager.getCountryName(ip); // then assertThat(result, equalTo("N/A")); diff --git a/src/test/java/fr/xephi/authme/listener/ListenerServiceTest.java b/src/test/java/fr/xephi/authme/listener/ListenerServiceTest.java index 7ff0202f1..bc999c533 100644 --- a/src/test/java/fr/xephi/authme/listener/ListenerServiceTest.java +++ b/src/test/java/fr/xephi/authme/listener/ListenerServiceTest.java @@ -3,7 +3,7 @@ package fr.xephi.authme.listener; import ch.jalu.injector.testing.BeforeInjecting; import ch.jalu.injector.testing.DelayedInjectionRunner; import ch.jalu.injector.testing.InjectDelayed; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.hooks.PluginHooks; import fr.xephi.authme.settings.Settings; diff --git a/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java b/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java index db6da711e..92522eb5c 100644 --- a/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java +++ b/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java @@ -1,10 +1,10 @@ package fr.xephi.authme.listener; import fr.xephi.authme.TestHelper; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.output.Messages; +import fr.xephi.authme.message.MessageKey; +import fr.xephi.authme.message.Messages; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerStatePermission; import fr.xephi.authme.service.AntiBotService; diff --git a/src/test/java/fr/xephi/authme/listener/PlayerListenerTest.java b/src/test/java/fr/xephi/authme/listener/PlayerListenerTest.java index d269726c8..74f9d5083 100644 --- a/src/test/java/fr/xephi/authme/listener/PlayerListenerTest.java +++ b/src/test/java/fr/xephi/authme/listener/PlayerListenerTest.java @@ -1,10 +1,10 @@ package fr.xephi.authme.listener; import fr.xephi.authme.service.AntiBotService; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.output.Messages; +import fr.xephi.authme.message.MessageKey; +import fr.xephi.authme.message.Messages; import fr.xephi.authme.process.Management; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.SpawnLoader; diff --git a/src/test/java/fr/xephi/authme/output/MessageKeyTest.java b/src/test/java/fr/xephi/authme/message/MessageKeyTest.java similarity index 95% rename from src/test/java/fr/xephi/authme/output/MessageKeyTest.java rename to src/test/java/fr/xephi/authme/message/MessageKeyTest.java index dda5eeb9d..3eb9f96ed 100644 --- a/src/test/java/fr/xephi/authme/output/MessageKeyTest.java +++ b/src/test/java/fr/xephi/authme/message/MessageKeyTest.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.output; +package fr.xephi.authme.message; import fr.xephi.authme.util.StringUtils; import org.junit.Test; diff --git a/src/test/java/fr/xephi/authme/output/MessagesFileConsistencyTest.java b/src/test/java/fr/xephi/authme/message/MessagesFileConsistencyTest.java similarity index 98% rename from src/test/java/fr/xephi/authme/output/MessagesFileConsistencyTest.java rename to src/test/java/fr/xephi/authme/message/MessagesFileConsistencyTest.java index 5cbf36a74..9e16994da 100644 --- a/src/test/java/fr/xephi/authme/output/MessagesFileConsistencyTest.java +++ b/src/test/java/fr/xephi/authme/message/MessagesFileConsistencyTest.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.output; +package fr.xephi.authme.message; import fr.xephi.authme.TestHelper; import fr.xephi.authme.util.StringUtils; diff --git a/src/test/java/fr/xephi/authme/output/MessagesFileYamlCheckerTest.java b/src/test/java/fr/xephi/authme/message/MessagesFileYamlCheckerTest.java similarity index 98% rename from src/test/java/fr/xephi/authme/output/MessagesFileYamlCheckerTest.java rename to src/test/java/fr/xephi/authme/message/MessagesFileYamlCheckerTest.java index 4f76882fa..ebb04fc2d 100644 --- a/src/test/java/fr/xephi/authme/output/MessagesFileYamlCheckerTest.java +++ b/src/test/java/fr/xephi/authme/message/MessagesFileYamlCheckerTest.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.output; +package fr.xephi.authme.message; import fr.xephi.authme.TestHelper; import fr.xephi.authme.util.StringUtils; diff --git a/src/test/java/fr/xephi/authme/output/MessagesIntegrationTest.java b/src/test/java/fr/xephi/authme/message/MessagesIntegrationTest.java similarity index 97% rename from src/test/java/fr/xephi/authme/output/MessagesIntegrationTest.java rename to src/test/java/fr/xephi/authme/message/MessagesIntegrationTest.java index ba8f03fb8..a7a4af313 100644 --- a/src/test/java/fr/xephi/authme/output/MessagesIntegrationTest.java +++ b/src/test/java/fr/xephi/authme/message/MessagesIntegrationTest.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.output; +package fr.xephi.authme.message; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.TestHelper; @@ -33,8 +33,8 @@ import static org.mockito.Mockito.verify; */ public class MessagesIntegrationTest { - private static final String YML_TEST_FILE = TestHelper.PROJECT_ROOT + "output/messages_test.yml"; - private static final String YML_DEFAULT_TEST_FILE = TestHelper.PROJECT_ROOT + "output/messages_default.yml"; + private static final String YML_TEST_FILE = TestHelper.PROJECT_ROOT + "message/messages_test.yml"; + private static final String YML_DEFAULT_TEST_FILE = TestHelper.PROJECT_ROOT + "message/messages_default.yml"; private Messages messages; @BeforeClass @@ -256,7 +256,7 @@ public class MessagesIntegrationTest { assumeThat(messages.retrieveSingle(key), equalTo("§cWrong password!")); Settings settings = mock(Settings.class); given(settings.getMessagesFile()).willReturn(TestHelper.getJarFile( - TestHelper.PROJECT_ROOT + "output/messages_test2.yml")); + TestHelper.PROJECT_ROOT + "message/messages_test2.yml")); // when messages.reload(settings); diff --git a/src/test/java/fr/xephi/authme/process/ProcessServiceTest.java b/src/test/java/fr/xephi/authme/process/ProcessServiceTest.java index 3e6ed8520..0c71cd510 100644 --- a/src/test/java/fr/xephi/authme/process/ProcessServiceTest.java +++ b/src/test/java/fr/xephi/authme/process/ProcessServiceTest.java @@ -1,7 +1,7 @@ package fr.xephi.authme.process; -import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.output.Messages; +import fr.xephi.authme.message.MessageKey; +import fr.xephi.authme.message.Messages; import fr.xephi.authme.permission.AuthGroupHandler; import fr.xephi.authme.permission.AuthGroupType; import fr.xephi.authme.permission.PermissionNode; diff --git a/src/test/java/fr/xephi/authme/process/email/AsyncAddEmailTest.java b/src/test/java/fr/xephi/authme/process/email/AsyncAddEmailTest.java index 4d013bd3b..e14c69f5e 100644 --- a/src/test/java/fr/xephi/authme/process/email/AsyncAddEmailTest.java +++ b/src/test/java/fr/xephi/authme/process/email/AsyncAddEmailTest.java @@ -1,10 +1,10 @@ package fr.xephi.authme.process.email; import fr.xephi.authme.TestHelper; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.process.ProcessService; import fr.xephi.authme.settings.properties.RegistrationSettings; import org.bukkit.entity.Player; diff --git a/src/test/java/fr/xephi/authme/process/email/AsyncChangeEmailTest.java b/src/test/java/fr/xephi/authme/process/email/AsyncChangeEmailTest.java index 7b9dbfdb6..ea18f86bb 100644 --- a/src/test/java/fr/xephi/authme/process/email/AsyncChangeEmailTest.java +++ b/src/test/java/fr/xephi/authme/process/email/AsyncChangeEmailTest.java @@ -1,9 +1,9 @@ package fr.xephi.authme.process.email; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.process.ProcessService; import fr.xephi.authme.settings.properties.RegistrationSettings; import org.bukkit.entity.Player; diff --git a/src/test/java/fr/xephi/authme/process/login/AsynchronousLoginTest.java b/src/test/java/fr/xephi/authme/process/login/AsynchronousLoginTest.java index b3dd38cf1..0644687cf 100644 --- a/src/test/java/fr/xephi/authme/process/login/AsynchronousLoginTest.java +++ b/src/test/java/fr/xephi/authme/process/login/AsynchronousLoginTest.java @@ -1,11 +1,11 @@ package fr.xephi.authme.process.login; import fr.xephi.authme.TestHelper; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.events.AuthMeAsyncPreLoginEvent; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerStatePermission; import fr.xephi.authme.process.ProcessService; diff --git a/src/test/java/fr/xephi/authme/process/unregister/AsynchronousUnregisterTest.java b/src/test/java/fr/xephi/authme/process/unregister/AsynchronousUnregisterTest.java index 24724768f..a3abe4b8e 100644 --- a/src/test/java/fr/xephi/authme/process/unregister/AsynchronousUnregisterTest.java +++ b/src/test/java/fr/xephi/authme/process/unregister/AsynchronousUnregisterTest.java @@ -1,11 +1,11 @@ package fr.xephi.authme.process.unregister; import fr.xephi.authme.TestHelper; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; -import fr.xephi.authme.cache.limbo.LimboCache; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; +import fr.xephi.authme.data.limbo.LimboCache; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.permission.AuthGroupHandler; import fr.xephi.authme.permission.AuthGroupType; import fr.xephi.authme.process.ProcessService; diff --git a/src/test/java/fr/xephi/authme/service/AntiBotServiceTest.java b/src/test/java/fr/xephi/authme/service/AntiBotServiceTest.java index ffe06b82a..7ecba73f6 100644 --- a/src/test/java/fr/xephi/authme/service/AntiBotServiceTest.java +++ b/src/test/java/fr/xephi/authme/service/AntiBotServiceTest.java @@ -4,8 +4,8 @@ import ch.jalu.injector.testing.BeforeInjecting; import ch.jalu.injector.testing.DelayedInjectionRunner; import ch.jalu.injector.testing.InjectDelayed; import fr.xephi.authme.ReflectionTestUtils; -import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.output.Messages; +import fr.xephi.authme.message.MessageKey; +import fr.xephi.authme.message.Messages; import fr.xephi.authme.permission.AdminPermission; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.settings.Settings; diff --git a/src/test/java/fr/xephi/authme/service/MigrationServiceTest.java b/src/test/java/fr/xephi/authme/service/MigrationServiceTest.java index aad9343d4..7283a4682 100644 --- a/src/test/java/fr/xephi/authme/service/MigrationServiceTest.java +++ b/src/test/java/fr/xephi/authme/service/MigrationServiceTest.java @@ -1,12 +1,11 @@ package fr.xephi.authme.service; import fr.xephi.authme.TestHelper; -import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.security.HashAlgorithm; import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.security.crypts.SHA256; -import fr.xephi.authme.service.MigrationService; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.SecuritySettings; import org.junit.BeforeClass; diff --git a/src/test/java/fr/xephi/authme/service/TeleportationServiceTest.java b/src/test/java/fr/xephi/authme/service/TeleportationServiceTest.java index 0a218a84d..30af5b0b2 100644 --- a/src/test/java/fr/xephi/authme/service/TeleportationServiceTest.java +++ b/src/test/java/fr/xephi/authme/service/TeleportationServiceTest.java @@ -1,12 +1,10 @@ package fr.xephi.authme.service; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; -import fr.xephi.authme.cache.limbo.PlayerData; +import fr.xephi.authme.data.auth.PlayerAuth; +import fr.xephi.authme.data.auth.PlayerCache; +import fr.xephi.authme.data.limbo.LimboPlayer; import fr.xephi.authme.events.FirstSpawnTeleportEvent; import fr.xephi.authme.events.SpawnTeleportEvent; -import fr.xephi.authme.service.BukkitService; -import fr.xephi.authme.service.TeleportationService; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.SpawnLoader; import fr.xephi.authme.settings.properties.RestrictionSettings; @@ -237,7 +235,7 @@ public class TeleportationServiceTest { given(settings.getProperty(RestrictionSettings.NO_TELEPORT)).willReturn(true); Player player = mock(Player.class); PlayerAuth auth = mock(PlayerAuth.class); - PlayerData limbo = mock(PlayerData.class); + LimboPlayer limbo = mock(LimboPlayer.class); // when teleportationService.teleportOnLogin(player, auth, limbo); @@ -255,7 +253,7 @@ public class TeleportationServiceTest { Location spawn = mockLocation(); given(spawnLoader.getSpawnLocation(player)).willReturn(spawn); PlayerAuth auth = mock(PlayerAuth.class); - PlayerData limbo = mock(PlayerData.class); + LimboPlayer limbo = mock(LimboPlayer.class); Location limboLocation = mockLocation(); given(limboLocation.getWorld().getName()).willReturn("forced1"); given(limbo.getLocation()).willReturn(limboLocation); @@ -279,7 +277,7 @@ public class TeleportationServiceTest { Location spawn = mockLocation(); given(spawnLoader.getSpawnLocation(player)).willReturn(spawn); PlayerAuth auth = mock(PlayerAuth.class); - PlayerData limbo = mock(PlayerData.class); + LimboPlayer limbo = mock(LimboPlayer.class); Location limboLocation = mockLocation(); given(limboLocation.getWorld().getName()).willReturn("Forced1"); // different case given(limbo.getLocation()).willReturn(limboLocation); @@ -306,7 +304,7 @@ public class TeleportationServiceTest { Player player = mock(Player.class); given(player.isOnline()).willReturn(true); - PlayerData limbo = mock(PlayerData.class); + LimboPlayer limbo = mock(LimboPlayer.class); Location limboLocation = mockLocation(); given(limbo.getLocation()).willReturn(limboLocation); @@ -335,7 +333,7 @@ public class TeleportationServiceTest { given(player.isOnline()).willReturn(true); World world = mock(World.class); given(player.getWorld()).willReturn(world); - PlayerData limbo = mock(PlayerData.class); + LimboPlayer limbo = mock(LimboPlayer.class); Location limboLocation = mockLocation(); given(limbo.getLocation()).willReturn(limboLocation); @@ -363,7 +361,7 @@ public class TeleportationServiceTest { given(player.isOnline()).willReturn(true); World world = mock(World.class); given(player.getWorld()).willReturn(world); - PlayerData limbo = mock(PlayerData.class); + LimboPlayer limbo = mock(LimboPlayer.class); Location location = mockLocation(); given(limbo.getLocation()).willReturn(location); @@ -388,7 +386,7 @@ public class TeleportationServiceTest { given(player.isOnline()).willReturn(true); World world = mock(World.class); given(player.getWorld()).willReturn(world); - PlayerData limbo = mock(PlayerData.class); + LimboPlayer limbo = mock(LimboPlayer.class); Location location = mockLocation(); given(limbo.getLocation()).willReturn(location); @@ -409,7 +407,7 @@ public class TeleportationServiceTest { PlayerAuth auth = PlayerAuth.builder().name("bobby").build(); Player player = mock(Player.class); - PlayerData limbo = mock(PlayerData.class); + LimboPlayer limbo = mock(LimboPlayer.class); // when teleportationService.teleportOnLogin(player, auth, limbo); diff --git a/src/test/java/fr/xephi/authme/service/ValidationServiceTest.java b/src/test/java/fr/xephi/authme/service/ValidationServiceTest.java index 2a85b131a..1a1cbbe45 100644 --- a/src/test/java/fr/xephi/authme/service/ValidationServiceTest.java +++ b/src/test/java/fr/xephi/authme/service/ValidationServiceTest.java @@ -5,11 +5,10 @@ import ch.jalu.injector.testing.DelayedInjectionRunner; import ch.jalu.injector.testing.InjectDelayed; import com.google.common.base.Strings; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.geoip.GeoLiteAPI; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.geoip.GeoIpManager; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerStatePermission; -import fr.xephi.authme.service.ValidationService; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.EmailSettings; import fr.xephi.authme.settings.properties.ProtectionSettings; @@ -46,7 +45,7 @@ public class ValidationServiceTest { @Mock private PermissionsManager permissionsManager; @Mock - private GeoLiteAPI geoLiteApi; + private GeoIpManager geoIpManager; @BeforeInjecting public void createService() { @@ -267,7 +266,7 @@ public class ValidationServiceTest { // then assertThat(result, equalTo(true)); - verifyZeroInteractions(geoLiteApi); + verifyZeroInteractions(geoIpManager); } @Test @@ -276,14 +275,14 @@ public class ValidationServiceTest { given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(asList("ch", "it")); given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(Collections.emptyList()); String ip = "127.0.0.1"; - given(geoLiteApi.getCountryCode(ip)).willReturn("CH"); + given(geoIpManager.getCountryCode(ip)).willReturn("CH"); // when boolean result = validationService.isCountryAdmitted(ip); // then assertThat(result, equalTo(true)); - verify(geoLiteApi).getCountryCode(ip); + verify(geoIpManager).getCountryCode(ip); } @Test @@ -292,14 +291,14 @@ public class ValidationServiceTest { given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(asList("ch", "it")); given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(Collections.emptyList()); String ip = "123.45.67.89"; - given(geoLiteApi.getCountryCode(ip)).willReturn("BR"); + given(geoIpManager.getCountryCode(ip)).willReturn("BR"); // when boolean result = validationService.isCountryAdmitted(ip); // then assertThat(result, equalTo(false)); - verify(geoLiteApi).getCountryCode(ip); + verify(geoIpManager).getCountryCode(ip); } @Test @@ -308,14 +307,14 @@ public class ValidationServiceTest { given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(Collections.emptyList()); given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(asList("ch", "it")); String ip = "127.0.0.1"; - given(geoLiteApi.getCountryCode(ip)).willReturn("BR"); + given(geoIpManager.getCountryCode(ip)).willReturn("BR"); // when boolean result = validationService.isCountryAdmitted(ip); // then assertThat(result, equalTo(true)); - verify(geoLiteApi).getCountryCode(ip); + verify(geoIpManager).getCountryCode(ip); } @Test @@ -324,14 +323,14 @@ public class ValidationServiceTest { given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(Collections.emptyList()); given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(asList("ch", "it")); String ip = "123.45.67.89"; - given(geoLiteApi.getCountryCode(ip)).willReturn("IT"); + given(geoIpManager.getCountryCode(ip)).willReturn("IT"); // when boolean result = validationService.isCountryAdmitted(ip); // then assertThat(result, equalTo(false)); - verify(geoLiteApi).getCountryCode(ip); + verify(geoIpManager).getCountryCode(ip); } private static void assertErrorEquals(ValidationResult validationResult, MessageKey messageKey, String... args) { diff --git a/src/test/java/fr/xephi/authme/settings/SettingsTest.java b/src/test/java/fr/xephi/authme/settings/SettingsTest.java index 3cde1f2d9..1e85a7420 100644 --- a/src/test/java/fr/xephi/authme/settings/SettingsTest.java +++ b/src/test/java/fr/xephi/authme/settings/SettingsTest.java @@ -22,7 +22,7 @@ import java.util.Collections; import java.util.List; import static fr.xephi.authme.settings.properties.PluginSettings.MESSAGES_LANGUAGE; -import static fr.xephi.authme.util.StringUtils.makePath; +import static fr.xephi.authme.util.FileUtils.makePath; import static org.hamcrest.Matchers.arrayContaining; import static org.hamcrest.Matchers.arrayWithSize; import static org.hamcrest.Matchers.endsWith; diff --git a/src/test/java/fr/xephi/authme/task/PlayerDataTaskManagerTest.java b/src/test/java/fr/xephi/authme/task/LimboPlayerTaskManagerTest.java similarity index 80% rename from src/test/java/fr/xephi/authme/task/PlayerDataTaskManagerTest.java rename to src/test/java/fr/xephi/authme/task/LimboPlayerTaskManagerTest.java index 93b552ca1..dbff584e8 100644 --- a/src/test/java/fr/xephi/authme/task/PlayerDataTaskManagerTest.java +++ b/src/test/java/fr/xephi/authme/task/LimboPlayerTaskManagerTest.java @@ -1,11 +1,11 @@ package fr.xephi.authme.task; import fr.xephi.authme.TestHelper; -import fr.xephi.authme.cache.auth.PlayerCache; -import fr.xephi.authme.cache.limbo.LimboCache; -import fr.xephi.authme.cache.limbo.PlayerData; -import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.output.Messages; +import fr.xephi.authme.data.auth.PlayerCache; +import fr.xephi.authme.data.limbo.LimboCache; +import fr.xephi.authme.data.limbo.LimboPlayer; +import fr.xephi.authme.message.MessageKey; +import fr.xephi.authme.message.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; @@ -31,7 +31,7 @@ import static org.mockito.Mockito.verifyZeroInteractions; * Test for {@link PlayerDataTaskManager}. */ @RunWith(MockitoJUnitRunner.class) -public class PlayerDataTaskManagerTest { +public class LimboPlayerTaskManagerTest { @InjectMocks private PlayerDataTaskManager playerDataTaskManager; @@ -60,8 +60,8 @@ public class PlayerDataTaskManagerTest { public void shouldRegisterMessageTask() { // given String name = "bobby"; - PlayerData playerData = mock(PlayerData.class); - given(limboCache.getPlayerData(name)).willReturn(playerData); + LimboPlayer limboPlayer = mock(LimboPlayer.class); + given(limboCache.getPlayerData(name)).willReturn(limboPlayer); MessageKey key = MessageKey.REGISTER_EMAIL_MESSAGE; given(messages.retrieve(key)).willReturn(new String[]{"Please register!"}); BukkitTask bukkiTask = mock(BukkitTask.class); @@ -73,7 +73,7 @@ public class PlayerDataTaskManagerTest { playerDataTaskManager.registerMessageTask(name, false); // then - verify(playerData).setMessageTask(bukkiTask); + verify(limboPlayer).setMessageTask(bukkiTask); verify(messages).retrieve(key); } @@ -97,8 +97,8 @@ public class PlayerDataTaskManagerTest { public void shouldNotScheduleTaskForZeroAsInterval() { // given String name = "Tester1"; - PlayerData playerData = mock(PlayerData.class); - given(limboCache.getPlayerData(name)).willReturn(playerData); + LimboPlayer limboPlayer = mock(LimboPlayer.class); + given(limboCache.getPlayerData(name)).willReturn(limboPlayer); BukkitTask bukkiTask = mock(BukkitTask.class); given(bukkitService.runTask(any(MessageTask.class))).willReturn(bukkiTask); given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(0); @@ -107,18 +107,18 @@ public class PlayerDataTaskManagerTest { playerDataTaskManager.registerMessageTask(name, true); // then - verifyZeroInteractions(playerData, bukkitService); + verifyZeroInteractions(limboPlayer, bukkitService); } @Test public void shouldCancelExistingMessageTask() { // given - PlayerData playerData = mock(PlayerData.class); + LimboPlayer limboPlayer = mock(LimboPlayer.class); BukkitTask existingMessageTask = mock(BukkitTask.class); - given(playerData.getMessageTask()).willReturn(existingMessageTask); + given(limboPlayer.getMessageTask()).willReturn(existingMessageTask); String name = "bobby"; - given(limboCache.getPlayerData(name)).willReturn(playerData); + given(limboCache.getPlayerData(name)).willReturn(limboPlayer); given(messages.retrieve(MessageKey.REGISTER_EMAIL_MESSAGE)) .willReturn(new String[]{"Please register", "Use /register"}); @@ -131,7 +131,7 @@ public class PlayerDataTaskManagerTest { playerDataTaskManager.registerMessageTask(name, false); // then - verify(playerData).setMessageTask(bukkiTask); + verify(limboPlayer).setMessageTask(bukkiTask); verify(messages).retrieve(MessageKey.REGISTER_EMAIL_MESSAGE); verify(existingMessageTask).cancel(); } @@ -142,8 +142,8 @@ public class PlayerDataTaskManagerTest { String name = "l33tPlayer"; Player player = mock(Player.class); given(player.getName()).willReturn(name); - PlayerData playerData = mock(PlayerData.class); - given(limboCache.getPlayerData(name)).willReturn(playerData); + LimboPlayer limboPlayer = mock(LimboPlayer.class); + given(limboCache.getPlayerData(name)).willReturn(limboPlayer); given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(30); BukkitTask bukkitTask = mock(BukkitTask.class); given(bukkitService.runTaskLater(any(TimeoutTask.class), anyLong())).willReturn(bukkitTask); @@ -152,7 +152,7 @@ public class PlayerDataTaskManagerTest { playerDataTaskManager.registerTimeoutTask(player); // then - verify(playerData).setTimeoutTask(bukkitTask); + verify(limboPlayer).setTimeoutTask(bukkitTask); verify(bukkitService).runTaskLater(any(TimeoutTask.class), eq(600L)); // 30 * TICKS_PER_SECOND verify(messages).retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR); } @@ -179,15 +179,15 @@ public class PlayerDataTaskManagerTest { String name = "snail"; Player player = mock(Player.class); given(player.getName()).willReturn(name); - PlayerData playerData = mock(PlayerData.class); - given(limboCache.getPlayerData(name)).willReturn(playerData); + LimboPlayer limboPlayer = mock(LimboPlayer.class); + given(limboCache.getPlayerData(name)).willReturn(limboPlayer); given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(0); // when playerDataTaskManager.registerTimeoutTask(player); // then - verifyZeroInteractions(playerData, bukkitService); + verifyZeroInteractions(limboPlayer, bukkitService); } @Test @@ -196,10 +196,10 @@ public class PlayerDataTaskManagerTest { String name = "l33tPlayer"; Player player = mock(Player.class); given(player.getName()).willReturn(name); - PlayerData playerData = mock(PlayerData.class); + LimboPlayer limboPlayer = mock(LimboPlayer.class); BukkitTask existingTask = mock(BukkitTask.class); - given(playerData.getTimeoutTask()).willReturn(existingTask); - given(limboCache.getPlayerData(name)).willReturn(playerData); + given(limboPlayer.getTimeoutTask()).willReturn(existingTask); + given(limboCache.getPlayerData(name)).willReturn(limboPlayer); given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(18); BukkitTask bukkitTask = mock(BukkitTask.class); given(bukkitService.runTaskLater(any(TimeoutTask.class), anyLong())).willReturn(bukkitTask); @@ -209,7 +209,7 @@ public class PlayerDataTaskManagerTest { // then verify(existingTask).cancel(); - verify(playerData).setTimeoutTask(bukkitTask); + verify(limboPlayer).setTimeoutTask(bukkitTask); verify(bukkitService).runTaskLater(any(TimeoutTask.class), eq(360L)); // 18 * TICKS_PER_SECOND verify(messages).retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR); } diff --git a/src/test/java/fr/xephi/authme/util/FileUtilsTest.java b/src/test/java/fr/xephi/authme/util/FileUtilsTest.java index 41059effb..f36acf755 100644 --- a/src/test/java/fr/xephi/authme/util/FileUtilsTest.java +++ b/src/test/java/fr/xephi/authme/util/FileUtilsTest.java @@ -119,6 +119,15 @@ public class FileUtilsTest { // Nothing happens } + @Test + public void shouldConstructPath() { + // given/when + String result = FileUtils.makePath("path", "to", "test-file.txt"); + + // then + assertThat(result, equalTo("path" + File.separator + "to" + File.separator + "test-file.txt")); + } + private static void createFiles(File... files) throws IOException { for (File file : files) { boolean result = file.getParentFile().mkdirs() & file.createNewFile(); diff --git a/src/test/java/fr/xephi/authme/util/PlayerUtilsTest.java b/src/test/java/fr/xephi/authme/util/PlayerUtilsTest.java index 444d0c497..14933a04a 100644 --- a/src/test/java/fr/xephi/authme/util/PlayerUtilsTest.java +++ b/src/test/java/fr/xephi/authme/util/PlayerUtilsTest.java @@ -15,7 +15,7 @@ import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; /** - * Test for {@link Utils}. + * Test for {@link PlayerUtils}. */ public class PlayerUtilsTest { diff --git a/src/test/java/fr/xephi/authme/util/StringUtilsTest.java b/src/test/java/fr/xephi/authme/util/StringUtilsTest.java index 72826b4cf..1be95d0d8 100644 --- a/src/test/java/fr/xephi/authme/util/StringUtilsTest.java +++ b/src/test/java/fr/xephi/authme/util/StringUtilsTest.java @@ -3,7 +3,6 @@ package fr.xephi.authme.util; import fr.xephi.authme.TestHelper; import org.junit.Test; -import java.io.File; import java.net.MalformedURLException; import static org.hamcrest.Matchers.equalTo; @@ -91,15 +90,6 @@ public class StringUtilsTest { assertThat(StringUtils.getDifference("test", "something"), greaterThan(0.88)); } - @Test - public void shouldConstructPath() { - // given/when - String result = StringUtils.makePath("path", "to", "test-file.txt"); - - // then - assertThat(result, equalTo("path" + File.separator + "to" + File.separator + "test-file.txt")); - } - @Test public void shouldHaveHiddenConstructor() { TestHelper.validateHasOnlyPrivateEmptyConstructor(StringUtils.class); diff --git a/src/test/java/tools/dependencygraph/DrawDependency.java b/src/test/java/tools/dependencygraph/DrawDependency.java index 6515f52d7..6b2c9c8af 100644 --- a/src/test/java/tools/dependencygraph/DrawDependency.java +++ b/src/test/java/tools/dependencygraph/DrawDependency.java @@ -8,7 +8,7 @@ import com.google.common.collect.Multimap; import fr.xephi.authme.ClassCollector; import fr.xephi.authme.TestHelper; import fr.xephi.authme.command.ExecutableCommand; -import fr.xephi.authme.converter.Converter; +import fr.xephi.authme.datasource.converter.Converter; import fr.xephi.authme.initialization.DataFolder; import fr.xephi.authme.process.AsynchronousProcess; import fr.xephi.authme.process.SynchronousProcess; diff --git a/src/test/java/tools/messages/MessageFileVerifier.java b/src/test/java/tools/messages/MessageFileVerifier.java index 8207091bd..f0be6bb44 100644 --- a/src/test/java/tools/messages/MessageFileVerifier.java +++ b/src/test/java/tools/messages/MessageFileVerifier.java @@ -5,7 +5,7 @@ import com.google.common.base.Predicate; import com.google.common.collect.HashMultimap; import com.google.common.collect.Iterables; import com.google.common.collect.Multimap; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import tools.utils.FileUtils; diff --git a/src/test/java/tools/messages/translation/ExportMessagesTask.java b/src/test/java/tools/messages/translation/ExportMessagesTask.java index 672dac398..7ea2a4196 100644 --- a/src/test/java/tools/messages/translation/ExportMessagesTask.java +++ b/src/test/java/tools/messages/translation/ExportMessagesTask.java @@ -2,7 +2,7 @@ package tools.messages.translation; import com.google.common.io.CharStreams; import com.google.gson.Gson; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.util.StringUtils; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; diff --git a/src/test/java/tools/messages/translation/ImportMessagesTask.java b/src/test/java/tools/messages/translation/ImportMessagesTask.java index 0685667da..c70caaa3a 100644 --- a/src/test/java/tools/messages/translation/ImportMessagesTask.java +++ b/src/test/java/tools/messages/translation/ImportMessagesTask.java @@ -2,7 +2,7 @@ package tools.messages.translation; import com.google.common.io.Resources; import com.google.gson.Gson; -import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.message.MessageKey; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import tools.messages.MessageFileVerifier; diff --git a/src/test/resources/fr/xephi/authme/cache/backup/sample-folder/data.json b/src/test/resources/fr/xephi/authme/data/backup/sample-folder/data.json similarity index 100% rename from src/test/resources/fr/xephi/authme/cache/backup/sample-folder/data.json rename to src/test/resources/fr/xephi/authme/data/backup/sample-folder/data.json diff --git a/src/test/resources/fr/xephi/authme/converter/crazylogin.db b/src/test/resources/fr/xephi/authme/datasource/converter/crazylogin.db similarity index 100% rename from src/test/resources/fr/xephi/authme/converter/crazylogin.db rename to src/test/resources/fr/xephi/authme/datasource/converter/crazylogin.db diff --git a/src/test/resources/fr/xephi/authme/output/messages_default.yml b/src/test/resources/fr/xephi/authme/message/messages_default.yml similarity index 100% rename from src/test/resources/fr/xephi/authme/output/messages_default.yml rename to src/test/resources/fr/xephi/authme/message/messages_default.yml diff --git a/src/test/resources/fr/xephi/authme/output/messages_test.yml b/src/test/resources/fr/xephi/authme/message/messages_test.yml similarity index 100% rename from src/test/resources/fr/xephi/authme/output/messages_test.yml rename to src/test/resources/fr/xephi/authme/message/messages_test.yml diff --git a/src/test/resources/fr/xephi/authme/output/messages_test2.yml b/src/test/resources/fr/xephi/authme/message/messages_test2.yml similarity index 100% rename from src/test/resources/fr/xephi/authme/output/messages_test2.yml rename to src/test/resources/fr/xephi/authme/message/messages_test2.yml From ac7bb5c0f6ff9e541b81367e798b24ecdf9b5b34 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Wed, 5 Oct 2016 22:08:29 +0200 Subject: [PATCH 16/18] Configurable antibot delay + delay only on startup #970 --- .../xephi/authme/service/AntiBotService.java | 18 +++++++++++++++--- .../properties/ProtectionSettings.java | 4 ++++ src/main/resources/config.yml | 2 ++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/xephi/authme/service/AntiBotService.java b/src/main/java/fr/xephi/authme/service/AntiBotService.java index be1eb8da8..24118d40c 100644 --- a/src/main/java/fr/xephi/authme/service/AntiBotService.java +++ b/src/main/java/fr/xephi/authme/service/AntiBotService.java @@ -29,9 +29,11 @@ public class AntiBotService implements SettingsDependent { // Settings private int duration; private int sensibility; + private int delay; // Service status private AntiBotStatus antiBotStatus; + private boolean startup; private BukkitTask disableTask; private int antibotPlayers; private final CopyOnWriteArrayList antibotKicked = new CopyOnWriteArrayList<>(); @@ -47,6 +49,7 @@ public class AntiBotService implements SettingsDependent { disableTask = null; antibotPlayers = 0; antiBotStatus = AntiBotStatus.DISABLED; + startup = true; // Load settings and start if required reload(settings); } @@ -56,6 +59,7 @@ public class AntiBotService implements SettingsDependent { // Load settings duration = settings.getProperty(ProtectionSettings.ANTIBOT_DURATION); sensibility = settings.getProperty(ProtectionSettings.ANTIBOT_SENSIBILITY); + delay = settings.getProperty(ProtectionSettings.ANTIBOT_DELAY); // Stop existing protection stopProtection(); @@ -66,13 +70,21 @@ public class AntiBotService implements SettingsDependent { return; } - // Schedule the bot activation - bukkitService.scheduleSyncDelayedTask(new Runnable() { + // Bot activation task + Runnable enableTask = new Runnable() { @Override public void run() { antiBotStatus = AntiBotStatus.LISTENING; } - }, 90 * TICKS_PER_SECOND); + }; + + // Delay the schedule on first start + if(startup) { + bukkitService.scheduleSyncDelayedTask(enableTask, delay * TICKS_PER_SECOND); + startup = false; + } else { + enableTask.run(); + } } private void startProtection() { diff --git a/src/main/java/fr/xephi/authme/settings/properties/ProtectionSettings.java b/src/main/java/fr/xephi/authme/settings/properties/ProtectionSettings.java index 5198a0cc2..cdd760bd2 100644 --- a/src/main/java/fr/xephi/authme/settings/properties/ProtectionSettings.java +++ b/src/main/java/fr/xephi/authme/settings/properties/ProtectionSettings.java @@ -42,6 +42,10 @@ public class ProtectionSettings implements SettingsHolder { public static final Property ANTIBOT_DURATION = newProperty("Protection.antiBotDuration", 10); + @Comment("Delay in seconds before the antibot activation") + public static final Property ANTIBOT_DELAY = + newProperty("Protection.antiBotDelay", 60); + private ProtectionSettings() { } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 7516890af..2dc4bb008 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -435,6 +435,8 @@ Protection: antiBotSensibility: 10 # Duration in minutes of the antibot automatic system antiBotDuration: 10 + # Delay in seconds before the antibot activation + antiBotDelay: 60 GroupOptions: # Registered permission group RegisteredPlayerGroup: '' From 4b2ad5135415aa1c7f1f2b357dfd487ad98f5c99 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Wed, 5 Oct 2016 22:45:26 +0200 Subject: [PATCH 17/18] #970 Fix & write unit tests for antibot startup delay config --- .../authme/service/AntiBotServiceTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/java/fr/xephi/authme/service/AntiBotServiceTest.java b/src/test/java/fr/xephi/authme/service/AntiBotServiceTest.java index 7ecba73f6..1ab74ec3e 100644 --- a/src/test/java/fr/xephi/authme/service/AntiBotServiceTest.java +++ b/src/test/java/fr/xephi/authme/service/AntiBotServiceTest.java @@ -11,6 +11,7 @@ import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.ProtectionSettings; import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitTask; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -22,6 +23,8 @@ import static fr.xephi.authme.TestHelper.runSyncDelayedTaskWithDelay; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; import static org.mockito.BDDMockito.given; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyLong; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.only; import static org.mockito.Mockito.reset; @@ -51,6 +54,7 @@ public class AntiBotServiceTest { given(settings.getProperty(ProtectionSettings.ANTIBOT_DURATION)).willReturn(10); given(settings.getProperty(ProtectionSettings.ANTIBOT_SENSIBILITY)).willReturn(5); given(settings.getProperty(ProtectionSettings.ENABLE_ANTIBOT)).willReturn(true); + given(settings.getProperty(ProtectionSettings.ANTIBOT_DELAY)).willReturn(8); } @Test @@ -204,6 +208,20 @@ public class AntiBotServiceTest { verify(messages, only()).send(players.get(1), MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE); } + @Test + public void shouldImmediatelyStartAfterFirstStartup() { + // given - listening antibot + runSyncDelayedTaskWithDelay(bukkitService); + given(bukkitService.runTaskLater(any(Runnable.class), anyLong())).willReturn(mock(BukkitTask.class)); + antiBotService.overrideAntiBotStatus(true); + + // when + antiBotService.reload(settings); + + // then + assertThat(antiBotService.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.LISTENING)); + } + private static int getAntiBotCount(AntiBotService antiBotService) { return ReflectionTestUtils.getFieldValue(AntiBotService.class, antiBotService, "antibotPlayers"); } From 71f3b863837ac9f20ea33d15a79d8ad01d6a0f2e Mon Sep 17 00:00:00 2001 From: ljacqu Date: Thu, 6 Oct 2016 20:29:50 +0200 Subject: [PATCH 18/18] Minor - fix checkTestMocks task and rename PlayerDataTaskManager - Fix tool task to scan test folder - Rename PlayerDataTaskManager to LimboPlayerTaskManager to match its test class --- .../authme/process/join/AsynchronousJoin.java | 8 ++++---- .../process/login/AsynchronousLogin.java | 6 +++--- .../ProcessSynchronousPlayerLogout.java | 8 ++++---- .../register/ProcessSyncEmailRegister.java | 8 ++++---- .../register/ProcessSyncPasswordRegister.java | 8 ++++---- .../unregister/AsynchronousUnregister.java | 8 ++++---- ...nager.java => LimboPlayerTaskManager.java} | 4 ++-- .../process/login/AsynchronousLoginTest.java | 4 ++-- .../AsynchronousUnregisterTest.java | 8 ++++---- .../task/LimboPlayerTaskManagerTest.java | 20 +++++++++---------- .../tools/checktestmocks/CheckTestMocks.java | 2 +- 11 files changed, 42 insertions(+), 42 deletions(-) rename src/main/java/fr/xephi/authme/task/{PlayerDataTaskManager.java => LimboPlayerTaskManager.java} (98%) diff --git a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java index de2762486..5ea7ebcba 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java @@ -19,7 +19,7 @@ import fr.xephi.authme.settings.properties.HooksSettings; 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.task.PlayerDataTaskManager; +import fr.xephi.authme.task.LimboPlayerTaskManager; import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.util.PlayerUtils; import org.apache.commons.lang.reflect.MethodUtils; @@ -67,7 +67,7 @@ public class AsynchronousJoin implements AsynchronousProcess { private BukkitService bukkitService; @Inject - private PlayerDataTaskManager playerDataTaskManager; + private LimboPlayerTaskManager limboPlayerTaskManager; @Inject private AsynchronousLogin asynchronousLogin; @@ -185,8 +185,8 @@ public class AsynchronousJoin implements AsynchronousProcess { }); // Timeout and message task - playerDataTaskManager.registerTimeoutTask(player); - playerDataTaskManager.registerMessageTask(name, isAuthAvailable); + limboPlayerTaskManager.registerTimeoutTask(player); + limboPlayerTaskManager.registerMessageTask(name, isAuthAvailable); } private boolean isPlayerUnrestricted(String name) { diff --git a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java index 6fe3ac960..ee91971b7 100644 --- a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java @@ -24,7 +24,7 @@ import fr.xephi.authme.settings.properties.EmailSettings; import fr.xephi.authme.settings.properties.HooksSettings; import fr.xephi.authme.settings.properties.PluginSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; -import fr.xephi.authme.task.PlayerDataTaskManager; +import fr.xephi.authme.task.LimboPlayerTaskManager; import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.util.PlayerUtils; import fr.xephi.authme.util.StringUtils; @@ -71,7 +71,7 @@ public class AsynchronousLogin implements AsynchronousProcess { private TempbanManager tempbanManager; @Inject - private PlayerDataTaskManager playerDataTaskManager; + private LimboPlayerTaskManager limboPlayerTaskManager; AsynchronousLogin() { } @@ -120,7 +120,7 @@ public class AsynchronousLogin implements AsynchronousProcess { service.send(player, MessageKey.USER_NOT_REGISTERED); // Recreate the message task to immediately send the message again as response // and to make sure we send the right register message (password vs. email registration) - playerDataTaskManager.registerMessageTask(name, false); + limboPlayerTaskManager.registerMessageTask(name, false); return null; } diff --git a/src/main/java/fr/xephi/authme/process/logout/ProcessSynchronousPlayerLogout.java b/src/main/java/fr/xephi/authme/process/logout/ProcessSynchronousPlayerLogout.java index 157e2a44e..72ff935e0 100644 --- a/src/main/java/fr/xephi/authme/process/logout/ProcessSynchronousPlayerLogout.java +++ b/src/main/java/fr/xephi/authme/process/logout/ProcessSynchronousPlayerLogout.java @@ -10,7 +10,7 @@ import fr.xephi.authme.process.ProcessService; import fr.xephi.authme.process.SynchronousProcess; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; -import fr.xephi.authme.task.PlayerDataTaskManager; +import fr.xephi.authme.task.LimboPlayerTaskManager; import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.service.TeleportationService; import org.bukkit.entity.Player; @@ -34,7 +34,7 @@ public class ProcessSynchronousPlayerLogout implements SynchronousProcess { private ProtocolLibService protocolLibService; @Inject - private PlayerDataTaskManager playerDataTaskManager; + private LimboPlayerTaskManager limboPlayerTaskManager; @Inject private SessionManager sessionManager; @@ -53,8 +53,8 @@ public class ProcessSynchronousPlayerLogout implements SynchronousProcess { protocolLibService.sendBlankInventoryPacket(player); } - playerDataTaskManager.registerTimeoutTask(player); - playerDataTaskManager.registerMessageTask(name, true); + limboPlayerTaskManager.registerTimeoutTask(player); + limboPlayerTaskManager.registerMessageTask(name, true); applyLogoutEffect(player); diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java index 1ea421148..de77a17d0 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java @@ -6,7 +6,7 @@ import fr.xephi.authme.permission.AuthGroupType; import fr.xephi.authme.process.ProcessService; import fr.xephi.authme.process.SynchronousProcess; import fr.xephi.authme.settings.properties.HooksSettings; -import fr.xephi.authme.task.PlayerDataTaskManager; +import fr.xephi.authme.task.LimboPlayerTaskManager; import fr.xephi.authme.util.PlayerUtils; import org.bukkit.entity.Player; @@ -19,7 +19,7 @@ public class ProcessSyncEmailRegister implements SynchronousProcess { private ProcessService service; @Inject - private PlayerDataTaskManager playerDataTaskManager; + private LimboPlayerTaskManager limboPlayerTaskManager; ProcessSyncEmailRegister() { } @@ -31,8 +31,8 @@ public class ProcessSyncEmailRegister implements SynchronousProcess { } service.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED); - playerDataTaskManager.registerTimeoutTask(player); - playerDataTaskManager.registerMessageTask(name, true); + limboPlayerTaskManager.registerTimeoutTask(player); + limboPlayerTaskManager.registerMessageTask(name, true); player.saveData(); ConsoleLogger.fine(player.getName() + " registered " + PlayerUtils.getPlayerIp(player)); diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java index eb2e5f5c7..cc190a3c5 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java @@ -10,7 +10,7 @@ import fr.xephi.authme.service.BungeeService; import fr.xephi.authme.settings.properties.EmailSettings; import fr.xephi.authme.settings.properties.HooksSettings; import fr.xephi.authme.settings.properties.RegistrationSettings; -import fr.xephi.authme.task.PlayerDataTaskManager; +import fr.xephi.authme.task.LimboPlayerTaskManager; import fr.xephi.authme.util.PlayerUtils; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -31,7 +31,7 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess { private LimboCache limboCache; @Inject - private PlayerDataTaskManager playerDataTaskManager; + private LimboPlayerTaskManager limboPlayerTaskManager; ProcessSyncPasswordRegister() { } @@ -54,8 +54,8 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess { private void requestLogin(Player player) { final String name = player.getName().toLowerCase(); limboCache.updatePlayerData(player); - playerDataTaskManager.registerTimeoutTask(player); - playerDataTaskManager.registerMessageTask(name, true); + limboPlayerTaskManager.registerTimeoutTask(player); + limboPlayerTaskManager.registerMessageTask(name, true); if (player.isInsideVehicle() && player.getVehicle() != null) { player.getVehicle().eject(); diff --git a/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java b/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java index 142ff6064..7d63d0555 100644 --- a/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java +++ b/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java @@ -13,7 +13,7 @@ import fr.xephi.authme.process.ProcessService; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; -import fr.xephi.authme.task.PlayerDataTaskManager; +import fr.xephi.authme.task.LimboPlayerTaskManager; import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.service.TeleportationService; import org.bukkit.command.CommandSender; @@ -46,7 +46,7 @@ public class AsynchronousUnregister implements AsynchronousProcess { private LimboCache limboCache; @Inject - private PlayerDataTaskManager playerDataTaskManager; + private LimboPlayerTaskManager limboPlayerTaskManager; @Inject private TeleportationService teleportationService; @@ -114,8 +114,8 @@ public class AsynchronousUnregister implements AsynchronousProcess { limboCache.deletePlayerData(player); limboCache.addPlayerData(player); - playerDataTaskManager.registerTimeoutTask(player); - playerDataTaskManager.registerMessageTask(name, false); + limboPlayerTaskManager.registerTimeoutTask(player); + limboPlayerTaskManager.registerMessageTask(name, false); applyBlindEffect(player); } authGroupHandler.setGroup(player, AuthGroupType.UNREGISTERED); diff --git a/src/main/java/fr/xephi/authme/task/PlayerDataTaskManager.java b/src/main/java/fr/xephi/authme/task/LimboPlayerTaskManager.java similarity index 98% rename from src/main/java/fr/xephi/authme/task/PlayerDataTaskManager.java rename to src/main/java/fr/xephi/authme/task/LimboPlayerTaskManager.java index af96adc4d..74b14005a 100644 --- a/src/main/java/fr/xephi/authme/task/PlayerDataTaskManager.java +++ b/src/main/java/fr/xephi/authme/task/LimboPlayerTaskManager.java @@ -20,7 +20,7 @@ import static fr.xephi.authme.service.BukkitService.TICKS_PER_SECOND; /** * Registers tasks associated with a PlayerData. */ -public class PlayerDataTaskManager { +public class LimboPlayerTaskManager { @Inject private Messages messages; @@ -37,7 +37,7 @@ public class PlayerDataTaskManager { @Inject private PlayerCache playerCache; - PlayerDataTaskManager() { + LimboPlayerTaskManager() { } diff --git a/src/test/java/fr/xephi/authme/process/login/AsynchronousLoginTest.java b/src/test/java/fr/xephi/authme/process/login/AsynchronousLoginTest.java index 0644687cf..27582a59f 100644 --- a/src/test/java/fr/xephi/authme/process/login/AsynchronousLoginTest.java +++ b/src/test/java/fr/xephi/authme/process/login/AsynchronousLoginTest.java @@ -13,7 +13,7 @@ import fr.xephi.authme.settings.properties.DatabaseSettings; import fr.xephi.authme.settings.properties.HooksSettings; import fr.xephi.authme.settings.properties.PluginSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; -import fr.xephi.authme.task.PlayerDataTaskManager; +import fr.xephi.authme.task.LimboPlayerTaskManager; import fr.xephi.authme.service.BukkitService; import org.bukkit.entity.Player; import org.junit.BeforeClass; @@ -58,7 +58,7 @@ public class AsynchronousLoginTest { @Mock private ProcessService processService; @Mock - private PlayerDataTaskManager playerDataTaskManager; + private LimboPlayerTaskManager limboPlayerTaskManager; @Mock private BukkitService bukkitService; @Mock diff --git a/src/test/java/fr/xephi/authme/process/unregister/AsynchronousUnregisterTest.java b/src/test/java/fr/xephi/authme/process/unregister/AsynchronousUnregisterTest.java index a3abe4b8e..318b782a7 100644 --- a/src/test/java/fr/xephi/authme/process/unregister/AsynchronousUnregisterTest.java +++ b/src/test/java/fr/xephi/authme/process/unregister/AsynchronousUnregisterTest.java @@ -13,7 +13,7 @@ import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; -import fr.xephi.authme.task.PlayerDataTaskManager; +import fr.xephi.authme.task.LimboPlayerTaskManager; import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.service.TeleportationService; import org.bukkit.command.CommandSender; @@ -55,7 +55,7 @@ public class AsynchronousUnregisterTest { @Mock private LimboCache limboCache; @Mock - private PlayerDataTaskManager playerDataTaskManager; + private LimboPlayerTaskManager limboPlayerTaskManager; @Mock private TeleportationService teleportationService; @Mock @@ -85,7 +85,7 @@ public class AsynchronousUnregisterTest { // then verify(service).send(player, MessageKey.WRONG_PASSWORD); verify(passwordSecurity).comparePassword(userPassword, password, name); - verifyZeroInteractions(dataSource, playerDataTaskManager, limboCache, authGroupHandler, teleportationService); + verifyZeroInteractions(dataSource, limboPlayerTaskManager, limboCache, authGroupHandler, teleportationService); verify(player, only()).getName(); } @@ -175,7 +175,7 @@ public class AsynchronousUnregisterTest { verify(dataSource).removeAuth(name); verify(playerCache).removePlayer(name); verify(authGroupHandler).setGroup(player, AuthGroupType.UNREGISTERED); - verifyZeroInteractions(teleportationService, playerDataTaskManager); + verifyZeroInteractions(teleportationService, limboPlayerTaskManager); verify(bukkitService, never()).runTask(any(Runnable.class)); } diff --git a/src/test/java/fr/xephi/authme/task/LimboPlayerTaskManagerTest.java b/src/test/java/fr/xephi/authme/task/LimboPlayerTaskManagerTest.java index dbff584e8..7a2f9eebc 100644 --- a/src/test/java/fr/xephi/authme/task/LimboPlayerTaskManagerTest.java +++ b/src/test/java/fr/xephi/authme/task/LimboPlayerTaskManagerTest.java @@ -28,13 +28,13 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; /** - * Test for {@link PlayerDataTaskManager}. + * Test for {@link LimboPlayerTaskManager}. */ @RunWith(MockitoJUnitRunner.class) public class LimboPlayerTaskManagerTest { @InjectMocks - private PlayerDataTaskManager playerDataTaskManager; + private LimboPlayerTaskManager limboPlayerTaskManager; @Mock private Messages messages; @@ -70,7 +70,7 @@ public class LimboPlayerTaskManagerTest { given(settings.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true); // when - playerDataTaskManager.registerMessageTask(name, false); + limboPlayerTaskManager.registerMessageTask(name, false); // then verify(limboPlayer).setMessageTask(bukkiTask); @@ -85,7 +85,7 @@ public class LimboPlayerTaskManagerTest { given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(5); // when - playerDataTaskManager.registerMessageTask(name, true); + limboPlayerTaskManager.registerMessageTask(name, true); // then verify(limboCache).getPlayerData(name); @@ -104,7 +104,7 @@ public class LimboPlayerTaskManagerTest { given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(0); // when - playerDataTaskManager.registerMessageTask(name, true); + limboPlayerTaskManager.registerMessageTask(name, true); // then verifyZeroInteractions(limboPlayer, bukkitService); @@ -128,7 +128,7 @@ public class LimboPlayerTaskManagerTest { given(settings.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true); // when - playerDataTaskManager.registerMessageTask(name, false); + limboPlayerTaskManager.registerMessageTask(name, false); // then verify(limboPlayer).setMessageTask(bukkiTask); @@ -149,7 +149,7 @@ public class LimboPlayerTaskManagerTest { given(bukkitService.runTaskLater(any(TimeoutTask.class), anyLong())).willReturn(bukkitTask); // when - playerDataTaskManager.registerTimeoutTask(player); + limboPlayerTaskManager.registerTimeoutTask(player); // then verify(limboPlayer).setTimeoutTask(bukkitTask); @@ -167,7 +167,7 @@ public class LimboPlayerTaskManagerTest { given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(27); // when - playerDataTaskManager.registerTimeoutTask(player); + limboPlayerTaskManager.registerTimeoutTask(player); // then verifyZeroInteractions(bukkitService, messages); @@ -184,7 +184,7 @@ public class LimboPlayerTaskManagerTest { given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(0); // when - playerDataTaskManager.registerTimeoutTask(player); + limboPlayerTaskManager.registerTimeoutTask(player); // then verifyZeroInteractions(limboPlayer, bukkitService); @@ -205,7 +205,7 @@ public class LimboPlayerTaskManagerTest { given(bukkitService.runTaskLater(any(TimeoutTask.class), anyLong())).willReturn(bukkitTask); // when - playerDataTaskManager.registerTimeoutTask(player); + limboPlayerTaskManager.registerTimeoutTask(player); // then verify(existingTask).cancel(); diff --git a/src/test/java/tools/checktestmocks/CheckTestMocks.java b/src/test/java/tools/checktestmocks/CheckTestMocks.java index b6d79c07a..def4e822f 100644 --- a/src/test/java/tools/checktestmocks/CheckTestMocks.java +++ b/src/test/java/tools/checktestmocks/CheckTestMocks.java @@ -36,7 +36,7 @@ public class CheckTestMocks implements AutoToolTask { @Override public void executeDefault() { - ClassCollector collector = new ClassCollector(TestHelper.SOURCES_FOLDER, TestHelper.PROJECT_ROOT); + ClassCollector collector = new ClassCollector(TestHelper.TEST_SOURCES_FOLDER, TestHelper.PROJECT_ROOT); for (Class clazz : collector.collectClasses(c -> isTestClassWithMocks(c))) { checkClass(clazz); }