Minor - make AuthMe.database private

- In favor of AuthMe.getDataSource()
This commit is contained in:
ljacqu
2015-12-29 11:55:57 +01:00
parent 571cb6d36b
commit 531327dd9b
17 changed files with 98 additions and 158 deletions
+42 -66
View File
@@ -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.security.PasswordSecurity;
import fr.xephi.authme.security.crypts.HashResult;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.Utils;
import org.bukkit.Bukkit;
@@ -12,34 +13,37 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import java.security.NoSuchAlgorithmException;
/**
* Deprecated API of AuthMe. Please use {@link NewAPI} instead.
*/
@Deprecated
public class API {
public static final String newline = System.getProperty("line.separator");
public static AuthMe instance;
private static PasswordSecurity passwordSecurity;
/**
* Constructor for API.
* Constructor for the deprecated API.
*
* @param instance AuthMe
*/
@Deprecated
public API(AuthMe instance) {
API.instance = instance;
passwordSecurity = instance.getPasswordSecurity();
}
/**
* Hook into AuthMe
* Hook into AuthMe.
*
* @return AuthMe instance
*/
@Deprecated
public static AuthMe hookAuthMe() {
if (instance != null)
if (instance != null) {
return instance;
}
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("AuthMe");
if (plugin == null || !(plugin instanceof AuthMe)) {
return null;
@@ -49,9 +53,10 @@ public class API {
}
/**
* @param player
* Return whether the player is authenticated.
*
* @return true if player is authenticate
* @param player The player to verify
* @return true if the player is authenticated
*/
@Deprecated
public static boolean isAuthenticated(Player player) {
@@ -59,8 +64,9 @@ public class API {
}
/**
* @param player
* Return whether the player is unrestricted.
*
* @param player The player to verify
* @return true if the player is unrestricted
*/
@Deprecated
@@ -68,13 +74,6 @@ public class API {
return Utils.isUnrestricted(player);
}
/**
* Method getLastLocation.
*
* @param player Player
*
* @return Location
*/
@Deprecated
public static Location getLastLocation(Player player) {
try {
@@ -92,13 +91,6 @@ public class API {
}
}
/**
* Method setPlayerInventory.
*
* @param player Player
* @param content ItemStack[]
* @param armor ItemStack[]
*/
@Deprecated
public static void setPlayerInventory(Player player, ItemStack[] content,
ItemStack[] armor) {
@@ -110,21 +102,23 @@ public class API {
}
/**
* @param playerName
* Check whether the given player name is registered.
*
* @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 instance.database.isAuthAvailable(player);
return instance.getDataSource().isAuthAvailable(player);
}
/**
* @param playerName String
* @param passwordToCheck String
* Check the password for the given player.
*
* @return true if the password is correct , false else
* @param playerName The name of the player
* @param passwordToCheck The password to check
* @return true if the password is correct, false otherwise
*/
@Deprecated
public static boolean checkPassword(String playerName,
@@ -132,71 +126,53 @@ public class API {
if (!isRegistered(playerName))
return false;
String player = playerName.toLowerCase();
PlayerAuth auth = instance.database.getAuth(player);
try {
return PasswordSecurity.comparePasswordWithHash(passwordToCheck, auth.getHash(), playerName);
} catch (NoSuchAlgorithmException e) {
return false;
}
PlayerAuth auth = instance.getDataSource().getAuth(player);
return passwordSecurity.comparePassword(passwordToCheck, auth.getHash(), playerName);
}
/**
* Register a player
* Register a player.
*
* @param playerName String
* @param password String
*
* @return true if the player is register correctly
* @param playerName The name of the player
* @param password The password
* @return true if the player was registered correctly
*/
@Deprecated
public static boolean registerPlayer(String playerName, String password) {
try {
String name = playerName.toLowerCase();
String hash = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
if (isRegistered(name)) {
return false;
}
PlayerAuth auth = new PlayerAuth(name, hash, "198.18.0.1", 0, "your@email.com", playerName);
return instance.database.saveAuth(auth);
} catch (NoSuchAlgorithmException ex) {
String name = playerName.toLowerCase();
HashResult hashResult = passwordSecurity.computeHash(Settings.getPasswordHash, password, name);
if (isRegistered(name)) {
return false;
}
PlayerAuth auth = PlayerAuth.builder()
.name(name)
.hash(hashResult.getHash())
.lastLogin(0)
.realName(playerName)
.build();
return instance.getDataSource().saveAuth(auth);
}
/**
* Force a player to login
* Force a player to log in.
*
* @param player * player
* @param player The player to log in
*/
@Deprecated
public static void forceLogin(Player player) {
instance.getManagement().performLogin(player, "dontneed", true);
}
/**
* Method getPlugin.
*
* @return AuthMe
*/
@Deprecated
public AuthMe getPlugin() {
return instance;
}
/**
* @param player
* Check whether the player is an NPC.
*
* @return true if player is a npc
*/
@Deprecated
public boolean isaNPC(Player player) {
return Utils.isNPC(player);
}
/**
* @param player
*
* @return true if player is a npc
* @param player The player to verify
* @return true if player is an npc
*/
@Deprecated
public boolean isNPC(Player player) {