mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-01-14 11:41:20 +01:00
Service cleanup
This commit is contained in:
parent
5c2d7139bc
commit
42dbb27728
@ -25,16 +25,17 @@ import fr.xephi.authme.output.Messages;
|
|||||||
import fr.xephi.authme.permission.PermissionsManager;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
import fr.xephi.authme.permission.PermissionsSystemType;
|
import fr.xephi.authme.permission.PermissionsSystemType;
|
||||||
import fr.xephi.authme.security.crypts.SHA256;
|
import fr.xephi.authme.security.crypts.SHA256;
|
||||||
|
import fr.xephi.authme.service.BackupService;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
import fr.xephi.authme.task.CleanupTask;
|
import fr.xephi.authme.task.CleanupTask;
|
||||||
import fr.xephi.authme.task.purge.PurgeService;
|
import fr.xephi.authme.task.purge.PurgeService;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.util.GeoLiteAPI;
|
import fr.xephi.authme.geoip.GeoLiteAPI;
|
||||||
import fr.xephi.authme.util.MigrationService;
|
import fr.xephi.authme.service.MigrationService;
|
||||||
import fr.xephi.authme.util.Utils;
|
import fr.xephi.authme.util.PlayerUtils;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -48,7 +49,7 @@ import org.bukkit.scheduler.BukkitScheduler;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import static fr.xephi.authme.util.BukkitService.TICKS_PER_MINUTE;
|
import static fr.xephi.authme.service.BukkitService.TICKS_PER_MINUTE;
|
||||||
import static fr.xephi.authme.util.Utils.isClassLoaded;
|
import static fr.xephi.authme.util.Utils.isClassLoaded;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -150,7 +151,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Do a backup on start
|
// Do a backup on start
|
||||||
new PerformBackup(this, settings).doBackup(PerformBackup.BackupCause.START);
|
new BackupService(this, settings).doBackup(BackupService.BackupCause.START);
|
||||||
|
|
||||||
// Set up Metrics
|
// Set up Metrics
|
||||||
MetricsManager.sendMetrics(this, settings);
|
MetricsManager.sendMetrics(this, settings);
|
||||||
@ -344,7 +345,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
|
|
||||||
// Do backup on stop if enabled
|
// Do backup on stop if enabled
|
||||||
if (settings != null) {
|
if (settings != null) {
|
||||||
new PerformBackup(this, settings).doBackup(PerformBackup.BackupCause.STOP);
|
new BackupService(this, settings).doBackup(BackupService.BackupCause.STOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for tasks and close data source
|
// Wait for tasks and close data source
|
||||||
@ -360,7 +361,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
|
|
||||||
public String replaceAllInfo(String message, Player player) {
|
public String replaceAllInfo(String message, Player player) {
|
||||||
String playersOnline = Integer.toString(bukkitService.getOnlinePlayers().size());
|
String playersOnline = Integer.toString(bukkitService.getOnlinePlayers().size());
|
||||||
String ipAddress = Utils.getPlayerIp(player);
|
String ipAddress = PlayerUtils.getPlayerIp(player);
|
||||||
Server server = getServer();
|
Server server = getServer();
|
||||||
return message
|
return message
|
||||||
.replace("&", "\u00a7")
|
.replace("&", "\u00a7")
|
||||||
|
@ -8,7 +8,7 @@ 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;
|
||||||
import fr.xephi.authme.util.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
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;
|
||||||
|
@ -8,7 +8,7 @@ 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;
|
||||||
import fr.xephi.authme.util.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
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;
|
||||||
|
@ -7,8 +7,8 @@ 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;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.util.Utils;
|
import fr.xephi.authme.util.PlayerUtils;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -108,7 +108,7 @@ public class TempbanManager implements SettingsDependent, HasCleanup {
|
|||||||
*/
|
*/
|
||||||
public void tempbanPlayer(final Player player) {
|
public void tempbanPlayer(final Player player) {
|
||||||
if (isEnabled) {
|
if (isEnabled) {
|
||||||
final String ip = Utils.getPlayerIp(player);
|
final String ip = PlayerUtils.getPlayerIp(player);
|
||||||
final String reason = messages.retrieveSingle(MessageKey.TEMPBAN_MAX_LOGINS);
|
final String reason = messages.retrieveSingle(MessageKey.TEMPBAN_MAX_LOGINS);
|
||||||
|
|
||||||
final Date expires = new Date();
|
final Date expires = new Date();
|
||||||
|
@ -14,9 +14,9 @@ import fr.xephi.authme.cache.limbo.PlayerData;
|
|||||||
import fr.xephi.authme.initialization.DataFolder;
|
import fr.xephi.authme.initialization.DataFolder;
|
||||||
import fr.xephi.authme.permission.PermissionsManager;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
import fr.xephi.authme.settings.SpawnLoader;
|
import fr.xephi.authme.settings.SpawnLoader;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.util.FileUtils;
|
import fr.xephi.authme.util.FileUtils;
|
||||||
import fr.xephi.authme.util.Utils;
|
import fr.xephi.authme.util.PlayerUtils;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -64,7 +64,7 @@ public class PlayerDataStorage {
|
|||||||
* @return PlayerData object if the data is exist, null otherwise.
|
* @return PlayerData object if the data is exist, null otherwise.
|
||||||
*/
|
*/
|
||||||
public PlayerData readData(Player player) {
|
public PlayerData readData(Player player) {
|
||||||
String id = Utils.getUUIDorName(player);
|
String id = PlayerUtils.getUUIDorName(player);
|
||||||
File file = new File(cacheDir, id + File.separator + "data.json");
|
File file = new File(cacheDir, id + File.separator + "data.json");
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
return null;
|
return null;
|
||||||
@ -85,7 +85,7 @@ public class PlayerDataStorage {
|
|||||||
* @param player player to save
|
* @param player player to save
|
||||||
*/
|
*/
|
||||||
public void saveData(Player player) {
|
public void saveData(Player player) {
|
||||||
String id = Utils.getUUIDorName(player);
|
String id = PlayerUtils.getUUIDorName(player);
|
||||||
Location location = spawnLoader.getPlayerLocationOrSpawn(player);
|
Location location = spawnLoader.getPlayerLocationOrSpawn(player);
|
||||||
String group = "";
|
String group = "";
|
||||||
if (permissionsManager.hasGroupSupport()) {
|
if (permissionsManager.hasGroupSupport()) {
|
||||||
@ -113,7 +113,7 @@ public class PlayerDataStorage {
|
|||||||
* @param player player to remove
|
* @param player player to remove
|
||||||
*/
|
*/
|
||||||
public void removeData(Player player) {
|
public void removeData(Player player) {
|
||||||
String id = Utils.getUUIDorName(player);
|
String id = PlayerUtils.getUUIDorName(player);
|
||||||
File file = new File(cacheDir, id);
|
File file = new File(cacheDir, id);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
FileUtils.purgeDirectory(file);
|
FileUtils.purgeDirectory(file);
|
||||||
@ -131,7 +131,7 @@ public class PlayerDataStorage {
|
|||||||
* @return true if data exist, false otherwise.
|
* @return true if data exist, false otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean hasData(Player player) {
|
public boolean hasData(Player player) {
|
||||||
String id = Utils.getUUIDorName(player);
|
String id = PlayerUtils.getUUIDorName(player);
|
||||||
File file = new File(cacheDir, id + File.separator + "data.json");
|
File file = new File(cacheDir, id + File.separator + "data.json");
|
||||||
return file.exists();
|
return file.exists();
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import com.github.authme.configme.properties.Property;
|
|||||||
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;
|
||||||
import fr.xephi.authme.util.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -5,7 +5,7 @@ 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.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -9,9 +9,9 @@ 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.PasswordSecurity;
|
||||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.util.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import fr.xephi.authme.util.ValidationService.ValidationResult;
|
import fr.xephi.authme.service.ValidationService.ValidationResult;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -15,7 +15,7 @@ import fr.xephi.authme.converter.SqliteToSql;
|
|||||||
import fr.xephi.authme.converter.vAuthConverter;
|
import fr.xephi.authme.converter.vAuthConverter;
|
||||||
import fr.xephi.authme.converter.xAuthConverter;
|
import fr.xephi.authme.converter.xAuthConverter;
|
||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -3,7 +3,7 @@ package fr.xephi.authme.command.executable.authme;
|
|||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
import fr.xephi.authme.permission.PermissionsManager;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
import fr.xephi.authme.process.Management;
|
import fr.xephi.authme.process.Management;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package fr.xephi.authme.command.executable.authme;
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ package fr.xephi.authme.command.executable.authme;
|
|||||||
|
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
import fr.xephi.authme.task.purge.PurgeService;
|
import fr.xephi.authme.task.purge.PurgeService;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
@ -9,9 +9,9 @@ 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.PasswordSecurity;
|
||||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.util.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import fr.xephi.authme.util.ValidationService.ValidationResult;
|
import fr.xephi.authme.service.ValidationService.ValidationResult;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ 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.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -5,7 +5,7 @@ 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.process.Management;
|
import fr.xephi.authme.process.Management;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ package fr.xephi.authme.command.executable.authme;
|
|||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.command.CommandService;
|
import fr.xephi.authme.command.CommandService;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -5,8 +5,8 @@ import fr.xephi.authme.command.CommandService;
|
|||||||
import fr.xephi.authme.command.PlayerCommand;
|
import fr.xephi.authme.command.PlayerCommand;
|
||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
import fr.xephi.authme.process.Management;
|
import fr.xephi.authme.process.Management;
|
||||||
import fr.xephi.authme.util.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import fr.xephi.authme.util.ValidationService.ValidationResult;
|
import fr.xephi.authme.service.ValidationService.ValidationResult;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -11,7 +11,7 @@ import fr.xephi.authme.output.MessageKey;
|
|||||||
import fr.xephi.authme.security.PasswordSecurity;
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
import fr.xephi.authme.security.RandomString;
|
import fr.xephi.authme.security.RandomString;
|
||||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||||
import fr.xephi.authme.service.RecoveryCodeManager;
|
import fr.xephi.authme.service.RecoveryCodeService;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -40,7 +40,7 @@ public class RecoverEmailCommand extends PlayerCommand {
|
|||||||
private SendMailSSL sendMailSsl;
|
private SendMailSSL sendMailSsl;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private RecoveryCodeManager recoveryCodeManager;
|
private RecoveryCodeService recoveryCodeService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void runCommand(Player player, List<String> arguments) {
|
public void runCommand(Player player, List<String> arguments) {
|
||||||
@ -69,7 +69,7 @@ public class RecoverEmailCommand extends PlayerCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recoveryCodeManager.isRecoveryCodeNeeded()) {
|
if (recoveryCodeService.isRecoveryCodeNeeded()) {
|
||||||
// Process /email recovery addr@example.com
|
// Process /email recovery addr@example.com
|
||||||
if (arguments.size() == 1) {
|
if (arguments.size() == 1) {
|
||||||
createAndSendRecoveryCode(player, email);
|
createAndSendRecoveryCode(player, email);
|
||||||
@ -83,20 +83,20 @@ public class RecoverEmailCommand extends PlayerCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createAndSendRecoveryCode(Player player, String email) {
|
private void createAndSendRecoveryCode(Player player, String email) {
|
||||||
String recoveryCode = recoveryCodeManager.generateCode(player.getName());
|
String recoveryCode = recoveryCodeService.generateCode(player.getName());
|
||||||
sendMailSsl.sendRecoveryCode(player.getName(), email, recoveryCode);
|
sendMailSsl.sendRecoveryCode(player.getName(), email, recoveryCode);
|
||||||
commandService.send(player, MessageKey.RECOVERY_CODE_SENT);
|
commandService.send(player, MessageKey.RECOVERY_CODE_SENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processRecoveryCode(Player player, String code, String email) {
|
private void processRecoveryCode(Player player, String code, String email) {
|
||||||
final String name = player.getName();
|
final String name = player.getName();
|
||||||
if (!recoveryCodeManager.isCodeValid(name, code)) {
|
if (!recoveryCodeService.isCodeValid(name, code)) {
|
||||||
commandService.send(player, MessageKey.INCORRECT_RECOVERY_CODE);
|
commandService.send(player, MessageKey.INCORRECT_RECOVERY_CODE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
generateAndSendNewPassword(player, email);
|
generateAndSendNewPassword(player, email);
|
||||||
recoveryCodeManager.removeCode(name);
|
recoveryCodeService.removeCode(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateAndSendNewPassword(Player player, String email) {
|
private void generateAndSendNewPassword(Player player, String email) {
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package fr.xephi.authme.util;
|
package fr.xephi.authme.geoip;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.maxmind.geoip.LookupService;
|
import com.maxmind.geoip.LookupService;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.initialization.DataFolder;
|
import fr.xephi.authme.initialization.DataFolder;
|
||||||
|
import fr.xephi.authme.util.FileUtils;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.io.File;
|
import java.io.File;
|
@ -22,9 +22,9 @@ import fr.xephi.authme.settings.properties.AuthMeSettingsRetriever;
|
|||||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.util.FileUtils;
|
import fr.xephi.authme.util.FileUtils;
|
||||||
import fr.xephi.authme.util.MigrationService;
|
import fr.xephi.authme.service.MigrationService;
|
||||||
import fr.xephi.authme.util.StringUtils;
|
import fr.xephi.authme.util.StringUtils;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -37,7 +37,7 @@ import java.util.List;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import static fr.xephi.authme.settings.properties.EmailSettings.RECALL_PLAYERS;
|
import static fr.xephi.authme.settings.properties.EmailSettings.RECALL_PLAYERS;
|
||||||
import static fr.xephi.authme.util.BukkitService.TICKS_PER_MINUTE;
|
import static fr.xephi.authme.service.BukkitService.TICKS_PER_MINUTE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes various services.
|
* Initializes various services.
|
||||||
|
@ -9,8 +9,8 @@ import fr.xephi.authme.hooks.PluginHooks;
|
|||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.SpawnLoader;
|
import fr.xephi.authme.settings.SpawnLoader;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.util.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ import fr.xephi.authme.hooks.PluginHooks;
|
|||||||
import fr.xephi.authme.initialization.SettingsDependent;
|
import fr.xephi.authme.initialization.SettingsDependent;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.util.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.entity.EntityEvent;
|
import org.bukkit.event.entity.EntityEvent;
|
||||||
|
@ -13,10 +13,10 @@ import fr.xephi.authme.settings.Settings;
|
|||||||
import fr.xephi.authme.settings.properties.ProtectionSettings;
|
import fr.xephi.authme.settings.properties.ProtectionSettings;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.util.StringUtils;
|
import fr.xephi.authme.util.StringUtils;
|
||||||
import fr.xephi.authme.util.Utils;
|
import fr.xephi.authme.util.Utils;
|
||||||
import fr.xephi.authme.util.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerLoginEvent;
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
|
@ -11,9 +11,9 @@ import fr.xephi.authme.settings.SpawnLoader;
|
|||||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.util.TeleportationService;
|
import fr.xephi.authme.service.TeleportationService;
|
||||||
import fr.xephi.authme.util.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
@ -7,7 +7,7 @@ import fr.xephi.authme.cache.auth.PlayerCache;
|
|||||||
import fr.xephi.authme.initialization.SettingsDependent;
|
import fr.xephi.authme.initialization.SettingsDependent;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -5,7 +5,7 @@ import fr.xephi.authme.ConsoleLogger;
|
|||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.util.FileUtils;
|
import fr.xephi.authme.util.FileUtils;
|
||||||
import fr.xephi.authme.util.StringUtils;
|
import fr.xephi.authme.util.StringUtils;
|
||||||
import org.apache.commons.mail.EmailConstants;
|
import org.apache.commons.mail.EmailConstants;
|
||||||
|
@ -9,7 +9,7 @@ import fr.xephi.authme.process.logout.AsynchronousLogout;
|
|||||||
import fr.xephi.authme.process.quit.AsynchronousQuit;
|
import fr.xephi.authme.process.quit.AsynchronousQuit;
|
||||||
import fr.xephi.authme.process.register.AsyncRegister;
|
import fr.xephi.authme.process.register.AsyncRegister;
|
||||||
import fr.xephi.authme.process.unregister.AsynchronousUnregister;
|
import fr.xephi.authme.process.unregister.AsynchronousUnregister;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ import fr.xephi.authme.permission.AuthGroupType;
|
|||||||
import fr.xephi.authme.permission.PermissionNode;
|
import fr.xephi.authme.permission.PermissionNode;
|
||||||
import fr.xephi.authme.permission.PermissionsManager;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.util.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import fr.xephi.authme.process.logout.ProcessSynchronousPlayerLogout;
|
|||||||
import fr.xephi.authme.process.quit.ProcessSyncronousPlayerQuit;
|
import fr.xephi.authme.process.quit.ProcessSyncronousPlayerQuit;
|
||||||
import fr.xephi.authme.process.register.ProcessSyncEmailRegister;
|
import fr.xephi.authme.process.register.ProcessSyncEmailRegister;
|
||||||
import fr.xephi.authme.process.register.ProcessSyncPasswordRegister;
|
import fr.xephi.authme.process.register.ProcessSyncPasswordRegister;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -20,8 +20,8 @@ import fr.xephi.authme.settings.properties.PluginSettings;
|
|||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.task.PlayerDataTaskManager;
|
import fr.xephi.authme.task.PlayerDataTaskManager;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.util.Utils;
|
import fr.xephi.authme.util.PlayerUtils;
|
||||||
import org.apache.commons.lang.reflect.MethodUtils;
|
import org.apache.commons.lang.reflect.MethodUtils;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
@ -32,7 +32,7 @@ import org.bukkit.potion.PotionEffectType;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static fr.xephi.authme.settings.properties.RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN;
|
import static fr.xephi.authme.settings.properties.RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN;
|
||||||
import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND;
|
import static fr.xephi.authme.service.BukkitService.TICKS_PER_SECOND;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asynchronous process for when a player joins.
|
* Asynchronous process for when a player joins.
|
||||||
@ -78,7 +78,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
|||||||
|
|
||||||
public void processJoin(final Player player) {
|
public void processJoin(final Player player) {
|
||||||
final String name = player.getName().toLowerCase();
|
final String name = player.getName().toLowerCase();
|
||||||
final String ip = Utils.getPlayerIp(player);
|
final String ip = PlayerUtils.getPlayerIp(player);
|
||||||
|
|
||||||
if (isPlayerUnrestricted(name)) {
|
if (isPlayerUnrestricted(name)) {
|
||||||
return;
|
return;
|
||||||
@ -249,7 +249,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
|||||||
private int countOnlinePlayersByIp(String ip) {
|
private int countOnlinePlayersByIp(String ip) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (Player player : bukkitService.getOnlinePlayers()) {
|
for (Player player : bukkitService.getOnlinePlayers()) {
|
||||||
if (ip.equalsIgnoreCase(Utils.getPlayerIp(player))) {
|
if (ip.equalsIgnoreCase(PlayerUtils.getPlayerIp(player))) {
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,9 @@ import fr.xephi.authme.settings.properties.HooksSettings;
|
|||||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.task.PlayerDataTaskManager;
|
import fr.xephi.authme.task.PlayerDataTaskManager;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
|
import fr.xephi.authme.util.PlayerUtils;
|
||||||
import fr.xephi.authme.util.StringUtils;
|
import fr.xephi.authme.util.StringUtils;
|
||||||
import fr.xephi.authme.util.Utils;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String ip = Utils.getPlayerIp(player);
|
final String ip = PlayerUtils.getPlayerIp(player);
|
||||||
if (hasReachedMaxLoggedInPlayersForIp(player, ip)) {
|
if (hasReachedMaxLoggedInPlayersForIp(player, ip)) {
|
||||||
service.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
service.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||||
return null;
|
return null;
|
||||||
@ -163,7 +163,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String ip = Utils.getPlayerIp(player);
|
final String ip = PlayerUtils.getPlayerIp(player);
|
||||||
|
|
||||||
// Increase the counts here before knowing the result of the login.
|
// Increase the counts here before knowing the result of the login.
|
||||||
captchaManager.increaseCount(name);
|
captchaManager.increaseCount(name);
|
||||||
@ -210,7 +210,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
|||||||
private void performLogin(Player player, PlayerAuth auth) {
|
private void performLogin(Player player, PlayerAuth auth) {
|
||||||
if (player.isOnline()) {
|
if (player.isOnline()) {
|
||||||
// Update auth to reflect this new login
|
// Update auth to reflect this new login
|
||||||
final String ip = Utils.getPlayerIp(player);
|
final String ip = PlayerUtils.getPlayerIp(player);
|
||||||
auth.setRealName(player.getName());
|
auth.setRealName(player.getName());
|
||||||
auth.setLastLogin(System.currentTimeMillis());
|
auth.setLastLogin(System.currentTimeMillis());
|
||||||
auth.setIp(ip);
|
auth.setIp(ip);
|
||||||
@ -311,7 +311,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
|||||||
final String name = player.getName();
|
final String name = player.getName();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (Player onlinePlayer : bukkitService.getOnlinePlayers()) {
|
for (Player onlinePlayer : bukkitService.getOnlinePlayers()) {
|
||||||
if (ip.equalsIgnoreCase(Utils.getPlayerIp(onlinePlayer))
|
if (ip.equalsIgnoreCase(PlayerUtils.getPlayerIp(onlinePlayer))
|
||||||
&& !onlinePlayer.getName().equals(name)
|
&& !onlinePlayer.getName().equals(name)
|
||||||
&& dataSource.isLogged(onlinePlayer.getName().toLowerCase())) {
|
&& dataSource.isLogged(onlinePlayer.getName().toLowerCase())) {
|
||||||
++count;
|
++count;
|
||||||
|
@ -12,8 +12,8 @@ import fr.xephi.authme.process.ProcessService;
|
|||||||
import fr.xephi.authme.process.SynchronousProcess;
|
import fr.xephi.authme.process.SynchronousProcess;
|
||||||
import fr.xephi.authme.service.BungeeService;
|
import fr.xephi.authme.service.BungeeService;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.util.TeleportationService;
|
import fr.xephi.authme.service.TeleportationService;
|
||||||
import org.apache.commons.lang.reflect.MethodUtils;
|
import org.apache.commons.lang.reflect.MethodUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
@ -11,15 +11,15 @@ import fr.xephi.authme.process.SynchronousProcess;
|
|||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.task.PlayerDataTaskManager;
|
import fr.xephi.authme.task.PlayerDataTaskManager;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.util.TeleportationService;
|
import fr.xephi.authme.service.TeleportationService;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND;
|
import static fr.xephi.authme.service.BukkitService.TICKS_PER_SECOND;
|
||||||
|
|
||||||
|
|
||||||
public class ProcessSynchronousPlayerLogout implements SynchronousProcess {
|
public class ProcessSynchronousPlayerLogout implements SynchronousProcess {
|
||||||
|
@ -11,8 +11,8 @@ import fr.xephi.authme.process.ProcessService;
|
|||||||
import fr.xephi.authme.process.SyncProcessManager;
|
import fr.xephi.authme.process.SyncProcessManager;
|
||||||
import fr.xephi.authme.settings.SpawnLoader;
|
import fr.xephi.authme.settings.SpawnLoader;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.util.Utils;
|
import fr.xephi.authme.util.PlayerUtils;
|
||||||
import fr.xephi.authme.util.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ public class AsynchronousQuit implements AsynchronousProcess {
|
|||||||
database.updateQuitLoc(auth);
|
database.updateQuitLoc(auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String ip = Utils.getPlayerIp(player);
|
final String ip = PlayerUtils.getPlayerIp(player);
|
||||||
PlayerAuth auth = PlayerAuth.builder()
|
PlayerAuth auth = PlayerAuth.builder()
|
||||||
.name(name)
|
.name(name)
|
||||||
.realName(player.getName())
|
.realName(player.getName())
|
||||||
|
@ -19,11 +19,11 @@ import fr.xephi.authme.settings.properties.PluginSettings;
|
|||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
|
import fr.xephi.authme.util.PlayerUtils;
|
||||||
import fr.xephi.authme.util.StringUtils;
|
import fr.xephi.authme.util.StringUtils;
|
||||||
import fr.xephi.authme.util.Utils;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import fr.xephi.authme.util.ValidationService;
|
import fr.xephi.authme.service.ValidationService.ValidationResult;
|
||||||
import fr.xephi.authme.util.ValidationService.ValidationResult;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ public class AsyncRegister implements AsynchronousProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final int maxRegPerIp = service.getProperty(RestrictionSettings.MAX_REGISTRATION_PER_IP);
|
final int maxRegPerIp = service.getProperty(RestrictionSettings.MAX_REGISTRATION_PER_IP);
|
||||||
final String ip = Utils.getPlayerIp(player);
|
final String ip = PlayerUtils.getPlayerIp(player);
|
||||||
if (maxRegPerIp > 0
|
if (maxRegPerIp > 0
|
||||||
&& !"127.0.0.1".equalsIgnoreCase(ip)
|
&& !"127.0.0.1".equalsIgnoreCase(ip)
|
||||||
&& !"localhost".equalsIgnoreCase(ip)
|
&& !"localhost".equalsIgnoreCase(ip)
|
||||||
@ -132,7 +132,7 @@ public class AsyncRegister implements AsynchronousProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final HashedPassword hashedPassword = passwordSecurity.computeHash(password, name);
|
final HashedPassword hashedPassword = passwordSecurity.computeHash(password, name);
|
||||||
final String ip = Utils.getPlayerIp(player);
|
final String ip = PlayerUtils.getPlayerIp(player);
|
||||||
PlayerAuth auth = PlayerAuth.builder()
|
PlayerAuth auth = PlayerAuth.builder()
|
||||||
.name(name)
|
.name(name)
|
||||||
.realName(player.getName())
|
.realName(player.getName())
|
||||||
@ -154,7 +154,7 @@ public class AsyncRegister implements AsynchronousProcess {
|
|||||||
|
|
||||||
private void passwordRegister(final Player player, String password, boolean autoLogin) {
|
private void passwordRegister(final Player player, String password, boolean autoLogin) {
|
||||||
final String name = player.getName().toLowerCase();
|
final String name = player.getName().toLowerCase();
|
||||||
final String ip = Utils.getPlayerIp(player);
|
final String ip = PlayerUtils.getPlayerIp(player);
|
||||||
final HashedPassword hashedPassword = passwordSecurity.computeHash(password, name);
|
final HashedPassword hashedPassword = passwordSecurity.computeHash(password, name);
|
||||||
PlayerAuth auth = PlayerAuth.builder()
|
PlayerAuth auth = PlayerAuth.builder()
|
||||||
.name(name)
|
.name(name)
|
||||||
|
@ -7,7 +7,7 @@ import fr.xephi.authme.process.ProcessService;
|
|||||||
import fr.xephi.authme.process.SynchronousProcess;
|
import fr.xephi.authme.process.SynchronousProcess;
|
||||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||||
import fr.xephi.authme.task.PlayerDataTaskManager;
|
import fr.xephi.authme.task.PlayerDataTaskManager;
|
||||||
import fr.xephi.authme.util.Utils;
|
import fr.xephi.authme.util.PlayerUtils;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -35,7 +35,7 @@ public class ProcessSyncEmailRegister implements SynchronousProcess {
|
|||||||
playerDataTaskManager.registerMessageTask(name, true);
|
playerDataTaskManager.registerMessageTask(name, true);
|
||||||
|
|
||||||
player.saveData();
|
player.saveData();
|
||||||
ConsoleLogger.fine(player.getName() + " registered " + Utils.getPlayerIp(player));
|
ConsoleLogger.fine(player.getName() + " registered " + PlayerUtils.getPlayerIp(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import fr.xephi.authme.settings.properties.EmailSettings;
|
|||||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.task.PlayerDataTaskManager;
|
import fr.xephi.authme.task.PlayerDataTaskManager;
|
||||||
import fr.xephi.authme.util.Utils;
|
import fr.xephi.authme.util.PlayerUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
player.saveData();
|
player.saveData();
|
||||||
ConsoleLogger.fine(player.getName() + " registered " + Utils.getPlayerIp(player));
|
ConsoleLogger.fine(player.getName() + " registered " + PlayerUtils.getPlayerIp(player));
|
||||||
|
|
||||||
// Kick Player after Registration is enabled, kick the player
|
// Kick Player after Registration is enabled, kick the player
|
||||||
if (service.getProperty(RegistrationSettings.FORCE_KICK_AFTER_REGISTER)) {
|
if (service.getProperty(RegistrationSettings.FORCE_KICK_AFTER_REGISTER)) {
|
||||||
|
@ -14,8 +14,8 @@ import fr.xephi.authme.security.PasswordSecurity;
|
|||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.task.PlayerDataTaskManager;
|
import fr.xephi.authme.task.PlayerDataTaskManager;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.util.TeleportationService;
|
import fr.xephi.authme.service.TeleportationService;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
@ -23,7 +23,7 @@ import org.bukkit.potion.PotionEffectType;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND;
|
import static fr.xephi.authme.service.BukkitService.TICKS_PER_SECOND;
|
||||||
|
|
||||||
public class AsynchronousUnregister implements AsynchronousProcess {
|
public class AsynchronousUnregister implements AsynchronousProcess {
|
||||||
|
|
||||||
|
@ -7,15 +7,14 @@ import fr.xephi.authme.permission.AdminPermission;
|
|||||||
import fr.xephi.authme.permission.PermissionsManager;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.properties.ProtectionSettings;
|
import fr.xephi.authme.settings.properties.ProtectionSettings;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
import static fr.xephi.authme.util.BukkitService.TICKS_PER_MINUTE;
|
import static fr.xephi.authme.service.BukkitService.TICKS_PER_MINUTE;
|
||||||
import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND;
|
import static fr.xephi.authme.service.BukkitService.TICKS_PER_SECOND;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The AntiBot Service Management class.
|
* The AntiBot Service Management class.
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package fr.xephi.authme;
|
package fr.xephi.authme.service;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.datasource.DataSourceType;
|
import fr.xephi.authme.datasource.DataSourceType;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.properties.BackupSettings;
|
import fr.xephi.authme.settings.properties.BackupSettings;
|
||||||
@ -19,7 +21,7 @@ import java.util.Date;
|
|||||||
*
|
*
|
||||||
* @author stefano
|
* @author stefano
|
||||||
*/
|
*/
|
||||||
public class PerformBackup {
|
public class BackupService {
|
||||||
|
|
||||||
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd_HH-mm");
|
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd_HH-mm");
|
||||||
|
|
||||||
@ -37,7 +39,7 @@ public class PerformBackup {
|
|||||||
* @param instance AuthMe
|
* @param instance AuthMe
|
||||||
* @param settings The plugin settings
|
* @param settings The plugin settings
|
||||||
*/
|
*/
|
||||||
public PerformBackup(AuthMe instance, Settings settings) {
|
public BackupService(AuthMe instance, Settings settings) {
|
||||||
this.dataFolder = instance.getDataFolder();
|
this.dataFolder = instance.getDataFolder();
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
this.dbName = settings.getProperty(DatabaseSettings.MYSQL_DATABASE);
|
this.dbName = settings.getProperty(DatabaseSettings.MYSQL_DATABASE);
|
@ -1,4 +1,4 @@
|
|||||||
package fr.xephi.authme.util;
|
package fr.xephi.authme.service;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
@ -1,4 +1,4 @@
|
|||||||
package fr.xephi.authme.util;
|
package fr.xephi.authme.service;
|
||||||
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
@ -16,7 +16,7 @@ import static fr.xephi.authme.util.Utils.MILLIS_PER_HOUR;
|
|||||||
/**
|
/**
|
||||||
* Manager for recovery codes.
|
* Manager for recovery codes.
|
||||||
*/
|
*/
|
||||||
public class RecoveryCodeManager implements SettingsDependent {
|
public class RecoveryCodeService implements SettingsDependent {
|
||||||
|
|
||||||
private Map<String, ExpiringEntry> recoveryCodes = new ConcurrentHashMap<>();
|
private Map<String, ExpiringEntry> recoveryCodes = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ public class RecoveryCodeManager implements SettingsDependent {
|
|||||||
private long recoveryCodeExpirationMillis;
|
private long recoveryCodeExpirationMillis;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
RecoveryCodeManager(Settings settings) {
|
RecoveryCodeService(Settings settings) {
|
||||||
reload(settings);
|
reload(settings);
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package fr.xephi.authme.util;
|
package fr.xephi.authme.service;
|
||||||
|
|
||||||
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;
|
@ -1,7 +1,8 @@
|
|||||||
package fr.xephi.authme.util;
|
package fr.xephi.authme.service;
|
||||||
|
|
||||||
import com.github.authme.configme.properties.Property;
|
import com.github.authme.configme.properties.Property;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
|
import fr.xephi.authme.geoip.GeoLiteAPI;
|
||||||
import fr.xephi.authme.initialization.Reloadable;
|
import fr.xephi.authme.initialization.Reloadable;
|
||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
import fr.xephi.authme.permission.PermissionsManager;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
@ -11,6 +12,8 @@ import fr.xephi.authme.settings.properties.EmailSettings;
|
|||||||
import fr.xephi.authme.settings.properties.ProtectionSettings;
|
import fr.xephi.authme.settings.properties.ProtectionSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
|
import fr.xephi.authme.util.CollectionUtils;
|
||||||
|
import fr.xephi.authme.util.Utils;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
@ -2,11 +2,11 @@ package fr.xephi.authme.task;
|
|||||||
|
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND;
|
import static fr.xephi.authme.service.BukkitService.TICKS_PER_SECOND;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Message shown to a player in a regular interval as long as he is not logged in.
|
* Message shown to a player in a regular interval as long as he is not logged in.
|
||||||
|
@ -9,13 +9,13 @@ import fr.xephi.authme.output.Messages;
|
|||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND;
|
import static fr.xephi.authme.service.BukkitService.TICKS_PER_SECOND;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers tasks associated with a PlayerData.
|
* Registers tasks associated with a PlayerData.
|
||||||
|
@ -6,8 +6,8 @@ import fr.xephi.authme.hooks.PluginHooks;
|
|||||||
import fr.xephi.authme.permission.PermissionsManager;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.properties.PurgeSettings;
|
import fr.xephi.authme.settings.properties.PurgeSettings;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.util.Utils;
|
import fr.xephi.authme.util.PlayerUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
@ -152,7 +152,7 @@ class PurgeExecutor {
|
|||||||
, makePath(settings.getProperty(PurgeSettings.DEFAULT_WORLD), "players"));
|
, makePath(settings.getProperty(PurgeSettings.DEFAULT_WORLD), "players"));
|
||||||
|
|
||||||
for (OfflinePlayer offlinePlayer : cleared) {
|
for (OfflinePlayer offlinePlayer : cleared) {
|
||||||
File playerFile = new File(dataFolder, Utils.getUUIDorName(offlinePlayer) + ".dat");
|
File playerFile = new File(dataFolder, PlayerUtils.getUUIDorName(offlinePlayer) + ".dat");
|
||||||
if (playerFile.delete()) {
|
if (playerFile.delete()) {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@ -184,7 +184,7 @@ class PurgeExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (OfflinePlayer offlinePlayer : cleared) {
|
for (OfflinePlayer offlinePlayer : cleared) {
|
||||||
File playerFile = new File(userDataFolder, Utils.getUUIDorName(offlinePlayer) + ".yml");
|
File playerFile = new File(userDataFolder, PlayerUtils.getUUIDorName(offlinePlayer) + ".yml");
|
||||||
if (playerFile.exists() && playerFile.delete()) {
|
if (playerFile.exists() && playerFile.delete()) {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import fr.xephi.authme.datasource.DataSource;
|
|||||||
import fr.xephi.authme.permission.PermissionsManager;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.properties.PurgeSettings;
|
import fr.xephi.authme.settings.properties.PurgeSettings;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.util.CollectionUtils;
|
import fr.xephi.authme.util.CollectionUtils;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
@ -9,6 +9,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public final class CollectionUtils {
|
public final class CollectionUtils {
|
||||||
|
|
||||||
|
// Utility class
|
||||||
private CollectionUtils() {
|
private CollectionUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ import static java.lang.String.format;
|
|||||||
*/
|
*/
|
||||||
public final class FileUtils {
|
public final class FileUtils {
|
||||||
|
|
||||||
|
// Utility class
|
||||||
private FileUtils() {
|
private FileUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
42
src/main/java/fr/xephi/authme/util/PlayerUtils.java
Normal file
42
src/main/java/fr/xephi/authme/util/PlayerUtils.java
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package fr.xephi.authme.util;
|
||||||
|
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Player utilities.
|
||||||
|
*/
|
||||||
|
public class PlayerUtils {
|
||||||
|
|
||||||
|
// Utility class
|
||||||
|
private PlayerUtils() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get player's UUID if can, name otherwise.
|
||||||
|
*
|
||||||
|
* @param player Player to retrieve
|
||||||
|
*
|
||||||
|
* @return player's UUID or Name in String.
|
||||||
|
*/
|
||||||
|
public static String getUUIDorName(OfflinePlayer player) {
|
||||||
|
// We may made this configurable in future
|
||||||
|
// so we can have uuid support.
|
||||||
|
try {
|
||||||
|
return player.getUniqueId().toString();
|
||||||
|
} catch (NoSuchMethodError ignore) {
|
||||||
|
return player.getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the IP of the given player.
|
||||||
|
*
|
||||||
|
* @param p The player to return the IP address for
|
||||||
|
*
|
||||||
|
* @return The player's IP address
|
||||||
|
*/
|
||||||
|
public static String getPlayerIp(Player p) {
|
||||||
|
return p.getAddress().getAddress().getHostAddress();
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,19 @@
|
|||||||
package fr.xephi.authme.util;
|
package fr.xephi.authme.util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runtime utilities.
|
||||||
|
*/
|
||||||
public class RuntimeUtils {
|
public class RuntimeUtils {
|
||||||
|
|
||||||
|
// Utility class
|
||||||
|
private RuntimeUtils() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the available core count of the JVM.
|
||||||
|
*
|
||||||
|
* @return the core count
|
||||||
|
*/
|
||||||
public static int getCoreCount() {
|
public static int getCoreCount() {
|
||||||
return Runtime.getRuntime().availableProcessors();
|
return Runtime.getRuntime().availableProcessors();
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,8 @@ import java.io.File;
|
|||||||
*/
|
*/
|
||||||
public final class StringUtils {
|
public final class StringUtils {
|
||||||
|
|
||||||
|
// Utility class
|
||||||
private StringUtils() {
|
private StringUtils() {
|
||||||
// Utility class
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,26 +16,10 @@ public final class Utils {
|
|||||||
/** Number of milliseconds in an hour. */
|
/** Number of milliseconds in an hour. */
|
||||||
public static final long MILLIS_PER_HOUR = 60 * MILLIS_PER_MINUTE;
|
public static final long MILLIS_PER_HOUR = 60 * MILLIS_PER_MINUTE;
|
||||||
|
|
||||||
|
// Utility class
|
||||||
private Utils() {
|
private Utils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get player's UUID if can, name otherwise.
|
|
||||||
*
|
|
||||||
* @param player Player to retrieve
|
|
||||||
*
|
|
||||||
* @return player's UUID or Name in String.
|
|
||||||
*/
|
|
||||||
public static String getUUIDorName(OfflinePlayer player) {
|
|
||||||
// We may made this configurable in future
|
|
||||||
// so we can have uuid support.
|
|
||||||
try {
|
|
||||||
return player.getUniqueId().toString();
|
|
||||||
} catch (NoSuchMethodError ignore) {
|
|
||||||
return player.getName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compile Pattern sneaky without throwing Exception.
|
* Compile Pattern sneaky without throwing Exception.
|
||||||
*
|
*
|
||||||
@ -52,17 +36,6 @@ public final class Utils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the IP of the given player.
|
|
||||||
*
|
|
||||||
* @param p The player to return the IP address for
|
|
||||||
*
|
|
||||||
* @return The player's IP address
|
|
||||||
*/
|
|
||||||
public static String getPlayerIp(Player p) {
|
|
||||||
return p.getAddress().getAddress().getHostAddress();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the class exists in the current class loader.
|
* Returns whether the class exists in the current class loader.
|
||||||
*
|
*
|
||||||
|
@ -15,7 +15,7 @@ import fr.xephi.authme.process.login.ProcessSyncPlayerLogin;
|
|||||||
import fr.xephi.authme.security.PasswordSecurity;
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.task.purge.PurgeService;
|
import fr.xephi.authme.task.purge.PurgeService;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package fr.xephi.authme;
|
package fr.xephi.authme;
|
||||||
|
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
@ -8,7 +8,7 @@ import fr.xephi.authme.datasource.DataSource;
|
|||||||
import fr.xephi.authme.hooks.PluginHooks;
|
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.util.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
|
@ -7,7 +7,7 @@ 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;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
@ -8,7 +8,7 @@ import fr.xephi.authme.cache.limbo.PlayerData;
|
|||||||
import fr.xephi.authme.initialization.DataFolder;
|
import fr.xephi.authme.initialization.DataFolder;
|
||||||
import fr.xephi.authme.permission.PermissionsManager;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
import fr.xephi.authme.settings.SpawnLoader;
|
import fr.xephi.authme.settings.SpawnLoader;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.util.StringUtils;
|
import fr.xephi.authme.util.StringUtils;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
@ -5,7 +5,7 @@ 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;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
import fr.xephi.authme.util.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -4,7 +4,7 @@ import fr.xephi.authme.cache.auth.PlayerAuth;
|
|||||||
import fr.xephi.authme.command.CommandService;
|
import fr.xephi.authme.command.CommandService;
|
||||||
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.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
@ -8,9 +8,9 @@ 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.PasswordSecurity;
|
||||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.util.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import fr.xephi.authme.util.ValidationService.ValidationResult;
|
import fr.xephi.authme.service.ValidationService.ValidationResult;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -5,7 +5,7 @@ import fr.xephi.authme.TestHelper;
|
|||||||
import fr.xephi.authme.command.CommandService;
|
import fr.xephi.authme.command.CommandService;
|
||||||
import fr.xephi.authme.converter.Converter;
|
import fr.xephi.authme.converter.Converter;
|
||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.util.StringUtils;
|
import fr.xephi.authme.util.StringUtils;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
@ -3,7 +3,7 @@ package fr.xephi.authme.command.executable.authme;
|
|||||||
import fr.xephi.authme.permission.PermissionsManager;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
import fr.xephi.authme.permission.PlayerPermission;
|
import fr.xephi.authme.permission.PlayerPermission;
|
||||||
import fr.xephi.authme.process.Management;
|
import fr.xephi.authme.process.Management;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package fr.xephi.authme.command.executable.authme;
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
import fr.xephi.authme.TestHelper;
|
import fr.xephi.authme.TestHelper;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package fr.xephi.authme.command.executable.authme;
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
import fr.xephi.authme.task.purge.PurgeService;
|
import fr.xephi.authme.task.purge.PurgeService;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -8,9 +8,9 @@ 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.PasswordSecurity;
|
||||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.util.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import fr.xephi.authme.util.ValidationService.ValidationResult;
|
import fr.xephi.authme.service.ValidationService.ValidationResult;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
@ -5,7 +5,7 @@ import fr.xephi.authme.cache.auth.PlayerCache;
|
|||||||
import fr.xephi.authme.command.CommandService;
|
import fr.xephi.authme.command.CommandService;
|
||||||
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.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
@ -4,7 +4,7 @@ import fr.xephi.authme.command.CommandService;
|
|||||||
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.process.Management;
|
import fr.xephi.authme.process.Management;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -6,8 +6,8 @@ import fr.xephi.authme.output.MessageKey;
|
|||||||
import fr.xephi.authme.process.Management;
|
import fr.xephi.authme.process.Management;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
import fr.xephi.authme.util.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import fr.xephi.authme.util.ValidationService.ValidationResult;
|
import fr.xephi.authme.service.ValidationService.ValidationResult;
|
||||||
import org.bukkit.command.BlockCommandSender;
|
import org.bukkit.command.BlockCommandSender;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -9,7 +9,7 @@ import fr.xephi.authme.mail.SendMailSSL;
|
|||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
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;
|
||||||
import fr.xephi.authme.service.RecoveryCodeManager;
|
import fr.xephi.authme.service.RecoveryCodeService;
|
||||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -63,7 +63,7 @@ public class RecoverEmailCommandTest {
|
|||||||
private SendMailSSL sendMailSsl;
|
private SendMailSSL sendMailSsl;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private RecoveryCodeManager recoveryCodeManager;
|
private RecoveryCodeService recoveryCodeService;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void initLogger() {
|
public static void initLogger() {
|
||||||
@ -177,8 +177,8 @@ public class RecoverEmailCommandTest {
|
|||||||
int hoursValid = 12;
|
int hoursValid = 12;
|
||||||
given(commandService.getProperty(SecuritySettings.RECOVERY_CODE_HOURS_VALID)).willReturn(hoursValid);
|
given(commandService.getProperty(SecuritySettings.RECOVERY_CODE_HOURS_VALID)).willReturn(hoursValid);
|
||||||
String code = "a94f37";
|
String code = "a94f37";
|
||||||
given(recoveryCodeManager.isRecoveryCodeNeeded()).willReturn(true);
|
given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(true);
|
||||||
given(recoveryCodeManager.generateCode(name)).willReturn(code);
|
given(recoveryCodeService.generateCode(name)).willReturn(code);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
command.executeCommand(sender, Collections.singletonList(email.toUpperCase()));
|
command.executeCommand(sender, Collections.singletonList(email.toUpperCase()));
|
||||||
@ -186,7 +186,7 @@ public class RecoverEmailCommandTest {
|
|||||||
// then
|
// then
|
||||||
verify(sendMailSsl).hasAllInformation();
|
verify(sendMailSsl).hasAllInformation();
|
||||||
verify(dataSource).getAuth(name);
|
verify(dataSource).getAuth(name);
|
||||||
verify(recoveryCodeManager).generateCode(name);
|
verify(recoveryCodeService).generateCode(name);
|
||||||
verify(commandService).send(sender, MessageKey.RECOVERY_CODE_SENT);
|
verify(commandService).send(sender, MessageKey.RECOVERY_CODE_SENT);
|
||||||
verify(sendMailSsl).sendRecoveryCode(name, email, code);
|
verify(sendMailSsl).sendRecoveryCode(name, email, code);
|
||||||
}
|
}
|
||||||
@ -203,8 +203,8 @@ public class RecoverEmailCommandTest {
|
|||||||
PlayerAuth auth = newAuthWithEmail(email);
|
PlayerAuth auth = newAuthWithEmail(email);
|
||||||
given(dataSource.getAuth(name)).willReturn(auth);
|
given(dataSource.getAuth(name)).willReturn(auth);
|
||||||
given(commandService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH)).willReturn(20);
|
given(commandService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH)).willReturn(20);
|
||||||
given(recoveryCodeManager.isRecoveryCodeNeeded()).willReturn(true);
|
given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(true);
|
||||||
given(recoveryCodeManager.isCodeValid(name, "bogus")).willReturn(false);
|
given(recoveryCodeService.isCodeValid(name, "bogus")).willReturn(false);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
command.executeCommand(sender, Arrays.asList(email, "bogus"));
|
command.executeCommand(sender, Arrays.asList(email, "bogus"));
|
||||||
@ -231,8 +231,8 @@ public class RecoverEmailCommandTest {
|
|||||||
given(commandService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH)).willReturn(20);
|
given(commandService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH)).willReturn(20);
|
||||||
given(passwordSecurity.computeHash(anyString(), eq(name)))
|
given(passwordSecurity.computeHash(anyString(), eq(name)))
|
||||||
.willAnswer(invocation -> new HashedPassword((String) invocation.getArguments()[0]));
|
.willAnswer(invocation -> new HashedPassword((String) invocation.getArguments()[0]));
|
||||||
given(recoveryCodeManager.isRecoveryCodeNeeded()).willReturn(true);
|
given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(true);
|
||||||
given(recoveryCodeManager.isCodeValid(name, code)).willReturn(true);
|
given(recoveryCodeService.isCodeValid(name, code)).willReturn(true);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
command.executeCommand(sender, Arrays.asList(email, code));
|
command.executeCommand(sender, Arrays.asList(email, code));
|
||||||
@ -245,7 +245,7 @@ public class RecoverEmailCommandTest {
|
|||||||
String generatedPassword = passwordCaptor.getValue();
|
String generatedPassword = passwordCaptor.getValue();
|
||||||
assertThat(generatedPassword, stringWithLength(20));
|
assertThat(generatedPassword, stringWithLength(20));
|
||||||
verify(dataSource).updatePassword(eq(name), any(HashedPassword.class));
|
verify(dataSource).updatePassword(eq(name), any(HashedPassword.class));
|
||||||
verify(recoveryCodeManager).removeCode(name);
|
verify(recoveryCodeService).removeCode(name);
|
||||||
verify(sendMailSsl).sendPasswordMail(name, email, generatedPassword);
|
verify(sendMailSsl).sendPasswordMail(name, email, generatedPassword);
|
||||||
verify(commandService).send(sender, MessageKey.RECOVERY_EMAIL_SENT_MESSAGE);
|
verify(commandService).send(sender, MessageKey.RECOVERY_EMAIL_SENT_MESSAGE);
|
||||||
}
|
}
|
||||||
@ -264,7 +264,7 @@ public class RecoverEmailCommandTest {
|
|||||||
given(commandService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH)).willReturn(20);
|
given(commandService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH)).willReturn(20);
|
||||||
given(passwordSecurity.computeHash(anyString(), eq(name)))
|
given(passwordSecurity.computeHash(anyString(), eq(name)))
|
||||||
.willAnswer(invocation -> new HashedPassword((String) invocation.getArguments()[0]));
|
.willAnswer(invocation -> new HashedPassword((String) invocation.getArguments()[0]));
|
||||||
given(recoveryCodeManager.isRecoveryCodeNeeded()).willReturn(false);
|
given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(false);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
command.executeCommand(sender, Collections.singletonList(email));
|
command.executeCommand(sender, Collections.singletonList(email));
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
package fr.xephi.authme.util;
|
package fr.xephi.authme.geoip;
|
||||||
|
|
||||||
import com.maxmind.geoip.Country;
|
import com.maxmind.geoip.Country;
|
||||||
import com.maxmind.geoip.LookupService;
|
import com.maxmind.geoip.LookupService;
|
||||||
|
import fr.xephi.authme.geoip.GeoLiteAPI;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -25,7 +26,7 @@ import static org.mockito.Mockito.verify;
|
|||||||
* Test for {@link GeoLiteAPI}.
|
* Test for {@link GeoLiteAPI}.
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class GeoLiteAPITest {
|
public class GeoIpManagerTest {
|
||||||
|
|
||||||
private GeoLiteAPI geoLiteApi;
|
private GeoLiteAPI geoLiteApi;
|
||||||
private File dataFolder;
|
private File dataFolder;
|
@ -8,7 +8,7 @@ import fr.xephi.authme.datasource.DataSource;
|
|||||||
import fr.xephi.authme.hooks.PluginHooks;
|
import fr.xephi.authme.hooks.PluginHooks;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.util.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
@ -12,8 +12,8 @@ import fr.xephi.authme.settings.Settings;
|
|||||||
import fr.xephi.authme.settings.properties.ProtectionSettings;
|
import fr.xephi.authme.settings.properties.ProtectionSettings;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.util.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerLoginEvent;
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
|
@ -10,9 +10,9 @@ import fr.xephi.authme.settings.Settings;
|
|||||||
import fr.xephi.authme.settings.SpawnLoader;
|
import fr.xephi.authme.settings.SpawnLoader;
|
||||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.util.TeleportationService;
|
import fr.xephi.authme.service.TeleportationService;
|
||||||
import fr.xephi.authme.util.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
@ -9,7 +9,7 @@ import fr.xephi.authme.permission.PermissionsManager;
|
|||||||
import fr.xephi.authme.permission.PlayerPermission;
|
import fr.xephi.authme.permission.PlayerPermission;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
import fr.xephi.authme.util.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -14,7 +14,7 @@ import fr.xephi.authme.settings.properties.HooksSettings;
|
|||||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.task.PlayerDataTaskManager;
|
import fr.xephi.authme.task.PlayerDataTaskManager;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -14,8 +14,8 @@ import fr.xephi.authme.security.crypts.HashedPassword;
|
|||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.task.PlayerDataTaskManager;
|
import fr.xephi.authme.task.PlayerDataTaskManager;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.util.TeleportationService;
|
import fr.xephi.authme.service.TeleportationService;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
@ -10,7 +10,6 @@ import fr.xephi.authme.permission.AdminPermission;
|
|||||||
import fr.xephi.authme.permission.PermissionsManager;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.properties.ProtectionSettings;
|
import fr.xephi.authme.settings.properties.ProtectionSettings;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package fr.xephi.authme.util;
|
package fr.xephi.authme.service;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ReflectionTestUtils;
|
import fr.xephi.authme.ReflectionTestUtils;
|
@ -1,4 +1,4 @@
|
|||||||
package fr.xephi.authme.util;
|
package fr.xephi.authme.service;
|
||||||
|
|
||||||
import fr.xephi.authme.TestHelper;
|
import fr.xephi.authme.TestHelper;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
@ -6,6 +6,7 @@ import fr.xephi.authme.datasource.DataSource;
|
|||||||
import fr.xephi.authme.security.HashAlgorithm;
|
import fr.xephi.authme.security.HashAlgorithm;
|
||||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||||
import fr.xephi.authme.security.crypts.SHA256;
|
import fr.xephi.authme.security.crypts.SHA256;
|
||||||
|
import fr.xephi.authme.service.MigrationService;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
@ -4,7 +4,7 @@ import ch.jalu.injector.testing.BeforeInjecting;
|
|||||||
import ch.jalu.injector.testing.DelayedInjectionRunner;
|
import ch.jalu.injector.testing.DelayedInjectionRunner;
|
||||||
import ch.jalu.injector.testing.InjectDelayed;
|
import ch.jalu.injector.testing.InjectDelayed;
|
||||||
import fr.xephi.authme.ReflectionTestUtils;
|
import fr.xephi.authme.ReflectionTestUtils;
|
||||||
import fr.xephi.authme.service.RecoveryCodeManager.ExpiringEntry;
|
import fr.xephi.authme.service.RecoveryCodeService.ExpiringEntry;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -20,13 +20,13 @@ import static org.junit.Assert.assertThat;
|
|||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link RecoveryCodeManager}.
|
* Test for {@link RecoveryCodeService}.
|
||||||
*/
|
*/
|
||||||
@RunWith(DelayedInjectionRunner.class)
|
@RunWith(DelayedInjectionRunner.class)
|
||||||
public class RecoveryCodeManagerTest {
|
public class RecoveryCodeServiceTest {
|
||||||
|
|
||||||
@InjectDelayed
|
@InjectDelayed
|
||||||
private RecoveryCodeManager recoveryCodeManager;
|
private RecoveryCodeService recoveryCodeService;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private Settings settings;
|
private Settings settings;
|
||||||
@ -39,16 +39,16 @@ public class RecoveryCodeManagerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldBeDisabledForNonPositiveLength() {
|
public void shouldBeDisabledForNonPositiveLength() {
|
||||||
assertThat(recoveryCodeManager.isRecoveryCodeNeeded(), equalTo(true));
|
assertThat(recoveryCodeService.isRecoveryCodeNeeded(), equalTo(true));
|
||||||
|
|
||||||
// given
|
// given
|
||||||
given(settings.getProperty(SecuritySettings.RECOVERY_CODE_LENGTH)).willReturn(0);
|
given(settings.getProperty(SecuritySettings.RECOVERY_CODE_LENGTH)).willReturn(0);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
recoveryCodeManager.reload(settings);
|
recoveryCodeService.reload(settings);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(recoveryCodeManager.isRecoveryCodeNeeded(), equalTo(false));
|
assertThat(recoveryCodeService.isRecoveryCodeNeeded(), equalTo(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -57,7 +57,7 @@ public class RecoveryCodeManagerTest {
|
|||||||
String name = "Bobbers";
|
String name = "Bobbers";
|
||||||
|
|
||||||
// when
|
// when
|
||||||
recoveryCodeManager.generateCode(name);
|
recoveryCodeService.generateCode(name);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
ExpiringEntry entry = getCodeMap().get(name);
|
ExpiringEntry entry = getCodeMap().get(name);
|
||||||
@ -72,7 +72,7 @@ public class RecoveryCodeManagerTest {
|
|||||||
setCodeInMap(player, code, System.currentTimeMillis() - 500);
|
setCodeInMap(player, code, System.currentTimeMillis() - 500);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
boolean result = recoveryCodeManager.isCodeValid(player, code);
|
boolean result = recoveryCodeService.isCodeValid(player, code);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(result, equalTo(false));
|
assertThat(result, equalTo(false));
|
||||||
@ -82,10 +82,10 @@ public class RecoveryCodeManagerTest {
|
|||||||
public void shouldRecognizeCorrectCode() {
|
public void shouldRecognizeCorrectCode() {
|
||||||
// given
|
// given
|
||||||
String player = "dragon";
|
String player = "dragon";
|
||||||
String code = recoveryCodeManager.generateCode(player);
|
String code = recoveryCodeService.generateCode(player);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
boolean result = recoveryCodeManager.isCodeValid(player, code);
|
boolean result = recoveryCodeService.isCodeValid(player, code);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(result, equalTo(true));
|
assertThat(result, equalTo(true));
|
||||||
@ -95,19 +95,19 @@ public class RecoveryCodeManagerTest {
|
|||||||
public void shouldRemoveCode() {
|
public void shouldRemoveCode() {
|
||||||
// given
|
// given
|
||||||
String player = "Tester";
|
String player = "Tester";
|
||||||
String code = recoveryCodeManager.generateCode(player);
|
String code = recoveryCodeService.generateCode(player);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
recoveryCodeManager.removeCode(player);
|
recoveryCodeService.removeCode(player);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(recoveryCodeManager.isCodeValid(player, code), equalTo(false));
|
assertThat(recoveryCodeService.isCodeValid(player, code), equalTo(false));
|
||||||
assertThat(getCodeMap().get(player), nullValue());
|
assertThat(getCodeMap().get(player), nullValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Map<String, ExpiringEntry> getCodeMap() {
|
private Map<String, ExpiringEntry> getCodeMap() {
|
||||||
return ReflectionTestUtils.getFieldValue(RecoveryCodeManager.class, recoveryCodeManager, "recoveryCodes");
|
return ReflectionTestUtils.getFieldValue(RecoveryCodeService.class, recoveryCodeService, "recoveryCodes");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setCodeInMap(String player, String code, long expiration) {
|
private void setCodeInMap(String player, String code, long expiration) {
|
@ -1,10 +1,12 @@
|
|||||||
package fr.xephi.authme.util;
|
package fr.xephi.authme.service;
|
||||||
|
|
||||||
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.cache.limbo.PlayerData;
|
import fr.xephi.authme.cache.limbo.PlayerData;
|
||||||
import fr.xephi.authme.events.FirstSpawnTeleportEvent;
|
import fr.xephi.authme.events.FirstSpawnTeleportEvent;
|
||||||
import fr.xephi.authme.events.SpawnTeleportEvent;
|
import fr.xephi.authme.events.SpawnTeleportEvent;
|
||||||
|
import fr.xephi.authme.service.BukkitService;
|
||||||
|
import fr.xephi.authme.service.TeleportationService;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.SpawnLoader;
|
import fr.xephi.authme.settings.SpawnLoader;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
@ -1,19 +1,21 @@
|
|||||||
package fr.xephi.authme.util;
|
package fr.xephi.authme.service;
|
||||||
|
|
||||||
import ch.jalu.injector.testing.BeforeInjecting;
|
import ch.jalu.injector.testing.BeforeInjecting;
|
||||||
import ch.jalu.injector.testing.DelayedInjectionRunner;
|
import ch.jalu.injector.testing.DelayedInjectionRunner;
|
||||||
import ch.jalu.injector.testing.InjectDelayed;
|
import ch.jalu.injector.testing.InjectDelayed;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
|
import fr.xephi.authme.geoip.GeoLiteAPI;
|
||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
import fr.xephi.authme.permission.PermissionsManager;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
import fr.xephi.authme.permission.PlayerStatePermission;
|
import fr.xephi.authme.permission.PlayerStatePermission;
|
||||||
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||||
import fr.xephi.authme.settings.properties.ProtectionSettings;
|
import fr.xephi.authme.settings.properties.ProtectionSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
import fr.xephi.authme.util.ValidationService.ValidationResult;
|
import fr.xephi.authme.service.ValidationService.ValidationResult;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
@ -9,7 +9,7 @@ import fr.xephi.authme.output.Messages;
|
|||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
@ -6,7 +6,7 @@ import fr.xephi.authme.datasource.DataSource;
|
|||||||
import fr.xephi.authme.permission.PermissionsManager;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.properties.PurgeSettings;
|
import fr.xephi.authme.settings.properties.PurgeSettings;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
69
src/test/java/fr/xephi/authme/util/PlayerUtilsTest.java
Normal file
69
src/test/java/fr/xephi/authme/util/PlayerUtilsTest.java
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
package fr.xephi.authme.util;
|
||||||
|
|
||||||
|
import fr.xephi.authme.TestHelper;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.mockito.BDDMockito.given;
|
||||||
|
import static org.mockito.Mockito.doThrow;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for {@link Utils}.
|
||||||
|
*/
|
||||||
|
public class PlayerUtilsTest {
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setAuthmeInstance() {
|
||||||
|
TestHelper.setupLogger();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldGetPlayerIp() {
|
||||||
|
// given
|
||||||
|
Player player = mock(Player.class);
|
||||||
|
String ip = "124.86.248.62";
|
||||||
|
TestHelper.mockPlayerIp(player, ip);
|
||||||
|
|
||||||
|
// when
|
||||||
|
String result = PlayerUtils.getPlayerIp(player);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(result, equalTo(ip));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldGetUuid() {
|
||||||
|
// given
|
||||||
|
UUID uuid = UUID.randomUUID();
|
||||||
|
Player player = mock(Player.class);
|
||||||
|
given(player.getUniqueId()).willReturn(uuid);
|
||||||
|
|
||||||
|
// when
|
||||||
|
String result = PlayerUtils.getUUIDorName(player);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(result, equalTo(uuid.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFallbackToName() {
|
||||||
|
// given
|
||||||
|
Player player = mock(Player.class);
|
||||||
|
doThrow(NoSuchMethodError.class).when(player).getUniqueId();
|
||||||
|
String name = "Bobby12";
|
||||||
|
given(player.getName()).willReturn(name);
|
||||||
|
|
||||||
|
// when
|
||||||
|
String result = PlayerUtils.getUUIDorName(player);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(result, equalTo(name));
|
||||||
|
}
|
||||||
|
}
|
@ -1,18 +1,13 @@
|
|||||||
package fr.xephi.authme.util;
|
package fr.xephi.authme.util;
|
||||||
|
|
||||||
import fr.xephi.authme.TestHelper;
|
import fr.xephi.authme.TestHelper;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.mockito.BDDMockito.given;
|
|
||||||
import static org.mockito.Mockito.doThrow;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link Utils}.
|
* Test for {@link Utils}.
|
||||||
@ -48,49 +43,6 @@ public class UtilsTest {
|
|||||||
assertThat(result.toString(), equalTo(".*?"));
|
assertThat(result.toString(), equalTo(".*?"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldGetPlayerIp() {
|
|
||||||
// given
|
|
||||||
Player player = mock(Player.class);
|
|
||||||
String ip = "124.86.248.62";
|
|
||||||
TestHelper.mockPlayerIp(player, ip);
|
|
||||||
|
|
||||||
// when
|
|
||||||
String result = Utils.getPlayerIp(player);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(result, equalTo(ip));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldGetUuid() {
|
|
||||||
// given
|
|
||||||
UUID uuid = UUID.randomUUID();
|
|
||||||
Player player = mock(Player.class);
|
|
||||||
given(player.getUniqueId()).willReturn(uuid);
|
|
||||||
|
|
||||||
// when
|
|
||||||
String result = Utils.getUUIDorName(player);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(result, equalTo(uuid.toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldFallbackToName() {
|
|
||||||
// given
|
|
||||||
Player player = mock(Player.class);
|
|
||||||
doThrow(NoSuchMethodError.class).when(player).getUniqueId();
|
|
||||||
String name = "Bobby12";
|
|
||||||
given(player.getName()).willReturn(name);
|
|
||||||
|
|
||||||
// when
|
|
||||||
String result = Utils.getUUIDorName(player);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(result, equalTo(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldHavePrivateConstructorOnly() {
|
public void shouldHavePrivateConstructorOnly() {
|
||||||
// given / when / then
|
// given / when / then
|
||||||
|
Loading…
Reference in New Issue
Block a user