mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-03 09:10:01 +01:00
Remove scheduler methods from the ProcessService
@ljacqu it's ok now? ;)
This commit is contained in:
parent
5007ca45f0
commit
55cc882002
@ -23,14 +23,15 @@ public class ProcessService {
|
||||
|
||||
@Inject
|
||||
private NewSetting settings;
|
||||
|
||||
@Inject
|
||||
private Messages messages;
|
||||
|
||||
@Inject
|
||||
private AuthMe plugin;
|
||||
|
||||
@Inject
|
||||
private ValidationService validationService;
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
/**
|
||||
* Retrieve a property's value.
|
||||
@ -93,37 +94,6 @@ public class ProcessService {
|
||||
return messages.retrieveSingle(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a task.
|
||||
*
|
||||
* @param task the task to run
|
||||
* @return the assigned task id
|
||||
*/
|
||||
public BukkitTask runTask(Runnable task) {
|
||||
return plugin.getServer().getScheduler().runTask(plugin, task);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a task at a later time.
|
||||
*
|
||||
* @param task the task to run
|
||||
* @param delay the delay before running the task
|
||||
* @return the assigned task id
|
||||
*/
|
||||
public BukkitTask runTaskLater(Runnable task, long delay) {
|
||||
return plugin.getServer().getScheduler().runTaskLater(plugin, task, delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule a synchronous delayed task.
|
||||
*
|
||||
* @param task the task to schedule
|
||||
* @return the task id
|
||||
*/
|
||||
public int scheduleSyncDelayedTask(Runnable task) {
|
||||
return plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, task);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit an event.
|
||||
*
|
||||
@ -161,14 +131,6 @@ public class ProcessService {
|
||||
return validationService.isEmailFreeForRegistration(email, sender);
|
||||
}
|
||||
|
||||
public Collection<? extends Player> getOnlinePlayers() {
|
||||
return bukkitService.getOnlinePlayers();
|
||||
}
|
||||
|
||||
public BukkitService getBukkitService() {
|
||||
return bukkitService;
|
||||
}
|
||||
|
||||
public boolean hasPermission(Player player, PermissionNode node) {
|
||||
return plugin.getPermissionsManager().hasPermission(player, node);
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import fr.xephi.authme.task.MessageTask;
|
||||
import fr.xephi.authme.task.TimeoutTask;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import fr.xephi.authme.util.Utils.GroupType;
|
||||
import org.apache.commons.lang.reflect.MethodUtils;
|
||||
@ -65,6 +66,9 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
||||
@Inject
|
||||
private SpawnLoader spawnLoader;
|
||||
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
private static final boolean DISABLE_COLLISIONS = MethodUtils
|
||||
.getAccessibleMethod(LivingEntity.class, "setCollidable", new Class[]{}) != null;
|
||||
|
||||
@ -93,7 +97,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
||||
}
|
||||
|
||||
if (isNameRestricted(name, ip, player.getAddress().getHostName())) {
|
||||
service.scheduleSyncDelayedTask(new Runnable() {
|
||||
bukkitService.scheduleSyncDelayedTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
AuthMePlayerListener.causeByAuthMe.putIfAbsent(name, true);
|
||||
@ -112,7 +116,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
||||
&& !"localhost".equalsIgnoreCase(ip)
|
||||
&& hasJoinedIp(player.getName(), ip)) {
|
||||
|
||||
service.scheduleSyncDelayedTask(new Runnable() {
|
||||
bukkitService.scheduleSyncDelayedTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// TODO: Messages entry
|
||||
@ -129,7 +133,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
||||
if (isAuthAvailable) {
|
||||
if (!service.getProperty(RestrictionSettings.NO_TELEPORT)) {
|
||||
if (Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) {
|
||||
service.scheduleSyncDelayedTask(new Runnable() {
|
||||
bukkitService.scheduleSyncDelayedTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnLoc, playerCache.isAuthenticated(name));
|
||||
@ -183,7 +187,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
||||
|
||||
if (!Settings.noTeleport && !needFirstSpawn(player) && Settings.isTeleportToSpawnEnabled
|
||||
|| (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) {
|
||||
service.scheduleSyncDelayedTask(new Runnable() {
|
||||
bukkitService.scheduleSyncDelayedTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnLoc, playerCache.isAuthenticated(name));
|
||||
@ -204,7 +208,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
||||
|
||||
final int registrationTimeout = service.getProperty(RestrictionSettings.TIMEOUT) * 20;
|
||||
|
||||
service.scheduleSyncDelayedTask(new Runnable() {
|
||||
bukkitService.scheduleSyncDelayedTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
player.setOp(false);
|
||||
@ -228,7 +232,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
||||
|
||||
int msgInterval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
||||
if (registrationTimeout > 0) {
|
||||
BukkitTask id = service.runTaskLater(new TimeoutTask(plugin, name, player), registrationTimeout);
|
||||
BukkitTask id = bukkitService.runTaskLater(new TimeoutTask(plugin, name, player), registrationTimeout);
|
||||
LimboPlayer limboPlayer = limboCache.getLimboPlayer(name);
|
||||
if (limboPlayer != null) {
|
||||
limboPlayer.setTimeoutTask(id);
|
||||
@ -244,7 +248,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
||||
: MessageKey.REGISTER_MESSAGE;
|
||||
}
|
||||
if (msgInterval > 0 && limboCache.getLimboPlayer(name) != null) {
|
||||
BukkitTask msgTask = service.runTaskLater(new MessageTask(service.getBukkitService(), plugin.getMessages(),
|
||||
BukkitTask msgTask = bukkitService.runTaskLater(new MessageTask(bukkitService, plugin.getMessages(),
|
||||
name, msg, msgInterval), 20L);
|
||||
LimboPlayer limboPlayer = limboCache.getLimboPlayer(name);
|
||||
if (limboPlayer != null) {
|
||||
@ -267,7 +271,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
||||
if (!tpEvent.isCancelled()) {
|
||||
if (player.isOnline() && tpEvent.getTo() != null && tpEvent.getTo().getWorld() != null) {
|
||||
final Location fLoc = tpEvent.getTo();
|
||||
service.scheduleSyncDelayedTask(new Runnable() {
|
||||
bukkitService.scheduleSyncDelayedTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
player.teleport(fLoc);
|
||||
@ -285,7 +289,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
||||
return;
|
||||
if (!player.hasPlayedBefore())
|
||||
return;
|
||||
service.scheduleSyncDelayedTask(new Runnable() {
|
||||
bukkitService.scheduleSyncDelayedTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (spawnLoc.getWorld() == null) {
|
||||
@ -334,7 +338,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
||||
|
||||
private boolean hasJoinedIp(String name, String ip) {
|
||||
int count = 0;
|
||||
for (Player player : service.getOnlinePlayers()) {
|
||||
for (Player player : bukkitService.getOnlinePlayers()) {
|
||||
if (ip.equalsIgnoreCase(Utils.getPlayerIp(player))
|
||||
&& !player.getName().equalsIgnoreCase(name)) {
|
||||
count++;
|
||||
|
@ -24,6 +24,7 @@ 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.task.MessageTask;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -58,6 +59,9 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
||||
@Inject
|
||||
private SyncProcessManager syncProcessManager;
|
||||
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
|
||||
AsynchronousLogin() { }
|
||||
|
||||
@ -103,7 +107,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
||||
String[] msg = service.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)
|
||||
? service.retrieveMessage(MessageKey.REGISTER_EMAIL_MESSAGE)
|
||||
: service.retrieveMessage(MessageKey.REGISTER_MESSAGE);
|
||||
BukkitTask messageTask = service.runTask(new MessageTask(service.getBukkitService(),
|
||||
BukkitTask messageTask = bukkitService.runTask(new MessageTask(bukkitService,
|
||||
name, msg, service.getProperty(RegistrationSettings.MESSAGE_INTERVAL)));
|
||||
limboPlayer.setMessageTask(messageTask);
|
||||
}
|
||||
@ -207,7 +211,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
||||
ConsoleLogger.info(player.getName() + " used the wrong password");
|
||||
}
|
||||
if (service.getProperty(RestrictionSettings.KICK_ON_WRONG_PASSWORD)) {
|
||||
service.scheduleSyncDelayedTask(new Runnable() {
|
||||
bukkitService.scheduleSyncDelayedTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
player.kickPlayer(service.retrieveSingleMessage(MessageKey.WRONG_PASSWORD));
|
||||
@ -237,7 +241,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
||||
ConsoleLogger.info("The user " + player.getName() + " has " + auths.size() + " accounts:");
|
||||
ConsoleLogger.info(message);
|
||||
|
||||
for (Player onlinePlayer : service.getOnlinePlayers()) {
|
||||
for (Player onlinePlayer : bukkitService.getOnlinePlayers()) {
|
||||
if (onlinePlayer.getName().equalsIgnoreCase(player.getName())
|
||||
&& permissionsManager.hasPermission(onlinePlayer, PlayerPermission.SEE_OWN_ACCOUNTS)) {
|
||||
onlinePlayer.sendMessage("You own " + auths.size() + " accounts:");
|
||||
|
@ -18,6 +18,7 @@ import fr.xephi.authme.settings.Settings;
|
||||
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.Utils;
|
||||
import fr.xephi.authme.util.Utils.GroupType;
|
||||
import org.apache.commons.lang.reflect.MethodUtils;
|
||||
@ -47,6 +48,9 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
|
||||
@Inject
|
||||
private DataSource dataSource;
|
||||
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Inject
|
||||
// TODO ljacqu 20160520: Need to check whether we want to inject PluginManager, or some intermediate service
|
||||
private PluginManager pluginManager;
|
||||
@ -151,7 +155,7 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
|
||||
String jm = AuthMePlayerListener.joinMessage.get(name);
|
||||
if (jm != null) {
|
||||
if (!jm.isEmpty()) {
|
||||
for (Player p : service.getOnlinePlayers()) {
|
||||
for (Player p : bukkitService.getOnlinePlayers()) {
|
||||
if (p.isOnline()) {
|
||||
p.sendMessage(jm);
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.process.AsynchronousProcess;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.process.SyncProcessManager;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import fr.xephi.authme.util.Utils.GroupType;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -31,6 +32,9 @@ public class AsynchronousLogout implements AsynchronousProcess {
|
||||
@Inject
|
||||
private SyncProcessManager syncProcessManager;
|
||||
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
AsynchronousLogout() { }
|
||||
|
||||
public void logout(final Player player) {
|
||||
@ -49,7 +53,7 @@ public class AsynchronousLogout implements AsynchronousProcess {
|
||||
|
||||
playerCache.removePlayer(name);
|
||||
database.setUnlogged(name);
|
||||
service.scheduleSyncDelayedTask(new Runnable() {
|
||||
bukkitService.scheduleSyncDelayedTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Utils.teleportToSpawn(player);
|
||||
|
@ -14,6 +14,8 @@ import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.task.MessageTask;
|
||||
import fr.xephi.authme.task.TimeoutTask;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
@ -36,6 +38,9 @@ public class ProcessSynchronousPlayerLogout implements SynchronousProcess {
|
||||
@Inject
|
||||
private LimboCache limboCache;
|
||||
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
ProcessSynchronousPlayerLogout() { }
|
||||
|
||||
private void sendBungeeMessage(Player player) {
|
||||
@ -66,10 +71,10 @@ public class ProcessSynchronousPlayerLogout implements SynchronousProcess {
|
||||
int timeOut = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
||||
int interval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
||||
if (timeOut != 0) {
|
||||
BukkitTask id = service.runTaskLater(new TimeoutTask(plugin, name, player), timeOut);
|
||||
BukkitTask id = bukkitService.runTaskLater(new TimeoutTask(plugin, name, player), timeOut);
|
||||
limboCache.getLimboPlayer(name).setTimeoutTask(id);
|
||||
}
|
||||
BukkitTask msgT = service.runTask(new MessageTask(service.getBukkitService(), plugin.getMessages(),
|
||||
BukkitTask msgT = bukkitService.runTask(new MessageTask(bukkitService, plugin.getMessages(),
|
||||
name, MessageKey.LOGIN_MESSAGE, interval));
|
||||
limboCache.getLimboPlayer(name).setMessageTask(msgT);
|
||||
if (player.isInsideVehicle() && player.getVehicle() != null) {
|
||||
|
@ -12,6 +12,7 @@ import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import fr.xephi.authme.task.MessageTask;
|
||||
import fr.xephi.authme.task.TimeoutTask;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
@ -29,6 +30,9 @@ public class ProcessSyncEmailRegister implements SynchronousProcess {
|
||||
@Inject
|
||||
private LimboCache limboCache;
|
||||
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
public ProcessSyncEmailRegister() { }
|
||||
|
||||
public void processEmailRegister(Player player) {
|
||||
@ -43,11 +47,11 @@ public class ProcessSyncEmailRegister implements SynchronousProcess {
|
||||
|
||||
if (limbo != null) {
|
||||
if (time != 0) {
|
||||
BukkitTask id = service.runTaskLater(new TimeoutTask(service.getAuthMe(), name, player), time);
|
||||
BukkitTask id = bukkitService.runTaskLater(new TimeoutTask(service.getAuthMe(), name, player), time);
|
||||
limbo.setTimeoutTask(id);
|
||||
}
|
||||
BukkitTask messageTask = service.runTask(new MessageTask(
|
||||
service.getBukkitService(), name, service.retrieveMessage(MessageKey.LOGIN_MESSAGE), msgInterval));
|
||||
BukkitTask messageTask = bukkitService.runTask(new MessageTask(
|
||||
bukkitService, name, service.retrieveMessage(MessageKey.LOGIN_MESSAGE), msgInterval));
|
||||
limbo.setMessageTask(messageTask);
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import fr.xephi.authme.task.MessageTask;
|
||||
import fr.xephi.authme.task.TimeoutTask;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -40,6 +41,9 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
|
||||
@Inject
|
||||
private ProcessService service;
|
||||
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
ProcessSyncPasswordRegister() { }
|
||||
|
||||
private void sendBungeeMessage(Player player) {
|
||||
@ -75,10 +79,10 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
|
||||
int interval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
||||
BukkitTask task;
|
||||
if (delay != 0) {
|
||||
task = service.runTaskLater(new TimeoutTask(service.getAuthMe(), name, player), delay);
|
||||
task = bukkitService.runTaskLater(new TimeoutTask(service.getAuthMe(), name, player), delay);
|
||||
cache.getLimboPlayer(name).setTimeoutTask(task);
|
||||
}
|
||||
task = service.runTask(new MessageTask(service.getBukkitService(), plugin.getMessages(),
|
||||
task = bukkitService.runTask(new MessageTask(bukkitService, plugin.getMessages(),
|
||||
name, MessageKey.LOGIN_MESSAGE, interval));
|
||||
cache.getLimboPlayer(name).setMessageTask(task);
|
||||
if (player.isInsideVehicle() && player.getVehicle() != null) {
|
||||
|
@ -16,6 +16,7 @@ import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.task.MessageTask;
|
||||
import fr.xephi.authme.task.TimeoutTask;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import fr.xephi.authme.util.Utils.GroupType;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -47,6 +48,9 @@ public class AsynchronousUnregister implements AsynchronousProcess {
|
||||
@Inject
|
||||
private LimboCache limboCache;
|
||||
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
AsynchronousUnregister() { }
|
||||
|
||||
public void unregister(Player player, String password, boolean force) {
|
||||
@ -69,10 +73,10 @@ public class AsynchronousUnregister implements AsynchronousProcess {
|
||||
LimboPlayer limboPlayer = limboCache.getLimboPlayer(name);
|
||||
int interval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
||||
if (timeOut != 0) {
|
||||
BukkitTask id = service.runTaskLater(new TimeoutTask(plugin, name, player), timeOut);
|
||||
BukkitTask id = bukkitService.runTaskLater(new TimeoutTask(plugin, name, player), timeOut);
|
||||
limboPlayer.setTimeoutTask(id);
|
||||
}
|
||||
limboPlayer.setMessageTask(service.runTask(new MessageTask(service.getBukkitService(),
|
||||
limboPlayer.setMessageTask(bukkitService.runTask(new MessageTask(bukkitService,
|
||||
plugin.getMessages(), name, MessageKey.REGISTER_MESSAGE, interval)));
|
||||
service.send(player, MessageKey.UNREGISTERED_SUCCESS);
|
||||
ConsoleLogger.info(player.getDisplayName() + " unregistered himself");
|
||||
|
Loading…
Reference in New Issue
Block a user