#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
This commit is contained in:
ljacqu 2016-07-20 21:22:09 +02:00
parent 86df740491
commit b671c94e0b
3 changed files with 36 additions and 79 deletions

View File

@ -659,16 +659,6 @@ public class AuthMe extends JavaPlugin {
// Use @Inject fields instead // 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 * @return process manager
* *
@ -678,34 +668,4 @@ public class AuthMe extends JavaPlugin {
public Management getManagement() { public Management getManagement() {
return management; 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;
}
} }

View File

@ -4,6 +4,7 @@ import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.hooks.PluginHooks;
import fr.xephi.authme.process.Management; import fr.xephi.authme.process.Management;
import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.security.crypts.HashedPassword;
@ -27,19 +28,19 @@ public class API {
private static DataSource dataSource; private static DataSource dataSource;
private static PasswordSecurity passwordSecurity; private static PasswordSecurity passwordSecurity;
private static Management management; private static Management management;
private static PluginHooks pluginHooks;
/** /*
* Constructor for the deprecated API. * Constructor.
*
* @param instance AuthMe
*/ */
@Deprecated
@Inject @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.instance = instance;
API.dataSource = dataSource; API.dataSource = dataSource;
API.passwordSecurity = passwordSecurity; API.passwordSecurity = passwordSecurity;
API.management = management; API.management = management;
API.pluginHooks = pluginHooks;
} }
/** /**
@ -47,7 +48,6 @@ public class API {
* *
* @return AuthMe instance * @return AuthMe instance
*/ */
@Deprecated
public static AuthMe hookAuthMe() { public static AuthMe hookAuthMe() {
if (instance != null) { if (instance != null) {
return instance; return instance;
@ -66,7 +66,6 @@ public class API {
* @param player The player to verify * @param player The player to verify
* @return true if the player is authenticated * @return true if the player is authenticated
*/ */
@Deprecated
public static boolean isAuthenticated(Player player) { public static boolean isAuthenticated(Player player) {
return PlayerCache.getInstance().isAuthenticated(player.getName()); return PlayerCache.getInstance().isAuthenticated(player.getName());
} }
@ -77,12 +76,10 @@ public class API {
* @param player The player to verify * @param player The player to verify
* @return true if the player is unrestricted * @return true if the player is unrestricted
*/ */
@Deprecated
public static boolean isUnrestricted(Player player) { public static boolean isUnrestricted(Player player) {
return Utils.isUnrestricted(player); return Utils.isUnrestricted(player);
} }
@Deprecated
public static Location getLastLocation(Player player) { public static Location getLastLocation(Player player) {
try { try {
PlayerAuth auth = PlayerCache.getInstance().getAuth(player.getName().toLowerCase()); PlayerAuth auth = PlayerCache.getInstance().getAuth(player.getName().toLowerCase());
@ -99,7 +96,6 @@ public class API {
} }
} }
@Deprecated
public static void setPlayerInventory(Player player, ItemStack[] content, public static void setPlayerInventory(Player player, ItemStack[] content,
ItemStack[] armor) { ItemStack[] armor) {
try { try {
@ -115,7 +111,6 @@ public class API {
* @param playerName The player name to verify * @param playerName The player name to verify
* @return true if player is registered * @return true if player is registered
*/ */
@Deprecated
public static boolean isRegistered(String playerName) { public static boolean isRegistered(String playerName) {
String player = playerName.toLowerCase(); String player = playerName.toLowerCase();
return dataSource.isAuthAvailable(player); return dataSource.isAuthAvailable(player);
@ -128,7 +123,6 @@ public class API {
* @param passwordToCheck The password to check * @param passwordToCheck The password to check
* @return true if the password is correct, false otherwise * @return true if the password is correct, false otherwise
*/ */
@Deprecated
public static boolean checkPassword(String playerName, String passwordToCheck) { public static boolean checkPassword(String playerName, String passwordToCheck) {
return isRegistered(playerName) && passwordSecurity.comparePassword(passwordToCheck, playerName); return isRegistered(playerName) && passwordSecurity.comparePassword(passwordToCheck, playerName);
} }
@ -140,7 +134,6 @@ public class API {
* @param password The password * @param password The password
* @return true if the player was registered correctly * @return true if the player was registered correctly
*/ */
@Deprecated
public static boolean registerPlayer(String playerName, String password) { public static boolean registerPlayer(String playerName, String password) {
String name = playerName.toLowerCase(); String name = playerName.toLowerCase();
HashedPassword hashedPassword = passwordSecurity.computeHash(password, name); HashedPassword hashedPassword = passwordSecurity.computeHash(password, name);
@ -161,12 +154,10 @@ public class API {
* *
* @param player The player to log in * @param player The player to log in
*/ */
@Deprecated
public static void forceLogin(Player player) { public static void forceLogin(Player player) {
management.performLogin(player, "dontneed", true); management.performLogin(player, "dontneed", true);
} }
@Deprecated
public AuthMe getPlugin() { public AuthMe getPlugin() {
return instance; return instance;
} }
@ -177,9 +168,8 @@ public class API {
* @param player The player to verify * @param player The player to verify
* @return true if player is an npc * @return true if player is an npc
*/ */
@Deprecated
public boolean isNPC(Player player) { public boolean isNPC(Player player) {
return instance.getPluginHooks().isNpc(player); return pluginHooks.isNpc(player);
} }
} }

View File

@ -3,12 +3,15 @@ package fr.xephi.authme.api;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache; 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.security.crypts.HashedPassword;
import fr.xephi.authme.util.Utils; import fr.xephi.authme.util.Utils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import javax.inject.Inject; import javax.inject.Inject;
@ -23,14 +26,22 @@ public class NewAPI {
public static NewAPI singleton; public static NewAPI singleton;
public final AuthMe plugin; public final AuthMe plugin;
/** private static PluginHooks pluginHooks;
private static DataSource dataSource;
private static PasswordSecurity passwordSecurity;
private static Management management;
/*
* Constructor for NewAPI. * Constructor for NewAPI.
*
* @param plugin The AuthMe plugin instance
*/ */
@Inject @Inject
public NewAPI(AuthMe plugin) { NewAPI(AuthMe plugin, PluginHooks pluginHooks, DataSource dataSource, PasswordSecurity passwordSecurity,
Management management) {
this.plugin = plugin; 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) { if (singleton != null) {
return singleton; return singleton;
} }
Plugin p = Bukkit.getServer().getPluginManager().getPlugin("AuthMe"); // NewAPI is initialized in AuthMe#onEnable -> if singleton is null,
if (p == null || !(p instanceof AuthMe)) { // it means AuthMe isn't initialized (yet)
return null; return null;
}
AuthMe authme = (AuthMe) p;
singleton = new NewAPI(authme);
return singleton;
} }
/** /**
@ -88,7 +95,7 @@ public class NewAPI {
* @return true if the player is an npc * @return true if the player is an npc
*/ */
public boolean isNPC(Player player) { 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) { public boolean isRegistered(String playerName) {
String player = playerName.toLowerCase(); 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 * @return true if the password is correct, false otherwise
*/ */
public boolean checkPassword(String playerName, String passwordToCheck) { 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) { public boolean registerPlayer(String playerName, String password) {
String name = playerName.toLowerCase(); String name = playerName.toLowerCase();
HashedPassword result = plugin.getPasswordSecurity().computeHash(password, name); HashedPassword result = passwordSecurity.computeHash(password, name);
if (isRegistered(name)) { if (isRegistered(name)) {
return false; return false;
} }
@ -158,7 +165,7 @@ public class NewAPI {
.password(result) .password(result)
.realName(playerName) .realName(playerName)
.build(); .build();
return plugin.getDataSource().saveAuth(auth); return dataSource.saveAuth(auth);
} }
/** /**
@ -167,7 +174,7 @@ public class NewAPI {
* @param player The player to log in * @param player The player to log in
*/ */
public void forceLogin(Player player) { 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 * @param player The player to log out
*/ */
public void forceLogout(Player player) { 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? * @param autoLogin Should the player be authenticated automatically after the registration?
*/ */
public void forceRegister(Player player, String password, boolean autoLogin) { 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 * @param player The player to unregister
*/ */
public void forceUnregister(Player player) { public void forceUnregister(Player player) {
plugin.getManagement().performUnregister(player, "", true); management.performUnregister(player, "", true);
} }
} }