#736 Remove getter for Management instance on main class

This commit is contained in:
ljacqu 2016-08-20 22:03:11 +02:00
parent 289ce7740f
commit 2f1613840e
3 changed files with 40 additions and 27 deletions

View File

@ -24,7 +24,6 @@ import fr.xephi.authme.listener.ServerListener;
import fr.xephi.authme.output.Messages; 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.process.Management;
import fr.xephi.authme.security.crypts.SHA256; import fr.xephi.authme.security.crypts.SHA256;
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;
@ -67,7 +66,6 @@ public class AuthMe extends JavaPlugin {
private static String pluginBuildNumber = "Unknown"; private static String pluginBuildNumber = "Unknown";
// Private instances // Private instances
private Management management;
private CommandHandler commandHandler; private CommandHandler commandHandler;
private PermissionsManager permsMan; private PermissionsManager permsMan;
private Settings settings; private Settings settings;
@ -226,6 +224,11 @@ public class AuthMe extends JavaPlugin {
} }
} }
/**
* Instantiates all services.
*
* @param injector the injector
*/
protected void instantiateServices(Injector injector) { protected void instantiateServices(Injector injector) {
// PlayerCache is still injected statically sometimes // PlayerCache is still injected statically sometimes
playerCache = PlayerCache.getInstance(); playerCache = PlayerCache.getInstance();
@ -235,7 +238,6 @@ public class AuthMe extends JavaPlugin {
permsMan = injector.getSingleton(PermissionsManager.class); permsMan = injector.getSingleton(PermissionsManager.class);
bukkitService = injector.getSingleton(BukkitService.class); bukkitService = injector.getSingleton(BukkitService.class);
commandHandler = injector.getSingleton(CommandHandler.class); commandHandler = injector.getSingleton(CommandHandler.class);
management = injector.getSingleton(Management.class);
geoLiteApi = injector.getSingleton(GeoLiteAPI.class); geoLiteApi = injector.getSingleton(GeoLiteAPI.class);
// Trigger construction of API classes; they will keep track of the singleton // Trigger construction of API classes; they will keep track of the singleton
@ -290,7 +292,9 @@ public class AuthMe extends JavaPlugin {
} }
} }
// Stop/unload the server/plugin as defined in the configuration /**
* Stops the server or disables the plugin, as defined in the configuration.
*/
public void stopOrUnload() { public void stopOrUnload() {
if (settings == null || settings.getProperty(SecuritySettings.STOP_SERVER_ON_PROBLEM)) { if (settings == null || settings.getProperty(SecuritySettings.STOP_SERVER_ON_PROBLEM)) {
ConsoleLogger.warning("THE SERVER IS GOING TO SHUT DOWN AS DEFINED IN THE CONFIGURATION!"); ConsoleLogger.warning("THE SERVER IS GOING TO SHUT DOWN AS DEFINED IN THE CONFIGURATION!");
@ -386,19 +390,4 @@ public class AuthMe extends JavaPlugin {
// Handle the command // Handle the command
return commandHandler.processCommand(sender, commandLabel, args); return commandHandler.processCommand(sender, commandLabel, args);
} }
// -------------
// Service getters (deprecated)
// Use @Inject fields instead
// -------------
/**
* @return process manager
*
* @deprecated should be used in API classes only (temporarily)
*/
@Deprecated
public Management getManagement() {
return management;
}
} }

View File

@ -14,6 +14,7 @@ import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.permission.PlayerStatePermission; import fr.xephi.authme.permission.PlayerStatePermission;
import fr.xephi.authme.process.AsynchronousProcess; import fr.xephi.authme.process.AsynchronousProcess;
import fr.xephi.authme.process.ProcessService; import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.process.login.AsynchronousLogin;
import fr.xephi.authme.settings.properties.HooksSettings; 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.RegistrationSettings; import fr.xephi.authme.settings.properties.RegistrationSettings;
@ -33,7 +34,9 @@ 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.util.BukkitService.TICKS_PER_SECOND;
/**
* Asynchronous process for when a player joins.
*/
public class AsynchronousJoin implements AsynchronousProcess { public class AsynchronousJoin implements AsynchronousProcess {
private static final boolean DISABLE_COLLISIONS = MethodUtils private static final boolean DISABLE_COLLISIONS = MethodUtils
@ -66,6 +69,9 @@ public class AsynchronousJoin implements AsynchronousProcess {
@Inject @Inject
private PlayerDataTaskManager playerDataTaskManager; private PlayerDataTaskManager playerDataTaskManager;
@Inject
private AsynchronousLogin asynchronousLogin;
AsynchronousJoin() { AsynchronousJoin() {
} }
@ -138,7 +144,12 @@ public class AsynchronousJoin implements AsynchronousProcess {
playerCache.removePlayer(name); playerCache.removePlayer(name);
if (auth != null && auth.getIp().equals(ip)) { if (auth != null && auth.getIp().equals(ip)) {
service.send(player, MessageKey.SESSION_RECONNECTION); service.send(player, MessageKey.SESSION_RECONNECTION);
plugin.getManagement().performLogin(player, "dontneed", true); bukkitService.runTaskAsynchronously(new Runnable() {
@Override
public void run() {
asynchronousLogin.login(player, "dontneed", true);
}
});
return; return;
} else if (service.getProperty(PluginSettings.SESSIONS_EXPIRE_ON_IP_CHANGE)) { } else if (service.getProperty(PluginSettings.SESSIONS_EXPIRE_ON_IP_CHANGE)) {
service.send(player, MessageKey.SESSION_EXPIRED); service.send(player, MessageKey.SESSION_EXPIRED);

View File

@ -1,6 +1,5 @@
package fr.xephi.authme.process.register; package fr.xephi.authme.process.register;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
@ -10,6 +9,7 @@ import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.process.AsynchronousProcess; import fr.xephi.authme.process.AsynchronousProcess;
import fr.xephi.authme.process.ProcessService; import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.process.SyncProcessManager; import fr.xephi.authme.process.SyncProcessManager;
import fr.xephi.authme.process.login.AsynchronousLogin;
import fr.xephi.authme.security.HashAlgorithm; import fr.xephi.authme.security.HashAlgorithm;
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;
@ -18,6 +18,7 @@ import fr.xephi.authme.settings.properties.EmailSettings;
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.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.util.ValidationService;
@ -30,11 +31,11 @@ import java.util.List;
import static fr.xephi.authme.permission.PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS; import static fr.xephi.authme.permission.PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS;
/**
* Asynchronous processing of a request for registration.
*/
public class AsyncRegister implements AsynchronousProcess { public class AsyncRegister implements AsynchronousProcess {
@Inject
private AuthMe plugin;
@Inject @Inject
private DataSource database; private DataSource database;
@ -59,6 +60,13 @@ public class AsyncRegister implements AsynchronousProcess {
@Inject @Inject
private SendMailSSL sendMailSsl; private SendMailSSL sendMailSsl;
@Inject
private AsynchronousLogin asynchronousLogin;
@Inject
private BukkitService bukkitService;
AsyncRegister() { } AsyncRegister() { }
private boolean preRegisterCheck(Player player, String password) { private boolean preRegisterCheck(Player player, String password) {
@ -145,7 +153,7 @@ public class AsyncRegister implements AsynchronousProcess {
syncProcessManager.processSyncEmailRegister(player); syncProcessManager.processSyncEmailRegister(player);
} }
private void passwordRegister(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 = Utils.getPlayerIp(player);
final HashedPassword hashedPassword = passwordSecurity.computeHash(password, name); final HashedPassword hashedPassword = passwordSecurity.computeHash(password, name);
@ -163,7 +171,12 @@ public class AsyncRegister implements AsynchronousProcess {
} }
if (!service.getProperty(RegistrationSettings.FORCE_LOGIN_AFTER_REGISTER) && autoLogin) { if (!service.getProperty(RegistrationSettings.FORCE_LOGIN_AFTER_REGISTER) && autoLogin) {
plugin.getManagement().performLogin(player, "dontneed", true); bukkitService.runTaskAsynchronously(new Runnable(){
@Override
public void run() {
asynchronousLogin.login(player, "dontneed", true);
}
});
} }
syncProcessManager.processSyncPasswordRegister(player); syncProcessManager.processSyncPasswordRegister(player);