- Add restore method in LimboCache
* Apply it to process that have use of it - Fix fly & walk speed not get restored
This commit is contained in:
parent
deffcb3e2b
commit
140275f366
@ -7,7 +7,6 @@ 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.cache.backup.PlayerDataStorage;
|
import fr.xephi.authme.cache.backup.PlayerDataStorage;
|
||||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||||
import fr.xephi.authme.cache.limbo.PlayerData;
|
|
||||||
import fr.xephi.authme.command.CommandHandler;
|
import fr.xephi.authme.command.CommandHandler;
|
||||||
import fr.xephi.authme.datasource.CacheDataSource;
|
import fr.xephi.authme.datasource.CacheDataSource;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
@ -442,8 +441,8 @@ public class AuthMe extends JavaPlugin {
|
|||||||
//returns only the async takss
|
//returns only the async takss
|
||||||
for (BukkitWorker pendingTask : getServer().getScheduler().getActiveWorkers()) {
|
for (BukkitWorker pendingTask : getServer().getScheduler().getActiveWorkers()) {
|
||||||
if (pendingTask.getOwner().equals(AuthMe.this)
|
if (pendingTask.getOwner().equals(AuthMe.this)
|
||||||
//it's not a peridic task
|
//it's not a peridic task
|
||||||
&& !getServer().getScheduler().isQueued(pendingTask.getTaskId())) {
|
&& !getServer().getScheduler().isQueued(pendingTask.getTaskId())) {
|
||||||
pendingTasks.add(pendingTask.getTaskId());
|
pendingTasks.add(pendingTask.getTaskId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -466,7 +465,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Iterator<Integer> iterator = pendingTasks.iterator(); iterator.hasNext();) {
|
for (Iterator<Integer> iterator = pendingTasks.iterator(); iterator.hasNext(); ) {
|
||||||
int taskId = iterator.next();
|
int taskId = iterator.next();
|
||||||
if (!getServer().getScheduler().isCurrentlyRunning(taskId)) {
|
if (!getServer().getScheduler().isCurrentlyRunning(taskId)) {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
@ -565,19 +564,8 @@ public class AuthMe extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
String name = player.getName().toLowerCase();
|
String name = player.getName().toLowerCase();
|
||||||
if (limboCache.hasPlayerData(name)) {
|
if (limboCache.hasPlayerData(name)) {
|
||||||
PlayerData limbo = limboCache.getPlayerData(name);
|
limboCache.restoreData(player);
|
||||||
if (!newSettings.getProperty(RestrictionSettings.NO_TELEPORT)) {
|
limboCache.removeFromCache(player);
|
||||||
player.teleport(limbo.getLoc());
|
|
||||||
}
|
|
||||||
Utils.addNormal(player, limbo.getGroup());
|
|
||||||
player.setOp(limbo.isOperator());
|
|
||||||
player.setAllowFlight(limbo.isCanFly());
|
|
||||||
player.setWalkSpeed(limbo.getWalkSpeed());
|
|
||||||
if (newSettings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)) {
|
|
||||||
limboCache.removePlayerData(player);
|
|
||||||
} else {
|
|
||||||
limboCache.deletePlayerData(player);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (newSettings.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)) {
|
if (newSettings.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)) {
|
||||||
Location loc = spawnLoader.getPlayerLocationOrSpawn(player);
|
Location loc = spawnLoader.getPlayerLocationOrSpawn(player);
|
||||||
|
|||||||
@ -189,7 +189,7 @@ public class PlayerDataStorage {
|
|||||||
JsonObject obj = new JsonObject();
|
JsonObject obj = new JsonObject();
|
||||||
obj.addProperty("group", playerData.getGroup());
|
obj.addProperty("group", playerData.getGroup());
|
||||||
|
|
||||||
Location loc = playerData.getLoc();
|
Location loc = playerData.getLocation();
|
||||||
JsonObject obj2 = new JsonObject();
|
JsonObject obj2 = new JsonObject();
|
||||||
obj2.addProperty("world", loc.getWorld().getName());
|
obj2.addProperty("world", loc.getWorld().getName());
|
||||||
obj2.addProperty("x", loc.getX());
|
obj2.addProperty("x", loc.getX());
|
||||||
|
|||||||
@ -2,7 +2,11 @@ package fr.xephi.authme.cache.limbo;
|
|||||||
|
|
||||||
import fr.xephi.authme.cache.backup.PlayerDataStorage;
|
import fr.xephi.authme.cache.backup.PlayerDataStorage;
|
||||||
import fr.xephi.authme.permission.PermissionsManager;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
|
import fr.xephi.authme.settings.NewSetting;
|
||||||
import fr.xephi.authme.settings.SpawnLoader;
|
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.StringUtils;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -19,18 +23,21 @@ public class LimboCache {
|
|||||||
private final ConcurrentHashMap<String, PlayerData> cache = new ConcurrentHashMap<>();
|
private final ConcurrentHashMap<String, PlayerData> cache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private PlayerDataStorage playerDataStorage;
|
private PlayerDataStorage playerDataStorage;
|
||||||
|
private NewSetting settings;
|
||||||
private PermissionsManager permissionsManager;
|
private PermissionsManager permissionsManager;
|
||||||
private SpawnLoader spawnLoader;
|
private SpawnLoader spawnLoader;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
LimboCache(PermissionsManager permissionsManager, SpawnLoader spawnLoader, PlayerDataStorage playerDataStorage) {
|
LimboCache(NewSetting settings, PermissionsManager permissionsManager,
|
||||||
|
SpawnLoader spawnLoader, PlayerDataStorage playerDataStorage) {
|
||||||
|
this.settings = settings;
|
||||||
this.permissionsManager = permissionsManager;
|
this.permissionsManager = permissionsManager;
|
||||||
this.spawnLoader = spawnLoader;
|
this.spawnLoader = spawnLoader;
|
||||||
this.playerDataStorage = playerDataStorage;
|
this.playerDataStorage = playerDataStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a limbo player.
|
* Load player data if exist, otherwise current player's data will be stored.
|
||||||
*
|
*
|
||||||
* @param player Player instance to add.
|
* @param player Player instance to add.
|
||||||
*/
|
*/
|
||||||
@ -49,7 +56,7 @@ public class LimboCache {
|
|||||||
if (playerDataStorage.hasData(player)) {
|
if (playerDataStorage.hasData(player)) {
|
||||||
PlayerData cache = playerDataStorage.readData(player);
|
PlayerData cache = playerDataStorage.readData(player);
|
||||||
if (cache != null) {
|
if (cache != null) {
|
||||||
location = cache.getLoc();
|
location = cache.getLocation();
|
||||||
playerGroup = cache.getGroup();
|
playerGroup = cache.getGroup();
|
||||||
operator = cache.isOperator();
|
operator = cache.isOperator();
|
||||||
flyEnabled = cache.isCanFly();
|
flyEnabled = cache.isCanFly();
|
||||||
@ -64,21 +71,42 @@ public class LimboCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove PlayerData and delete cache.json from disk.
|
* Restore player's data to player if exist.
|
||||||
|
*
|
||||||
|
* @param player Player instance to restore
|
||||||
|
*/
|
||||||
|
public void restoreData(Player player) {
|
||||||
|
String lowerName = player.getName().toLowerCase();
|
||||||
|
if (cache.containsKey(lowerName)) {
|
||||||
|
PlayerData data = cache.get(lowerName);
|
||||||
|
player.setOp(data.isOperator());
|
||||||
|
player.setAllowFlight(data.isCanFly());
|
||||||
|
player.setWalkSpeed(data.getWalkSpeed());
|
||||||
|
player.setFlySpeed(data.getFlySpeed());
|
||||||
|
restoreGroup(player, data.getGroup());
|
||||||
|
if (!settings.getProperty(RestrictionSettings.NO_TELEPORT)) {
|
||||||
|
player.teleport(data.getLocation());
|
||||||
|
}
|
||||||
|
data.clearTasks();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove PlayerData from cache and disk.
|
||||||
*
|
*
|
||||||
* @param player Player player to remove.
|
* @param player Player player to remove.
|
||||||
*/
|
*/
|
||||||
public void deletePlayerData(Player player) {
|
public void deletePlayerData(Player player) {
|
||||||
removePlayerData(player);
|
removeFromCache(player);
|
||||||
playerDataStorage.removeData(player);
|
playerDataStorage.removeData(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove PlayerData from cache, without deleting cache.json file.
|
* Remove PlayerData from cache.
|
||||||
*
|
*
|
||||||
* @param player Player player to remove.
|
* @param player player to remove.
|
||||||
*/
|
*/
|
||||||
public void removePlayerData(Player player) {
|
public void removeFromCache(Player player) {
|
||||||
String name = player.getName().toLowerCase();
|
String name = player.getName().toLowerCase();
|
||||||
PlayerData cachedPlayer = cache.remove(name);
|
PlayerData cachedPlayer = cache.remove(name);
|
||||||
if (cachedPlayer != null) {
|
if (cachedPlayer != null) {
|
||||||
@ -117,7 +145,15 @@ public class LimboCache {
|
|||||||
*/
|
*/
|
||||||
public void updatePlayerData(Player player) {
|
public void updatePlayerData(Player player) {
|
||||||
checkNotNull(player);
|
checkNotNull(player);
|
||||||
removePlayerData(player);
|
removeFromCache(player);
|
||||||
addPlayerData(player);
|
addPlayerData(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void restoreGroup(Player player, String group) {
|
||||||
|
if (!settings.getProperty(PluginSettings.ENABLE_PERMISSION_CHECK)
|
||||||
|
|| !permissionsManager.hasGroupSupport() || StringUtils.isEmpty(group)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
permissionsManager.setGroup(player, group);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,7 +33,7 @@ public class PlayerData {
|
|||||||
*
|
*
|
||||||
* @return The player's location
|
* @return The player's location
|
||||||
*/
|
*/
|
||||||
public Location getLoc() {
|
public Location getLocation() {
|
||||||
return loc;
|
return loc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -66,14 +66,14 @@ public class AuthGroupHandler {
|
|||||||
return permissionsManager.addGroup(player, settings.getProperty(SecuritySettings.UNLOGGEDIN_GROUP));
|
return permissionsManager.addGroup(player, settings.getProperty(SecuritySettings.UNLOGGEDIN_GROUP));
|
||||||
|
|
||||||
case LOGGED_IN:
|
case LOGGED_IN:
|
||||||
// Get the limbo player data
|
// Get the player data
|
||||||
PlayerData limbo = limboCache.getPlayerData(player.getName().toLowerCase());
|
PlayerData data = limboCache.getPlayerData(player.getName().toLowerCase());
|
||||||
if (limbo == null) {
|
if (data == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the players group
|
// Get the players group
|
||||||
String realGroup = limbo.getGroup();
|
String realGroup = data.getGroup();
|
||||||
|
|
||||||
// Remove the other group types groups, set the real group
|
// Remove the other group types groups, set the real group
|
||||||
permissionsManager.removeGroups(player,
|
permissionsManager.removeGroups(player,
|
||||||
|
|||||||
@ -115,11 +115,11 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
limboCache.updatePlayerData(player);
|
|
||||||
|
|
||||||
final boolean isAuthAvailable = database.isAuthAvailable(name);
|
final boolean isAuthAvailable = database.isAuthAvailable(name);
|
||||||
|
|
||||||
if (isAuthAvailable) {
|
if (isAuthAvailable) {
|
||||||
|
limboCache.addPlayerData(player);
|
||||||
service.setGroup(player, AuthGroupType.NOT_LOGGED_IN);
|
service.setGroup(player, AuthGroupType.NOT_LOGGED_IN);
|
||||||
|
|
||||||
// Protect inventory
|
// Protect inventory
|
||||||
@ -150,7 +150,9 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Not Registered
|
// Not Registered. Delete old data, load default one.
|
||||||
|
limboCache.deletePlayerData(player);
|
||||||
|
limboCache.addPlayerData(player);
|
||||||
|
|
||||||
// Groups logic
|
// Groups logic
|
||||||
service.setGroup(player, AuthGroupType.UNREGISTERED);
|
service.setGroup(player, AuthGroupType.UNREGISTERED);
|
||||||
|
|||||||
@ -3,20 +3,16 @@ package fr.xephi.authme.process.login;
|
|||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
|
||||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||||
import fr.xephi.authme.cache.limbo.PlayerData;
|
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.events.LoginEvent;
|
import fr.xephi.authme.events.LoginEvent;
|
||||||
import fr.xephi.authme.events.RestoreInventoryEvent;
|
import fr.xephi.authme.events.RestoreInventoryEvent;
|
||||||
import fr.xephi.authme.listener.AuthMePlayerListener;
|
import fr.xephi.authme.listener.AuthMePlayerListener;
|
||||||
import fr.xephi.authme.listener.protocollib.ProtocolLibService;
|
import fr.xephi.authme.listener.protocollib.ProtocolLibService;
|
||||||
import fr.xephi.authme.permission.AuthGroupType;
|
|
||||||
import fr.xephi.authme.process.ProcessService;
|
import fr.xephi.authme.process.ProcessService;
|
||||||
import fr.xephi.authme.process.SynchronousProcess;
|
import fr.xephi.authme.process.SynchronousProcess;
|
||||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||||
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.util.BukkitService;
|
import fr.xephi.authme.util.BukkitService;
|
||||||
import fr.xephi.authme.util.TeleportationService;
|
import fr.xephi.authme.util.TeleportationService;
|
||||||
import org.apache.commons.lang.reflect.MethodUtils;
|
import org.apache.commons.lang.reflect.MethodUtils;
|
||||||
@ -60,7 +56,8 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
|
|||||||
@Inject
|
@Inject
|
||||||
private TeleportationService teleportationService;
|
private TeleportationService teleportationService;
|
||||||
|
|
||||||
ProcessSyncPlayerLogin() { }
|
ProcessSyncPlayerLogin() {
|
||||||
|
}
|
||||||
|
|
||||||
private void restoreInventory(Player player) {
|
private void restoreInventory(Player player) {
|
||||||
RestoreInventoryEvent event = new RestoreInventoryEvent(player);
|
RestoreInventoryEvent event = new RestoreInventoryEvent(player);
|
||||||
@ -83,26 +80,12 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
|
|||||||
public void processPlayerLogin(Player player) {
|
public void processPlayerLogin(Player player) {
|
||||||
final String name = player.getName().toLowerCase();
|
final String name = player.getName().toLowerCase();
|
||||||
// Limbo contains the State of the Player before /login
|
// Limbo contains the State of the Player before /login
|
||||||
final PlayerData limbo = limboCache.getPlayerData(name);
|
if (limboCache.hasPlayerData(name)) {
|
||||||
final PlayerAuth auth = dataSource.getAuth(name);
|
limboCache.restoreData(player);
|
||||||
|
limboCache.deletePlayerData(player);
|
||||||
if (limbo != null) {
|
// do we really need to use location from database for now?
|
||||||
// Restore Op state and Permission Group
|
// because LimboCache#restoreData teleport player to last location.
|
||||||
player.setOp(limbo.isOperator());
|
//teleportationService.teleportOnLogin(player, auth, limbo);
|
||||||
// Restore primary group
|
|
||||||
service.setGroup(player, AuthGroupType.LOGGED_IN);
|
|
||||||
// Restore can-fly state
|
|
||||||
player.setAllowFlight(limbo.isCanFly());
|
|
||||||
|
|
||||||
// Restore speed
|
|
||||||
if (!service.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)
|
|
||||||
&& service.getProperty(RestrictionSettings.REMOVE_SPEED)) {
|
|
||||||
player.setWalkSpeed(limbo.getWalkSpeed());
|
|
||||||
player.setFlySpeed(0.2F);
|
|
||||||
}
|
|
||||||
|
|
||||||
teleportationService.teleportOnLogin(player, auth, limbo);
|
|
||||||
|
|
||||||
if (RESTORE_COLLISIONS && !service.getProperty(KEEP_COLLISIONS_DISABLED)) {
|
if (RESTORE_COLLISIONS && !service.getProperty(KEEP_COLLISIONS_DISABLED)) {
|
||||||
player.setCollidable(true);
|
player.setCollidable(true);
|
||||||
}
|
}
|
||||||
@ -110,9 +93,6 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
|
|||||||
if (service.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) {
|
if (service.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) {
|
||||||
restoreInventory(player);
|
restoreInventory(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up no longer used temporary data
|
|
||||||
limboCache.deletePlayerData(player);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We can now display the join message (if delayed)
|
// We can now display the join message (if delayed)
|
||||||
@ -157,10 +137,10 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendTo(Player player) {
|
private void sendTo(Player player) {
|
||||||
if(!service.getProperty(HooksSettings.BUNGEECORD)) {
|
if (!service.getProperty(HooksSettings.BUNGEECORD)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(service.getProperty(HooksSettings.BUNGEECORD_SERVER).isEmpty()) {
|
if (service.getProperty(HooksSettings.BUNGEECORD_SERVER).isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +151,7 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendBungeeMessage(Player player) {
|
private void sendBungeeMessage(Player player) {
|
||||||
if(!service.getProperty(HooksSettings.BUNGEECORD)) {
|
if (!service.getProperty(HooksSettings.BUNGEECORD)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -50,7 +50,7 @@ public class AsynchronousLogout implements AsynchronousProcess {
|
|||||||
database.updateQuitLoc(auth);
|
database.updateQuitLoc(auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
limboCache.updatePlayerData(player);
|
limboCache.addPlayerData(player);
|
||||||
playerCache.removePlayer(name);
|
playerCache.removePlayer(name);
|
||||||
database.setUnlogged(name);
|
database.setUnlogged(name);
|
||||||
syncProcessManager.processSyncPlayerLogout(player);
|
syncProcessManager.processSyncPlayerLogout(player);
|
||||||
|
|||||||
@ -45,7 +45,8 @@ public class ProcessSynchronousPlayerLogout implements SynchronousProcess {
|
|||||||
@Inject
|
@Inject
|
||||||
private SessionManager sessionManager;
|
private SessionManager sessionManager;
|
||||||
|
|
||||||
ProcessSynchronousPlayerLogout() { }
|
ProcessSynchronousPlayerLogout() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void sendBungeeMessage(Player player) {
|
private void sendBungeeMessage(Player player) {
|
||||||
@ -82,9 +83,7 @@ public class ProcessSynchronousPlayerLogout implements SynchronousProcess {
|
|||||||
|
|
||||||
private void applyLogoutEffect(Player player) {
|
private void applyLogoutEffect(Player player) {
|
||||||
// dismount player
|
// dismount player
|
||||||
if (player.isInsideVehicle() && player.getVehicle() != null) {
|
player.leaveVehicle();
|
||||||
player.getVehicle().eject();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply Blindness effect
|
// Apply Blindness effect
|
||||||
final int timeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
final int timeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
||||||
|
|||||||
@ -2,12 +2,8 @@ package fr.xephi.authme.process.quit;
|
|||||||
|
|
||||||
import fr.xephi.authme.cache.backup.PlayerDataStorage;
|
import fr.xephi.authme.cache.backup.PlayerDataStorage;
|
||||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||||
import fr.xephi.authme.cache.limbo.PlayerData;
|
|
||||||
import fr.xephi.authme.process.ProcessService;
|
import fr.xephi.authme.process.ProcessService;
|
||||||
import fr.xephi.authme.process.SynchronousProcess;
|
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;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -25,27 +21,12 @@ public class ProcessSyncronousPlayerQuit implements SynchronousProcess {
|
|||||||
private LimboCache limboCache;
|
private LimboCache limboCache;
|
||||||
|
|
||||||
public void processSyncQuit(Player player) {
|
public void processSyncQuit(Player player) {
|
||||||
PlayerData limbo = limboCache.getPlayerData(player.getName().toLowerCase());
|
if (limboCache.hasPlayerData(player.getName().toLowerCase())) { // it mean player is not authenticated
|
||||||
if (limbo != null) { // it mean player is not authenticated
|
limboCache.removeFromCache(player);
|
||||||
// Only delete if we don't need player's last location
|
|
||||||
if (service.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)) {
|
|
||||||
limboCache.removePlayerData(player);
|
|
||||||
} else {
|
|
||||||
// Restore data if its about to delete PlayerData
|
|
||||||
if (!StringUtils.isEmpty(limbo.getGroup())) {
|
|
||||||
Utils.addNormal(player, limbo.getGroup());
|
|
||||||
}
|
|
||||||
player.setOp(limbo.isOperator());
|
|
||||||
player.setAllowFlight(limbo.isCanFly());
|
|
||||||
player.setWalkSpeed(limbo.getWalkSpeed());
|
|
||||||
limboCache.deletePlayerData(player);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Write player's location, so we could retrieve it later on player next join
|
// Save player's data, so we could retrieve it later on player next join
|
||||||
if (service.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)) {
|
if (!playerDataStorage.hasData(player)) {
|
||||||
if (!playerDataStorage.hasData(player)) {
|
playerDataStorage.saveData(player);
|
||||||
playerDataStorage.saveData(player);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import com.google.common.io.ByteStreams;
|
|||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||||
import fr.xephi.authme.cache.limbo.PlayerData;
|
|
||||||
import fr.xephi.authme.events.LoginEvent;
|
import fr.xephi.authme.events.LoginEvent;
|
||||||
import fr.xephi.authme.events.RestoreInventoryEvent;
|
import fr.xephi.authme.events.RestoreInventoryEvent;
|
||||||
import fr.xephi.authme.listener.protocollib.ProtocolLibService;
|
import fr.xephi.authme.listener.protocollib.ProtocolLibService;
|
||||||
@ -20,6 +19,7 @@ import fr.xephi.authme.settings.properties.RegistrationSettings;
|
|||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
import fr.xephi.authme.task.PlayerDataTaskManager;
|
import fr.xephi.authme.task.PlayerDataTaskManager;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.util.BukkitService;
|
||||||
|
import fr.xephi.authme.util.TeleportationService;
|
||||||
import fr.xephi.authme.util.Utils;
|
import fr.xephi.authme.util.Utils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -35,23 +35,21 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private AuthMe plugin;
|
private AuthMe plugin;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ProcessService service;
|
private ProcessService service;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private BukkitService bukkitService;
|
private BukkitService bukkitService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ProtocolLibService protocolLibService;
|
private ProtocolLibService protocolLibService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private LimboCache limboCache;
|
private LimboCache limboCache;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private PlayerDataTaskManager playerDataTaskManager;
|
private PlayerDataTaskManager playerDataTaskManager;
|
||||||
|
@Inject
|
||||||
|
private TeleportationService teleportationService;
|
||||||
|
|
||||||
ProcessSyncPasswordRegister() { }
|
ProcessSyncPasswordRegister() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void sendBungeeMessage(Player player) {
|
private void sendBungeeMessage(Player player) {
|
||||||
@ -69,7 +67,7 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
|
|||||||
}
|
}
|
||||||
for (String command : service.getProperty(RegistrationSettings.FORCE_REGISTER_COMMANDS_AS_CONSOLE)) {
|
for (String command : service.getProperty(RegistrationSettings.FORCE_REGISTER_COMMANDS_AS_CONSOLE)) {
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||||
command.replace("%p", player.getName()));
|
command.replace("%p", player.getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,10 +91,8 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
|
|||||||
|
|
||||||
public void processPasswordRegister(Player player) {
|
public void processPasswordRegister(Player player) {
|
||||||
final String name = player.getName().toLowerCase();
|
final String name = player.getName().toLowerCase();
|
||||||
PlayerData limbo = limboCache.getPlayerData(name);
|
if (limboCache.hasPlayerData(name)) {
|
||||||
if (limbo != null) {
|
teleportationService.teleportOnJoin(player);
|
||||||
Utils.teleportToSpawn(player);
|
|
||||||
|
|
||||||
if (service.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) {
|
if (service.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) {
|
||||||
RestoreInventoryEvent event = new RestoreInventoryEvent(player);
|
RestoreInventoryEvent event = new RestoreInventoryEvent(player);
|
||||||
bukkitService.callEvent(event);
|
bukkitService.callEvent(event);
|
||||||
@ -104,7 +100,7 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
|
|||||||
player.updateInventory();
|
player.updateInventory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
limboCache.restoreData(player);
|
||||||
limboCache.deletePlayerData(player);
|
limboCache.deletePlayerData(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -62,6 +62,7 @@ public class AsynchronousUnregister implements AsynchronousProcess {
|
|||||||
if (!Settings.getRegisteredGroup.isEmpty()) {
|
if (!Settings.getRegisteredGroup.isEmpty()) {
|
||||||
service.setGroup(player, AuthGroupType.UNREGISTERED);
|
service.setGroup(player, AuthGroupType.UNREGISTERED);
|
||||||
}
|
}
|
||||||
|
limboCache.deletePlayerData(player);
|
||||||
limboCache.addPlayerData(player);
|
limboCache.addPlayerData(player);
|
||||||
playerDataTaskManager.registerTimeoutTask(player);
|
playerDataTaskManager.registerTimeoutTask(player);
|
||||||
playerDataTaskManager.registerMessageTask(name, false);
|
playerDataTaskManager.registerMessageTask(name, false);
|
||||||
|
|||||||
@ -102,7 +102,7 @@ public class TeleportationService implements Reloadable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The world in PlayerData is from where the player comes, before any teleportation by AuthMe
|
// The world in PlayerData is from where the player comes, before any teleportation by AuthMe
|
||||||
String worldName = limbo.getLoc().getWorld().getName();
|
String worldName = limbo.getLocation().getWorld().getName();
|
||||||
if (mustForceSpawnAfterLogin(worldName)) {
|
if (mustForceSpawnAfterLogin(worldName)) {
|
||||||
teleportToSpawn(player, true);
|
teleportToSpawn(player, true);
|
||||||
} else if (settings.getProperty(TELEPORT_UNAUTHED_TO_SPAWN)) {
|
} else if (settings.getProperty(TELEPORT_UNAUTHED_TO_SPAWN)) {
|
||||||
@ -110,7 +110,7 @@ public class TeleportationService implements Reloadable {
|
|||||||
Location location = buildLocationFromAuth(player, auth);
|
Location location = buildLocationFromAuth(player, auth);
|
||||||
teleportBackFromSpawn(player, location);
|
teleportBackFromSpawn(player, location);
|
||||||
} else {
|
} else {
|
||||||
teleportBackFromSpawn(player, limbo.getLoc());
|
teleportBackFromSpawn(player, limbo.getLocation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -280,7 +280,7 @@ public class TeleportationServiceTest {
|
|||||||
PlayerData limbo = mock(PlayerData.class);
|
PlayerData limbo = mock(PlayerData.class);
|
||||||
Location limboLocation = mockLocation();
|
Location limboLocation = mockLocation();
|
||||||
given(limboLocation.getWorld().getName()).willReturn("forced1");
|
given(limboLocation.getWorld().getName()).willReturn("forced1");
|
||||||
given(limbo.getLoc()).willReturn(limboLocation);
|
given(limbo.getLocation()).willReturn(limboLocation);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
teleportationService.teleportOnLogin(player, auth, limbo);
|
teleportationService.teleportOnLogin(player, auth, limbo);
|
||||||
@ -304,7 +304,7 @@ public class TeleportationServiceTest {
|
|||||||
PlayerData limbo = mock(PlayerData.class);
|
PlayerData limbo = mock(PlayerData.class);
|
||||||
Location limboLocation = mockLocation();
|
Location limboLocation = mockLocation();
|
||||||
given(limboLocation.getWorld().getName()).willReturn("Forced1"); // different case
|
given(limboLocation.getWorld().getName()).willReturn("Forced1"); // different case
|
||||||
given(limbo.getLoc()).willReturn(limboLocation);
|
given(limbo.getLocation()).willReturn(limboLocation);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
teleportationService.teleportOnLogin(player, auth, limbo);
|
teleportationService.teleportOnLogin(player, auth, limbo);
|
||||||
@ -330,7 +330,7 @@ public class TeleportationServiceTest {
|
|||||||
given(player.isOnline()).willReturn(true);
|
given(player.isOnline()).willReturn(true);
|
||||||
PlayerData limbo = mock(PlayerData.class);
|
PlayerData limbo = mock(PlayerData.class);
|
||||||
Location limboLocation = mockLocation();
|
Location limboLocation = mockLocation();
|
||||||
given(limbo.getLoc()).willReturn(limboLocation);
|
given(limbo.getLocation()).willReturn(limboLocation);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
teleportationService.teleportOnLogin(player, auth, limbo);
|
teleportationService.teleportOnLogin(player, auth, limbo);
|
||||||
@ -359,7 +359,7 @@ public class TeleportationServiceTest {
|
|||||||
given(player.getWorld()).willReturn(world);
|
given(player.getWorld()).willReturn(world);
|
||||||
PlayerData limbo = mock(PlayerData.class);
|
PlayerData limbo = mock(PlayerData.class);
|
||||||
Location limboLocation = mockLocation();
|
Location limboLocation = mockLocation();
|
||||||
given(limbo.getLoc()).willReturn(limboLocation);
|
given(limbo.getLocation()).willReturn(limboLocation);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
teleportationService.teleportOnLogin(player, auth, limbo);
|
teleportationService.teleportOnLogin(player, auth, limbo);
|
||||||
@ -387,7 +387,7 @@ public class TeleportationServiceTest {
|
|||||||
given(player.getWorld()).willReturn(world);
|
given(player.getWorld()).willReturn(world);
|
||||||
PlayerData limbo = mock(PlayerData.class);
|
PlayerData limbo = mock(PlayerData.class);
|
||||||
Location location = mockLocation();
|
Location location = mockLocation();
|
||||||
given(limbo.getLoc()).willReturn(location);
|
given(limbo.getLocation()).willReturn(location);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
teleportationService.teleportOnLogin(player, auth, limbo);
|
teleportationService.teleportOnLogin(player, auth, limbo);
|
||||||
@ -412,7 +412,7 @@ public class TeleportationServiceTest {
|
|||||||
given(player.getWorld()).willReturn(world);
|
given(player.getWorld()).willReturn(world);
|
||||||
PlayerData limbo = mock(PlayerData.class);
|
PlayerData limbo = mock(PlayerData.class);
|
||||||
Location location = mockLocation();
|
Location location = mockLocation();
|
||||||
given(limbo.getLoc()).willReturn(location);
|
given(limbo.getLocation()).willReturn(location);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
teleportationService.teleportOnLogin(player, auth, limbo);
|
teleportationService.teleportOnLogin(player, auth, limbo);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user