From b671c94e0b0ce902cb823c37d64fd332ae123bc2 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Wed, 20 Jul 2016 21:22:09 +0200 Subject: [PATCH] #736 Remove service getters on AuthMe - Remove getX() methods on AuthMe: API classes will be instantiated by injection, too. It doesn't make sense to expose the constructor for the API classes anyway; we are internally responsible for creating these objects and having them created by third-party is not intended - Remove deprecated annotations on individual methods on API -> whole class is deprecated, annotation on the class is enough --- src/main/java/fr/xephi/authme/AuthMe.java | 40 --------------- src/main/java/fr/xephi/authme/api/API.java | 26 +++------- src/main/java/fr/xephi/authme/api/NewAPI.java | 49 +++++++++++-------- 3 files changed, 36 insertions(+), 79 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index dac3dc039..9909ab8a1 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -659,16 +659,6 @@ public class AuthMe extends JavaPlugin { // Use @Inject fields instead // ------------- - /** - * @return permission manager - * - * @deprecated should be used in API classes only (temporarily) - */ - @Deprecated - public PermissionsManager getPermissionsManager() { - return this.permsMan; - } - /** * @return process manager * @@ -678,34 +668,4 @@ public class AuthMe extends JavaPlugin { public Management getManagement() { return management; } - - /** - * @return the datasource - * - * @deprecated should be used in API classes only (temporarily) - */ - @Deprecated - public DataSource getDataSource() { - return database; - } - - /** - * @return password manager - * - * @deprecated should be used in API classes only (temporarily) - */ - @Deprecated - public PasswordSecurity getPasswordSecurity() { - return passwordSecurity; - } - - /** - * @return plugin hooks - * - * @deprecated should be used in API classes only (temporarily) - */ - @Deprecated - public PluginHooks getPluginHooks() { - return pluginHooks; - } } diff --git a/src/main/java/fr/xephi/authme/api/API.java b/src/main/java/fr/xephi/authme/api/API.java index ca75cee11..937d4f12b 100644 --- a/src/main/java/fr/xephi/authme/api/API.java +++ b/src/main/java/fr/xephi/authme/api/API.java @@ -4,6 +4,7 @@ import fr.xephi.authme.AuthMe; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerCache; 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.security.crypts.HashedPassword; @@ -27,19 +28,19 @@ public class API { private static DataSource dataSource; private static PasswordSecurity passwordSecurity; private static Management management; + private static PluginHooks pluginHooks; - /** - * Constructor for the deprecated API. - * - * @param instance AuthMe + /* + * Constructor. */ - @Deprecated @Inject - API(AuthMe instance, DataSource dataSource, PasswordSecurity passwordSecurity, Management management) { + API(AuthMe instance, DataSource dataSource, PasswordSecurity passwordSecurity, Management management, + PluginHooks pluginHooks) { API.instance = instance; API.dataSource = dataSource; API.passwordSecurity = passwordSecurity; API.management = management; + API.pluginHooks = pluginHooks; } /** @@ -47,7 +48,6 @@ public class API { * * @return AuthMe instance */ - @Deprecated public static AuthMe hookAuthMe() { if (instance != null) { return instance; @@ -66,7 +66,6 @@ public class API { * @param player The player to verify * @return true if the player is authenticated */ - @Deprecated public static boolean isAuthenticated(Player player) { return PlayerCache.getInstance().isAuthenticated(player.getName()); } @@ -77,12 +76,10 @@ public class API { * @param player The player to verify * @return true if the player is unrestricted */ - @Deprecated public static boolean isUnrestricted(Player player) { return Utils.isUnrestricted(player); } - @Deprecated public static Location getLastLocation(Player player) { try { PlayerAuth auth = PlayerCache.getInstance().getAuth(player.getName().toLowerCase()); @@ -99,7 +96,6 @@ public class API { } } - @Deprecated public static void setPlayerInventory(Player player, ItemStack[] content, ItemStack[] armor) { try { @@ -115,7 +111,6 @@ public class API { * @param playerName The player name to verify * @return true if player is registered */ - @Deprecated public static boolean isRegistered(String playerName) { String player = playerName.toLowerCase(); return dataSource.isAuthAvailable(player); @@ -128,7 +123,6 @@ public class API { * @param passwordToCheck The password to check * @return true if the password is correct, false otherwise */ - @Deprecated public static boolean checkPassword(String playerName, String passwordToCheck) { return isRegistered(playerName) && passwordSecurity.comparePassword(passwordToCheck, playerName); } @@ -140,7 +134,6 @@ public class API { * @param password The password * @return true if the player was registered correctly */ - @Deprecated public static boolean registerPlayer(String playerName, String password) { String name = playerName.toLowerCase(); HashedPassword hashedPassword = passwordSecurity.computeHash(password, name); @@ -161,12 +154,10 @@ public class API { * * @param player The player to log in */ - @Deprecated public static void forceLogin(Player player) { management.performLogin(player, "dontneed", true); } - @Deprecated public AuthMe getPlugin() { return instance; } @@ -177,9 +168,8 @@ public class API { * @param player The player to verify * @return true if player is an npc */ - @Deprecated public boolean isNPC(Player player) { - return instance.getPluginHooks().isNpc(player); + return pluginHooks.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 5e0063e97..cdb5e4158 100644 --- a/src/main/java/fr/xephi/authme/api/NewAPI.java +++ b/src/main/java/fr/xephi/authme/api/NewAPI.java @@ -3,12 +3,15 @@ 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.datasource.DataSource; +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.Utils; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; import javax.inject.Inject; @@ -23,14 +26,22 @@ public class NewAPI { public static NewAPI singleton; public final AuthMe plugin; - /** + private static PluginHooks pluginHooks; + private static DataSource dataSource; + private static PasswordSecurity passwordSecurity; + private static Management management; + + /* * Constructor for NewAPI. - * - * @param plugin The AuthMe plugin instance */ @Inject - public NewAPI(AuthMe plugin) { + NewAPI(AuthMe plugin, PluginHooks pluginHooks, DataSource dataSource, PasswordSecurity passwordSecurity, + Management management) { this.plugin = plugin; + NewAPI.pluginHooks = pluginHooks; + NewAPI.dataSource = dataSource; + NewAPI.passwordSecurity = passwordSecurity; + NewAPI.management = management; } /** @@ -43,13 +54,9 @@ public class NewAPI { if (singleton != null) { return singleton; } - Plugin p = Bukkit.getServer().getPluginManager().getPlugin("AuthMe"); - if (p == null || !(p instanceof AuthMe)) { - return null; - } - AuthMe authme = (AuthMe) p; - singleton = new NewAPI(authme); - return singleton; + // NewAPI is initialized in AuthMe#onEnable -> if singleton is null, + // it means AuthMe isn't initialized (yet) + return null; } /** @@ -88,7 +95,7 @@ public class NewAPI { * @return true if the player is an npc */ public boolean isNPC(Player player) { - return plugin.getPluginHooks().isNpc(player); + return pluginHooks.isNpc(player); } /** @@ -125,7 +132,7 @@ public class NewAPI { */ public boolean isRegistered(String playerName) { String player = playerName.toLowerCase(); - return plugin.getDataSource().isAuthAvailable(player); + return dataSource.isAuthAvailable(player); } /** @@ -136,7 +143,7 @@ public class NewAPI { * @return true if the password is correct, false otherwise */ public boolean checkPassword(String playerName, String passwordToCheck) { - return isRegistered(playerName) && plugin.getPasswordSecurity().comparePassword(passwordToCheck, playerName); + return isRegistered(playerName) && passwordSecurity.comparePassword(passwordToCheck, playerName); } /** @@ -149,7 +156,7 @@ public class NewAPI { */ public boolean registerPlayer(String playerName, String password) { String name = playerName.toLowerCase(); - HashedPassword result = plugin.getPasswordSecurity().computeHash(password, name); + HashedPassword result = passwordSecurity.computeHash(password, name); if (isRegistered(name)) { return false; } @@ -158,7 +165,7 @@ public class NewAPI { .password(result) .realName(playerName) .build(); - return plugin.getDataSource().saveAuth(auth); + return dataSource.saveAuth(auth); } /** @@ -167,7 +174,7 @@ public class NewAPI { * @param player The player to log in */ public void forceLogin(Player player) { - plugin.getManagement().performLogin(player, "dontneed", true); + management.performLogin(player, "dontneed", true); } /** @@ -176,7 +183,7 @@ public class NewAPI { * @param player The player to log out */ public void forceLogout(Player player) { - plugin.getManagement().performLogout(player); + management.performLogout(player); } /** @@ -187,7 +194,7 @@ public class NewAPI { * @param autoLogin Should the player be authenticated automatically after the registration? */ public void forceRegister(Player player, String password, boolean autoLogin) { - plugin.getManagement().performRegister(player, password, null, autoLogin); + management.performRegister(player, password, null, autoLogin); } /** @@ -206,6 +213,6 @@ public class NewAPI { * @param player The player to unregister */ public void forceUnregister(Player player) { - plugin.getManagement().performUnregister(player, "", true); + management.performUnregister(player, "", true); } }