- Remove unnecessary @Inject on field.

- Teleport player to spawn immediately on PlayerLoginEvent.
- Only save authenticated player's location on quit.
- Fix player's last location get reset if fail to login.
This commit is contained in:
DNx5
2016-06-29 20:25:01 +07:00
parent 609b148157
commit 22a4ef93bf
7 changed files with 88 additions and 62 deletions
@@ -22,7 +22,6 @@ import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.task.LimboPlayerTaskManager;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.TeleportationService;
import fr.xephi.authme.util.Utils;
import org.apache.commons.lang.reflect.MethodUtils;
import org.bukkit.GameMode;
@@ -63,9 +62,6 @@ public class AsynchronousJoin implements AsynchronousProcess {
@Inject
private PluginHooks pluginHooks;
@Inject
private TeleportationService teleportationService;
@Inject
private BukkitService bukkitService;
@@ -75,7 +71,8 @@ public class AsynchronousJoin implements AsynchronousProcess {
@Inject
private LimboPlayerTaskManager limboPlayerTaskManager;
AsynchronousJoin() { }
AsynchronousJoin() {
}
public void processJoin(final Player player) {
@@ -122,12 +119,12 @@ public class AsynchronousJoin implements AsynchronousProcess {
return;
}
limboCache.updateLimboPlayer(player);
final boolean isAuthAvailable = database.isAuthAvailable(name);
if (isAuthAvailable) {
service.setGroup(player, AuthGroupType.NOT_LOGGED_IN);
teleportationService.teleportOnJoin(player);
limboCache.updateLimboPlayer(player);
// Protect inventory
if (service.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) {
@@ -166,13 +163,6 @@ public class AsynchronousJoin implements AsynchronousProcess {
if (!service.getProperty(RegistrationSettings.FORCE)) {
return;
}
teleportationService.teleportOnJoin(player);
}
// The user is not logged in
if (!limboCache.hasLimboPlayer(name)) {
limboCache.addLimboPlayer(player);
}
final int registrationTimeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
@@ -211,11 +201,12 @@ public class AsynchronousJoin implements AsynchronousProcess {
/**
* Returns whether the name is restricted based on the restriction settings.
*
* @param name The name to check
* @param ip The IP address of the player
* @param name The name to check
* @param ip The IP address of the player
* @param domain The hostname of the IP address
*
* @return True if the name is restricted (IP/domain is not allowed for the given name),
* false if the restrictions are met or if the name has no restrictions to it
* false if the restrictions are met or if the name has no restrictions to it
*/
private boolean isNameRestricted(String name, String ip, String domain) {
if (!service.getProperty(RestrictionSettings.ENABLE_RESTRICTED_USERS)) {
@@ -242,7 +233,8 @@ public class AsynchronousJoin implements AsynchronousProcess {
* settings and permissions). If this is the case, the player is kicked.
*
* @param player the player to verify
* @param ip the ip address of the player
* @param ip the ip address of the player
*
* @return true if the verification is OK (no infraction), false if player has been kicked
*/
private boolean validatePlayerCountForIp(final Player player, String ip) {
@@ -4,12 +4,12 @@ import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.SessionManager;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.cache.limbo.LimboCache;
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.process.SyncProcessManager;
import fr.xephi.authme.settings.SpawnLoader;
import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.util.Utils;
@@ -35,15 +35,15 @@ public class AsynchronousQuit implements AsynchronousProcess {
@Inject
private PlayerCache playerCache;
@Inject
private LimboCache limboCache;
@Inject
private SyncProcessManager syncProcessManager;
@Inject
private SessionManager sessionManager;
@Inject
private SpawnLoader spawnLoader;
AsynchronousQuit() {
}
@@ -55,10 +55,9 @@ public class AsynchronousQuit implements AsynchronousProcess {
final String name = player.getName().toLowerCase();
String ip = Utils.getPlayerIp(player);
if (playerCache.isAuthenticated(name)) {
if (service.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)) {
Location loc = player.getLocation();
Location loc = player.isDead() ? spawnLoader.getSpawnLocation(player) : player.getLocation();
PlayerAuth auth = PlayerAuth.builder()
.name(name).location(loc)
.realName(player.getName()).build();
@@ -1,8 +1,12 @@
package fr.xephi.authme.process.quit;
import fr.xephi.authme.cache.backup.JsonCache;
import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.cache.limbo.LimboPlayer;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.process.SynchronousProcess;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.util.StringUtils;
import fr.xephi.authme.util.Utils;
import org.bukkit.entity.Player;
@@ -12,20 +16,43 @@ import javax.inject.Inject;
public class ProcessSyncronousPlayerQuit implements SynchronousProcess {
@Inject
private JsonCache jsonCache;
@Inject
private DataSource database;
@Inject
private ProcessService service;
@Inject
private LimboCache limboCache;
public void processSyncQuit(Player player) {
LimboPlayer limbo = limboCache.getLimboPlayer(player.getName().toLowerCase());
if (limbo != null) {
if (!StringUtils.isEmpty(limbo.getGroup())) {
Utils.addNormal(player, limbo.getGroup());
if (limbo != null) { // it mean player is not authenticated
// Only delete if we don't need player's last location
if (service.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)) {
limboCache.removeLimboPlayer(player);
} else {
// Restore data if its about to delete LimboPlayer
if (!StringUtils.isEmpty(limbo.getGroup())) {
Utils.addNormal(player, limbo.getGroup());
}
player.setOp(limbo.isOperator());
player.setAllowFlight(limbo.isCanFly());
player.setWalkSpeed(limbo.getWalkSpeed());
limboCache.deleteLimboPlayer(player);
}
} else {
// Write player's location, so we could retrieve it later on player next join
if (service.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)) {
if (!jsonCache.doesCacheExist(player)) {
jsonCache.writeCache(player);
}
}
player.setOp(limbo.isOperator());
player.setAllowFlight(limbo.isCanFly());
player.setWalkSpeed(limbo.getWalkSpeed());
limboCache.deleteLimboPlayer(player);
}
player.leaveVehicle();
}
}