#707 Convert async processes as services
(work in progress - rough, untested changes)
This commit is contained in:
@@ -1,9 +1,5 @@
|
||||
package fr.xephi.authme.process;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.hooks.PluginHooks;
|
||||
import fr.xephi.authme.process.email.AsyncAddEmail;
|
||||
import fr.xephi.authme.process.email.AsyncChangeEmail;
|
||||
import fr.xephi.authme.process.join.AsynchronousJoin;
|
||||
@@ -12,63 +8,110 @@ 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 org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
public class Management {
|
||||
|
||||
@Inject
|
||||
private AuthMe plugin;
|
||||
private BukkitService bukkitService;
|
||||
|
||||
// Processes
|
||||
@Inject
|
||||
private BukkitScheduler sched;
|
||||
private AsyncAddEmail asyncAddEmail;
|
||||
@Inject
|
||||
private ProcessService processService;
|
||||
private AsyncChangeEmail asyncChangeEmail;
|
||||
@Inject
|
||||
private DataSource dataSource;
|
||||
private AsynchronousLogout asynchronousLogout;
|
||||
@Inject
|
||||
private PlayerCache playerCache;
|
||||
private AsynchronousQuit asynchronousQuit;
|
||||
@Inject
|
||||
private PluginHooks pluginHooks;
|
||||
private AsynchronousJoin asynchronousJoin;
|
||||
@Inject
|
||||
private AsyncRegister asyncRegister;
|
||||
@Inject
|
||||
private AsynchronousLogin asynchronousLogin;
|
||||
@Inject
|
||||
private AsynchronousUnregister asynchronousUnregister;
|
||||
|
||||
Management() { }
|
||||
|
||||
public void performLogin(final Player player, final String password, final boolean forceLogin) {
|
||||
runTask(new AsynchronousLogin(player, password, forceLogin, plugin, dataSource, processService));
|
||||
runTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
asynchronousLogin.login(player, password, forceLogin);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void performLogout(final Player player) {
|
||||
runTask(new AsynchronousLogout(player, plugin, dataSource, processService));
|
||||
runTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
asynchronousLogout.logout(player);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void performRegister(final Player player, final String password, final String email, final boolean autoLogin) {
|
||||
runTask(new AsyncRegister(player, password, email, plugin, dataSource, playerCache, processService, autoLogin));
|
||||
runTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
asyncRegister.register(player, password, email, autoLogin);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void performUnregister(final Player player, final String password, final boolean force) {
|
||||
runTask(new AsynchronousUnregister(player, password, force, plugin, processService));
|
||||
public void performUnregister(final Player player, final String password, final boolean isForce) {
|
||||
runTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
asynchronousUnregister.unregister(player, password, isForce);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void performJoin(final Player player) {
|
||||
runTask(new AsynchronousJoin(player, plugin, dataSource, playerCache, pluginHooks, processService));
|
||||
runTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
asynchronousJoin.processJoin(player);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void performQuit(final Player player, final boolean isKick) {
|
||||
runTask(new AsynchronousQuit(player, plugin, dataSource, isKick, processService));
|
||||
runTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
asynchronousQuit.processQuit(player, isKick);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void performAddEmail(final Player player, final String newEmail) {
|
||||
runTask(new AsyncAddEmail(player, newEmail, dataSource, playerCache, processService));
|
||||
runTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
asyncAddEmail.addEmail(player, newEmail);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void performChangeEmail(final Player player, final String oldEmail, final String newEmail) {
|
||||
runTask(new AsyncChangeEmail(player, oldEmail, newEmail, dataSource, playerCache, processService));
|
||||
runTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
asyncChangeEmail.changeEmail(player, oldEmail, newEmail);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void runTask(Process process) {
|
||||
sched.runTaskAsynchronously(plugin, process);
|
||||
private void runTask(Runnable runnable) {
|
||||
bukkitService.runTaskAsynchronously(runnable);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user