Various code householding
- Adjust javadoc - Remove unused PlayerAuth constructor - Replace legacy Settings with NewSetting calls - Add process service to all (a)sync processes - Change IP manager to only cache the calls to the VeryGames API
This commit is contained in:
@@ -6,22 +6,22 @@ import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.process.Process;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import fr.xephi.authme.util.Utils.GroupType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class AsynchronousLogout {
|
||||
public class AsynchronousLogout implements Process {
|
||||
|
||||
protected final Player player;
|
||||
protected final String name;
|
||||
protected final AuthMe plugin;
|
||||
protected final DataSource database;
|
||||
protected boolean canLogout = true;
|
||||
private final Messages m;
|
||||
private final Player player;
|
||||
private final String name;
|
||||
private final AuthMe plugin;
|
||||
private final DataSource database;
|
||||
private boolean canLogout = true;
|
||||
private final ProcessService service;
|
||||
|
||||
/**
|
||||
* Constructor for AsynchronousLogout.
|
||||
@@ -29,29 +29,30 @@ public class AsynchronousLogout {
|
||||
* @param player Player
|
||||
* @param plugin AuthMe
|
||||
* @param database DataSource
|
||||
* @param service The process service
|
||||
*/
|
||||
public AsynchronousLogout(Player player, AuthMe plugin, DataSource database) {
|
||||
this.m = plugin.getMessages();
|
||||
public AsynchronousLogout(Player player, AuthMe plugin, DataSource database, ProcessService service) {
|
||||
this.player = player;
|
||||
this.plugin = plugin;
|
||||
this.database = database;
|
||||
this.name = player.getName().toLowerCase();
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
private void preLogout() {
|
||||
if (!PlayerCache.getInstance().isAuthenticated(name)) {
|
||||
m.send(player, MessageKey.NOT_LOGGED_IN);
|
||||
service.send(player, MessageKey.NOT_LOGGED_IN);
|
||||
canLogout = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void process() {
|
||||
@Override
|
||||
public void run() {
|
||||
preLogout();
|
||||
if (!canLogout) {
|
||||
return;
|
||||
}
|
||||
final Player p = player;
|
||||
BukkitScheduler scheduler = p.getServer().getScheduler();
|
||||
PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
|
||||
database.updateSession(auth);
|
||||
auth.setQuitLocX(p.getLocation().getX());
|
||||
@@ -62,7 +63,7 @@ public class AsynchronousLogout {
|
||||
|
||||
PlayerCache.getInstance().removePlayer(name);
|
||||
database.setUnlogged(name);
|
||||
scheduler.scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
service.scheduleSyncDelayedTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Utils.teleportToSpawn(p);
|
||||
@@ -73,6 +74,6 @@ public class AsynchronousLogout {
|
||||
}
|
||||
LimboCache.getInstance().addLimboPlayer(player);
|
||||
Utils.setGroup(player, GroupType.NOTLOGGEDIN);
|
||||
scheduler.scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerLogout(p, plugin));
|
||||
service.scheduleSyncDelayedTask(new ProcessSynchronousPlayerLogout(p, plugin, service));
|
||||
}
|
||||
}
|
||||
|
||||
+19
-22
@@ -7,37 +7,40 @@ import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
import fr.xephi.authme.events.LogoutEvent;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.process.Process;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
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 org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class ProcessSyncronousPlayerLogout implements Runnable {
|
||||
public class ProcessSynchronousPlayerLogout implements Process {
|
||||
|
||||
protected final Player player;
|
||||
protected final AuthMe plugin;
|
||||
protected final String name;
|
||||
private final Messages m;
|
||||
private final Player player;
|
||||
private final AuthMe plugin;
|
||||
private final String name;
|
||||
private final ProcessService service;
|
||||
|
||||
/**
|
||||
* Constructor for ProcessSyncronousPlayerLogout.
|
||||
* Constructor for ProcessSynchronousPlayerLogout.
|
||||
*
|
||||
* @param player Player
|
||||
* @param plugin AuthMe
|
||||
* @param service The process service
|
||||
*/
|
||||
public ProcessSyncronousPlayerLogout(Player player, AuthMe plugin) {
|
||||
this.m = plugin.getMessages();
|
||||
public ProcessSynchronousPlayerLogout(Player player, AuthMe plugin, ProcessService service) {
|
||||
this.player = player;
|
||||
this.plugin = plugin;
|
||||
this.name = player.getName().toLowerCase();
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
protected void sendBungeeMessage() {
|
||||
@@ -56,11 +59,6 @@ public class ProcessSyncronousPlayerLogout implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method run.
|
||||
*
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
if (plugin.sessions.containsKey(name)) {
|
||||
@@ -70,19 +68,18 @@ public class ProcessSyncronousPlayerLogout implements Runnable {
|
||||
if (Settings.protectInventoryBeforeLogInEnabled) {
|
||||
plugin.inventoryProtector.sendBlankInventoryPacket(player);
|
||||
}
|
||||
int timeOut = Settings.getRegistrationTimeout * 20;
|
||||
int interval = Settings.getWarnMessageInterval;
|
||||
BukkitScheduler sched = player.getServer().getScheduler();
|
||||
int timeOut = service.getProperty(RestrictionSettings.TIMEOUT) * 20;
|
||||
int interval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
||||
if (timeOut != 0) {
|
||||
BukkitTask id = sched.runTaskLater(plugin, new TimeoutTask(plugin, name, player), timeOut);
|
||||
BukkitTask id = service.runTaskLater(new TimeoutTask(plugin, name, player), timeOut);
|
||||
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id);
|
||||
}
|
||||
BukkitTask msgT = sched.runTask(plugin, new MessageTask(plugin, name, MessageKey.LOGIN_MESSAGE, interval));
|
||||
BukkitTask msgT = service.runTask(new MessageTask(plugin, name, MessageKey.LOGIN_MESSAGE, interval));
|
||||
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT);
|
||||
if (player.isInsideVehicle() && player.getVehicle() != null) {
|
||||
player.getVehicle().eject();
|
||||
}
|
||||
if (Settings.applyBlindEffect) {
|
||||
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeOut, 2));
|
||||
}
|
||||
player.setOp(false);
|
||||
@@ -92,7 +89,7 @@ public class ProcessSyncronousPlayerLogout implements Runnable {
|
||||
if (Settings.bungee) {
|
||||
sendBungeeMessage();
|
||||
}
|
||||
m.send(player, MessageKey.LOGOUT_SUCCESS);
|
||||
service.send(player, MessageKey.LOGOUT_SUCCESS);
|
||||
ConsoleLogger.info(player.getName() + " logged out");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user