mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-24 11:15:19 +01:00
Minor - make AuthMe.database private
- In favor of AuthMe.getDataSource()
This commit is contained in:
parent
571cb6d36b
commit
531327dd9b
@ -102,12 +102,12 @@ public class AuthMe extends JavaPlugin {
|
|||||||
private JsonCache playerBackup;
|
private JsonCache playerBackup;
|
||||||
private ModuleManager moduleManager;
|
private ModuleManager moduleManager;
|
||||||
private PasswordSecurity passwordSecurity;
|
private PasswordSecurity passwordSecurity;
|
||||||
|
private DataSource database;
|
||||||
|
|
||||||
// Public Instances
|
// Public Instances
|
||||||
public NewAPI api;
|
public NewAPI api;
|
||||||
public SendMailSSL mail;
|
public SendMailSSL mail;
|
||||||
public DataManager dataManager;
|
public DataManager dataManager;
|
||||||
public DataSource database;
|
|
||||||
public OtherAccounts otherAccounts;
|
public OtherAccounts otherAccounts;
|
||||||
public Location essentialsSpawn;
|
public Location essentialsSpawn;
|
||||||
|
|
||||||
|
@ -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.security.PasswordSecurity;
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
|
import fr.xephi.authme.security.crypts.HashResult;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.util.Utils;
|
import fr.xephi.authme.util.Utils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -12,34 +13,37 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Deprecated API of AuthMe. Please use {@link NewAPI} instead.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public class API {
|
public class API {
|
||||||
|
|
||||||
public static final String newline = System.getProperty("line.separator");
|
public static final String newline = System.getProperty("line.separator");
|
||||||
public static AuthMe instance;
|
public static AuthMe instance;
|
||||||
|
private static PasswordSecurity passwordSecurity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for API.
|
* Constructor for the deprecated API.
|
||||||
*
|
*
|
||||||
* @param instance AuthMe
|
* @param instance AuthMe
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public API(AuthMe instance) {
|
public API(AuthMe instance) {
|
||||||
API.instance = instance;
|
API.instance = instance;
|
||||||
|
passwordSecurity = instance.getPasswordSecurity();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook into AuthMe
|
* Hook into AuthMe.
|
||||||
*
|
*
|
||||||
* @return AuthMe instance
|
* @return AuthMe instance
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static AuthMe hookAuthMe() {
|
public static AuthMe hookAuthMe() {
|
||||||
if (instance != null)
|
if (instance != null) {
|
||||||
return instance;
|
return instance;
|
||||||
|
}
|
||||||
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("AuthMe");
|
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("AuthMe");
|
||||||
if (plugin == null || !(plugin instanceof AuthMe)) {
|
if (plugin == null || !(plugin instanceof AuthMe)) {
|
||||||
return null;
|
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
|
@Deprecated
|
||||||
public static boolean isAuthenticated(Player player) {
|
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
|
* @return true if the player is unrestricted
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@ -68,13 +74,6 @@ public class API {
|
|||||||
return Utils.isUnrestricted(player);
|
return Utils.isUnrestricted(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getLastLocation.
|
|
||||||
*
|
|
||||||
* @param player Player
|
|
||||||
*
|
|
||||||
* @return Location
|
|
||||||
*/
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static Location getLastLocation(Player player) {
|
public static Location getLastLocation(Player player) {
|
||||||
try {
|
try {
|
||||||
@ -92,13 +91,6 @@ public class API {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method setPlayerInventory.
|
|
||||||
*
|
|
||||||
* @param player Player
|
|
||||||
* @param content ItemStack[]
|
|
||||||
* @param armor ItemStack[]
|
|
||||||
*/
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static void setPlayerInventory(Player player, ItemStack[] content,
|
public static void setPlayerInventory(Player player, ItemStack[] content,
|
||||||
ItemStack[] armor) {
|
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
|
* @return true if player is registered
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static boolean isRegistered(String playerName) {
|
public static boolean isRegistered(String playerName) {
|
||||||
String player = playerName.toLowerCase();
|
String player = playerName.toLowerCase();
|
||||||
return instance.database.isAuthAvailable(player);
|
return instance.getDataSource().isAuthAvailable(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param playerName String
|
* Check the password for the given player.
|
||||||
* @param passwordToCheck String
|
|
||||||
*
|
*
|
||||||
* @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
|
@Deprecated
|
||||||
public static boolean checkPassword(String playerName,
|
public static boolean checkPassword(String playerName,
|
||||||
@ -132,71 +126,53 @@ public class API {
|
|||||||
if (!isRegistered(playerName))
|
if (!isRegistered(playerName))
|
||||||
return false;
|
return false;
|
||||||
String player = playerName.toLowerCase();
|
String player = playerName.toLowerCase();
|
||||||
PlayerAuth auth = instance.database.getAuth(player);
|
PlayerAuth auth = instance.getDataSource().getAuth(player);
|
||||||
try {
|
return passwordSecurity.comparePassword(passwordToCheck, auth.getHash(), playerName);
|
||||||
return PasswordSecurity.comparePasswordWithHash(passwordToCheck, auth.getHash(), playerName);
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a player
|
* Register a player.
|
||||||
*
|
*
|
||||||
* @param playerName String
|
* @param playerName The name of the player
|
||||||
* @param password String
|
* @param password The password
|
||||||
*
|
* @return true if the player was registered correctly
|
||||||
* @return true if the player is register correctly
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static boolean registerPlayer(String playerName, String password) {
|
public static boolean registerPlayer(String playerName, String password) {
|
||||||
try {
|
String name = playerName.toLowerCase();
|
||||||
String name = playerName.toLowerCase();
|
HashResult hashResult = passwordSecurity.computeHash(Settings.getPasswordHash, password, name);
|
||||||
String hash = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
|
if (isRegistered(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) {
|
|
||||||
return false;
|
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
|
@Deprecated
|
||||||
public static void forceLogin(Player player) {
|
public static void forceLogin(Player player) {
|
||||||
instance.getManagement().performLogin(player, "dontneed", true);
|
instance.getManagement().performLogin(player, "dontneed", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getPlugin.
|
|
||||||
*
|
|
||||||
* @return AuthMe
|
|
||||||
*/
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public AuthMe getPlugin() {
|
public AuthMe getPlugin() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param player
|
* Check whether the player is an NPC.
|
||||||
*
|
*
|
||||||
* @return true if player is a npc
|
* @param player The player to verify
|
||||||
*/
|
* @return true if player is an npc
|
||||||
@Deprecated
|
|
||||||
public boolean isaNPC(Player player) {
|
|
||||||
return Utils.isNPC(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param player
|
|
||||||
*
|
|
||||||
* @return true if player is a npc
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean isNPC(Player player) {
|
public boolean isNPC(Player player) {
|
||||||
|
@ -7,7 +7,6 @@ import fr.xephi.authme.command.CommandService;
|
|||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
import fr.xephi.authme.security.PasswordSecurity;
|
|
||||||
import fr.xephi.authme.security.crypts.HashResult;
|
import fr.xephi.authme.security.crypts.HashResult;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -72,10 +71,8 @@ public class ChangePasswordAdminCommand implements ExecutableCommand {
|
|||||||
HashResult hashResult = commandService.getPasswordSecurity().computeHash(playerPass, playerNameLowerCase);
|
HashResult hashResult = commandService.getPasswordSecurity().computeHash(playerPass, playerNameLowerCase);
|
||||||
auth.setHash(hashResult.getHash());
|
auth.setHash(hashResult.getHash());
|
||||||
auth.setSalt(hashResult.getSalt());
|
auth.setSalt(hashResult.getSalt());
|
||||||
if (PasswordSecurity.userSalt.containsKey(playerNameLowerCase)) {
|
|
||||||
auth.setSalt(PasswordSecurity.userSalt.get(playerNameLowerCase));
|
// TODO #358: updatePassword(auth) needs to update the salt, too.
|
||||||
commandService.getDataSource().updateSalt(auth);
|
|
||||||
}
|
|
||||||
if (!dataSource.updatePassword(auth)) {
|
if (!dataSource.updatePassword(auth)) {
|
||||||
commandService.send(sender, MessageKey.ERROR);
|
commandService.send(sender, MessageKey.ERROR);
|
||||||
} else {
|
} else {
|
||||||
|
@ -24,7 +24,7 @@ public class PurgeBannedPlayersCommand implements ExecutableCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Purge the banned players
|
// Purge the banned players
|
||||||
plugin.database.purgeBanned(bannedPlayers);
|
plugin.getDataSource().purgeBanned(bannedPlayers);
|
||||||
if (Settings.purgeEssentialsFile && plugin.ess != null)
|
if (Settings.purgeEssentialsFile && plugin.ess != null)
|
||||||
plugin.dataManager.purgeEssentials(bannedPlayers);
|
plugin.dataManager.purgeEssentials(bannedPlayers);
|
||||||
if (Settings.purgePlayerDat)
|
if (Settings.purgePlayerDat)
|
||||||
|
@ -27,7 +27,7 @@ public class CrazyLoginConverter implements Converter {
|
|||||||
* @param sender CommandSender
|
* @param sender CommandSender
|
||||||
*/
|
*/
|
||||||
public CrazyLoginConverter(AuthMe instance, CommandSender sender) {
|
public CrazyLoginConverter(AuthMe instance, CommandSender sender) {
|
||||||
this.database = instance.database;
|
this.database = instance.getDataSource();
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ public class RoyalAuthConverter implements Converter {
|
|||||||
|
|
||||||
public RoyalAuthConverter(AuthMe plugin) {
|
public RoyalAuthConverter(AuthMe plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.data = plugin.database;
|
this.data = plugin.getDataSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -21,16 +21,14 @@ public class SqliteToSql implements Converter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (plugin.database.getType() != DataSourceType.MYSQL)
|
if (plugin.getDataSource().getType() != DataSourceType.MYSQL) {
|
||||||
{
|
|
||||||
sender.sendMessage("Please config your mySQL connection and re-run this command");
|
sender.sendMessage("Please config your mySQL connection and re-run this command");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
SQLite data = new SQLite();
|
SQLite data = new SQLite();
|
||||||
for (PlayerAuth auth : data.getAllAuths())
|
for (PlayerAuth auth : data.getAllAuths()) {
|
||||||
{
|
plugin.getDataSource().saveAuth(auth);
|
||||||
plugin.database.saveAuth(auth);
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
sender.sendMessage(plugin.getMessages().retrieve(MessageKey.ERROR));
|
sender.sendMessage(plugin.getMessages().retrieve(MessageKey.ERROR));
|
||||||
|
@ -23,7 +23,7 @@ class vAuthFileReader {
|
|||||||
*/
|
*/
|
||||||
public vAuthFileReader(AuthMe plugin) {
|
public vAuthFileReader(AuthMe plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.database = plugin.database;
|
this.database = plugin.getDataSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void convert() {
|
public void convert() {
|
||||||
|
@ -30,7 +30,7 @@ class xAuthToFlat {
|
|||||||
*/
|
*/
|
||||||
public xAuthToFlat(AuthMe instance, CommandSender sender) {
|
public xAuthToFlat(AuthMe instance, CommandSender sender) {
|
||||||
this.instance = instance;
|
this.instance = instance;
|
||||||
this.database = instance.database;
|
this.database = instance.getDataSource();
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import fr.xephi.authme.AuthMe;
|
|||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
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 org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||||
|
|
||||||
@ -24,15 +25,6 @@ public class BungeeCordMessage implements PluginMessageListener {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method onPluginMessageReceived.
|
|
||||||
*
|
|
||||||
* @param channel String
|
|
||||||
* @param player Player
|
|
||||||
* @param message byte[]
|
|
||||||
*
|
|
||||||
* @see org.bukkit.plugin.messaging.PluginMessageListener#onPluginMessageReceived(String, Player, byte[])
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
||||||
if (!channel.equals("BungeeCord")) {
|
if (!channel.equals("BungeeCord")) {
|
||||||
@ -50,21 +42,22 @@ public class BungeeCordMessage implements PluginMessageListener {
|
|||||||
final String[] args = str.split(";");
|
final String[] args = str.split(";");
|
||||||
final String act = args[0];
|
final String act = args[0];
|
||||||
final String name = args[1];
|
final String name = args[1];
|
||||||
|
final DataSource dataSource = plugin.getDataSource();
|
||||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PlayerAuth auth = plugin.database.getAuth(name);
|
PlayerAuth auth = dataSource.getAuth(name);
|
||||||
if (auth == null) {
|
if (auth == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ("login".equals(act)) {
|
if ("login".equals(act)) {
|
||||||
PlayerCache.getInstance().updatePlayer(auth);
|
PlayerCache.getInstance().updatePlayer(auth);
|
||||||
plugin.database.setLogged(name);
|
dataSource.setLogged(name);
|
||||||
ConsoleLogger.info("Player " + auth.getNickname()
|
ConsoleLogger.info("Player " + auth.getNickname()
|
||||||
+ " has logged in from one of your server!");
|
+ " has logged in from one of your server!");
|
||||||
} else if ("logout".equals(act)) {
|
} else if ("logout".equals(act)) {
|
||||||
PlayerCache.getInstance().removePlayer(name);
|
PlayerCache.getInstance().removePlayer(name);
|
||||||
plugin.database.setUnlogged(name);
|
dataSource.setUnlogged(name);
|
||||||
ConsoleLogger.info("Player " + auth.getNickname()
|
ConsoleLogger.info("Player " + auth.getNickname()
|
||||||
+ " has logged out from one of your server!");
|
+ " has logged out from one of your server!");
|
||||||
} else if ("register".equals(act)) {
|
} else if ("register".equals(act)) {
|
||||||
@ -73,10 +66,11 @@ public class BungeeCordMessage implements PluginMessageListener {
|
|||||||
} else if ("changepassword".equals(act)) {
|
} else if ("changepassword".equals(act)) {
|
||||||
final String password = args[2];
|
final String password = args[2];
|
||||||
auth.setHash(password);
|
auth.setHash(password);
|
||||||
if (args.length == 4)
|
if (args.length == 4) {
|
||||||
auth.setSalt(args[3]);
|
auth.setSalt(args[3]);
|
||||||
|
}
|
||||||
PlayerCache.getInstance().updatePlayer(auth);
|
PlayerCache.getInstance().updatePlayer(auth);
|
||||||
plugin.database.updatePassword(auth);
|
dataSource.updatePassword(auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (plugin.database.isAuthAvailable(player.getName().toLowerCase())) {
|
if (plugin.getDataSource().isAuthAvailable(player.getName().toLowerCase())) {
|
||||||
m.send(player, MessageKey.LOGIN_MESSAGE);
|
m.send(player, MessageKey.LOGIN_MESSAGE);
|
||||||
} else {
|
} else {
|
||||||
if (Settings.emailRegistration) {
|
if (Settings.emailRegistration) {
|
||||||
@ -221,8 +221,9 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onPreLogin(AsyncPlayerPreLoginEvent event) {
|
public void onPreLogin(AsyncPlayerPreLoginEvent event) {
|
||||||
PlayerAuth auth = plugin.database.getAuth(event.getName());
|
PlayerAuth auth = plugin.getDataSource().getAuth(event.getName());
|
||||||
if (auth != null && auth.getRealName() != null && !auth.getRealName().isEmpty() && !auth.getRealName().equals("Player") && !auth.getRealName().equals(event.getName())) {
|
if (auth != null && auth.getRealName() != null && !auth.getRealName().isEmpty() &&
|
||||||
|
!auth.getRealName().equals("Player") && !auth.getRealName().equals(event.getName())) {
|
||||||
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
||||||
event.setKickMessage("You should join using username: " + ChatColor.AQUA + auth.getRealName() +
|
event.setKickMessage("You should join using username: " + ChatColor.AQUA + auth.getRealName() +
|
||||||
ChatColor.RESET + "\nnot: " + ChatColor.RED + event.getName()); // TODO: write a better message
|
ChatColor.RESET + "\nnot: " + ChatColor.RED + event.getName()); // TODO: write a better message
|
||||||
@ -231,7 +232,7 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
|
|
||||||
if (auth != null && auth.getRealName().equals("Player")) {
|
if (auth != null && auth.getRealName().equals("Player")) {
|
||||||
auth.setRealName(event.getName());
|
auth.setRealName(event.getName());
|
||||||
plugin.database.saveAuth(auth);
|
plugin.getDataSource().saveAuth(auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auth == null && Settings.enableProtection) {
|
if (auth == null && Settings.enableProtection) {
|
||||||
@ -302,7 +303,7 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final String name = player.getName().toLowerCase();
|
final String name = player.getName().toLowerCase();
|
||||||
boolean isAuthAvailable = plugin.database.isAuthAvailable(name);
|
boolean isAuthAvailable = plugin.getDataSource().isAuthAvailable(name);
|
||||||
|
|
||||||
if (Settings.isKickNonRegisteredEnabled && !isAuthAvailable) {
|
if (Settings.isKickNonRegisteredEnabled && !isAuthAvailable) {
|
||||||
if (Settings.antiBotInAction) {
|
if (Settings.antiBotInAction) {
|
||||||
@ -475,9 +476,16 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
String name = player.getName().toLowerCase();
|
String name = player.getName().toLowerCase();
|
||||||
Location spawn = plugin.getSpawnLocation(player);
|
Location spawn = plugin.getSpawnLocation(player);
|
||||||
if (Settings.isSaveQuitLocationEnabled && plugin.database.isAuthAvailable(name)) {
|
if (Settings.isSaveQuitLocationEnabled && plugin.getDataSource().isAuthAvailable(name)) {
|
||||||
PlayerAuth auth = new PlayerAuth(name, spawn.getX(), spawn.getY(), spawn.getZ(), spawn.getWorld().getName(), player.getName());
|
PlayerAuth auth = PlayerAuth.builder()
|
||||||
plugin.database.updateQuitLoc(auth);
|
.name(name)
|
||||||
|
.realName(player.getName())
|
||||||
|
.locX(spawn.getX())
|
||||||
|
.locY(spawn.getY())
|
||||||
|
.locZ(spawn.getZ())
|
||||||
|
.locWorld(spawn.getWorld().getName())
|
||||||
|
.build();
|
||||||
|
plugin.getDataSource().updateQuitLoc(auth);
|
||||||
}
|
}
|
||||||
if (spawn != null && spawn.getWorld() != null) {
|
if (spawn != null && spawn.getWorld() != null) {
|
||||||
event.setRespawnLocation(spawn);
|
event.setRespawnLocation(spawn);
|
||||||
|
@ -33,7 +33,7 @@ public class Management {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
new AsynchronousLogin(player, password, forceLogin, plugin, plugin.database).process();
|
new AsynchronousLogin(player, password, forceLogin, plugin, plugin.getDataSource()).process();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -43,7 +43,7 @@ public class Management {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
new AsynchronousLogout(player, plugin, plugin.database).process();
|
new AsynchronousLogout(player, plugin, plugin.getDataSource()).process();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -53,7 +53,7 @@ public class Management {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
new AsyncRegister(player, password, email, plugin, plugin.database).process();
|
new AsyncRegister(player, password, email, plugin, plugin.getDataSource()).process();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ public class Management {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
new AsynchronousJoin(player, plugin, plugin.database).process();
|
new AsynchronousJoin(player, plugin, plugin.getDataSource()).process();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -84,7 +84,7 @@ public class Management {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
new AsynchronousQuit(player, plugin, plugin.database, isKick).process();
|
new AsynchronousQuit(player, plugin, plugin.getDataSource(), isKick).process();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -40,7 +40,7 @@ public class AsyncChangeEmail {
|
|||||||
|
|
||||||
if (Settings.getmaxRegPerEmail > 0) {
|
if (Settings.getmaxRegPerEmail > 0) {
|
||||||
if (!plugin.getPermissionsManager().hasPermission(player, PlayerPermission.ALLOW_MULTIPLE_ACCOUNTS)
|
if (!plugin.getPermissionsManager().hasPermission(player, PlayerPermission.ALLOW_MULTIPLE_ACCOUNTS)
|
||||||
&& plugin.database.getAllAuthsByEmail(newEmail).size() >= Settings.getmaxRegPerEmail) {
|
&& plugin.getDataSource().getAllAuthsByEmail(newEmail).size() >= Settings.getmaxRegPerEmail) {
|
||||||
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
|
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -68,7 +68,7 @@ public class AsyncChangeEmail {
|
|||||||
}
|
}
|
||||||
String old = auth.getEmail();
|
String old = auth.getEmail();
|
||||||
auth.setEmail(newEmail);
|
auth.setEmail(newEmail);
|
||||||
if (!plugin.database.updateEmail(auth)) {
|
if (!plugin.getDataSource().updateEmail(auth)) {
|
||||||
m.send(player, MessageKey.ERROR);
|
m.send(player, MessageKey.ERROR);
|
||||||
auth.setEmail(old);
|
auth.setEmail(old);
|
||||||
return;
|
return;
|
||||||
@ -81,7 +81,7 @@ public class AsyncChangeEmail {
|
|||||||
}
|
}
|
||||||
m.send(player, MessageKey.EMAIL_CHANGED_SUCCESS);
|
m.send(player, MessageKey.EMAIL_CHANGED_SUCCESS);
|
||||||
} else {
|
} else {
|
||||||
if (plugin.database.isAuthAvailable(playerName)) {
|
if (plugin.getDataSource().isAuthAvailable(playerName)) {
|
||||||
m.send(player, MessageKey.LOGIN_MESSAGE);
|
m.send(player, MessageKey.LOGIN_MESSAGE);
|
||||||
} else {
|
} else {
|
||||||
if (Settings.emailRegistration) {
|
if (Settings.emailRegistration) {
|
||||||
|
@ -6,7 +6,6 @@ import fr.xephi.authme.cache.auth.PlayerCache;
|
|||||||
import fr.xephi.authme.cache.backup.JsonCache;
|
import fr.xephi.authme.cache.backup.JsonCache;
|
||||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||||
import fr.xephi.authme.security.PasswordSecurity;
|
|
||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
import fr.xephi.authme.output.Messages;
|
import fr.xephi.authme.output.Messages;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
@ -20,16 +19,12 @@ import org.bukkit.potion.PotionEffectType;
|
|||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public class AsynchronousUnregister {
|
public class AsynchronousUnregister {
|
||||||
|
|
||||||
protected final Player player;
|
private final Player player;
|
||||||
protected final String name;
|
private final String name;
|
||||||
protected final String password;
|
private final String password;
|
||||||
protected final boolean force;
|
private final boolean force;
|
||||||
private final AuthMe plugin;
|
private final AuthMe plugin;
|
||||||
private final Messages m;
|
private final Messages m;
|
||||||
private final JsonCache playerCache;
|
private final JsonCache playerCache;
|
||||||
@ -52,18 +47,13 @@ public class AsynchronousUnregister {
|
|||||||
this.playerCache = new JsonCache();
|
this.playerCache = new JsonCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getIp.
|
|
||||||
*
|
|
||||||
* @return String
|
|
||||||
*/
|
|
||||||
protected String getIp() {
|
protected String getIp() {
|
||||||
return plugin.getIP(player);
|
return plugin.getIP(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process() {
|
public void process() {
|
||||||
if (force || plugin.getPasswordSecurity().comparePassword(password, PlayerCache.getInstance().getAuth(name).getHash(), player.getName())) {
|
if (force || plugin.getPasswordSecurity().comparePassword(password, PlayerCache.getInstance().getAuth(name).getHash(), player.getName())) {
|
||||||
if (!plugin.database.removeAuth(name)) {
|
if (!plugin.getDataSource().removeAuth(name)) {
|
||||||
m.send(player, MessageKey.ERROR);
|
m.send(player, MessageKey.ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -28,16 +28,6 @@ public class PasswordSecurity {
|
|||||||
this.supportOldAlgorithm = supportOldAlgorithm;
|
this.supportOldAlgorithm = supportOldAlgorithm;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static String createSalt(int length) {
|
|
||||||
return RandomString.generateHex(length);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static String getHash(HashAlgorithm alg, String password, String playerName) throws NoSuchAlgorithmException {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static boolean comparePasswordWithHash(String password, String hash,
|
public static boolean comparePasswordWithHash(String password, String hash,
|
||||||
String playerName) throws NoSuchAlgorithmException {
|
String playerName) throws NoSuchAlgorithmException {
|
||||||
@ -142,12 +132,12 @@ public class PasswordSecurity {
|
|||||||
try {
|
try {
|
||||||
EncryptionMethod method = algo.getClazz().newInstance();
|
EncryptionMethod method = algo.getClazz().newInstance();
|
||||||
if (method.comparePassword(hash, password, salt, playerName)) {
|
if (method.comparePassword(hash, password, salt, playerName)) {
|
||||||
PlayerAuth nAuth = AuthMe.getInstance().database.getAuth(playerName);
|
PlayerAuth nAuth = AuthMe.getInstance().getDataSource().getAuth(playerName);
|
||||||
if (nAuth != null) {
|
if (nAuth != null) {
|
||||||
nAuth.setHash(getHash(Settings.getPasswordHash, password, playerName));
|
// nAuth.setHash(getHash(Settings.getPasswordHash, password, playerName));
|
||||||
nAuth.setSalt(userSalt.containsKey(playerName) ? userSalt.get(playerName) : "");
|
nAuth.setSalt(userSalt.containsKey(playerName) ? userSalt.get(playerName) : "");
|
||||||
AuthMe.getInstance().database.updatePassword(nAuth);
|
AuthMe.getInstance().getDataSource().updatePassword(nAuth);
|
||||||
AuthMe.getInstance().database.updateSalt(nAuth);
|
AuthMe.getInstance().getDataSource().updateSalt(nAuth);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package fr.xephi.authme.security.crypts.description;
|
package fr.xephi.authme.security.crypts.description;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type of salt used by an encryption algorithms.
|
* The type of salt used by an encryption algorithm.
|
||||||
*/
|
*/
|
||||||
public enum SaltType {
|
public enum SaltType {
|
||||||
|
|
||||||
|
@ -143,13 +143,9 @@ public final class Utils {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Settings.isForcedRegistrationEnabled) {
|
if (!Settings.isForcedRegistrationEnabled && !plugin.getDataSource().isAuthAvailable(player.getName())) {
|
||||||
// TODO ljacqu 20151123: Use a getter to retrieve things from AuthMe
|
return true;
|
||||||
if (!plugin.database.isAuthAvailable(player.getName())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,15 +155,6 @@ public final class Utils {
|
|||||||
&& (Settings.getUnrestrictedName.contains(player.getName().toLowerCase()));
|
&& (Settings.getUnrestrictedName.contains(player.getName().toLowerCase()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method packCoords.
|
|
||||||
*
|
|
||||||
* @param x double
|
|
||||||
* @param y double
|
|
||||||
* @param z double
|
|
||||||
* @param w String
|
|
||||||
* @param pl Player
|
|
||||||
*/
|
|
||||||
public static void packCoords(double x, double y, double z, String w, final Player pl) {
|
public static void packCoords(double x, double y, double z, String w, final Player pl) {
|
||||||
World theWorld;
|
World theWorld;
|
||||||
if (w.equals("unavailableworld")) {
|
if (w.equals("unavailableworld")) {
|
||||||
|
Loading…
Reference in New Issue
Block a user