Service cleanup

This commit is contained in:
Gabriele C 2016-10-04 19:08:18 +02:00
parent 5c2d7139bc
commit 42dbb27728
89 changed files with 319 additions and 257 deletions

View File

@ -25,16 +25,17 @@ import fr.xephi.authme.output.Messages;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.PermissionsSystemType;
import fr.xephi.authme.security.crypts.SHA256;
import fr.xephi.authme.service.BackupService;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.task.CleanupTask;
import fr.xephi.authme.task.purge.PurgeService;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.GeoLiteAPI;
import fr.xephi.authme.util.MigrationService;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.geoip.GeoLiteAPI;
import fr.xephi.authme.service.MigrationService;
import fr.xephi.authme.util.PlayerUtils;
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@ -48,7 +49,7 @@ import org.bukkit.scheduler.BukkitScheduler;
import java.io.File;
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;
/**
@ -150,7 +151,7 @@ public class AuthMe extends JavaPlugin {
}
// Do a backup on start
new PerformBackup(this, settings).doBackup(PerformBackup.BackupCause.START);
new BackupService(this, settings).doBackup(BackupService.BackupCause.START);
// Set up Metrics
MetricsManager.sendMetrics(this, settings);
@ -344,7 +345,7 @@ public class AuthMe extends JavaPlugin {
// Do backup on stop if enabled
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
@ -360,7 +361,7 @@ public class AuthMe extends JavaPlugin {
public String replaceAllInfo(String message, Player player) {
String playersOnline = Integer.toString(bukkitService.getOnlinePlayers().size());
String ipAddress = Utils.getPlayerIp(player);
String ipAddress = PlayerUtils.getPlayerIp(player);
Server server = getServer();
return message
.replace("&", "\u00a7")

View File

@ -8,7 +8,7 @@ import fr.xephi.authme.hooks.PluginHooks;
import fr.xephi.authme.process.Management;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.crypts.HashedPassword;
import fr.xephi.authme.util.ValidationService;
import fr.xephi.authme.service.ValidationService;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;

View File

@ -8,7 +8,7 @@ import fr.xephi.authme.hooks.PluginHooks;
import fr.xephi.authme.process.Management;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.crypts.HashedPassword;
import fr.xephi.authme.util.ValidationService;
import fr.xephi.authme.service.ValidationService;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;

View File

@ -7,8 +7,8 @@ import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.util.PlayerUtils;
import org.bukkit.entity.Player;
import javax.inject.Inject;
@ -108,7 +108,7 @@ public class TempbanManager implements SettingsDependent, HasCleanup {
*/
public void tempbanPlayer(final Player player) {
if (isEnabled) {
final String ip = Utils.getPlayerIp(player);
final String ip = PlayerUtils.getPlayerIp(player);
final String reason = messages.retrieveSingle(MessageKey.TEMPBAN_MAX_LOGINS);
final Date expires = new Date();

View File

@ -14,9 +14,9 @@ import fr.xephi.authme.cache.limbo.PlayerData;
import fr.xephi.authme.initialization.DataFolder;
import fr.xephi.authme.permission.PermissionsManager;
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.Utils;
import fr.xephi.authme.util.PlayerUtils;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
@ -64,7 +64,7 @@ public class PlayerDataStorage {
* @return PlayerData object if the data is exist, null otherwise.
*/
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");
if (!file.exists()) {
return null;
@ -85,7 +85,7 @@ public class PlayerDataStorage {
* @param player player to save
*/
public void saveData(Player player) {
String id = Utils.getUUIDorName(player);
String id = PlayerUtils.getUUIDorName(player);
Location location = spawnLoader.getPlayerLocationOrSpawn(player);
String group = "";
if (permissionsManager.hasGroupSupport()) {
@ -113,7 +113,7 @@ public class PlayerDataStorage {
* @param player player to remove
*/
public void removeData(Player player) {
String id = Utils.getUUIDorName(player);
String id = PlayerUtils.getUUIDorName(player);
File file = new File(cacheDir, id);
if (file.exists()) {
FileUtils.purgeDirectory(file);
@ -131,7 +131,7 @@ public class PlayerDataStorage {
* @return true if data exist, false otherwise.
*/
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");
return file.exists();
}

View File

@ -4,7 +4,7 @@ import com.github.authme.configme.properties.Property;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.ValidationService;
import fr.xephi.authme.service.ValidationService;
import org.bukkit.command.CommandSender;
import javax.inject.Inject;

View File

@ -5,7 +5,7 @@ import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.service.BukkitService;
import org.bukkit.command.CommandSender;
import javax.inject.Inject;

View File

@ -9,9 +9,9 @@ import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.crypts.HashedPassword;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.ValidationService;
import fr.xephi.authme.util.ValidationService.ValidationResult;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.service.ValidationService;
import fr.xephi.authme.service.ValidationService.ValidationResult;
import org.bukkit.command.CommandSender;
import javax.inject.Inject;

View File

@ -15,7 +15,7 @@ import fr.xephi.authme.converter.SqliteToSql;
import fr.xephi.authme.converter.vAuthConverter;
import fr.xephi.authme.converter.xAuthConverter;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.service.BukkitService;
import org.bukkit.command.CommandSender;
import javax.inject.Inject;

View File

@ -3,7 +3,7 @@ package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.permission.PermissionsManager;
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.entity.Player;

View File

@ -1,7 +1,7 @@
package fr.xephi.authme.command.executable.authme;
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.entity.Player;

View File

@ -2,7 +2,7 @@ package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.command.ExecutableCommand;
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.command.CommandSender;

View File

@ -9,9 +9,9 @@ import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.crypts.HashedPassword;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.ValidationService;
import fr.xephi.authme.util.ValidationService.ValidationResult;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.service.ValidationService;
import fr.xephi.authme.service.ValidationService.ValidationResult;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

View File

@ -6,7 +6,7 @@ import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.service.BukkitService;
import org.bukkit.command.CommandSender;
import javax.inject.Inject;

View File

@ -5,7 +5,7 @@ import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
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.entity.Player;

View File

@ -3,7 +3,7 @@ package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandService;
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.command.CommandSender;
import org.bukkit.entity.Player;

View File

@ -5,8 +5,8 @@ import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.PlayerCommand;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.process.Management;
import fr.xephi.authme.util.ValidationService;
import fr.xephi.authme.util.ValidationService.ValidationResult;
import fr.xephi.authme.service.ValidationService;
import fr.xephi.authme.service.ValidationService.ValidationResult;
import org.bukkit.entity.Player;
import javax.inject.Inject;

View File

@ -11,7 +11,7 @@ import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.RandomString;
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 javax.inject.Inject;
@ -40,7 +40,7 @@ public class RecoverEmailCommand extends PlayerCommand {
private SendMailSSL sendMailSsl;
@Inject
private RecoveryCodeManager recoveryCodeManager;
private RecoveryCodeService recoveryCodeService;
@Override
public void runCommand(Player player, List<String> arguments) {
@ -69,7 +69,7 @@ public class RecoverEmailCommand extends PlayerCommand {
return;
}
if (recoveryCodeManager.isRecoveryCodeNeeded()) {
if (recoveryCodeService.isRecoveryCodeNeeded()) {
// Process /email recovery addr@example.com
if (arguments.size() == 1) {
createAndSendRecoveryCode(player, email);
@ -83,20 +83,20 @@ public class RecoverEmailCommand extends PlayerCommand {
}
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);
commandService.send(player, MessageKey.RECOVERY_CODE_SENT);
}
private void processRecoveryCode(Player player, String code, String email) {
final String name = player.getName();
if (!recoveryCodeManager.isCodeValid(name, code)) {
if (!recoveryCodeService.isCodeValid(name, code)) {
commandService.send(player, MessageKey.INCORRECT_RECOVERY_CODE);
return;
}
generateAndSendNewPassword(player, email);
recoveryCodeManager.removeCode(name);
recoveryCodeService.removeCode(name);
}
private void generateAndSendNewPassword(Player player, String email) {

View File

@ -1,9 +1,10 @@
package fr.xephi.authme.util;
package fr.xephi.authme.geoip;
import com.google.common.annotations.VisibleForTesting;
import com.maxmind.geoip.LookupService;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.initialization.DataFolder;
import fr.xephi.authme.util.FileUtils;
import javax.inject.Inject;
import java.io.File;

View 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.EmailSettings;
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.MigrationService;
import fr.xephi.authme.service.MigrationService;
import fr.xephi.authme.util.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.bukkit.Bukkit;
@ -37,7 +37,7 @@ import java.util.List;
import java.util.logging.Logger;
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.

View File

@ -9,8 +9,8 @@ import fr.xephi.authme.hooks.PluginHooks;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.SpawnLoader;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.ValidationService;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.service.ValidationService;
import org.bukkit.Location;
import org.bukkit.entity.Player;

View File

@ -6,7 +6,7 @@ import fr.xephi.authme.hooks.PluginHooks;
import fr.xephi.authme.initialization.SettingsDependent;
import fr.xephi.authme.settings.Settings;
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.Player;
import org.bukkit.event.entity.EntityEvent;

View File

@ -13,10 +13,10 @@ import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.ProtectionSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
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.Utils;
import fr.xephi.authme.util.ValidationService;
import fr.xephi.authme.service.ValidationService;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerLoginEvent;

View File

@ -11,9 +11,9 @@ import fr.xephi.authme.settings.SpawnLoader;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.TeleportationService;
import fr.xephi.authme.util.ValidationService;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.service.TeleportationService;
import fr.xephi.authme.service.ValidationService;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;

View File

@ -7,7 +7,7 @@ import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.initialization.SettingsDependent;
import fr.xephi.authme.settings.Settings;
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 javax.inject.Inject;

View File

@ -5,7 +5,7 @@ import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.EmailSettings;
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.StringUtils;
import org.apache.commons.mail.EmailConstants;

View File

@ -9,7 +9,7 @@ import fr.xephi.authme.process.logout.AsynchronousLogout;
import fr.xephi.authme.process.quit.AsynchronousQuit;
import fr.xephi.authme.process.register.AsyncRegister;
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.entity.Player;

View File

@ -8,7 +8,7 @@ import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.permission.PermissionsManager;
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.entity.Player;

View File

@ -5,7 +5,7 @@ import fr.xephi.authme.process.logout.ProcessSynchronousPlayerLogout;
import fr.xephi.authme.process.quit.ProcessSyncronousPlayerQuit;
import fr.xephi.authme.process.register.ProcessSyncEmailRegister;
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 javax.inject.Inject;

View File

@ -20,8 +20,8 @@ import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.task.PlayerDataTaskManager;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.util.PlayerUtils;
import org.apache.commons.lang.reflect.MethodUtils;
import org.bukkit.GameMode;
import org.bukkit.entity.LivingEntity;
@ -32,7 +32,7 @@ import org.bukkit.potion.PotionEffectType;
import javax.inject.Inject;
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.
@ -78,7 +78,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
public void processJoin(final Player player) {
final String name = player.getName().toLowerCase();
final String ip = Utils.getPlayerIp(player);
final String ip = PlayerUtils.getPlayerIp(player);
if (isPlayerUnrestricted(name)) {
return;
@ -249,7 +249,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
private int countOnlinePlayersByIp(String ip) {
int count = 0;
for (Player player : bukkitService.getOnlinePlayers()) {
if (ip.equalsIgnoreCase(Utils.getPlayerIp(player))) {
if (ip.equalsIgnoreCase(PlayerUtils.getPlayerIp(player))) {
++count;
}
}

View File

@ -25,9 +25,9 @@ import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
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.Utils;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@ -130,7 +130,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
return null;
}
final String ip = Utils.getPlayerIp(player);
final String ip = PlayerUtils.getPlayerIp(player);
if (hasReachedMaxLoggedInPlayersForIp(player, ip)) {
service.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
return null;
@ -163,7 +163,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
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.
captchaManager.increaseCount(name);
@ -210,7 +210,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
private void performLogin(Player player, PlayerAuth auth) {
if (player.isOnline()) {
// Update auth to reflect this new login
final String ip = Utils.getPlayerIp(player);
final String ip = PlayerUtils.getPlayerIp(player);
auth.setRealName(player.getName());
auth.setLastLogin(System.currentTimeMillis());
auth.setIp(ip);
@ -311,7 +311,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
final String name = player.getName();
int count = 0;
for (Player onlinePlayer : bukkitService.getOnlinePlayers()) {
if (ip.equalsIgnoreCase(Utils.getPlayerIp(onlinePlayer))
if (ip.equalsIgnoreCase(PlayerUtils.getPlayerIp(onlinePlayer))
&& !onlinePlayer.getName().equals(name)
&& dataSource.isLogged(onlinePlayer.getName().toLowerCase())) {
++count;

View File

@ -12,8 +12,8 @@ import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.process.SynchronousProcess;
import fr.xephi.authme.service.BungeeService;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.TeleportationService;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.service.TeleportationService;
import org.apache.commons.lang.reflect.MethodUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity;

View File

@ -11,15 +11,15 @@ import fr.xephi.authme.process.SynchronousProcess;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.task.PlayerDataTaskManager;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.TeleportationService;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.service.TeleportationService;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
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 {

View File

@ -11,8 +11,8 @@ import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.process.SyncProcessManager;
import fr.xephi.authme.settings.SpawnLoader;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.util.ValidationService;
import fr.xephi.authme.util.PlayerUtils;
import fr.xephi.authme.service.ValidationService;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -63,7 +63,7 @@ public class AsynchronousQuit implements AsynchronousProcess {
database.updateQuitLoc(auth);
}
final String ip = Utils.getPlayerIp(player);
final String ip = PlayerUtils.getPlayerIp(player);
PlayerAuth auth = PlayerAuth.builder()
.name(name)
.realName(player.getName())

View File

@ -19,11 +19,11 @@ import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
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.Utils;
import fr.xephi.authme.util.ValidationService;
import fr.xephi.authme.util.ValidationService.ValidationResult;
import fr.xephi.authme.service.ValidationService;
import fr.xephi.authme.service.ValidationService.ValidationResult;
import org.bukkit.Bukkit;
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 String ip = Utils.getPlayerIp(player);
final String ip = PlayerUtils.getPlayerIp(player);
if (maxRegPerIp > 0
&& !"127.0.0.1".equalsIgnoreCase(ip)
&& !"localhost".equalsIgnoreCase(ip)
@ -132,7 +132,7 @@ public class AsyncRegister implements AsynchronousProcess {
}
final HashedPassword hashedPassword = passwordSecurity.computeHash(password, name);
final String ip = Utils.getPlayerIp(player);
final String ip = PlayerUtils.getPlayerIp(player);
PlayerAuth auth = PlayerAuth.builder()
.name(name)
.realName(player.getName())
@ -154,7 +154,7 @@ public class AsyncRegister implements AsynchronousProcess {
private void passwordRegister(final Player player, String password, boolean autoLogin) {
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);
PlayerAuth auth = PlayerAuth.builder()
.name(name)

View File

@ -7,7 +7,7 @@ import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.process.SynchronousProcess;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.task.PlayerDataTaskManager;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.util.PlayerUtils;
import org.bukkit.entity.Player;
import javax.inject.Inject;
@ -35,7 +35,7 @@ public class ProcessSyncEmailRegister implements SynchronousProcess {
playerDataTaskManager.registerMessageTask(name, true);
player.saveData();
ConsoleLogger.fine(player.getName() + " registered " + Utils.getPlayerIp(player));
ConsoleLogger.fine(player.getName() + " registered " + PlayerUtils.getPlayerIp(player));
}
}

View File

@ -11,7 +11,7 @@ import fr.xephi.authme.settings.properties.EmailSettings;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
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.entity.Player;
@ -74,7 +74,7 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
}
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
if (service.getProperty(RegistrationSettings.FORCE_KICK_AFTER_REGISTER)) {

View File

@ -14,8 +14,8 @@ import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.task.PlayerDataTaskManager;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.TeleportationService;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.service.TeleportationService;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
@ -23,7 +23,7 @@ import org.bukkit.potion.PotionEffectType;
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 {

View File

@ -7,15 +7,14 @@ import fr.xephi.authme.permission.AdminPermission;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.ProtectionSettings;
import fr.xephi.authme.util.BukkitService;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
import javax.inject.Inject;
import java.util.concurrent.CopyOnWriteArrayList;
import static fr.xephi.authme.util.BukkitService.TICKS_PER_MINUTE;
import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND;
import static fr.xephi.authme.service.BukkitService.TICKS_PER_MINUTE;
import static fr.xephi.authme.service.BukkitService.TICKS_PER_SECOND;
/**
* The AntiBot Service Management class.

View File

@ -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.settings.Settings;
import fr.xephi.authme.settings.properties.BackupSettings;
@ -19,7 +21,7 @@ import java.util.Date;
*
* @author stefano
*/
public class PerformBackup {
public class BackupService {
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd_HH-mm");
@ -37,7 +39,7 @@ public class PerformBackup {
* @param instance AuthMe
* @param settings The plugin settings
*/
public PerformBackup(AuthMe instance, Settings settings) {
public BackupService(AuthMe instance, Settings settings) {
this.dataFolder = instance.getDataFolder();
this.settings = settings;
this.dbName = settings.getProperty(DatabaseSettings.MYSQL_DATABASE);

View File

@ -1,4 +1,4 @@
package fr.xephi.authme.util;
package fr.xephi.authme.service;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;

View File

@ -1,4 +1,4 @@
package fr.xephi.authme.util;
package fr.xephi.authme.service;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;

View File

@ -16,7 +16,7 @@ import static fr.xephi.authme.util.Utils.MILLIS_PER_HOUR;
/**
* Manager for recovery codes.
*/
public class RecoveryCodeManager implements SettingsDependent {
public class RecoveryCodeService implements SettingsDependent {
private Map<String, ExpiringEntry> recoveryCodes = new ConcurrentHashMap<>();
@ -24,7 +24,7 @@ public class RecoveryCodeManager implements SettingsDependent {
private long recoveryCodeExpirationMillis;
@Inject
RecoveryCodeManager(Settings settings) {
RecoveryCodeService(Settings settings) {
reload(settings);
}

View File

@ -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.PlayerCache;

View File

@ -1,7 +1,8 @@
package fr.xephi.authme.util;
package fr.xephi.authme.service;
import com.github.authme.configme.properties.Property;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.geoip.GeoLiteAPI;
import fr.xephi.authme.initialization.Reloadable;
import fr.xephi.authme.output.MessageKey;
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.RestrictionSettings;
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 javax.annotation.PostConstruct;

View File

@ -2,11 +2,11 @@ package fr.xephi.authme.task;
import fr.xephi.authme.cache.auth.PlayerCache;
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.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.

View File

@ -9,13 +9,13 @@ import fr.xephi.authme.output.Messages;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
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.scheduler.BukkitTask;
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.

View File

@ -6,8 +6,8 @@ import fr.xephi.authme.hooks.PluginHooks;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.PurgeSettings;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.util.PlayerUtils;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
@ -152,7 +152,7 @@ class PurgeExecutor {
, makePath(settings.getProperty(PurgeSettings.DEFAULT_WORLD), "players"));
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()) {
i++;
}
@ -184,7 +184,7 @@ class PurgeExecutor {
}
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()) {
i++;
}

View File

@ -5,7 +5,7 @@ import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.settings.Settings;
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 org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;

View File

@ -9,6 +9,7 @@ import java.util.List;
*/
public final class CollectionUtils {
// Utility class
private CollectionUtils() {
}

View File

@ -15,6 +15,7 @@ import static java.lang.String.format;
*/
public final class FileUtils {
// Utility class
private FileUtils() {
}

View 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();
}
}

View File

@ -1,6 +1,19 @@
package fr.xephi.authme.util;
/**
* Runtime utilities.
*/
public class RuntimeUtils {
// Utility class
private RuntimeUtils() {
}
/**
* Return the available core count of the JVM.
*
* @return the core count
*/
public static int getCoreCount() {
return Runtime.getRuntime().availableProcessors();
}

View File

@ -11,8 +11,8 @@ import java.io.File;
*/
public final class StringUtils {
// Utility class
private StringUtils() {
// Utility class
}
/**

View File

@ -16,26 +16,10 @@ public final class Utils {
/** Number of milliseconds in an hour. */
public static final long MILLIS_PER_HOUR = 60 * MILLIS_PER_MINUTE;
// Utility class
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.
*
@ -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.
*

View File

@ -15,7 +15,7 @@ import fr.xephi.authme.process.login.ProcessSyncPlayerLogin;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.Settings;
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.Server;
import org.bukkit.plugin.PluginDescriptionFile;

View File

@ -1,6 +1,6 @@
package fr.xephi.authme;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.service.BukkitService;
import org.bukkit.entity.Player;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;

View File

@ -8,7 +8,7 @@ import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.hooks.PluginHooks;
import fr.xephi.authme.process.Management;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.util.ValidationService;
import fr.xephi.authme.service.ValidationService;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Server;

View File

@ -7,7 +7,7 @@ import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.settings.Settings;
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.junit.Test;
import org.junit.runner.RunWith;

View File

@ -8,7 +8,7 @@ import fr.xephi.authme.cache.limbo.PlayerData;
import fr.xephi.authme.initialization.DataFolder;
import fr.xephi.authme.permission.PermissionsManager;
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 org.bukkit.Location;
import org.bukkit.World;

View File

@ -5,7 +5,7 @@ import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.settings.Settings;
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.entity.Player;
import org.junit.Test;

View File

@ -4,7 +4,7 @@ import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.datasource.DataSource;
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.junit.Test;
import org.junit.runner.RunWith;

View File

@ -8,9 +8,9 @@ import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.crypts.HashedPassword;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.ValidationService;
import fr.xephi.authme.util.ValidationService.ValidationResult;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.service.ValidationService;
import fr.xephi.authme.service.ValidationService.ValidationResult;
import org.bukkit.command.CommandSender;
import org.junit.BeforeClass;
import org.junit.Test;

View File

@ -5,7 +5,7 @@ import fr.xephi.authme.TestHelper;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.converter.Converter;
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 org.bukkit.command.CommandSender;
import org.junit.BeforeClass;

View File

@ -3,7 +3,7 @@ package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.PlayerPermission;
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.entity.Player;
import org.junit.Test;

View File

@ -1,7 +1,7 @@
package fr.xephi.authme.command.executable.authme;
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.entity.Player;
import org.junit.Test;

View File

@ -1,7 +1,7 @@
package fr.xephi.authme.command.executable.authme;
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.command.CommandSender;
import org.junit.Test;

View File

@ -8,9 +8,9 @@ import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.crypts.HashedPassword;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.ValidationService;
import fr.xephi.authme.util.ValidationService.ValidationResult;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.service.ValidationService;
import fr.xephi.authme.service.ValidationService.ValidationResult;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.junit.BeforeClass;

View File

@ -5,7 +5,7 @@ import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.datasource.DataSource;
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.junit.Test;
import org.junit.runner.RunWith;

View File

@ -4,7 +4,7 @@ import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
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.entity.Player;
import org.junit.Test;

View File

@ -6,8 +6,8 @@ import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.process.Management;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.util.ValidationService;
import fr.xephi.authme.util.ValidationService.ValidationResult;
import fr.xephi.authme.service.ValidationService;
import fr.xephi.authme.service.ValidationService.ValidationResult;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

View File

@ -9,7 +9,7 @@ import fr.xephi.authme.mail.SendMailSSL;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.security.PasswordSecurity;
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.SecuritySettings;
import org.bukkit.entity.Player;
@ -63,7 +63,7 @@ public class RecoverEmailCommandTest {
private SendMailSSL sendMailSsl;
@Mock
private RecoveryCodeManager recoveryCodeManager;
private RecoveryCodeService recoveryCodeService;
@BeforeClass
public static void initLogger() {
@ -177,8 +177,8 @@ public class RecoverEmailCommandTest {
int hoursValid = 12;
given(commandService.getProperty(SecuritySettings.RECOVERY_CODE_HOURS_VALID)).willReturn(hoursValid);
String code = "a94f37";
given(recoveryCodeManager.isRecoveryCodeNeeded()).willReturn(true);
given(recoveryCodeManager.generateCode(name)).willReturn(code);
given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(true);
given(recoveryCodeService.generateCode(name)).willReturn(code);
// when
command.executeCommand(sender, Collections.singletonList(email.toUpperCase()));
@ -186,7 +186,7 @@ public class RecoverEmailCommandTest {
// then
verify(sendMailSsl).hasAllInformation();
verify(dataSource).getAuth(name);
verify(recoveryCodeManager).generateCode(name);
verify(recoveryCodeService).generateCode(name);
verify(commandService).send(sender, MessageKey.RECOVERY_CODE_SENT);
verify(sendMailSsl).sendRecoveryCode(name, email, code);
}
@ -203,8 +203,8 @@ public class RecoverEmailCommandTest {
PlayerAuth auth = newAuthWithEmail(email);
given(dataSource.getAuth(name)).willReturn(auth);
given(commandService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH)).willReturn(20);
given(recoveryCodeManager.isRecoveryCodeNeeded()).willReturn(true);
given(recoveryCodeManager.isCodeValid(name, "bogus")).willReturn(false);
given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(true);
given(recoveryCodeService.isCodeValid(name, "bogus")).willReturn(false);
// when
command.executeCommand(sender, Arrays.asList(email, "bogus"));
@ -231,8 +231,8 @@ public class RecoverEmailCommandTest {
given(commandService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH)).willReturn(20);
given(passwordSecurity.computeHash(anyString(), eq(name)))
.willAnswer(invocation -> new HashedPassword((String) invocation.getArguments()[0]));
given(recoveryCodeManager.isRecoveryCodeNeeded()).willReturn(true);
given(recoveryCodeManager.isCodeValid(name, code)).willReturn(true);
given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(true);
given(recoveryCodeService.isCodeValid(name, code)).willReturn(true);
// when
command.executeCommand(sender, Arrays.asList(email, code));
@ -245,7 +245,7 @@ public class RecoverEmailCommandTest {
String generatedPassword = passwordCaptor.getValue();
assertThat(generatedPassword, stringWithLength(20));
verify(dataSource).updatePassword(eq(name), any(HashedPassword.class));
verify(recoveryCodeManager).removeCode(name);
verify(recoveryCodeService).removeCode(name);
verify(sendMailSsl).sendPasswordMail(name, email, generatedPassword);
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(passwordSecurity.computeHash(anyString(), eq(name)))
.willAnswer(invocation -> new HashedPassword((String) invocation.getArguments()[0]));
given(recoveryCodeManager.isRecoveryCodeNeeded()).willReturn(false);
given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(false);
// when
command.executeCommand(sender, Collections.singletonList(email));

View File

@ -1,7 +1,8 @@
package fr.xephi.authme.util;
package fr.xephi.authme.geoip;
import com.maxmind.geoip.Country;
import com.maxmind.geoip.LookupService;
import fr.xephi.authme.geoip.GeoLiteAPI;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@ -25,7 +26,7 @@ import static org.mockito.Mockito.verify;
* Test for {@link GeoLiteAPI}.
*/
@RunWith(MockitoJUnitRunner.class)
public class GeoLiteAPITest {
public class GeoIpManagerTest {
private GeoLiteAPI geoLiteApi;
private File dataFolder;

View File

@ -8,7 +8,7 @@ import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.hooks.PluginHooks;
import fr.xephi.authme.settings.Settings;
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.Player;
import org.bukkit.event.HandlerList;

View File

@ -12,8 +12,8 @@ import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.ProtectionSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.ValidationService;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.service.ValidationService;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerLoginEvent;

View File

@ -10,9 +10,9 @@ import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.SpawnLoader;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.TeleportationService;
import fr.xephi.authme.util.ValidationService;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.service.TeleportationService;
import fr.xephi.authme.service.ValidationService;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;

View File

@ -9,7 +9,7 @@ import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.settings.Settings;
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.entity.Player;
import org.junit.Test;

View File

@ -14,7 +14,7 @@ import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
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.junit.BeforeClass;
import org.junit.Test;

View File

@ -14,8 +14,8 @@ import fr.xephi.authme.security.crypts.HashedPassword;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.task.PlayerDataTaskManager;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.TeleportationService;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.service.TeleportationService;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.junit.BeforeClass;

View File

@ -10,7 +10,6 @@ import fr.xephi.authme.permission.AdminPermission;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.ProtectionSettings;
import fr.xephi.authme.util.BukkitService;
import org.bukkit.entity.Player;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@ -1,4 +1,4 @@
package fr.xephi.authme.util;
package fr.xephi.authme.service;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ReflectionTestUtils;

View File

@ -1,4 +1,4 @@
package fr.xephi.authme.util;
package fr.xephi.authme.service;
import fr.xephi.authme.TestHelper;
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.crypts.HashedPassword;
import fr.xephi.authme.security.crypts.SHA256;
import fr.xephi.authme.service.MigrationService;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.SecuritySettings;
import org.junit.BeforeClass;

View File

@ -4,7 +4,7 @@ import ch.jalu.injector.testing.BeforeInjecting;
import ch.jalu.injector.testing.DelayedInjectionRunner;
import ch.jalu.injector.testing.InjectDelayed;
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.properties.SecuritySettings;
import org.junit.Test;
@ -20,13 +20,13 @@ import static org.junit.Assert.assertThat;
import static org.mockito.BDDMockito.given;
/**
* Test for {@link RecoveryCodeManager}.
* Test for {@link RecoveryCodeService}.
*/
@RunWith(DelayedInjectionRunner.class)
public class RecoveryCodeManagerTest {
public class RecoveryCodeServiceTest {
@InjectDelayed
private RecoveryCodeManager recoveryCodeManager;
private RecoveryCodeService recoveryCodeService;
@Mock
private Settings settings;
@ -39,16 +39,16 @@ public class RecoveryCodeManagerTest {
@Test
public void shouldBeDisabledForNonPositiveLength() {
assertThat(recoveryCodeManager.isRecoveryCodeNeeded(), equalTo(true));
assertThat(recoveryCodeService.isRecoveryCodeNeeded(), equalTo(true));
// given
given(settings.getProperty(SecuritySettings.RECOVERY_CODE_LENGTH)).willReturn(0);
// when
recoveryCodeManager.reload(settings);
recoveryCodeService.reload(settings);
// then
assertThat(recoveryCodeManager.isRecoveryCodeNeeded(), equalTo(false));
assertThat(recoveryCodeService.isRecoveryCodeNeeded(), equalTo(false));
}
@Test
@ -57,7 +57,7 @@ public class RecoveryCodeManagerTest {
String name = "Bobbers";
// when
recoveryCodeManager.generateCode(name);
recoveryCodeService.generateCode(name);
// then
ExpiringEntry entry = getCodeMap().get(name);
@ -72,7 +72,7 @@ public class RecoveryCodeManagerTest {
setCodeInMap(player, code, System.currentTimeMillis() - 500);
// when
boolean result = recoveryCodeManager.isCodeValid(player, code);
boolean result = recoveryCodeService.isCodeValid(player, code);
// then
assertThat(result, equalTo(false));
@ -82,10 +82,10 @@ public class RecoveryCodeManagerTest {
public void shouldRecognizeCorrectCode() {
// given
String player = "dragon";
String code = recoveryCodeManager.generateCode(player);
String code = recoveryCodeService.generateCode(player);
// when
boolean result = recoveryCodeManager.isCodeValid(player, code);
boolean result = recoveryCodeService.isCodeValid(player, code);
// then
assertThat(result, equalTo(true));
@ -95,19 +95,19 @@ public class RecoveryCodeManagerTest {
public void shouldRemoveCode() {
// given
String player = "Tester";
String code = recoveryCodeManager.generateCode(player);
String code = recoveryCodeService.generateCode(player);
// when
recoveryCodeManager.removeCode(player);
recoveryCodeService.removeCode(player);
// then
assertThat(recoveryCodeManager.isCodeValid(player, code), equalTo(false));
assertThat(recoveryCodeService.isCodeValid(player, code), equalTo(false));
assertThat(getCodeMap().get(player), nullValue());
}
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) {

View File

@ -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.PlayerCache;
import fr.xephi.authme.cache.limbo.PlayerData;
import fr.xephi.authme.events.FirstSpawnTeleportEvent;
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.SpawnLoader;
import fr.xephi.authme.settings.properties.RestrictionSettings;

View File

@ -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.DelayedInjectionRunner;
import ch.jalu.injector.testing.InjectDelayed;
import com.google.common.base.Strings;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.geoip.GeoLiteAPI;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.PlayerStatePermission;
import fr.xephi.authme.service.ValidationService;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.EmailSettings;
import fr.xephi.authme.settings.properties.ProtectionSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
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.junit.Test;
import org.junit.runner.RunWith;

View File

@ -9,7 +9,7 @@ import fr.xephi.authme.output.Messages;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
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.scheduler.BukkitTask;
import org.junit.BeforeClass;

View File

@ -6,7 +6,7 @@ import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.settings.Settings;
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.command.CommandSender;
import org.bukkit.entity.Player;

View 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));
}
}

View File

@ -1,18 +1,13 @@
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}.
@ -48,49 +43,6 @@ public class UtilsTest {
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
public void shouldHavePrivateConstructorOnly() {
// given / when / then