Merge CommandService and ProcessService to CommonService
- Replace CommandService and ProcessService with CommonService: a service that offers our typical needs to work with settings, messages and permissions - Remove validation methods from CommonService: inject ValidationService directly. Validation methods are not used very frequently and therefore don't belong in CommonService. Their presence was a relict from our architecture before injection was used.
This commit is contained in:
@@ -1,114 +0,0 @@
|
||||
package fr.xephi.authme.process;
|
||||
|
||||
import com.github.authme.configme.properties.Property;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.message.Messages;
|
||||
import fr.xephi.authme.permission.AuthGroupHandler;
|
||||
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.service.ValidationService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Service for asynchronous and synchronous processes.
|
||||
*/
|
||||
public class ProcessService {
|
||||
|
||||
@Inject
|
||||
private Settings settings;
|
||||
|
||||
@Inject
|
||||
private Messages messages;
|
||||
|
||||
@Inject
|
||||
private ValidationService validationService;
|
||||
|
||||
@Inject
|
||||
private PermissionsManager permissionsManager;
|
||||
|
||||
@Inject
|
||||
private AuthGroupHandler authGroupHandler;
|
||||
|
||||
/**
|
||||
* Retrieve a property's value.
|
||||
*
|
||||
* @param property the property to retrieve
|
||||
* @param <T> the property type
|
||||
* @return the property's value
|
||||
*/
|
||||
public <T> T getProperty(Property<T> property) {
|
||||
return settings.getProperty(property);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the settings manager.
|
||||
*
|
||||
* @return settings manager
|
||||
*/
|
||||
public Settings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to the command sender.
|
||||
*
|
||||
* @param sender the command sender
|
||||
* @param key the message key
|
||||
*/
|
||||
public void send(CommandSender sender, MessageKey key) {
|
||||
messages.send(sender, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to the command sender with the given replacements.
|
||||
*
|
||||
* @param sender the command sender
|
||||
* @param key the message key
|
||||
* @param replacements the replacements to apply to the message
|
||||
*/
|
||||
public void send(CommandSender sender, MessageKey key, String... replacements) {
|
||||
messages.send(sender, key, replacements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a message.
|
||||
*
|
||||
* @param key the key of the message
|
||||
* @return the message, split by line
|
||||
*/
|
||||
public String[] retrieveMessage(MessageKey key) {
|
||||
return messages.retrieve(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a message as one piece.
|
||||
*
|
||||
* @param key the key of the message
|
||||
* @return the message
|
||||
*/
|
||||
public String retrieveSingleMessage(MessageKey key) {
|
||||
return messages.retrieveSingle(key);
|
||||
}
|
||||
|
||||
public boolean validateEmail(String email) {
|
||||
return validationService.validateEmail(email);
|
||||
}
|
||||
|
||||
public boolean isEmailFreeForRegistration(String email, CommandSender sender) {
|
||||
return validationService.isEmailFreeForRegistration(email, sender);
|
||||
}
|
||||
|
||||
public boolean hasPermission(Player player, PermissionNode node) {
|
||||
return permissionsManager.hasPermission(player, node);
|
||||
}
|
||||
|
||||
public boolean setGroup(Player player, AuthGroupType group) {
|
||||
return authGroupHandler.setGroup(player, group);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.process.AsynchronousProcess;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -19,7 +19,7 @@ public class AsyncChangePassword implements AsynchronousProcess {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Inject
|
||||
private ProcessService processService;
|
||||
private CommonService commonService;
|
||||
|
||||
@Inject
|
||||
private PasswordSecurity passwordSecurity;
|
||||
@@ -39,15 +39,15 @@ public class AsyncChangePassword implements AsynchronousProcess {
|
||||
auth.setPassword(hashedPassword);
|
||||
|
||||
if (!dataSource.updatePassword(auth)) {
|
||||
processService.send(player, MessageKey.ERROR);
|
||||
commonService.send(player, MessageKey.ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
playerCache.updatePlayer(auth);
|
||||
processService.send(player, MessageKey.PASSWORD_CHANGED_SUCCESS);
|
||||
commonService.send(player, MessageKey.PASSWORD_CHANGED_SUCCESS);
|
||||
ConsoleLogger.info(player.getName() + " changed his password");
|
||||
} else {
|
||||
processService.send(player, MessageKey.WRONG_PASSWORD);
|
||||
commonService.send(player, MessageKey.WRONG_PASSWORD);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@ import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.process.AsynchronousProcess;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -18,7 +19,7 @@ import javax.inject.Inject;
|
||||
public class AsyncAddEmail implements AsynchronousProcess {
|
||||
|
||||
@Inject
|
||||
private ProcessService service;
|
||||
private CommonService service;
|
||||
|
||||
@Inject
|
||||
private DataSource dataSource;
|
||||
@@ -26,6 +27,9 @@ public class AsyncAddEmail implements AsynchronousProcess {
|
||||
@Inject
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@Inject
|
||||
private ValidationService validationService;
|
||||
|
||||
AsyncAddEmail() { }
|
||||
|
||||
public void addEmail(Player player, String email) {
|
||||
@@ -37,9 +41,9 @@ public class AsyncAddEmail implements AsynchronousProcess {
|
||||
|
||||
if (currentEmail != null && !"your@email.com".equals(currentEmail)) {
|
||||
service.send(player, MessageKey.USAGE_CHANGE_EMAIL);
|
||||
} else if (!service.validateEmail(email)) {
|
||||
} else if (!validationService.validateEmail(email)) {
|
||||
service.send(player, MessageKey.INVALID_EMAIL);
|
||||
} else if (!service.isEmailFreeForRegistration(email, player)) {
|
||||
} else if (!validationService.isEmailFreeForRegistration(email, player)) {
|
||||
service.send(player, MessageKey.EMAIL_ALREADY_USED_ERROR);
|
||||
} else {
|
||||
auth.setEmail(email);
|
||||
|
||||
@@ -5,7 +5,8 @@ import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.process.AsynchronousProcess;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -17,7 +18,7 @@ import javax.inject.Inject;
|
||||
public class AsyncChangeEmail implements AsynchronousProcess {
|
||||
|
||||
@Inject
|
||||
private ProcessService service;
|
||||
private CommonService service;
|
||||
|
||||
@Inject
|
||||
private PlayerCache playerCache;
|
||||
@@ -25,6 +26,9 @@ public class AsyncChangeEmail implements AsynchronousProcess {
|
||||
@Inject
|
||||
private DataSource dataSource;
|
||||
|
||||
@Inject
|
||||
private ValidationService validationService;
|
||||
|
||||
AsyncChangeEmail() { }
|
||||
|
||||
public void changeEmail(Player player, String oldEmail, String newEmail) {
|
||||
@@ -35,11 +39,11 @@ public class AsyncChangeEmail implements AsynchronousProcess {
|
||||
|
||||
if (currentEmail == null) {
|
||||
service.send(player, MessageKey.USAGE_ADD_EMAIL);
|
||||
} else if (newEmail == null || !service.validateEmail(newEmail)) {
|
||||
} else if (newEmail == null || !validationService.validateEmail(newEmail)) {
|
||||
service.send(player, MessageKey.INVALID_NEW_EMAIL);
|
||||
} else if (!oldEmail.equals(currentEmail)) {
|
||||
service.send(player, MessageKey.INVALID_OLD_EMAIL);
|
||||
} else if (!service.isEmailFreeForRegistration(newEmail, player)) {
|
||||
} else if (!validationService.isEmailFreeForRegistration(newEmail, player)) {
|
||||
service.send(player, MessageKey.EMAIL_ALREADY_USED_ERROR);
|
||||
} else {
|
||||
saveNewEmail(auth, player, newEmail);
|
||||
|
||||
@@ -13,7 +13,7 @@ import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.permission.AuthGroupType;
|
||||
import fr.xephi.authme.permission.PlayerStatePermission;
|
||||
import fr.xephi.authme.process.AsynchronousProcess;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.process.login.AsynchronousLogin;
|
||||
import fr.xephi.authme.settings.commandconfig.CommandManager;
|
||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||
@@ -45,7 +45,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
||||
private DataSource database;
|
||||
|
||||
@Inject
|
||||
private ProcessService service;
|
||||
private CommonService service;
|
||||
|
||||
@Inject
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@@ -16,7 +16,7 @@ import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.permission.PlayerPermission;
|
||||
import fr.xephi.authme.permission.PlayerStatePermission;
|
||||
import fr.xephi.authme.process.AsynchronousProcess;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.process.SyncProcessManager;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
@@ -44,7 +44,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Inject
|
||||
private ProcessService service;
|
||||
private CommonService service;
|
||||
|
||||
@Inject
|
||||
private PermissionsManager permissionsManager;
|
||||
|
||||
@@ -8,13 +8,13 @@ import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.events.LoginEvent;
|
||||
import fr.xephi.authme.events.RestoreInventoryEvent;
|
||||
import fr.xephi.authme.listener.PlayerListener;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.process.SynchronousProcess;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.BungeeService;
|
||||
import fr.xephi.authme.service.TeleportationService;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.commandconfig.CommandManager;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.TeleportationService;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -33,9 +33,6 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
|
||||
@Inject
|
||||
private BungeeService bungeeService;
|
||||
|
||||
@Inject
|
||||
private ProcessService service;
|
||||
|
||||
@Inject
|
||||
private LimboCache limboCache;
|
||||
|
||||
@@ -54,6 +51,9 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
|
||||
@Inject
|
||||
private CommandManager commandManager;
|
||||
|
||||
@Inject
|
||||
private Settings settings;
|
||||
|
||||
ProcessSyncPlayerLogin() {
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
|
||||
// because LimboCache#restoreData teleport player to last location.
|
||||
}
|
||||
|
||||
if (service.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) {
|
||||
if (settings.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) {
|
||||
restoreInventory(player);
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
|
||||
}
|
||||
}
|
||||
|
||||
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
|
||||
if (settings.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
|
||||
player.removePotionEffect(PotionEffectType.BLINDNESS);
|
||||
}
|
||||
|
||||
@@ -103,13 +103,13 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
|
||||
player.saveData();
|
||||
|
||||
// Login is done, display welcome message
|
||||
if (service.getProperty(RegistrationSettings.USE_WELCOME_MESSAGE)) {
|
||||
if (service.getProperty(RegistrationSettings.BROADCAST_WELCOME_MESSAGE)) {
|
||||
for (String s : service.getSettings().getWelcomeMessage()) {
|
||||
if (settings.getProperty(RegistrationSettings.USE_WELCOME_MESSAGE)) {
|
||||
if (settings.getProperty(RegistrationSettings.BROADCAST_WELCOME_MESSAGE)) {
|
||||
for (String s : settings.getWelcomeMessage()) {
|
||||
Bukkit.getServer().broadcastMessage(plugin.replaceAllInfo(s, player));
|
||||
}
|
||||
} else {
|
||||
for (String s : service.getSettings().getWelcomeMessage()) {
|
||||
for (String s : settings.getWelcomeMessage()) {
|
||||
player.sendMessage(plugin.replaceAllInfo(s, player));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import fr.xephi.authme.data.limbo.LimboCache;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.process.AsynchronousProcess;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.process.SyncProcessManager;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -19,7 +19,7 @@ public class AsynchronousLogout implements AsynchronousProcess {
|
||||
private DataSource database;
|
||||
|
||||
@Inject
|
||||
private ProcessService service;
|
||||
private CommonService service;
|
||||
|
||||
@Inject
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@@ -6,7 +6,7 @@ import fr.xephi.authme.events.LogoutEvent;
|
||||
import fr.xephi.authme.listener.protocollib.ProtocolLibService;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.permission.AuthGroupType;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.process.SynchronousProcess;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
@@ -25,7 +25,7 @@ import static fr.xephi.authme.service.BukkitService.TICKS_PER_SECOND;
|
||||
public class ProcessSynchronousPlayerLogout implements SynchronousProcess {
|
||||
|
||||
@Inject
|
||||
private ProcessService service;
|
||||
private CommonService service;
|
||||
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@@ -7,7 +7,7 @@ import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.datasource.CacheDataSource;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.process.AsynchronousProcess;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.process.SyncProcessManager;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
@@ -27,7 +27,7 @@ public class AsynchronousQuit implements AsynchronousProcess {
|
||||
private DataSource database;
|
||||
|
||||
@Inject
|
||||
private ProcessService service;
|
||||
private CommonService service;
|
||||
|
||||
@Inject
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@@ -7,7 +7,7 @@ import fr.xephi.authme.mail.SendMailSSL;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.process.AsynchronousProcess;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.process.SyncProcessManager;
|
||||
import fr.xephi.authme.process.login.AsynchronousLogin;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
@@ -51,7 +51,7 @@ public class AsyncRegister implements AsynchronousProcess {
|
||||
@Inject
|
||||
private PasswordSecurity passwordSecurity;
|
||||
@Inject
|
||||
private ProcessService service;
|
||||
private CommonService service;
|
||||
@Inject
|
||||
private SyncProcessManager syncProcessManager;
|
||||
@Inject
|
||||
|
||||
@@ -3,7 +3,7 @@ package fr.xephi.authme.process.register;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.permission.AuthGroupType;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.process.SynchronousProcess;
|
||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||
import fr.xephi.authme.task.LimboPlayerTaskManager;
|
||||
@@ -16,7 +16,7 @@ import javax.inject.Inject;
|
||||
public class ProcessSyncEmailRegister implements SynchronousProcess {
|
||||
|
||||
@Inject
|
||||
private ProcessService service;
|
||||
private CommonService service;
|
||||
|
||||
@Inject
|
||||
private LimboPlayerTaskManager limboPlayerTaskManager;
|
||||
|
||||
@@ -4,7 +4,7 @@ import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.data.limbo.LimboCache;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.permission.AuthGroupType;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.process.SynchronousProcess;
|
||||
import fr.xephi.authme.service.BungeeService;
|
||||
import fr.xephi.authme.settings.commandconfig.CommandManager;
|
||||
@@ -25,7 +25,7 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
|
||||
private BungeeService bungeeService;
|
||||
|
||||
@Inject
|
||||
private ProcessService service;
|
||||
private CommonService service;
|
||||
|
||||
@Inject
|
||||
private LimboCache limboCache;
|
||||
|
||||
@@ -9,7 +9,7 @@ import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.permission.AuthGroupHandler;
|
||||
import fr.xephi.authme.permission.AuthGroupType;
|
||||
import fr.xephi.authme.process.AsynchronousProcess;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
@@ -31,7 +31,7 @@ public class AsynchronousUnregister implements AsynchronousProcess {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Inject
|
||||
private ProcessService service;
|
||||
private CommonService service;
|
||||
|
||||
@Inject
|
||||
private PasswordSecurity passwordSecurity;
|
||||
|
||||
Reference in New Issue
Block a user