From 7b5a857f744159d0b0fbf0feb7a0d4fd9091c793 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Fri, 7 Oct 2016 19:19:12 +0200 Subject: [PATCH 1/7] Remove useless packages --- src/main/java/fr/xephi/authme/AuthMe.java | 8 +-- src/main/java/fr/xephi/authme/api/API.java | 10 +-- src/main/java/fr/xephi/authme/api/NewAPI.java | 10 +-- .../initialization/OnShutdownPlayerSaver.java | 6 +- .../authme/listener/ListenerService.java | 10 +-- .../xephi/authme/listener/ServerListener.java | 16 ++--- .../authme/process/join/AsynchronousJoin.java | 8 +-- .../GeoIpService.java} | 8 +-- .../PluginHookService.java} | 6 +- .../authme/service/ValidationService.java | 5 +- .../fr/xephi/authme/settings/SpawnLoader.java | 14 ++-- .../authme/task/purge/PurgeExecutor.java | 6 +- .../java/fr/xephi/authme/api/NewAPITest.java | 6 +- .../authme/listener/ListenerServiceTest.java | 10 +-- .../authme/listener/ServerListenerTest.java | 20 +++--- .../GeoIpServiceTest.java} | 19 ++--- .../PluginHookServiceTest.java} | 69 ++++++++++--------- .../authme/service/ValidationServiceTest.java | 21 +++--- .../authme/settings/SpawnLoaderTest.java | 4 +- 19 files changed, 128 insertions(+), 128 deletions(-) rename src/main/java/fr/xephi/authme/{geoip/GeoIpManager.java => service/GeoIpService.java} (96%) rename src/main/java/fr/xephi/authme/{hooks/PluginHooks.java => service/PluginHookService.java} (97%) rename src/test/java/fr/xephi/authme/{geoip/GeoIpManagerTest.java => service/GeoIpServiceTest.java} (83%) rename src/test/java/fr/xephi/authme/{hooks/PluginHooksTest.java => service/PluginHookServiceTest.java} (73%) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index eaee0347d..04922d4a9 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -26,6 +26,7 @@ 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.service.GeoIpService; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.PluginSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; @@ -33,7 +34,6 @@ 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.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 GeoIpService geoIpService; 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); + geoIpService = injector.getSingleton(GeoIpService.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}", geoIpService.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 8073cf632..7fa027882 100644 --- a/src/main/java/fr/xephi/authme/api/API.java +++ b/src/main/java/fr/xephi/authme/api/API.java @@ -4,7 +4,7 @@ import fr.xephi.authme.AuthMe; 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.service.PluginHookService; import fr.xephi.authme.process.Management; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.crypts.HashedPassword; @@ -28,7 +28,7 @@ public class API { private static DataSource dataSource; private static PasswordSecurity passwordSecurity; private static Management management; - private static PluginHooks pluginHooks; + private static PluginHookService pluginHookService; private static ValidationService validationService; /* @@ -36,12 +36,12 @@ public class API { */ @Inject API(AuthMe instance, DataSource dataSource, PasswordSecurity passwordSecurity, Management management, - PluginHooks pluginHooks, ValidationService validationService) { + PluginHookService pluginHookService, ValidationService validationService) { API.instance = instance; API.dataSource = dataSource; API.passwordSecurity = passwordSecurity; API.management = management; - API.pluginHooks = pluginHooks; + API.pluginHookService = pluginHookService; API.validationService = validationService; } @@ -171,7 +171,7 @@ public class API { * @return true if player is an npc */ public boolean isNPC(Player player) { - return pluginHooks.isNpc(player); + return pluginHookService.isNpc(player); } } diff --git a/src/main/java/fr/xephi/authme/api/NewAPI.java b/src/main/java/fr/xephi/authme/api/NewAPI.java index d42d765d0..5805e4afd 100644 --- a/src/main/java/fr/xephi/authme/api/NewAPI.java +++ b/src/main/java/fr/xephi/authme/api/NewAPI.java @@ -4,7 +4,7 @@ import fr.xephi.authme.AuthMe; 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.service.PluginHookService; import fr.xephi.authme.process.Management; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.crypts.HashedPassword; @@ -27,7 +27,7 @@ public class NewAPI { public static NewAPI singleton; public final AuthMe plugin; - private final PluginHooks pluginHooks; + private final PluginHookService pluginHookService; private final DataSource dataSource; private final PasswordSecurity passwordSecurity; private final Management management; @@ -38,10 +38,10 @@ public class NewAPI { * Constructor for NewAPI. */ @Inject - NewAPI(AuthMe plugin, PluginHooks pluginHooks, DataSource dataSource, PasswordSecurity passwordSecurity, + NewAPI(AuthMe plugin, PluginHookService pluginHookService, DataSource dataSource, PasswordSecurity passwordSecurity, Management management, ValidationService validationService, PlayerCache playerCache) { this.plugin = plugin; - this.pluginHooks = pluginHooks; + this.pluginHookService = pluginHookService; this.dataSource = dataSource; this.passwordSecurity = passwordSecurity; this.management = management; @@ -100,7 +100,7 @@ public class NewAPI { * @return true if the player is an npc */ public boolean isNPC(Player player) { - return pluginHooks.isNpc(player); + return pluginHookService.isNpc(player); } /** diff --git a/src/main/java/fr/xephi/authme/initialization/OnShutdownPlayerSaver.java b/src/main/java/fr/xephi/authme/initialization/OnShutdownPlayerSaver.java index 079fc76a2..6141e47ef 100644 --- a/src/main/java/fr/xephi/authme/initialization/OnShutdownPlayerSaver.java +++ b/src/main/java/fr/xephi/authme/initialization/OnShutdownPlayerSaver.java @@ -5,7 +5,7 @@ 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.service.PluginHookService; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.SpawnLoader; import fr.xephi.authme.settings.properties.RestrictionSettings; @@ -36,7 +36,7 @@ public class OnShutdownPlayerSaver { @Inject private SpawnLoader spawnLoader; @Inject - private PluginHooks pluginHooks; + private PluginHookService pluginHookService; @Inject private PlayerCache playerCache; @@ -54,7 +54,7 @@ public class OnShutdownPlayerSaver { private void savePlayer(Player player) { final String name = player.getName().toLowerCase(); - if (pluginHooks.isNpc(player) || validationService.isUnrestricted(name)) { + if (pluginHookService.isNpc(player) || validationService.isUnrestricted(name)) { return; } if (limboCache.hasPlayerData(name)) { diff --git a/src/main/java/fr/xephi/authme/listener/ListenerService.java b/src/main/java/fr/xephi/authme/listener/ListenerService.java index 279bfd6c2..03928bf5d 100644 --- a/src/main/java/fr/xephi/authme/listener/ListenerService.java +++ b/src/main/java/fr/xephi/authme/listener/ListenerService.java @@ -2,7 +2,7 @@ package fr.xephi.authme.listener; import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.hooks.PluginHooks; +import fr.xephi.authme.service.PluginHookService; import fr.xephi.authme.initialization.SettingsDependent; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.RegistrationSettings; @@ -20,17 +20,17 @@ import javax.inject.Inject; class ListenerService implements SettingsDependent { private final DataSource dataSource; - private final PluginHooks pluginHooks; + private final PluginHookService pluginHookService; private final PlayerCache playerCache; private final ValidationService validationService; private boolean isRegistrationForced; @Inject - ListenerService(Settings settings, DataSource dataSource, PluginHooks pluginHooks, + ListenerService(Settings settings, DataSource dataSource, PluginHookService pluginHookService, PlayerCache playerCache, ValidationService validationService) { this.dataSource = dataSource; - this.pluginHooks = pluginHooks; + this.pluginHookService = pluginHookService; this.playerCache = playerCache; this.validationService = validationService; reload(settings); @@ -79,7 +79,7 @@ class ListenerService implements SettingsDependent { * @return true if the associated event should be canceled, false otherwise */ public boolean shouldCancelEvent(Player player) { - return player != null && !checkAuth(player.getName()) && !pluginHooks.isNpc(player); + return player != null && !checkAuth(player.getName()) && !pluginHookService.isNpc(player); } @Override diff --git a/src/main/java/fr/xephi/authme/listener/ServerListener.java b/src/main/java/fr/xephi/authme/listener/ServerListener.java index e3cbb813a..909ab4f26 100644 --- a/src/main/java/fr/xephi/authme/listener/ServerListener.java +++ b/src/main/java/fr/xephi/authme/listener/ServerListener.java @@ -1,7 +1,7 @@ package fr.xephi.authme.listener; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.hooks.PluginHooks; +import fr.xephi.authme.service.PluginHookService; import fr.xephi.authme.listener.protocollib.ProtocolLibService; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.settings.SpawnLoader; @@ -17,7 +17,7 @@ import javax.inject.Inject; public class ServerListener implements Listener { @Inject - private PluginHooks pluginHooks; + private PluginHookService pluginHookService; @Inject private SpawnLoader spawnLoader; @Inject @@ -38,13 +38,13 @@ public class ServerListener implements Listener { permissionsManager.onPluginDisable(pluginName); if ("Essentials".equalsIgnoreCase(pluginName)) { - pluginHooks.unhookEssentials(); + pluginHookService.unhookEssentials(); ConsoleLogger.info("Essentials has been disabled: unhooking"); } else if ("Multiverse-Core".equalsIgnoreCase(pluginName)) { - pluginHooks.unhookMultiverse(); + pluginHookService.unhookMultiverse(); ConsoleLogger.info("Multiverse-Core has been disabled: unhooking"); } else if ("CombatTagPlus".equalsIgnoreCase(pluginName)) { - pluginHooks.unhookCombatPlus(); + pluginHookService.unhookCombatPlus(); ConsoleLogger.info("CombatTagPlus has been disabled: unhooking"); } else if ("EssentialsSpawn".equalsIgnoreCase(pluginName)) { spawnLoader.unloadEssentialsSpawn(); @@ -68,11 +68,11 @@ public class ServerListener implements Listener { permissionsManager.onPluginEnable(pluginName); if ("Essentials".equalsIgnoreCase(pluginName)) { - pluginHooks.tryHookToEssentials(); + pluginHookService.tryHookToEssentials(); } else if ("Multiverse-Core".equalsIgnoreCase(pluginName)) { - pluginHooks.tryHookToMultiverse(); + pluginHookService.tryHookToMultiverse(); } else if ("CombatTagPlus".equalsIgnoreCase(pluginName)) { - pluginHooks.tryHookToCombatPlus(); + pluginHookService.tryHookToCombatPlus(); } else if ("EssentialsSpawn".equalsIgnoreCase(pluginName)) { spawnLoader.loadEssentialsSpawn(); } else if ("ProtocolLib".equalsIgnoreCase(pluginName)) { 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 5ea7ebcba..89e7a671e 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java @@ -8,7 +8,7 @@ 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.service.PluginHookService; import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.permission.AuthGroupType; import fr.xephi.authme.permission.PlayerStatePermission; @@ -61,7 +61,7 @@ public class AsynchronousJoin implements AsynchronousProcess { private SessionManager sessionManager; @Inject - private PluginHooks pluginHooks; + private PluginHookService pluginHookService; @Inject private BukkitService bukkitService; @@ -95,7 +95,7 @@ public class AsynchronousJoin implements AsynchronousProcess { } if (service.getProperty(HooksSettings.DISABLE_SOCIAL_SPY)) { - pluginHooks.setEssentialsSocialSpyStatus(player, false); + pluginHookService.setEssentialsSocialSpyStatus(player, false); } if (isNameRestricted(name, ip, player.getAddress().getHostName())) { @@ -172,7 +172,7 @@ public class AsynchronousJoin implements AsynchronousProcess { player.setWalkSpeed(0.0f); } player.setNoDamageTicks(registrationTimeout); - if (pluginHooks.isEssentialsAvailable() && service.getProperty(HooksSettings.USE_ESSENTIALS_MOTD)) { + if (pluginHookService.isEssentialsAvailable() && service.getProperty(HooksSettings.USE_ESSENTIALS_MOTD)) { player.performCommand("motd"); } if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) { diff --git a/src/main/java/fr/xephi/authme/geoip/GeoIpManager.java b/src/main/java/fr/xephi/authme/service/GeoIpService.java similarity index 96% rename from src/main/java/fr/xephi/authme/geoip/GeoIpManager.java rename to src/main/java/fr/xephi/authme/service/GeoIpService.java index bd397a97c..f1335c7df 100644 --- a/src/main/java/fr/xephi/authme/geoip/GeoIpManager.java +++ b/src/main/java/fr/xephi/authme/service/GeoIpService.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.geoip; +package fr.xephi.authme.service; import com.google.common.annotations.VisibleForTesting; import com.maxmind.geoip.LookupService; @@ -17,7 +17,7 @@ import java.net.URLConnection; import java.util.concurrent.TimeUnit; import java.util.zip.GZIPInputStream; -public class GeoIpManager { +public class GeoIpService { 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) { + GeoIpService(@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) { + GeoIpService(@DataFolder File dataFolder, LookupService lookupService) { this.dataFile = dataFolder; this.lookupService = lookupService; } diff --git a/src/main/java/fr/xephi/authme/hooks/PluginHooks.java b/src/main/java/fr/xephi/authme/service/PluginHookService.java similarity index 97% rename from src/main/java/fr/xephi/authme/hooks/PluginHooks.java rename to src/main/java/fr/xephi/authme/service/PluginHookService.java index f3a066e19..9ebcd712a 100644 --- a/src/main/java/fr/xephi/authme/hooks/PluginHooks.java +++ b/src/main/java/fr/xephi/authme/service/PluginHookService.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.hooks; +package fr.xephi.authme.service; import ch.jalu.injector.annotations.NoFieldScan; import com.earth2me.essentials.Essentials; @@ -19,7 +19,7 @@ import java.io.File; * Hooks into third-party plugins and allows to perform actions on them. */ @NoFieldScan -public class PluginHooks { +public class PluginHookService { private final PluginManager pluginManager; private Essentials essentials; @@ -32,7 +32,7 @@ public class PluginHooks { * @param pluginManager The server's plugin manager */ @Inject - public PluginHooks(PluginManager pluginManager) { + public PluginHookService(PluginManager pluginManager) { this.pluginManager = pluginManager; tryHookToCombatPlus(); tryHookToEssentials(); diff --git a/src/main/java/fr/xephi/authme/service/ValidationService.java b/src/main/java/fr/xephi/authme/service/ValidationService.java index 030657ce5..e3a69fc94 100644 --- a/src/main/java/fr/xephi/authme/service/ValidationService.java +++ b/src/main/java/fr/xephi/authme/service/ValidationService.java @@ -2,7 +2,6 @@ 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.initialization.Reloadable; import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.permission.PermissionsManager; @@ -36,7 +35,7 @@ public class ValidationService implements Reloadable { @Inject private PermissionsManager permissionsManager; @Inject - private GeoIpManager geoIpManager; + private GeoIpService geoIpService; private Pattern passwordRegex; private Set unrestrictedNames; @@ -115,7 +114,7 @@ public class ValidationService implements Reloadable { return true; } - String countryCode = geoIpManager.getCountryCode(hostAddress); + String countryCode = geoIpService.getCountryCode(hostAddress); return validateWhitelistAndBlacklist(countryCode, ProtectionSettings.COUNTRIES_WHITELIST, ProtectionSettings.COUNTRIES_BLACKLIST); diff --git a/src/main/java/fr/xephi/authme/settings/SpawnLoader.java b/src/main/java/fr/xephi/authme/settings/SpawnLoader.java index 3345ef8df..b3a06f5eb 100644 --- a/src/main/java/fr/xephi/authme/settings/SpawnLoader.java +++ b/src/main/java/fr/xephi/authme/settings/SpawnLoader.java @@ -2,7 +2,7 @@ package fr.xephi.authme.settings; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.hooks.PluginHooks; +import fr.xephi.authme.service.PluginHookService; import fr.xephi.authme.initialization.DataFolder; import fr.xephi.authme.initialization.Reloadable; import fr.xephi.authme.settings.properties.HooksSettings; @@ -32,7 +32,7 @@ public class SpawnLoader implements Reloadable { private final File authMeConfigurationFile; private final Settings settings; - private final PluginHooks pluginHooks; + private final PluginHookService pluginHookService; private FileConfiguration authMeConfiguration; private String[] spawnPriority; private Location essentialsSpawn; @@ -42,18 +42,18 @@ public class SpawnLoader implements Reloadable { * * @param pluginFolder The AuthMe data folder * @param settings The setting instance - * @param pluginHooks The plugin hooks instance + * @param pluginHookService The plugin hooks instance * @param dataSource The plugin auth database instance */ @Inject - SpawnLoader(@DataFolder File pluginFolder, Settings settings, PluginHooks pluginHooks, + SpawnLoader(@DataFolder File pluginFolder, Settings settings, PluginHookService pluginHookService, DataSource dataSource) { File spawnFile = new File(pluginFolder, "spawn.yml"); // TODO ljacqu 20160312: Check if resource could be copied and handle the case if not FileUtils.copyFileFromResource(spawnFile, "spawn.yml"); this.authMeConfigurationFile = new File(pluginFolder, "spawn.yml"); this.settings = settings; - this.pluginHooks = pluginHooks; + this.pluginHookService = pluginHookService; reload(); } @@ -112,7 +112,7 @@ public class SpawnLoader implements Reloadable { */ public void loadEssentialsSpawn() { // EssentialsSpawn cannot run without Essentials, so it's fine to get the Essentials data folder - File essentialsFolder = pluginHooks.getEssentialsDataFolder(); + File essentialsFolder = pluginHookService.getEssentialsDataFolder(); if (essentialsFolder == null) { return; } @@ -160,7 +160,7 @@ public class SpawnLoader implements Reloadable { break; case "multiverse": if (settings.getProperty(HooksSettings.MULTIVERSE)) { - spawnLoc = pluginHooks.getMultiverseSpawn(world); + spawnLoc = pluginHookService.getMultiverseSpawn(world); } break; case "essentials": 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 43476e750..985630cfa 100644 --- a/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java +++ b/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java @@ -2,7 +2,7 @@ package fr.xephi.authme.task.purge; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.hooks.PluginHooks; +import fr.xephi.authme.service.PluginHookService; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.PurgeSettings; @@ -33,7 +33,7 @@ class PurgeExecutor { private PermissionsManager permissionsManager; @Inject - private PluginHooks pluginHooks; + private PluginHookService pluginHookService; @Inject private BukkitService bukkitService; @@ -172,7 +172,7 @@ class PurgeExecutor { } int i = 0; - File essentialsDataFolder = pluginHooks.getEssentialsDataFolder(); + File essentialsDataFolder = pluginHookService.getEssentialsDataFolder(); if (essentialsDataFolder == null) { ConsoleLogger.info("Cannot purge Essentials: plugin is not loaded"); return; diff --git a/src/test/java/fr/xephi/authme/api/NewAPITest.java b/src/test/java/fr/xephi/authme/api/NewAPITest.java index 64e4c7c85..02dfbec26 100644 --- a/src/test/java/fr/xephi/authme/api/NewAPITest.java +++ b/src/test/java/fr/xephi/authme/api/NewAPITest.java @@ -5,7 +5,7 @@ import fr.xephi.authme.ReflectionTestUtils; 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.service.PluginHookService; import fr.xephi.authme.process.Management; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.service.ValidationService; @@ -46,7 +46,7 @@ public class NewAPITest { @Mock private AuthMe authMe; @Mock - private PluginHooks pluginHooks; + private PluginHookService pluginHookService; @Mock private ValidationService validationService; @Mock @@ -86,7 +86,7 @@ public class NewAPITest { public void shouldReturnIfPlayerIsNpc() { // given Player player = mock(Player.class); - given(pluginHooks.isNpc(player)).willReturn(true); + given(pluginHookService.isNpc(player)).willReturn(true); // when boolean result = api.isNPC(player); diff --git a/src/test/java/fr/xephi/authme/listener/ListenerServiceTest.java b/src/test/java/fr/xephi/authme/listener/ListenerServiceTest.java index bc999c533..15f9e7973 100644 --- a/src/test/java/fr/xephi/authme/listener/ListenerServiceTest.java +++ b/src/test/java/fr/xephi/authme/listener/ListenerServiceTest.java @@ -5,7 +5,7 @@ import ch.jalu.injector.testing.DelayedInjectionRunner; import ch.jalu.injector.testing.InjectDelayed; import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.hooks.PluginHooks; +import fr.xephi.authme.service.PluginHookService; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.service.ValidationService; @@ -41,7 +41,7 @@ public class ListenerServiceTest { private DataSource dataSource; @Mock - private PluginHooks pluginHooks; + private PluginHookService pluginHookService; @Mock private PlayerCache playerCache; @@ -161,14 +161,14 @@ public class ListenerServiceTest { Player player = mockPlayerWithName(playerName); EntityEvent event = mock(EntityEvent.class); given(event.getEntity()).willReturn(player); - given(pluginHooks.isNpc(player)).willReturn(true); + given(pluginHookService.isNpc(player)).willReturn(true); // when boolean result = listenerService.shouldCancelEvent(event); // then assertThat(result, equalTo(false)); - verify(pluginHooks).isNpc(player); + verify(pluginHookService).isNpc(player); } @Test @@ -215,7 +215,7 @@ public class ListenerServiceTest { assertThat(result, equalTo(true)); verify(playerCache).isAuthenticated(playerName); verifyZeroInteractions(dataSource); - verify(pluginHooks).isNpc(player); + verify(pluginHookService).isNpc(player); } private static Player mockPlayerWithName(String name) { diff --git a/src/test/java/fr/xephi/authme/listener/ServerListenerTest.java b/src/test/java/fr/xephi/authme/listener/ServerListenerTest.java index 0c1686a11..266a437ff 100644 --- a/src/test/java/fr/xephi/authme/listener/ServerListenerTest.java +++ b/src/test/java/fr/xephi/authme/listener/ServerListenerTest.java @@ -1,7 +1,7 @@ package fr.xephi.authme.listener; import fr.xephi.authme.TestHelper; -import fr.xephi.authme.hooks.PluginHooks; +import fr.xephi.authme.service.PluginHookService; import fr.xephi.authme.listener.protocollib.ProtocolLibService; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.settings.SpawnLoader; @@ -41,7 +41,7 @@ public class ServerListenerTest { private PermissionsManager permissionsManager; @Mock - private PluginHooks pluginHooks; + private PluginHookService pluginHookService; @Mock private ProtocolLibService protocolLibService; @@ -59,7 +59,7 @@ public class ServerListenerTest { checkEnableHandling(ESSENTIALS, new Runnable() { @Override public void run() { - verify(pluginHooks).tryHookToEssentials(); + verify(pluginHookService).tryHookToEssentials(); } }); checkEnableHandling(ESSENTIALS_SPAWN, new Runnable() { @@ -71,13 +71,13 @@ public class ServerListenerTest { checkEnableHandling(MULTIVERSE, new Runnable() { @Override public void run() { - verify(pluginHooks).tryHookToMultiverse(); + verify(pluginHookService).tryHookToMultiverse(); } }); checkEnableHandling(COMBAT_TAG, new Runnable() { @Override public void run() { - verify(pluginHooks).tryHookToCombatPlus(); + verify(pluginHookService).tryHookToCombatPlus(); } }); checkEnableHandling(PROTOCOL_LIB, new Runnable() { @@ -99,7 +99,7 @@ public class ServerListenerTest { checkDisableHandling(ESSENTIALS, new Runnable() { @Override public void run() { - verify(pluginHooks).unhookEssentials(); + verify(pluginHookService).unhookEssentials(); } }); checkDisableHandling(ESSENTIALS_SPAWN, new Runnable() { @@ -111,13 +111,13 @@ public class ServerListenerTest { checkDisableHandling(MULTIVERSE, new Runnable() { @Override public void run() { - verify(pluginHooks).unhookMultiverse(); + verify(pluginHookService).unhookMultiverse(); } }); checkDisableHandling(COMBAT_TAG, new Runnable() { @Override public void run() { - verify(pluginHooks).unhookCombatPlus(); + verify(pluginHookService).unhookCombatPlus(); } }); checkDisableHandling(PROTOCOL_LIB, new Runnable() { @@ -164,8 +164,8 @@ public class ServerListenerTest { } private void verifyNoMoreInteractionsAndReset() { - verifyNoMoreInteractions(permissionsManager, pluginHooks, protocolLibService, spawnLoader); - reset(permissionsManager, pluginHooks, protocolLibService, spawnLoader); + verifyNoMoreInteractions(permissionsManager, pluginHookService, protocolLibService, spawnLoader); + reset(permissionsManager, pluginHookService, protocolLibService, spawnLoader); } private static T mockEventWithPluginName(Class eventClass, String name) { diff --git a/src/test/java/fr/xephi/authme/geoip/GeoIpManagerTest.java b/src/test/java/fr/xephi/authme/service/GeoIpServiceTest.java similarity index 83% rename from src/test/java/fr/xephi/authme/geoip/GeoIpManagerTest.java rename to src/test/java/fr/xephi/authme/service/GeoIpServiceTest.java index a4d459ca5..5d1d9681f 100644 --- a/src/test/java/fr/xephi/authme/geoip/GeoIpManagerTest.java +++ b/src/test/java/fr/xephi/authme/service/GeoIpServiceTest.java @@ -1,7 +1,8 @@ -package fr.xephi.authme.geoip; +package fr.xephi.authme.service; import com.maxmind.geoip.Country; import com.maxmind.geoip.LookupService; +import fr.xephi.authme.service.GeoIpService; 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 GeoIpService}. */ @RunWith(MockitoJUnitRunner.class) -public class GeoIpManagerTest { +public class GeoIpServiceTest { - private GeoIpManager geoIpManager; + private GeoIpService geoIpService; 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); + geoIpService = new GeoIpService(dataFolder, lookupService); } @Test @@ -51,7 +52,7 @@ public class GeoIpManagerTest { given(lookupService.getCountry(ip)).willReturn(country); // when - String result = geoIpManager.getCountryCode(ip); + String result = geoIpService.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 = geoIpService.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 = geoIpService.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 = geoIpService.getCountryName(ip); // then assertThat(result, equalTo("N/A")); diff --git a/src/test/java/fr/xephi/authme/hooks/PluginHooksTest.java b/src/test/java/fr/xephi/authme/service/PluginHookServiceTest.java similarity index 73% rename from src/test/java/fr/xephi/authme/hooks/PluginHooksTest.java rename to src/test/java/fr/xephi/authme/service/PluginHookServiceTest.java index eef561443..970bcef45 100644 --- a/src/test/java/fr/xephi/authme/hooks/PluginHooksTest.java +++ b/src/test/java/fr/xephi/authme/service/PluginHookServiceTest.java @@ -1,10 +1,11 @@ -package fr.xephi.authme.hooks; +package fr.xephi.authme.service; import com.earth2me.essentials.Essentials; import com.earth2me.essentials.User; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MultiverseWorld; +import fr.xephi.authme.service.PluginHookService; import fr.xephi.authme.ReflectionTestUtils; import fr.xephi.authme.TestHelper; import org.bukkit.Location; @@ -29,9 +30,9 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; /** - * Test for {@link PluginHooks}. + * Test for {@link PluginHookService}. */ -public class PluginHooksTest { +public class PluginHookServiceTest { /** The plugin name of Essentials. */ private static final String ESSENTIALS = "Essentials"; @@ -47,15 +48,15 @@ public class PluginHooksTest { public void shouldHookIntoEssentials() { // given PluginManager pluginManager = mock(PluginManager.class); - PluginHooks pluginHooks = new PluginHooks(pluginManager); + PluginHookService pluginHookService = new PluginHookService(pluginManager); setPluginAvailable(pluginManager, ESSENTIALS, Essentials.class); - assertThat(pluginHooks.isEssentialsAvailable(), equalTo(false)); + assertThat(pluginHookService.isEssentialsAvailable(), equalTo(false)); // when - pluginHooks.tryHookToEssentials(); + pluginHookService.tryHookToEssentials(); // then - assertThat(pluginHooks.isEssentialsAvailable(), equalTo(true)); + assertThat(pluginHookService.isEssentialsAvailable(), equalTo(true)); } // Note ljacqu 20160312: Cannot test with Multiverse or CombatTagPlus because their classes are declared final @@ -67,10 +68,10 @@ public class PluginHooksTest { setPluginAvailable(pluginManager, ESSENTIALS, Essentials.class); // when - PluginHooks pluginHooks = new PluginHooks(pluginManager); + PluginHookService pluginHookService = new PluginHookService(pluginManager); // then - assertThat(pluginHooks.isEssentialsAvailable(), equalTo(true)); + assertThat(pluginHookService.isEssentialsAvailable(), equalTo(true)); } @Test @@ -80,10 +81,10 @@ public class PluginHooksTest { setPluginAvailable(pluginManager, MULTIVERSE, MultiverseCore.class); // when - PluginHooks pluginHooks = new PluginHooks(pluginManager); + PluginHookService pluginHookService = new PluginHookService(pluginManager); // then - assertThat(pluginHooks.isMultiverseAvailable(), equalTo(true)); + assertThat(pluginHookService.isMultiverseAvailable(), equalTo(true)); } @Test @@ -96,10 +97,10 @@ public class PluginHooksTest { PluginManager pluginManager = mock(PluginManager.class); setPluginAvailable(pluginManager, ESSENTIALS, ess); - PluginHooks pluginHooks = new PluginHooks(pluginManager); + PluginHookService pluginHookService = new PluginHookService(pluginManager); // when - File dataFolder = pluginHooks.getEssentialsDataFolder(); + File dataFolder = pluginHookService.getEssentialsDataFolder(); // then assertThat(dataFolder, equalTo(essDataFolder)); @@ -109,10 +110,10 @@ public class PluginHooksTest { public void shouldReturnNullForUnhookedEssentials() { // given PluginManager pluginManager = mock(PluginManager.class); - PluginHooks pluginHooks = new PluginHooks(pluginManager); + PluginHookService pluginHookService = new PluginHookService(pluginManager); // when - File result = pluginHooks.getEssentialsDataFolder(); + File result = pluginHookService.getEssentialsDataFolder(); // then assertThat(result, nullValue()); @@ -129,10 +130,10 @@ public class PluginHooksTest { PluginManager pluginManager = mock(PluginManager.class); setPluginAvailable(pluginManager, ESSENTIALS, ess); - PluginHooks pluginHooks = new PluginHooks(pluginManager); + PluginHookService pluginHookService = new PluginHookService(pluginManager); // when - pluginHooks.setEssentialsSocialSpyStatus(player, true); + pluginHookService.setEssentialsSocialSpyStatus(player, true); // then verify(ess).getUser(player); @@ -142,10 +143,10 @@ public class PluginHooksTest { @Test public void shouldNotDoAnythingForUnhookedEssentials() { // given - PluginHooks pluginHooks = new PluginHooks(mock(PluginManager.class)); + PluginHookService pluginHookService = new PluginHookService(mock(PluginManager.class)); // when/then - pluginHooks.setEssentialsSocialSpyStatus(mock(Player.class), false); + pluginHookService.setEssentialsSocialSpyStatus(mock(Player.class), false); } @Test @@ -154,15 +155,15 @@ public class PluginHooksTest { PluginManager pluginManager = mock(PluginManager.class); setPluginAvailable(pluginManager, ESSENTIALS, Essentials.class); setPluginAvailable(pluginManager, MULTIVERSE, MultiverseCore.class); - PluginHooks pluginHooks = new PluginHooks(pluginManager); + PluginHookService pluginHookService = new PluginHookService(pluginManager); // when - pluginHooks.unhookEssentials(); - pluginHooks.unhookMultiverse(); + pluginHookService.unhookEssentials(); + pluginHookService.unhookMultiverse(); // then - assertThat(pluginHooks.isEssentialsAvailable(), equalTo(false)); - assertThat(pluginHooks.isMultiverseAvailable(), equalTo(false)); + assertThat(pluginHookService.isEssentialsAvailable(), equalTo(false)); + assertThat(pluginHookService.isMultiverseAvailable(), equalTo(false)); } @Test @@ -173,23 +174,23 @@ public class PluginHooksTest { doThrow(IllegalStateException.class).when(pluginManager).getPlugin(anyString()); // when - PluginHooks pluginHooks = new PluginHooks(pluginManager); + PluginHookService pluginHookService = new PluginHookService(pluginManager); // then - assertThat(pluginHooks.isEssentialsAvailable(), equalTo(false)); - assertThat(pluginHooks.isMultiverseAvailable(), equalTo(false)); - assertThat(pluginHooks.isCombatTagPlusAvailable(), equalTo(false)); + assertThat(pluginHookService.isEssentialsAvailable(), equalTo(false)); + assertThat(pluginHookService.isMultiverseAvailable(), equalTo(false)); + assertThat(pluginHookService.isCombatTagPlusAvailable(), equalTo(false)); } @Test public void shouldReturnNullForUnavailableMultiverse() { // given PluginManager pluginManager = mock(PluginManager.class); - PluginHooks pluginHooks = new PluginHooks(pluginManager); + PluginHookService pluginHookService = new PluginHookService(pluginManager); World world = mock(World.class); // when - Location result = pluginHooks.getMultiverseSpawn(world); + Location result = pluginHookService.getMultiverseSpawn(world); // then assertThat(result, nullValue()); @@ -211,10 +212,10 @@ public class PluginHooksTest { PluginManager pluginManager = mock(PluginManager.class); setPluginAvailable(pluginManager, MULTIVERSE, multiverse); - PluginHooks pluginHooks = new PluginHooks(pluginManager); + PluginHookService pluginHookService = new PluginHookService(pluginManager); // when - Location spawn = pluginHooks.getMultiverseSpawn(world); + Location spawn = pluginHookService.getMultiverseSpawn(world); // then assertThat(spawn, equalTo(location)); @@ -234,10 +235,10 @@ public class PluginHooksTest { MultiverseCore multiverse = mock(MultiverseCore.class); setPluginAvailable(pluginManager, MULTIVERSE, multiverse); given(multiverse.getMVWorldManager()).willReturn(mvWorldManager); - PluginHooks pluginHooks = new PluginHooks(pluginManager); + PluginHookService pluginHookService = new PluginHookService(pluginManager); // when - Location spawn = pluginHooks.getMultiverseSpawn(world); + Location spawn = pluginHookService.getMultiverseSpawn(world); // then assertThat(spawn, nullValue()); diff --git a/src/test/java/fr/xephi/authme/service/ValidationServiceTest.java b/src/test/java/fr/xephi/authme/service/ValidationServiceTest.java index 1a1cbbe45..a011d212e 100644 --- a/src/test/java/fr/xephi/authme/service/ValidationServiceTest.java +++ b/src/test/java/fr/xephi/authme/service/ValidationServiceTest.java @@ -5,7 +5,6 @@ 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.message.MessageKey; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerStatePermission; @@ -45,7 +44,7 @@ public class ValidationServiceTest { @Mock private PermissionsManager permissionsManager; @Mock - private GeoIpManager geoIpManager; + private GeoIpService geoIpService; @BeforeInjecting public void createService() { @@ -266,7 +265,7 @@ public class ValidationServiceTest { // then assertThat(result, equalTo(true)); - verifyZeroInteractions(geoIpManager); + verifyZeroInteractions(geoIpService); } @Test @@ -275,14 +274,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(geoIpService.getCountryCode(ip)).willReturn("CH"); // when boolean result = validationService.isCountryAdmitted(ip); // then assertThat(result, equalTo(true)); - verify(geoIpManager).getCountryCode(ip); + verify(geoIpService).getCountryCode(ip); } @Test @@ -291,14 +290,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(geoIpService.getCountryCode(ip)).willReturn("BR"); // when boolean result = validationService.isCountryAdmitted(ip); // then assertThat(result, equalTo(false)); - verify(geoIpManager).getCountryCode(ip); + verify(geoIpService).getCountryCode(ip); } @Test @@ -307,14 +306,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(geoIpService.getCountryCode(ip)).willReturn("BR"); // when boolean result = validationService.isCountryAdmitted(ip); // then assertThat(result, equalTo(true)); - verify(geoIpManager).getCountryCode(ip); + verify(geoIpService).getCountryCode(ip); } @Test @@ -323,14 +322,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(geoIpService.getCountryCode(ip)).willReturn("IT"); // when boolean result = validationService.isCountryAdmitted(ip); // then assertThat(result, equalTo(false)); - verify(geoIpManager).getCountryCode(ip); + verify(geoIpService).getCountryCode(ip); } private static void assertErrorEquals(ValidationResult validationResult, MessageKey messageKey, String... args) { diff --git a/src/test/java/fr/xephi/authme/settings/SpawnLoaderTest.java b/src/test/java/fr/xephi/authme/settings/SpawnLoaderTest.java index 8449b121f..1ca06911a 100644 --- a/src/test/java/fr/xephi/authme/settings/SpawnLoaderTest.java +++ b/src/test/java/fr/xephi/authme/settings/SpawnLoaderTest.java @@ -6,7 +6,7 @@ import ch.jalu.injector.testing.InjectDelayed; import com.google.common.io.Files; import fr.xephi.authme.TestHelper; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.hooks.PluginHooks; +import fr.xephi.authme.service.PluginHookService; import fr.xephi.authme.initialization.DataFolder; import fr.xephi.authme.settings.properties.RestrictionSettings; import org.bukkit.Location; @@ -42,7 +42,7 @@ public class SpawnLoaderTest { private DataSource dataSource; @Mock - private PluginHooks pluginHooks; + private PluginHookService pluginHookService; @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder(); From d235b26ac39a9ee5c1b39ca430b0ed37b26f39d2 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Fri, 7 Oct 2016 19:43:54 +0200 Subject: [PATCH 2/7] Main class cleanup --- src/main/java/fr/xephi/authme/AuthMe.java | 70 ++++++++++------------- 1 file changed, 30 insertions(+), 40 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 04922d4a9..8e9818bf2 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -5,7 +5,6 @@ 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.data.auth.PlayerAuth; import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.command.CommandHandler; import fr.xephi.authme.datasource.DataSource; @@ -47,7 +46,6 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitScheduler; import java.io.File; -import java.util.Date; import static fr.xephi.authme.service.BukkitService.TICKS_PER_MINUTE; import static fr.xephi.authme.util.Utils.isClassLoaded; @@ -134,8 +132,12 @@ public class AuthMe extends JavaPlugin { */ @Override public void onEnable() { + // Load the plugin version data from the plugin description file + loadPluginInfo(); + + // Initialize the plugin try { - initializeServices(); + initialize(); } catch (Exception e) { ConsoleLogger.logException("Aborting initialization of AuthMe:", e); stopOrUnload(); @@ -172,10 +174,27 @@ public class AuthMe extends JavaPlugin { cleanupTask.runTaskTimerAsynchronously(this, CLEANUP_INTERVAL, CLEANUP_INTERVAL); } - private void initializeServices() throws Exception { - // Set the plugin instance and load plugin info from the plugin description. - loadPluginInfo(); + /** + * Load the version and build number of the plugin from the description file. + */ + private void loadPluginInfo() { + String versionRaw = this.getDescription().getVersion(); + int index = versionRaw.lastIndexOf("-"); + if (index != -1) { + pluginVersion = versionRaw.substring(0, index); + pluginBuildNumber = versionRaw.substring(index + 1); + if (pluginBuildNumber.startsWith("b")) { + pluginBuildNumber = pluginBuildNumber.substring(1); + } + } + } + /** + * Initialize the plugin and all the services. + * + * @throws Exception if the initialization fails + */ + private void initialize() throws Exception { // Set the Logger instance and log file path ConsoleLogger.setLogger(getLogger()); ConsoleLogger.setLogFile(new File(getDataFolder(), LOG_FILENAME)); @@ -211,8 +230,11 @@ public class AuthMe extends JavaPlugin { instantiateServices(injector); - // Reload support hook - reloadSupportHook(); + // TODO: does this still make sense? -sgdc3 + // If the server is empty (fresh start) just set all the players as unlogged + if (bukkitService.getOnlinePlayers().size() == 0) { + database.purgeLogged(); + } // Register event listeners registerEventListeners(injector); @@ -221,19 +243,6 @@ public class AuthMe extends JavaPlugin { initializer.scheduleRecallEmailTask(settings, database, messages); } - // Get version and build number of the plugin - private void loadPluginInfo() { - String versionRaw = this.getDescription().getVersion(); - int index = versionRaw.lastIndexOf("-"); - if (index != -1) { - pluginVersion = versionRaw.substring(0, index); - pluginBuildNumber = versionRaw.substring(index + 1); - if (pluginBuildNumber.startsWith("b")) { - pluginBuildNumber = pluginBuildNumber.substring(1); - } - } - } - /** * Instantiates all services. * @@ -315,24 +324,6 @@ public class AuthMe extends JavaPlugin { } } - // TODO: check this, do we really need it? -sgdc3 - private void reloadSupportHook() { - if (database != null) { - int playersOnline = bukkitService.getOnlinePlayers().size(); - if (playersOnline == 0) { - database.purgeLogged(); - } else if (settings.getProperty(SecuritySettings.USE_RELOAD_COMMAND_SUPPORT)) { - for (PlayerAuth auth : database.getLoggedPlayers()) { - if (auth != null) { - auth.setLastLogin(new Date().getTime()); - database.updateSession(auth); - playerCache.addPlayer(auth); - } - } - } - } - } - @Override public void onDisable() { // onDisable is also called when we prematurely abort, so any field may be null @@ -377,7 +368,6 @@ public class AuthMe extends JavaPlugin { .replace("{COUNTRY}", geoIpService.getCountryName(ipAddress)); } - /** * Handle Bukkit commands. * From a2732da0c3f3f5cbf76405acb25a662439f3fb7b Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Fri, 7 Oct 2016 19:51:10 +0200 Subject: [PATCH 3/7] Remove intellij dictionaries useless, just exclude them --- .gitignore | 4 ---- .idea/dictionaries/Tim.xml | 7 ------- 2 files changed, 11 deletions(-) delete mode 100644 .idea/dictionaries/Tim.xml diff --git a/.gitignore b/.gitignore index 607894b51..573eb0612 100644 --- a/.gitignore +++ b/.gitignore @@ -22,10 +22,6 @@ hs_err_pid* # Include the project's code style settings file !.idea/codeStyleSettings.xml -# Include the project's dictionary -!.idea/dictionaries/ -!.idea/dictionaries/* - # File-based project format: *.ipr *.iws diff --git a/.idea/dictionaries/Tim.xml b/.idea/dictionaries/Tim.xml deleted file mode 100644 index 1cd4a23ca..000000000 --- a/.idea/dictionaries/Tim.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - authme - - - From dd9312f581e83c509f74a2c619a48358a7f7f89e Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sat, 8 Oct 2016 00:38:51 +0200 Subject: [PATCH 4/7] Minor improvements in tool tasks - Use java 8 types in UpdateDocsTask - Simplify permissions page writing task to write to the file without any options - Various minor simplifications (Java 8) to avoid casting etc. --- src/test/java/tools/docs/UpdateDocsTask.java | 40 ++++++------------- .../EncryptionMethodInfoGatherer.java | 5 +-- .../permissions/PermissionNodesGatherer.java | 34 ++++------------ .../permissions/PermissionsListWriter.java | 35 +--------------- src/test/java/tools/utils/TagValue.java | 15 ++++++- 5 files changed, 36 insertions(+), 93 deletions(-) diff --git a/src/test/java/tools/docs/UpdateDocsTask.java b/src/test/java/tools/docs/UpdateDocsTask.java index 48624afe0..df051bd61 100644 --- a/src/test/java/tools/docs/UpdateDocsTask.java +++ b/src/test/java/tools/docs/UpdateDocsTask.java @@ -9,14 +9,15 @@ import tools.utils.ToolTask; import java.util.Scanner; import java.util.Set; +import java.util.function.Consumer; /** * Task that runs all tasks which update files in the docs folder. */ public class UpdateDocsTask implements AutoToolTask { - private static final Set> TASKS = ImmutableSet.>of( - CommandPageCreater.class, HashAlgorithmsDescriptionTask.class, PermissionsListWriter.class); + private static final Set> TASKS = ImmutableSet + .of(CommandPageCreater.class, HashAlgorithmsDescriptionTask.class, PermissionsListWriter.class); @Override public String getTaskName() { @@ -25,22 +26,14 @@ public class UpdateDocsTask implements AutoToolTask { @Override public void execute(final Scanner scanner) { - executeTasks(new TaskRunner() { - @Override - public void execute(ToolTask task) { - task.execute(scanner); - } - }); + executeTasks(task -> task.execute(scanner)); } @Override public void executeDefault() { - executeTasks(new TaskRunner() { - @Override - public void execute(ToolTask task) { - if (task instanceof AutoToolTask) { - ((AutoToolTask) task).executeDefault(); - } + executeTasks(task -> { + if (task instanceof AutoToolTask) { + ((AutoToolTask) task).executeDefault(); } }); } @@ -49,24 +42,15 @@ public class UpdateDocsTask implements AutoToolTask { try { return clazz.newInstance(); } catch (IllegalAccessException | InstantiationException e) { - throw new UnsupportedOperationException(e); + throw new UnsupportedOperationException("Could not instantiate task class '" + clazz + "'", e); } } - private static void executeTasks(TaskRunner runner) { + private static void executeTasks(Consumer taskRunner) { for (Class taskClass : TASKS) { - try { - ToolTask task = instantiateTask(taskClass); - System.out.println("\nRunning " + task.getTaskName() + "\n-------------------"); - runner.execute(task); - } catch (UnsupportedOperationException e) { - System.err.println("Error running task of class '" + taskClass + "'"); - e.printStackTrace(); - } + ToolTask task = instantiateTask(taskClass); + System.out.println("\nRunning " + task.getTaskName() + "\n-------------------"); + taskRunner.accept(task); } } - - private interface TaskRunner { - void execute(ToolTask task); - } } diff --git a/src/test/java/tools/hashmethods/EncryptionMethodInfoGatherer.java b/src/test/java/tools/hashmethods/EncryptionMethodInfoGatherer.java index 057f14bbb..bcc48c7cf 100644 --- a/src/test/java/tools/hashmethods/EncryptionMethodInfoGatherer.java +++ b/src/test/java/tools/hashmethods/EncryptionMethodInfoGatherer.java @@ -3,6 +3,7 @@ package tools.hashmethods; import ch.jalu.injector.Injector; import ch.jalu.injector.InjectorBuilder; import com.github.authme.configme.properties.Property; +import com.google.common.collect.ImmutableSet; import fr.xephi.authme.security.HashAlgorithm; import fr.xephi.authme.security.crypts.EncryptionMethod; import fr.xephi.authme.security.crypts.HexSaltedMethod; @@ -19,7 +20,6 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; -import static com.google.common.collect.Sets.newHashSet; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -30,9 +30,8 @@ import static org.mockito.Mockito.when; */ public class EncryptionMethodInfoGatherer { - @SuppressWarnings("unchecked") private final static Set> RELEVANT_ANNOTATIONS = - newHashSet(HasSalt.class, Recommendation.class, AsciiRestricted.class); + ImmutableSet.of(HasSalt.class, Recommendation.class, AsciiRestricted.class); private static Injector injector = createInitializer(); diff --git a/src/test/java/tools/permissions/PermissionNodesGatherer.java b/src/test/java/tools/permissions/PermissionNodesGatherer.java index 58b5df4e3..d5f7e6e9d 100644 --- a/src/test/java/tools/permissions/PermissionNodesGatherer.java +++ b/src/test/java/tools/permissions/PermissionNodesGatherer.java @@ -1,18 +1,14 @@ package tools.permissions; -import fr.xephi.authme.permission.AdminPermission; +import fr.xephi.authme.ClassCollector; import fr.xephi.authme.permission.PermissionNode; -import fr.xephi.authme.permission.PlayerPermission; -import fr.xephi.authme.permission.PlayerStatePermission; import tools.utils.FileUtils; import tools.utils.ToolsConstants; import java.util.EnumSet; import java.util.HashMap; import java.util.Map; -import java.util.Set; import java.util.TreeMap; -import java.util.TreeSet; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -31,36 +27,22 @@ public class PermissionNodesGatherer { + "(.*?)\\s+\\*/" // Capture everything until we encounter '*/' + "\\s+([A-Z_]+)\\("); // Match the enum name (e.g. 'LOGIN'), until before the first '(' - /** - * Return a sorted collection of all permission nodes. - * - * @return AuthMe permission nodes sorted alphabetically - */ - public Set gatherNodes() { - Set nodes = new TreeSet<>(); - for (PermissionNode perm : PlayerPermission.values()) { - nodes.add(perm.getNode()); - } - for (PermissionNode perm : AdminPermission.values()) { - nodes.add(perm.getNode()); - } - return nodes; - } - /** * Return a sorted collection of all permission nodes, including its JavaDoc description. * * @return Ordered map whose keys are the permission nodes and the values the associated JavaDoc */ - public Map gatherNodesWithJavaDoc() { + public & PermissionNode> Map gatherNodesWithJavaDoc() { Map result = new TreeMap<>(); result.put("authme.admin.*", "Give access to all admin commands."); result.put("authme.player.*", "Permission to use all player (non-admin) commands."); - // TODO ljacqu 20160109: Add authme.player.email manual description? + result.put("authme.player.email", "Grants all email permissions."); - addDescriptionsForClass(PlayerPermission.class, result); - addDescriptionsForClass(AdminPermission.class, result); - addDescriptionsForClass(PlayerStatePermission.class, result); + new ClassCollector(ToolsConstants.MAIN_SOURCE_ROOT, "") + .collectClasses(PermissionNode.class) + .stream() + .filter(Class::isEnum) + .forEach(clz -> addDescriptionsForClass((Class) clz, result)); return result; } diff --git a/src/test/java/tools/permissions/PermissionsListWriter.java b/src/test/java/tools/permissions/PermissionsListWriter.java index e0c43b227..43d3b4530 100644 --- a/src/test/java/tools/permissions/PermissionsListWriter.java +++ b/src/test/java/tools/permissions/PermissionsListWriter.java @@ -8,7 +8,6 @@ import tools.utils.ToolsConstants; import java.util.Map; import java.util.Scanner; -import java.util.Set; /** * Task responsible for formatting a permissions node list and @@ -25,23 +24,7 @@ public class PermissionsListWriter implements AutoToolTask { @Override public void execute(Scanner scanner) { - // Ask if result should be written to file - System.out.println("Include description? [Enter 'n' for no]"); - boolean includeDescription = !matches("n", scanner); - - boolean writeToFile = false; - if (includeDescription) { - System.out.println("Write to file? [Enter 'n' for no]"); - writeToFile = !matches("n", scanner); - } - - if (!includeDescription) { - outputSimpleList(); - } else if (writeToFile) { - generateAndWriteFile(); - } else { - System.out.println(generatePermissionsList()); - } + generateAndWriteFile(); } @Override @@ -70,20 +53,4 @@ public class PermissionsListWriter implements AutoToolTask { } return permissionTags; } - - private static void outputSimpleList() { - PermissionNodesGatherer gatherer = new PermissionNodesGatherer(); - Set nodes = gatherer.gatherNodes(); - for (String node : nodes) { - System.out.println(node); - } - System.out.println(); - System.out.println("Total: " + nodes.size()); - } - - private static boolean matches(String answer, Scanner sc) { - String userInput = sc.nextLine(); - return answer.equalsIgnoreCase(userInput); - } - } diff --git a/src/test/java/tools/utils/TagValue.java b/src/test/java/tools/utils/TagValue.java index ad73a816d..3941ee5c2 100644 --- a/src/test/java/tools/utils/TagValue.java +++ b/src/test/java/tools/utils/TagValue.java @@ -3,7 +3,12 @@ package tools.utils; import java.util.ArrayList; import java.util.List; - +/** + * Value of a tag. + * + * @param the tag value type + * @see TagReplacer + */ public abstract class TagValue { private final T value; @@ -18,6 +23,9 @@ public abstract class TagValue { public abstract boolean isEmpty(); + /** + * Text value. + */ public static final class TextTagValue extends TagValue { public TextTagValue(String value) { super(value); @@ -29,9 +37,12 @@ public abstract class TagValue { } } + /** + * List value (iterable). + */ public static final class NestedTagValue extends TagValue> { public NestedTagValue() { - super(new ArrayList()); + super(new ArrayList<>()); } @Override From a8d5b198076bbf2d33db0c33e45986f3ec26b272 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sat, 8 Oct 2016 14:58:06 +0200 Subject: [PATCH 5/7] Move all doc generating tasks into docs package --- src/test/java/tools/docs/UpdateDocsTask.java | 6 +++--- .../java/tools/{ => docs}/commands/CommandPageCreater.java | 4 ++-- src/test/java/tools/{ => docs}/commands/commands.tpl.md | 0 .../hashmethods/EncryptionMethodInfoGatherer.java | 2 +- .../hashmethods/HashAlgorithmsDescriptionTask.java | 4 ++-- .../tools/{ => docs}/hashmethods/MethodDescription.java | 2 +- .../tools/{ => docs}/hashmethods/hash_algorithms.tpl.md | 0 .../{ => docs}/permissions/PermissionNodesGatherer.java | 2 +- .../tools/{ => docs}/permissions/PermissionsListWriter.java | 6 +++--- .../tools/{ => docs}/permissions/permission_nodes.tpl.md | 0 src/test/java/tools/permissions/README.md | 2 -- 11 files changed, 13 insertions(+), 15 deletions(-) rename src/test/java/tools/{ => docs}/commands/CommandPageCreater.java (96%) rename src/test/java/tools/{ => docs}/commands/commands.tpl.md (100%) rename src/test/java/tools/{ => docs}/hashmethods/EncryptionMethodInfoGatherer.java (99%) rename src/test/java/tools/{ => docs}/hashmethods/HashAlgorithmsDescriptionTask.java (97%) rename src/test/java/tools/{ => docs}/hashmethods/MethodDescription.java (98%) rename src/test/java/tools/{ => docs}/hashmethods/hash_algorithms.tpl.md (100%) rename src/test/java/tools/{ => docs}/permissions/PermissionNodesGatherer.java (99%) rename src/test/java/tools/{ => docs}/permissions/PermissionsListWriter.java (87%) rename src/test/java/tools/{ => docs}/permissions/permission_nodes.tpl.md (100%) delete mode 100644 src/test/java/tools/permissions/README.md diff --git a/src/test/java/tools/docs/UpdateDocsTask.java b/src/test/java/tools/docs/UpdateDocsTask.java index df051bd61..86ba85ba6 100644 --- a/src/test/java/tools/docs/UpdateDocsTask.java +++ b/src/test/java/tools/docs/UpdateDocsTask.java @@ -1,9 +1,9 @@ package tools.docs; import com.google.common.collect.ImmutableSet; -import tools.commands.CommandPageCreater; -import tools.hashmethods.HashAlgorithmsDescriptionTask; -import tools.permissions.PermissionsListWriter; +import tools.docs.commands.CommandPageCreater; +import tools.docs.hashmethods.HashAlgorithmsDescriptionTask; +import tools.docs.permissions.PermissionsListWriter; import tools.utils.AutoToolTask; import tools.utils.ToolTask; diff --git a/src/test/java/tools/commands/CommandPageCreater.java b/src/test/java/tools/docs/commands/CommandPageCreater.java similarity index 96% rename from src/test/java/tools/commands/CommandPageCreater.java rename to src/test/java/tools/docs/commands/CommandPageCreater.java index d5375a2f8..6a2f5edfe 100644 --- a/src/test/java/tools/commands/CommandPageCreater.java +++ b/src/test/java/tools/docs/commands/CommandPageCreater.java @@ -1,4 +1,4 @@ -package tools.commands; +package tools.docs.commands; import fr.xephi.authme.command.CommandArgumentDescription; import fr.xephi.authme.command.CommandDescription; @@ -37,7 +37,7 @@ public class CommandPageCreater implements AutoToolTask { addCommandsInfo(commandTags, baseCommands); FileUtils.generateFileFromTemplate( - ToolsConstants.TOOLS_SOURCE_ROOT + "commands/commands.tpl.md", + ToolsConstants.TOOLS_SOURCE_ROOT + "docs/commands/commands.tpl.md", OUTPUT_FILE, TagValueHolder.create().put("commands", commandTags)); System.out.println("Wrote to '" + OUTPUT_FILE + "' with " + baseCommands.size() + " base commands."); diff --git a/src/test/java/tools/commands/commands.tpl.md b/src/test/java/tools/docs/commands/commands.tpl.md similarity index 100% rename from src/test/java/tools/commands/commands.tpl.md rename to src/test/java/tools/docs/commands/commands.tpl.md diff --git a/src/test/java/tools/hashmethods/EncryptionMethodInfoGatherer.java b/src/test/java/tools/docs/hashmethods/EncryptionMethodInfoGatherer.java similarity index 99% rename from src/test/java/tools/hashmethods/EncryptionMethodInfoGatherer.java rename to src/test/java/tools/docs/hashmethods/EncryptionMethodInfoGatherer.java index bcc48c7cf..00809a73a 100644 --- a/src/test/java/tools/hashmethods/EncryptionMethodInfoGatherer.java +++ b/src/test/java/tools/docs/hashmethods/EncryptionMethodInfoGatherer.java @@ -1,4 +1,4 @@ -package tools.hashmethods; +package tools.docs.hashmethods; import ch.jalu.injector.Injector; import ch.jalu.injector.InjectorBuilder; diff --git a/src/test/java/tools/hashmethods/HashAlgorithmsDescriptionTask.java b/src/test/java/tools/docs/hashmethods/HashAlgorithmsDescriptionTask.java similarity index 97% rename from src/test/java/tools/hashmethods/HashAlgorithmsDescriptionTask.java rename to src/test/java/tools/docs/hashmethods/HashAlgorithmsDescriptionTask.java index 9f0a7b366..95da44d53 100644 --- a/src/test/java/tools/hashmethods/HashAlgorithmsDescriptionTask.java +++ b/src/test/java/tools/docs/hashmethods/HashAlgorithmsDescriptionTask.java @@ -1,4 +1,4 @@ -package tools.hashmethods; +package tools.docs.hashmethods; import fr.xephi.authme.security.HashAlgorithm; import tools.utils.AutoToolTask; @@ -17,7 +17,7 @@ import java.util.Scanner; */ public class HashAlgorithmsDescriptionTask implements AutoToolTask { - private static final String CUR_FOLDER = ToolsConstants.TOOLS_SOURCE_ROOT + "hashmethods/"; + private static final String CUR_FOLDER = ToolsConstants.TOOLS_SOURCE_ROOT + "docs/hashmethods/"; private static final String OUTPUT_FILE = ToolsConstants.DOCS_FOLDER + "hash_algorithms.md"; @Override diff --git a/src/test/java/tools/hashmethods/MethodDescription.java b/src/test/java/tools/docs/hashmethods/MethodDescription.java similarity index 98% rename from src/test/java/tools/hashmethods/MethodDescription.java rename to src/test/java/tools/docs/hashmethods/MethodDescription.java index 587654679..f4d8a255e 100644 --- a/src/test/java/tools/hashmethods/MethodDescription.java +++ b/src/test/java/tools/docs/hashmethods/MethodDescription.java @@ -1,4 +1,4 @@ -package tools.hashmethods; +package tools.docs.hashmethods; import fr.xephi.authme.security.crypts.EncryptionMethod; import fr.xephi.authme.security.crypts.description.SaltType; diff --git a/src/test/java/tools/hashmethods/hash_algorithms.tpl.md b/src/test/java/tools/docs/hashmethods/hash_algorithms.tpl.md similarity index 100% rename from src/test/java/tools/hashmethods/hash_algorithms.tpl.md rename to src/test/java/tools/docs/hashmethods/hash_algorithms.tpl.md diff --git a/src/test/java/tools/permissions/PermissionNodesGatherer.java b/src/test/java/tools/docs/permissions/PermissionNodesGatherer.java similarity index 99% rename from src/test/java/tools/permissions/PermissionNodesGatherer.java rename to src/test/java/tools/docs/permissions/PermissionNodesGatherer.java index d5f7e6e9d..9c469e8e0 100644 --- a/src/test/java/tools/permissions/PermissionNodesGatherer.java +++ b/src/test/java/tools/docs/permissions/PermissionNodesGatherer.java @@ -1,4 +1,4 @@ -package tools.permissions; +package tools.docs.permissions; import fr.xephi.authme.ClassCollector; import fr.xephi.authme.permission.PermissionNode; diff --git a/src/test/java/tools/permissions/PermissionsListWriter.java b/src/test/java/tools/docs/permissions/PermissionsListWriter.java similarity index 87% rename from src/test/java/tools/permissions/PermissionsListWriter.java rename to src/test/java/tools/docs/permissions/PermissionsListWriter.java index 43d3b4530..6d1b48d74 100644 --- a/src/test/java/tools/permissions/PermissionsListWriter.java +++ b/src/test/java/tools/docs/permissions/PermissionsListWriter.java @@ -1,4 +1,4 @@ -package tools.permissions; +package tools.docs.permissions; import tools.utils.AutoToolTask; import tools.utils.FileUtils; @@ -15,6 +15,7 @@ import java.util.Scanner; */ public class PermissionsListWriter implements AutoToolTask { + private static final String TEMPLATE_FILE = ToolsConstants.TOOLS_SOURCE_ROOT + "docs/permissions/permission_nodes.tpl.md"; private static final String PERMISSIONS_OUTPUT_FILE = ToolsConstants.DOCS_FOLDER + "permission_nodes.md"; @Override @@ -36,8 +37,7 @@ public class PermissionsListWriter implements AutoToolTask { final NestedTagValue permissionsTagValue = generatePermissionsList(); TagValueHolder tags = TagValueHolder.create().put("nodes", permissionsTagValue); - FileUtils.generateFileFromTemplate( - ToolsConstants.TOOLS_SOURCE_ROOT + "permissions/permission_nodes.tpl.md", PERMISSIONS_OUTPUT_FILE, tags); + FileUtils.generateFileFromTemplate(TEMPLATE_FILE, PERMISSIONS_OUTPUT_FILE, tags); System.out.println("Wrote to '" + PERMISSIONS_OUTPUT_FILE + "'"); System.out.println("Before committing, please verify the output!"); } diff --git a/src/test/java/tools/permissions/permission_nodes.tpl.md b/src/test/java/tools/docs/permissions/permission_nodes.tpl.md similarity index 100% rename from src/test/java/tools/permissions/permission_nodes.tpl.md rename to src/test/java/tools/docs/permissions/permission_nodes.tpl.md diff --git a/src/test/java/tools/permissions/README.md b/src/test/java/tools/permissions/README.md deleted file mode 100644 index 9603cd386..000000000 --- a/src/test/java/tools/permissions/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# About -Helper script to generate a page with an up-to-date list of permission nodes. From 93c61a051173d86deb331eaa430d06abb1a2c057 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sat, 8 Oct 2016 23:00:26 +0200 Subject: [PATCH 6/7] #976 Create translations doc page --- docs/translations.md | 39 +++++ src/test/java/tools/docs/UpdateDocsTask.java | 4 +- .../TranslationPageGenerator.java | 143 ++++++++++++++++++ .../translations/TranslationsGatherer.java | 86 +++++++++++ .../docs/translations/translations.tpl.md | 14 ++ 5 files changed, 285 insertions(+), 1 deletion(-) create mode 100644 docs/translations.md create mode 100644 src/test/java/tools/docs/translations/TranslationPageGenerator.java create mode 100644 src/test/java/tools/docs/translations/TranslationsGatherer.java create mode 100644 src/test/java/tools/docs/translations/translations.tpl.md diff --git a/docs/translations.md b/docs/translations.md new file mode 100644 index 000000000..bec2c4dca --- /dev/null +++ b/docs/translations.md @@ -0,0 +1,39 @@ + + + +# AuthMe Translations +The following translations are available in AuthMe. Use the code in your +config.yml to use the language file. + +Code | Language | Translated |   +---- | -------- | ---------: | --- +en | English | 100% | bar +bg | Bulgarian | 73% | bar +br | Brazilian | 100% | bar +cz | Czech | 91% | bar +de | German | 97% | bar +es | Spanish | 100% | bar +eu | Basque | 66% | bar +fi | Finnish | 70% | bar +fr | French | 97% | bar +gl | Galician | 74% | bar +hu | Hungarian | 97% | bar +id | Indonesian | 74% | bar +it | Italian | 100% | bar +ko | Korean | 76% | bar +lt | Latvian | 57% | bar +nl | Dutch | 80% | bar +pl | Polish | 95% | bar +pt | Portuguese | 91% | bar +ru | Russian | 97% | bar +sk | Slovakian | 50% | bar +tr | Turkish | 85% | bar +uk | Ukrainian | 97% | bar +vn | Vietnamese | 85% | bar +zhcn | Chinese (China) | 85% | bar +zhhk | Chinese (Hong Kong) | 85% | bar +zhtw | Chinese (Taiwan) | 85% | bar + +--- + +This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Sat Oct 08 22:53:13 CEST 2016 diff --git a/src/test/java/tools/docs/UpdateDocsTask.java b/src/test/java/tools/docs/UpdateDocsTask.java index 86ba85ba6..cfdb69ef9 100644 --- a/src/test/java/tools/docs/UpdateDocsTask.java +++ b/src/test/java/tools/docs/UpdateDocsTask.java @@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableSet; import tools.docs.commands.CommandPageCreater; import tools.docs.hashmethods.HashAlgorithmsDescriptionTask; import tools.docs.permissions.PermissionsListWriter; +import tools.docs.translations.TranslationPageGenerator; import tools.utils.AutoToolTask; import tools.utils.ToolTask; @@ -17,7 +18,8 @@ import java.util.function.Consumer; public class UpdateDocsTask implements AutoToolTask { private static final Set> TASKS = ImmutableSet - .of(CommandPageCreater.class, HashAlgorithmsDescriptionTask.class, PermissionsListWriter.class); + .of(CommandPageCreater.class, HashAlgorithmsDescriptionTask.class, + PermissionsListWriter.class, TranslationPageGenerator.class); @Override public String getTaskName() { diff --git a/src/test/java/tools/docs/translations/TranslationPageGenerator.java b/src/test/java/tools/docs/translations/TranslationPageGenerator.java new file mode 100644 index 000000000..e7785bd7a --- /dev/null +++ b/src/test/java/tools/docs/translations/TranslationPageGenerator.java @@ -0,0 +1,143 @@ +package tools.docs.translations; + +import com.google.common.collect.ImmutableMap; +import tools.docs.translations.TranslationsGatherer.TranslationInfo; +import tools.utils.AutoToolTask; +import tools.utils.FileUtils; +import tools.utils.TagValue.NestedTagValue; +import tools.utils.TagValueHolder; +import tools.utils.ToolsConstants; + +import java.util.Arrays; +import java.util.Map; +import java.util.Scanner; +import java.util.stream.Collectors; + +import static com.google.common.base.Objects.firstNonNull; + +/** + * Generates the translations page in docs. + */ +public class TranslationPageGenerator implements AutoToolTask { + + private static final String DOCS_PAGE = ToolsConstants.DOCS_FOLDER + "translations.md"; + private static final String TEMPLATE_FILE = ToolsConstants.TOOLS_SOURCE_ROOT + "docs/translations/translations.tpl.md"; + private static final Map LANGUAGE_NAMES = buildLanguageNames(); + + // Color configuration for the bars shown next to translation percentage + /** + * Percentage threshold under which the color will be computed from COLOR_0 to COLOR_1; + * above which COLOR_1 to COLOR_2 is used. + */ + private static final int COLOR_1_PERCENTAGE = 75; + // Colors are in RGB format, displayed as an int array of three values whose entries are in the range [0, 15]. + private static final int[] COLOR_0 = { 9, 0, 0}; + private static final int[] COLOR_1 = {12, 9, 0}; + private static final int[] COLOR_2 = { 6, 15, 6}; + + private final TranslationsGatherer gatherer = new TranslationsGatherer(); + + @Override + public String getTaskName() { + return "updateTranslations"; + } + + @Override + public void execute(Scanner scanner) { + executeDefault(); + } + + @Override + public void executeDefault() { + NestedTagValue translationValuesHolder = new NestedTagValue(); + + for (TranslationInfo translation : gatherer.getTranslationInfo()) { + int percentage = (int) Math.round(translation.percentTranslated * 100); + String name = firstNonNull(LANGUAGE_NAMES.get(translation.code), "?"); + TagValueHolder valueHolder = TagValueHolder.create() + .put("code", translation.code) + .put("name", name) + .put("percentage", Integer.toString(percentage)) + .put("color", computeColor(percentage)); + translationValuesHolder.add(valueHolder); + } + + TagValueHolder tags = TagValueHolder.create().put("languages", translationValuesHolder); + FileUtils.generateFileFromTemplate(TEMPLATE_FILE, DOCS_PAGE, tags); + } + + /** + * Returns the color for the given percentage as a 6-digit hex color code. + * + * @param percentage the percentage to generate a color for + * @return the color + */ + private String computeColor(int percentage) { + int[] color; + if (percentage < COLOR_1_PERCENTAGE) { + color = computeColor(percentage, COLOR_0, COLOR_1, 0, COLOR_1_PERCENTAGE); + } else { + color = computeColor(percentage, COLOR_1, COLOR_2, COLOR_1_PERCENTAGE, 100); + } + + return Arrays.stream(color) + .mapToObj(i -> Integer.toString(i, 16)) + .map(s -> s + s) + .collect(Collectors.joining()); + } + + /** + * Computes the color as the transition between two given colors. + * + * @param percentage the percentage to compute the color for + * @param colorA the color at the start of the range + * @param colorB the color at the end of the range + * @param rangeMin range start + * @param rangeMax range end + * @return color for the given percentage + */ + private static int[] computeColor(int percentage, int[] colorA, int[] colorB, int rangeMin, int rangeMax) { + double max = rangeMax - rangeMin; + double n = percentage - rangeMin; + + return new int[]{ + (int) (colorA[0] + n / max * (colorB[0] - colorA[0])), + (int) (colorA[1] + n / max * (colorB[1] - colorA[1])), + (int) (colorA[2] + n / max * (colorB[2] - colorA[2])) + }; + } + + /** + * @return map of language code -> language name + */ + private static Map buildLanguageNames() { + return ImmutableMap.builder() + .put("bg", "Bulgarian") + .put("br", "Brazilian") + .put("cz", "Czech") + .put("de", "German") + .put("en", "English") + .put("es", "Spanish") + .put("eu", "Basque") + .put("fi", "Finnish") + .put("fr", "French") + .put("gl", "Galician") + .put("hu", "Hungarian") + .put("id", "Indonesian") + .put("it", "Italian") + .put("ko", "Korean") + .put("lt", "Latvian") + .put("nl", "Dutch") + .put("pl", "Polish") + .put("pt", "Portuguese") + .put("ru", "Russian") + .put("sk", "Slovakian") + .put("tr", "Turkish") + .put("uk", "Ukrainian") + .put("vn", "Vietnamese") + .put("zhcn", "Chinese (China)") + .put("zhhk", "Chinese (Hong Kong)") + .put("zhtw", "Chinese (Taiwan)") + .build(); + } +} diff --git a/src/test/java/tools/docs/translations/TranslationsGatherer.java b/src/test/java/tools/docs/translations/TranslationsGatherer.java new file mode 100644 index 000000000..233b93324 --- /dev/null +++ b/src/test/java/tools/docs/translations/TranslationsGatherer.java @@ -0,0 +1,86 @@ +package tools.docs.translations; + +import fr.xephi.authme.message.MessageKey; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import tools.utils.ToolsConstants; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Gathers all available translations of AuthMe. + */ +public class TranslationsGatherer { + + private static final Pattern MESSAGES_PATTERN = Pattern.compile("messages_([a-z]{2,4})\\.yml"); + private static final String MESSAGES_FOLDER = ToolsConstants.MAIN_RESOURCES_ROOT + "messages/"; + + private List translationInfo = new ArrayList<>(); + + public TranslationsGatherer() { + gatherTranslations(); + translationInfo.sort((e1, e2) -> getCode(e1).compareTo(getCode(e2))); + } + + public List getTranslationInfo() { + return translationInfo; + } + + private void gatherTranslations() { + File[] files = new File(MESSAGES_FOLDER).listFiles(); + if (files == null) { + throw new IllegalStateException("Cannot read files of '" + MESSAGES_FOLDER + "'"); + } + for (File file : files) { + String code = getLanguageCode(file.getName()); + if (code != null) { + processMessagesFile(code, file); + } + } + } + + private void processMessagesFile(String code, File file) { + FileConfiguration configuration = YamlConfiguration.loadConfiguration(file); + int availableMessages = 0; + for (MessageKey key : MessageKey.values()) { + if (configuration.contains(key.getKey())) { + ++availableMessages; + } + } + translationInfo.add(new TranslationInfo(code, (double) availableMessages / MessageKey.values().length)); + } + + private String getLanguageCode(String messagesFile) { + Matcher matcher = MESSAGES_PATTERN.matcher(messagesFile); + if (matcher.find()) { + return matcher.group(1); + } + return null; + } + + public static final class TranslationInfo { + public final String code; + public final double percentTranslated; + + TranslationInfo(String code, double percentTranslated) { + this.code = code; + this.percentTranslated = percentTranslated; + } + } + + /** + * Returns the language code from the translation info for sorting purposes. + * Returns "a" for "en" language code to sort English on top. + * + * @param info the translation info + * @return the language code for sorting + */ + private static String getCode(TranslationInfo info) { + return "en".equals(info.code) ? "a" : info.code; + } + +} diff --git a/src/test/java/tools/docs/translations/translations.tpl.md b/src/test/java/tools/docs/translations/translations.tpl.md new file mode 100644 index 000000000..faad36b5f --- /dev/null +++ b/src/test/java/tools/docs/translations/translations.tpl.md @@ -0,0 +1,14 @@ + + + +# AuthMe Translations +The following translations are available in AuthMe. Use the code in your +config.yml to use the language file. + +Code | Language | Translated |   +---- | -------- | ---------: | --- +[#languages] +{code} | {name} | {percentage}% | bar +[/#languages] + +{gen_footer} From fc08e9dbd1e04be38700834755012b81a948b520 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sun, 9 Oct 2016 09:52:07 +0200 Subject: [PATCH 7/7] #976 Link messages file in doc, #836 update Hungarian messages --- docs/translations.md | 62 +++++++++---------- src/main/resources/messages/messages_hu.yml | 4 +- .../docs/translations/translations.tpl.md | 8 +-- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/docs/translations.md b/docs/translations.md index bec2c4dca..c261bb8f6 100644 --- a/docs/translations.md +++ b/docs/translations.md @@ -1,39 +1,39 @@ - + # AuthMe Translations -The following translations are available in AuthMe. Use the code in your -config.yml to use the language file. +The following translations are available in AuthMe. Set `messagesLanguage` to the language code +in your config.yml to use the language, or use another language code to start a new translation. Code | Language | Translated |   ----- | -------- | ---------: | --- -en | English | 100% | bar -bg | Bulgarian | 73% | bar -br | Brazilian | 100% | bar -cz | Czech | 91% | bar -de | German | 97% | bar -es | Spanish | 100% | bar -eu | Basque | 66% | bar -fi | Finnish | 70% | bar -fr | French | 97% | bar -gl | Galician | 74% | bar -hu | Hungarian | 97% | bar -id | Indonesian | 74% | bar -it | Italian | 100% | bar -ko | Korean | 76% | bar -lt | Latvian | 57% | bar -nl | Dutch | 80% | bar -pl | Polish | 95% | bar -pt | Portuguese | 91% | bar -ru | Russian | 97% | bar -sk | Slovakian | 50% | bar -tr | Turkish | 85% | bar -uk | Ukrainian | 97% | bar -vn | Vietnamese | 85% | bar -zhcn | Chinese (China) | 85% | bar -zhhk | Chinese (Hong Kong) | 85% | bar -zhtw | Chinese (Taiwan) | 85% | bar +---- | -------- | ---------: | ------ +[en](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_en.yml) | English | 100% | bar +[bg](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_bg.yml) | Bulgarian | 73% | bar +[br](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_br.yml) | Brazilian | 100% | bar +[cz](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_cz.yml) | Czech | 91% | bar +[de](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_de.yml) | German | 97% | bar +[es](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_es.yml) | Spanish | 100% | bar +[eu](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_eu.yml) | Basque | 66% | bar +[fi](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_fi.yml) | Finnish | 70% | bar +[fr](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_fr.yml) | French | 97% | bar +[gl](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_gl.yml) | Galician | 74% | bar +[hu](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_hu.yml) | Hungarian | 100% | bar +[id](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_id.yml) | Indonesian | 74% | bar +[it](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_it.yml) | Italian | 100% | bar +[ko](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_ko.yml) | Korean | 76% | bar +[lt](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_lt.yml) | Latvian | 57% | bar +[nl](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_nl.yml) | Dutch | 80% | bar +[pl](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_pl.yml) | Polish | 95% | bar +[pt](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_pt.yml) | Portuguese | 91% | bar +[ru](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_ru.yml) | Russian | 97% | bar +[sk](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_sk.yml) | Slovakian | 50% | bar +[tr](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_tr.yml) | Turkish | 85% | bar +[uk](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_uk.yml) | Ukrainian | 97% | bar +[vn](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_vn.yml) | Vietnamese | 85% | bar +[zhcn](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_zhcn.yml) | Chinese (China) | 85% | bar +[zhhk](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_zhhk.yml) | Chinese (Hong Kong) | 85% | bar +[zhtw](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_zhtw.yml) | Chinese (Taiwan) | 85% | bar --- -This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Sat Oct 08 22:53:13 CEST 2016 +This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Sun Oct 09 09:42:48 CEST 2016 diff --git a/src/main/resources/messages/messages_hu.yml b/src/main/resources/messages/messages_hu.yml index f9bd43e51..e985d72bc 100644 --- a/src/main/resources/messages/messages_hu.yml +++ b/src/main/resources/messages/messages_hu.yml @@ -70,5 +70,5 @@ incomplete_email_settings: 'Hiba: nem lett beállítva az össze szükséges be accounts_owned_other: 'A %name nevű játékosnak, %count db regisztrációja van:' kicked_admin_registered: 'Adminisztrátor által regisztrálva lettél; kérlek lépj be újra!' accounts_owned_self: '%count db regisztrációd van:' -# TODO recovery_code_incorrect: 'The recovery code is not correct! Use /email recovery [email] to generate a new one' -# TODO recovery_code_sent: 'A recovery code to reset your password has been sent to your email.' \ No newline at end of file +recovery_code_incorrect: 'A visszaállító kód helytelen volt! Használd a következő parancsot: /email recovery [email címed] egy új generálásához' +recovery_code_sent: 'A jelszavad visszaállításához szükséges kódot sikeresen kiküldtük az email címedre!' diff --git a/src/test/java/tools/docs/translations/translations.tpl.md b/src/test/java/tools/docs/translations/translations.tpl.md index faad36b5f..199d4029c 100644 --- a/src/test/java/tools/docs/translations/translations.tpl.md +++ b/src/test/java/tools/docs/translations/translations.tpl.md @@ -2,13 +2,13 @@ # AuthMe Translations -The following translations are available in AuthMe. Use the code in your -config.yml to use the language file. +The following translations are available in AuthMe. Set `messagesLanguage` to the language code +in your config.yml to use the language, or use another language code to start a new translation. Code | Language | Translated |   ----- | -------- | ---------: | --- +---- | -------- | ---------: | ------ [#languages] -{code} | {name} | {percentage}% | bar +[{code}](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_{code}.yml) | {name} | {percentage}% | bar [/#languages] {gen_footer}