- Renamed JsonCache to PlayerDataStorage

* the methods inside it renamed to fit with class name
  * cache folder changed into playerdata
- Renamed LimboPlayer to PlayerData
- Added fly speed to PlayerData
- Removed player's name from PlayerData object
- Added getPlayerLocationOrSpawn method in spawn loader.
This commit is contained in:
DNx5 2016-07-03 21:52:46 +07:00
parent 7ea0763966
commit deffcb3e2b
26 changed files with 554 additions and 220 deletions

View File

@ -12,9 +12,280 @@
<XML> <XML>
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" /> <option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
</XML> </XML>
<codeStyleSettings language="JAVA">
<arrangement>
<rules>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<FINAL>true</FINAL>
<PUBLIC>true</PUBLIC>
<STATIC>true</STATIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<FINAL>true</FINAL>
<PROTECTED>true</PROTECTED>
<STATIC>true</STATIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<FINAL>true</FINAL>
<PACKAGE_PRIVATE>true</PACKAGE_PRIVATE>
<STATIC>true</STATIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<FINAL>true</FINAL>
<PRIVATE>true</PRIVATE>
<STATIC>true</STATIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<PUBLIC>true</PUBLIC>
<STATIC>true</STATIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<PROTECTED>true</PROTECTED>
<STATIC>true</STATIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<PACKAGE_PRIVATE>true</PACKAGE_PRIVATE>
<STATIC>true</STATIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<PRIVATE>true</PRIVATE>
<STATIC>true</STATIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<INITIALIZER_BLOCK>true</INITIALIZER_BLOCK>
<STATIC>true</STATIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<FINAL>true</FINAL>
<PUBLIC>true</PUBLIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<FINAL>true</FINAL>
<PROTECTED>true</PROTECTED>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<FINAL>true</FINAL>
<PACKAGE_PRIVATE>true</PACKAGE_PRIVATE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<FINAL>true</FINAL>
<PRIVATE>true</PRIVATE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<PUBLIC>true</PUBLIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<PROTECTED>true</PROTECTED>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<PACKAGE_PRIVATE>true</PACKAGE_PRIVATE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<PRIVATE>true</PRIVATE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<FIELD>true</FIELD>
</match>
</rule>
</section>
<section>
<rule>
<match>
<INITIALIZER_BLOCK>true</INITIALIZER_BLOCK>
</match>
</rule>
</section>
<section>
<rule>
<match>
<CONSTRUCTOR>true</CONSTRUCTOR>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<METHOD>true</METHOD>
<STATIC>true</STATIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<METHOD>true</METHOD>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<METHOD>true</METHOD>
<PRIVATE>true</PRIVATE>
<STATIC>true</STATIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<ENUM>true</ENUM>
</match>
</rule>
</section>
<section>
<rule>
<match>
<INTERFACE>true</INTERFACE>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<CLASS>true</CLASS>
<STATIC>true</STATIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<CLASS>true</CLASS>
</match>
</rule>
</section>
</rules>
</arrangement>
</codeStyleSettings>
</value> </value>
</option> </option>
<option name="USE_PER_PROJECT_SETTINGS" value="true" /> <option name="USE_PER_PROJECT_SETTINGS" value="true" />
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Project" />
</component> </component>
</project> </project>

View File

@ -5,9 +5,9 @@ import fr.xephi.authme.api.API;
import fr.xephi.authme.api.NewAPI; import fr.xephi.authme.api.NewAPI;
import fr.xephi.authme.cache.auth.PlayerAuth; 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.JsonCache; 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.LimboPlayer; 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;
@ -564,8 +564,8 @@ public class AuthMe extends JavaPlugin {
return; return;
} }
String name = player.getName().toLowerCase(); String name = player.getName().toLowerCase();
if (limboCache.hasLimboPlayer(name)) { if (limboCache.hasPlayerData(name)) {
LimboPlayer limbo = limboCache.getLimboPlayer(name); PlayerData limbo = limboCache.getPlayerData(name);
if (!newSettings.getProperty(RestrictionSettings.NO_TELEPORT)) { if (!newSettings.getProperty(RestrictionSettings.NO_TELEPORT)) {
player.teleport(limbo.getLoc()); player.teleport(limbo.getLoc());
} }
@ -574,14 +574,13 @@ public class AuthMe extends JavaPlugin {
player.setAllowFlight(limbo.isCanFly()); player.setAllowFlight(limbo.isCanFly());
player.setWalkSpeed(limbo.getWalkSpeed()); player.setWalkSpeed(limbo.getWalkSpeed());
if (newSettings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)) { if (newSettings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)) {
limboCache.removeLimboPlayer(player); limboCache.removePlayerData(player);
} else { } else {
limboCache.deleteLimboPlayer(player); limboCache.deletePlayerData(player);
} }
} else { } else {
if (newSettings.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)) { if (newSettings.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)) {
Location loc = Location loc = spawnLoader.getPlayerLocationOrSpawn(player);
player.isOnline() && player.isDead() ? spawnLoader.getSpawnLocation(player) : player.getLocation();
final PlayerAuth auth = PlayerAuth.builder() final PlayerAuth auth = PlayerAuth.builder()
.name(player.getName().toLowerCase()) .name(player.getName().toLowerCase())
.realName(player.getName()) .realName(player.getName())
@ -590,9 +589,9 @@ public class AuthMe extends JavaPlugin {
} }
if (newSettings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN) if (newSettings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)
&& !newSettings.getProperty(RestrictionSettings.NO_TELEPORT)) { && !newSettings.getProperty(RestrictionSettings.NO_TELEPORT)) {
JsonCache jsonCache = initializer.getIfAvailable(JsonCache.class); PlayerDataStorage playerDataStorage = initializer.getIfAvailable(PlayerDataStorage.class);
if (jsonCache != null && !jsonCache.doesCacheExist(player)) { if (playerDataStorage != null && !playerDataStorage.hasData(player)) {
jsonCache.writeCache(player); playerDataStorage.saveData(player);
} }
} }
} }

View File

@ -4,6 +4,7 @@ package fr.xephi.authme.cache.auth;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
/** /**
* Used to manage player's Authenticated status
*/ */
public class PlayerCache { public class PlayerCache {
@ -55,11 +56,11 @@ public class PlayerCache {
} }
/** /**
* Method isAuthenticated. * get player's authenticated status.
* *
* @param user String * @param user player's name
* *
* @return boolean * @return true if player is logged in, false otherwise.
*/ */
public boolean isAuthenticated(String user) { public boolean isAuthenticated(String user) {
return cache.containsKey(user.toLowerCase()); return cache.containsKey(user.toLowerCase());

View File

@ -11,7 +11,7 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer; import com.google.gson.JsonSerializer;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.limbo.LimboPlayer; import fr.xephi.authme.cache.limbo.PlayerData;
import fr.xephi.authme.initialization.DataFolder; import fr.xephi.authme.initialization.DataFolder;
import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.settings.SpawnLoader; import fr.xephi.authme.settings.SpawnLoader;
@ -27,7 +27,10 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Type; import java.lang.reflect.Type;
public class JsonCache { /**
* Class used to store player's data (OP, flying, speed, position) to disk.
*/
public class PlayerDataStorage {
private final Gson gson; private final Gson gson;
private final File cacheDir; private final File cacheDir;
@ -36,60 +39,77 @@ public class JsonCache {
private BukkitService bukkitService; private BukkitService bukkitService;
@Inject @Inject
JsonCache(@DataFolder File dataFolder, PermissionsManager permsMan, PlayerDataStorage(@DataFolder File dataFolder, PermissionsManager permsMan,
SpawnLoader spawnLoader, BukkitService bukkitService) { SpawnLoader spawnLoader, BukkitService bukkitService) {
this.permissionsManager = permsMan; this.permissionsManager = permsMan;
this.spawnLoader = spawnLoader; this.spawnLoader = spawnLoader;
this.bukkitService = bukkitService; this.bukkitService = bukkitService;
cacheDir = new File(dataFolder, "cache"); cacheDir = new File(dataFolder, "playerdata");
if (!cacheDir.exists() && !cacheDir.isDirectory() && !cacheDir.mkdir()) { if (!cacheDir.exists() && !cacheDir.isDirectory() && !cacheDir.mkdir()) {
ConsoleLogger.showError("Failed to create cache directory."); ConsoleLogger.showError("Failed to create userdata directory.");
} }
gson = new GsonBuilder() gson = new GsonBuilder()
.registerTypeAdapter(LimboPlayer.class, new LimboPlayerSerializer()) .registerTypeAdapter(PlayerData.class, new PlayerDataSerializer())
.registerTypeAdapter(LimboPlayer.class, new LimboPlayerDeserializer()) .registerTypeAdapter(PlayerData.class, new PlayerDataDeserializer())
.setPrettyPrinting() .setPrettyPrinting()
.create(); .create();
} }
public LimboPlayer readCache(Player player) { /**
* Read and construct new PlayerData from existing player data.
*
* @param player player to read
*
* @return PlayerData object if the data is exist, null otherwise.
*/
public PlayerData readData(Player player) {
String id = Utils.getUUIDorName(player); String id = Utils.getUUIDorName(player);
File file = new File(cacheDir, id + File.separator + "cache.json"); File file = new File(cacheDir, id + File.separator + "data.json");
if (!file.exists()) { if (!file.exists()) {
return null; return null;
} }
try { try {
String str = Files.toString(file, Charsets.UTF_8); String str = Files.toString(file, Charsets.UTF_8);
return gson.fromJson(str, LimboPlayer.class); return gson.fromJson(str, PlayerData.class);
} catch (IOException e) { } catch (IOException e) {
ConsoleLogger.writeStackTrace(e); ConsoleLogger.writeStackTrace(e);
return null; return null;
} }
} }
public void writeCache(Player player) { /**
* Save player data (OP, flying, location, etc) to disk.
*
* @param player player to save
*/
public void saveData(Player player) {
String id = Utils.getUUIDorName(player); String id = Utils.getUUIDorName(player);
String name = player.getName().toLowerCase(); Location location = spawnLoader.getPlayerLocationOrSpawn(player);
Location location =
player.isOnline() && player.isDead() ? spawnLoader.getSpawnLocation(player) : player.getLocation();
String group = permissionsManager.getPrimaryGroup(player); String group = permissionsManager.getPrimaryGroup(player);
boolean operator = player.isOp(); boolean operator = player.isOp();
boolean canFly = player.getAllowFlight(); boolean canFly = player.getAllowFlight();
float walkSpeed = player.getWalkSpeed(); float walkSpeed = player.getWalkSpeed();
LimboPlayer limboPlayer = new LimboPlayer(name, location, operator, group, canFly, walkSpeed); float flySpeed = player.getFlySpeed();
PlayerData playerData = new PlayerData(location, operator, group, canFly, walkSpeed, flySpeed);
try { try {
File file = new File(cacheDir, id + File.separator + "cache.json"); File file = new File(cacheDir, id + File.separator + "data.json");
Files.createParentDirs(file); Files.createParentDirs(file);
Files.touch(file); Files.touch(file);
Files.write(gson.toJson(limboPlayer), file, Charsets.UTF_8); Files.write(gson.toJson(playerData), file, Charsets.UTF_8);
} catch (IOException e) { } catch (IOException e) {
ConsoleLogger.logException("Failed to write " + player.getName() + " cache.", e); ConsoleLogger.logException("Failed to write " + player.getName() + " data.", e);
} }
} }
public void removeCache(Player player) { /**
* Remove player data, this will delete
* "playerdata/&lt;uuid or name&gt;/" folder from disk.
*
* @param player player to remove
*/
public void removeData(Player player) {
String id = Utils.getUUIDorName(player); String id = Utils.getUUIDorName(player);
File file = new File(cacheDir, id); File file = new File(cacheDir, id);
if (file.exists()) { if (file.exists()) {
@ -100,16 +120,23 @@ public class JsonCache {
} }
} }
public boolean doesCacheExist(Player player) { /**
* Use to check is player data is exist.
*
* @param player player to check
*
* @return true if data exist, false otherwise.
*/
public boolean hasData(Player player) {
String id = Utils.getUUIDorName(player); String id = Utils.getUUIDorName(player);
File file = new File(cacheDir, id + File.separator + "cache.json"); File file = new File(cacheDir, id + File.separator + "data.json");
return file.exists(); return file.exists();
} }
private class LimboPlayerDeserializer implements JsonDeserializer<LimboPlayer> { private class PlayerDataDeserializer implements JsonDeserializer<PlayerData> {
@Override @Override
public LimboPlayer deserialize(JsonElement jsonElement, Type type, public PlayerData deserialize(JsonElement jsonElement, Type type,
JsonDeserializationContext context) { JsonDeserializationContext context) {
JsonObject jsonObject = jsonElement.getAsJsonObject(); JsonObject jsonObject = jsonElement.getAsJsonObject();
if (jsonObject == null) { if (jsonObject == null) {
return null; return null;
@ -120,6 +147,7 @@ public class JsonCache {
boolean operator = false; boolean operator = false;
boolean canFly = false; boolean canFly = false;
float walkSpeed = 0.2f; float walkSpeed = 0.2f;
float flySpeed = 0.2f;
JsonElement e; JsonElement e;
if ((e = jsonObject.getAsJsonObject("location")) != null) { if ((e = jsonObject.getAsJsonObject("location")) != null) {
@ -146,19 +174,22 @@ public class JsonCache {
if ((e = jsonObject.get("walk-speed")) != null) { if ((e = jsonObject.get("walk-speed")) != null) {
walkSpeed = e.getAsFloat(); walkSpeed = e.getAsFloat();
} }
if ((e = jsonObject.get("fly-speed")) != null) {
flySpeed = e.getAsFloat();
}
return new LimboPlayer("", loc, operator, group, canFly, walkSpeed); return new PlayerData(loc, operator, group, canFly, walkSpeed, flySpeed);
} }
} }
private class LimboPlayerSerializer implements JsonSerializer<LimboPlayer> { private class PlayerDataSerializer implements JsonSerializer<PlayerData> {
@Override @Override
public JsonElement serialize(LimboPlayer limboPlayer, Type type, public JsonElement serialize(PlayerData playerData, Type type,
JsonSerializationContext context) { JsonSerializationContext context) {
JsonObject obj = new JsonObject(); JsonObject obj = new JsonObject();
obj.addProperty("group", limboPlayer.getGroup()); obj.addProperty("group", playerData.getGroup());
Location loc = limboPlayer.getLoc(); Location loc = playerData.getLoc();
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());
@ -168,9 +199,10 @@ public class JsonCache {
obj2.addProperty("pitch", loc.getPitch()); obj2.addProperty("pitch", loc.getPitch());
obj.add("location", obj2); obj.add("location", obj2);
obj.addProperty("operator", limboPlayer.isOperator()); obj.addProperty("operator", playerData.isOperator());
obj.addProperty("can-fly", limboPlayer.isCanFly()); obj.addProperty("can-fly", playerData.isCanFly());
obj.addProperty("walk-speed", limboPlayer.getWalkSpeed()); obj.addProperty("walk-speed", playerData.getWalkSpeed());
obj.addProperty("fly-speed", playerData.getFlySpeed());
return obj; return obj;
} }
} }

View File

@ -1,6 +1,6 @@
package fr.xephi.authme.cache.limbo; package fr.xephi.authme.cache.limbo;
import fr.xephi.authme.cache.backup.JsonCache; import fr.xephi.authme.cache.backup.PlayerDataStorage;
import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.settings.SpawnLoader; import fr.xephi.authme.settings.SpawnLoader;
import org.bukkit.Location; import org.bukkit.Location;
@ -12,21 +12,21 @@ import java.util.concurrent.ConcurrentHashMap;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* Manages all {@link LimboPlayer} instances. * Manages all {@link PlayerData} instances.
*/ */
public class LimboCache { public class LimboCache {
private final ConcurrentHashMap<String, LimboPlayer> cache = new ConcurrentHashMap<>(); private final ConcurrentHashMap<String, PlayerData> cache = new ConcurrentHashMap<>();
private JsonCache jsonCache; private PlayerDataStorage playerDataStorage;
private PermissionsManager permissionsManager; private PermissionsManager permissionsManager;
private SpawnLoader spawnLoader; private SpawnLoader spawnLoader;
@Inject @Inject
LimboCache(PermissionsManager permissionsManager, SpawnLoader spawnLoader, JsonCache jsonCache) { LimboCache(PermissionsManager permissionsManager, SpawnLoader spawnLoader, PlayerDataStorage playerDataStorage) {
this.permissionsManager = permissionsManager; this.permissionsManager = permissionsManager;
this.spawnLoader = spawnLoader; this.spawnLoader = spawnLoader;
this.jsonCache = jsonCache; this.playerDataStorage = playerDataStorage;
} }
/** /**
@ -34,88 +34,90 @@ public class LimboCache {
* *
* @param player Player instance to add. * @param player Player instance to add.
*/ */
public void addLimboPlayer(Player player) { public void addPlayerData(Player player) {
String name = player.getName().toLowerCase(); String name = player.getName().toLowerCase();
Location location = player.isDead() ? spawnLoader.getSpawnLocation(player) : player.getLocation(); Location location = spawnLoader.getPlayerLocationOrSpawn(player);
boolean operator = player.isOp(); boolean operator = player.isOp();
boolean flyEnabled = player.getAllowFlight(); boolean flyEnabled = player.getAllowFlight();
float walkSpeed = player.getWalkSpeed(); float walkSpeed = player.getWalkSpeed();
float flySpeed = player.getFlySpeed();
String playerGroup = ""; String playerGroup = "";
if (permissionsManager.hasGroupSupport()) { if (permissionsManager.hasGroupSupport()) {
playerGroup = permissionsManager.getPrimaryGroup(player); playerGroup = permissionsManager.getPrimaryGroup(player);
} }
if (jsonCache.doesCacheExist(player)) { if (playerDataStorage.hasData(player)) {
LimboPlayer cache = jsonCache.readCache(player); PlayerData cache = playerDataStorage.readData(player);
if (cache != null) { if (cache != null) {
location = cache.getLoc(); location = cache.getLoc();
playerGroup = cache.getGroup(); playerGroup = cache.getGroup();
operator = cache.isOperator(); operator = cache.isOperator();
flyEnabled = cache.isCanFly(); flyEnabled = cache.isCanFly();
walkSpeed = cache.getWalkSpeed(); walkSpeed = cache.getWalkSpeed();
flySpeed = cache.getFlySpeed();
} }
} else { } else {
jsonCache.writeCache(player); playerDataStorage.saveData(player);
} }
cache.put(name, new LimboPlayer(name, location, operator, playerGroup, flyEnabled, walkSpeed)); cache.put(name, new PlayerData(location, operator, playerGroup, flyEnabled, walkSpeed, flySpeed));
} }
/** /**
* Remove LimboPlayer and delete cache.json from disk. * Remove PlayerData and delete cache.json from disk.
* *
* @param player Player player to remove. * @param player Player player to remove.
*/ */
public void deleteLimboPlayer(Player player) { public void deletePlayerData(Player player) {
removeLimboPlayer(player); removePlayerData(player);
jsonCache.removeCache(player); playerDataStorage.removeData(player);
} }
/** /**
* Remove LimboPlayer from cache, without deleting cache.json file. * Remove PlayerData from cache, without deleting cache.json file.
* *
* @param player Player player to remove. * @param player Player player to remove.
*/ */
public void removeLimboPlayer(Player player) { public void removePlayerData(Player player) {
String name = player.getName().toLowerCase(); String name = player.getName().toLowerCase();
LimboPlayer cachedPlayer = cache.remove(name); PlayerData cachedPlayer = cache.remove(name);
if (cachedPlayer != null) { if (cachedPlayer != null) {
cachedPlayer.clearTasks(); cachedPlayer.clearTasks();
} }
} }
/** /**
* Method getLimboPlayer. * Method getPlayerData.
* *
* @param name String * @param name String
* *
* @return LimboPlayer * @return PlayerData
*/ */
public LimboPlayer getLimboPlayer(String name) { public PlayerData getPlayerData(String name) {
checkNotNull(name); checkNotNull(name);
return cache.get(name.toLowerCase()); return cache.get(name.toLowerCase());
} }
/** /**
* Method hasLimboPlayer. * Method hasPlayerData.
* *
* @param name String * @param name String
* *
* @return boolean * @return boolean
*/ */
public boolean hasLimboPlayer(String name) { public boolean hasPlayerData(String name) {
checkNotNull(name); checkNotNull(name);
return cache.containsKey(name.toLowerCase()); return cache.containsKey(name.toLowerCase());
} }
/** /**
* Method updateLimboPlayer. * Method updatePlayerData.
* *
* @param player Player * @param player Player
*/ */
public void updateLimboPlayer(Player player) { public void updatePlayerData(Player player) {
checkNotNull(player); checkNotNull(player);
removeLimboPlayer(player); removePlayerData(player);
addLimboPlayer(player); addPlayerData(player);
} }
} }

View File

@ -7,34 +7,25 @@ import org.bukkit.scheduler.BukkitTask;
* Represents a player which is not logged in and keeps track of certain states (like OP status, flying) * Represents a player which is not logged in and keeps track of certain states (like OP status, flying)
* which may be revoked from the player until he has logged in or registered. * which may be revoked from the player until he has logged in or registered.
*/ */
public class LimboPlayer { public class PlayerData {
private final String name;
private final boolean canFly; private final boolean canFly;
private final boolean operator; private final boolean operator;
private final String group; private final String group;
private final Location loc; private final Location loc;
private final float walkSpeed; private final float walkSpeed;
private final float flySpeed;
private BukkitTask timeoutTask = null; private BukkitTask timeoutTask = null;
private BukkitTask messageTask = null; private BukkitTask messageTask = null;
public LimboPlayer(String name, Location loc, boolean operator, public PlayerData(Location loc, boolean operator,
String group, boolean fly, float walkSpeed) { String group, boolean fly, float walkSpeed, float flySpeed) {
this.name = name;
this.loc = loc; this.loc = loc;
this.operator = operator; this.operator = operator;
this.group = group; this.group = group;
this.canFly = fly; this.canFly = fly;
this.walkSpeed = walkSpeed; this.walkSpeed = walkSpeed;
} this.flySpeed = flySpeed;
/**
* Return the name of the player.
*
* @return The player's name
*/
public String getName() {
return name;
} }
/** /**
@ -72,6 +63,10 @@ public class LimboPlayer {
return walkSpeed; return walkSpeed;
} }
public float getFlySpeed() {
return flySpeed;
}
/** /**
* Return the timeout task, which kicks the player if he hasn't registered or logged in * Return the timeout task, which kicks the player if he hasn't registered or logged in
* after a configurable amount of time. * after a configurable amount of time.

View File

@ -11,7 +11,7 @@ import fr.xephi.authme.permission.AuthGroupHandler;
import fr.xephi.authme.permission.AuthGroupType; import fr.xephi.authme.permission.AuthGroupType;
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.settings.properties.RestrictionSettings;
import fr.xephi.authme.task.LimboPlayerTaskManager; import fr.xephi.authme.task.PlayerDataTaskManager;
import fr.xephi.authme.util.BukkitService; import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.Utils; import fr.xephi.authme.util.Utils;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -45,7 +45,7 @@ public class UnregisterAdminCommand implements ExecutableCommand {
private LimboCache limboCache; private LimboCache limboCache;
@Inject @Inject
private LimboPlayerTaskManager limboPlayerTaskManager; private PlayerDataTaskManager playerDataTaskManager;
@Inject @Inject
private AuthGroupHandler authGroupHandler; private AuthGroupHandler authGroupHandler;
@ -96,9 +96,9 @@ public class UnregisterAdminCommand implements ExecutableCommand {
// TODO #765: Remove use of Utils method and behave according to settings // TODO #765: Remove use of Utils method and behave according to settings
Utils.teleportToSpawn(target); Utils.teleportToSpawn(target);
limboCache.addLimboPlayer(target); limboCache.addPlayerData(target);
limboPlayerTaskManager.registerTimeoutTask(target); playerDataTaskManager.registerTimeoutTask(target);
limboPlayerTaskManager.registerMessageTask(target.getName(), false); playerDataTaskManager.registerMessageTask(target.getName(), false);
final int timeout = commandService.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND; final int timeout = commandService.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
if (commandService.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) { if (commandService.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {

View File

@ -2,12 +2,11 @@ package fr.xephi.authme.permission;
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.LimboPlayer; import fr.xephi.authme.cache.limbo.PlayerData;
import fr.xephi.authme.settings.NewSetting; import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.PluginSettings; import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.settings.properties.SecuritySettings; import fr.xephi.authme.settings.properties.SecuritySettings;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import javax.inject.Inject; import javax.inject.Inject;
@ -68,7 +67,7 @@ public class AuthGroupHandler {
case LOGGED_IN: case LOGGED_IN:
// Get the limbo player data // Get the limbo player data
LimboPlayer limbo = limboCache.getLimboPlayer(player.getName().toLowerCase()); PlayerData limbo = limboCache.getPlayerData(player.getName().toLowerCase());
if (limbo == null) { if (limbo == null) {
return false; return false;
} }

View File

@ -19,7 +19,7 @@ import fr.xephi.authme.settings.properties.PluginSettings;
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.settings.properties.RestrictionSettings;
import fr.xephi.authme.settings.properties.SecuritySettings; import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.task.LimboPlayerTaskManager; import fr.xephi.authme.task.PlayerDataTaskManager;
import fr.xephi.authme.util.BukkitService; import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.Utils; import fr.xephi.authme.util.Utils;
import org.apache.commons.lang.reflect.MethodUtils; import org.apache.commons.lang.reflect.MethodUtils;
@ -65,7 +65,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
private BukkitService bukkitService; private BukkitService bukkitService;
@Inject @Inject
private LimboPlayerTaskManager limboPlayerTaskManager; private PlayerDataTaskManager playerDataTaskManager;
AsynchronousJoin() { AsynchronousJoin() {
} }
@ -115,7 +115,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
return; return;
} }
limboCache.updateLimboPlayer(player); limboCache.updatePlayerData(player);
final boolean isAuthAvailable = database.isAuthAvailable(name); final boolean isAuthAvailable = database.isAuthAvailable(name);
@ -186,8 +186,8 @@ public class AsynchronousJoin implements AsynchronousProcess {
}); });
// Timeout and message task // Timeout and message task
limboPlayerTaskManager.registerTimeoutTask(player); playerDataTaskManager.registerTimeoutTask(player);
limboPlayerTaskManager.registerMessageTask(name, isAuthAvailable); playerDataTaskManager.registerMessageTask(name, isAuthAvailable);
} }
private boolean isPlayerUnrestricted(String name) { private boolean isPlayerUnrestricted(String name) {

View File

@ -6,7 +6,7 @@ import fr.xephi.authme.cache.TempbanManager;
import fr.xephi.authme.cache.auth.PlayerAuth; 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.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.cache.limbo.LimboPlayer; import fr.xephi.authme.cache.limbo.PlayerData;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.events.AuthMeAsyncPreLoginEvent; import fr.xephi.authme.events.AuthMeAsyncPreLoginEvent;
import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.MessageKey;
@ -23,7 +23,7 @@ import fr.xephi.authme.settings.properties.DatabaseSettings;
import fr.xephi.authme.settings.properties.EmailSettings; import fr.xephi.authme.settings.properties.EmailSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.settings.properties.SecuritySettings; import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.task.LimboPlayerTaskManager; import fr.xephi.authme.task.PlayerDataTaskManager;
import fr.xephi.authme.util.BukkitService; import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.StringUtils; import fr.xephi.authme.util.StringUtils;
import fr.xephi.authme.util.Utils; import fr.xephi.authme.util.Utils;
@ -70,7 +70,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
private TempbanManager tempbanManager; private TempbanManager tempbanManager;
@Inject @Inject
private LimboPlayerTaskManager limboPlayerTaskManager; private PlayerDataTaskManager playerDataTaskManager;
AsynchronousLogin() { } AsynchronousLogin() { }
@ -106,7 +106,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
service.send(player, MessageKey.USER_NOT_REGISTERED); service.send(player, MessageKey.USER_NOT_REGISTERED);
// TODO ljacqu 20160612: Why is the message task being canceled and added again here? // TODO ljacqu 20160612: Why is the message task being canceled and added again here?
limboPlayerTaskManager.registerMessageTask(name, false); playerDataTaskManager.registerMessageTask(name, false);
return null; return null;
} }
@ -197,9 +197,9 @@ public class AsynchronousLogin implements AsynchronousProcess {
// task, we schedule it in the end // task, we schedule it in the end
// so that we can be sure, and have not to care if it might be // so that we can be sure, and have not to care if it might be
// processed in other order. // processed in other order.
LimboPlayer limboPlayer = limboCache.getLimboPlayer(name); PlayerData playerData = limboCache.getPlayerData(name);
if (limboPlayer != null) { if (playerData != null) {
limboPlayer.clearTasks(); playerData.clearTasks();
} }
syncProcessManager.processSyncPlayerLogin(player); syncProcessManager.processSyncPlayerLogin(player);
} else if (player.isOnline()) { } else if (player.isOnline()) {

View File

@ -5,7 +5,7 @@ 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.auth.PlayerAuth;
import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.cache.limbo.LimboPlayer; 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;
@ -83,7 +83,7 @@ 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 LimboPlayer limbo = limboCache.getLimboPlayer(name); final PlayerData limbo = limboCache.getPlayerData(name);
final PlayerAuth auth = dataSource.getAuth(name); final PlayerAuth auth = dataSource.getAuth(name);
if (limbo != null) { if (limbo != null) {
@ -112,7 +112,7 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
} }
// Clean up no longer used temporary data // Clean up no longer used temporary data
limboCache.deleteLimboPlayer(player); limboCache.deletePlayerData(player);
} }
// We can now display the join message (if delayed) // We can now display the join message (if delayed)

View File

@ -50,7 +50,7 @@ public class AsynchronousLogout implements AsynchronousProcess {
database.updateQuitLoc(auth); database.updateQuitLoc(auth);
} }
limboCache.updateLimboPlayer(player); limboCache.updatePlayerData(player);
playerCache.removePlayer(name); playerCache.removePlayer(name);
database.setUnlogged(name); database.setUnlogged(name);
syncProcessManager.processSyncPlayerLogout(player); syncProcessManager.processSyncPlayerLogout(player);

View File

@ -14,7 +14,7 @@ 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.settings.properties.RestrictionSettings;
import fr.xephi.authme.task.LimboPlayerTaskManager; import fr.xephi.authme.task.PlayerDataTaskManager;
import fr.xephi.authme.util.BukkitService; import fr.xephi.authme.util.BukkitService;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
@ -40,7 +40,7 @@ public class ProcessSynchronousPlayerLogout implements SynchronousProcess {
private ProtocolLibService protocolLibService; private ProtocolLibService protocolLibService;
@Inject @Inject
private LimboPlayerTaskManager limboPlayerTaskManager; private PlayerDataTaskManager playerDataTaskManager;
@Inject @Inject
private SessionManager sessionManager; private SessionManager sessionManager;
@ -66,8 +66,8 @@ public class ProcessSynchronousPlayerLogout implements SynchronousProcess {
protocolLibService.sendBlankInventoryPacket(player); protocolLibService.sendBlankInventoryPacket(player);
} }
limboPlayerTaskManager.registerTimeoutTask(player); playerDataTaskManager.registerTimeoutTask(player);
limboPlayerTaskManager.registerMessageTask(name, true); playerDataTaskManager.registerMessageTask(name, true);
applyLogoutEffect(player); applyLogoutEffect(player);

View File

@ -57,7 +57,7 @@ public class AsynchronousQuit implements AsynchronousProcess {
String ip = Utils.getPlayerIp(player); String ip = Utils.getPlayerIp(player);
if (playerCache.isAuthenticated(name)) { if (playerCache.isAuthenticated(name)) {
if (service.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)) { if (service.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)) {
Location loc = player.isDead() ? spawnLoader.getSpawnLocation(player) : player.getLocation(); Location loc = spawnLoader.getPlayerLocationOrSpawn(player);
PlayerAuth auth = PlayerAuth.builder() PlayerAuth auth = PlayerAuth.builder()
.name(name).location(loc) .name(name).location(loc)
.realName(player.getName()).build(); .realName(player.getName()).build();

View File

@ -1,8 +1,8 @@
package fr.xephi.authme.process.quit; package fr.xephi.authme.process.quit;
import fr.xephi.authme.cache.backup.JsonCache; 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.LimboPlayer; 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.settings.properties.RestrictionSettings;
@ -16,7 +16,7 @@ import javax.inject.Inject;
public class ProcessSyncronousPlayerQuit implements SynchronousProcess { public class ProcessSyncronousPlayerQuit implements SynchronousProcess {
@Inject @Inject
private JsonCache jsonCache; private PlayerDataStorage playerDataStorage;
@Inject @Inject
private ProcessService service; private ProcessService service;
@ -25,26 +25,26 @@ public class ProcessSyncronousPlayerQuit implements SynchronousProcess {
private LimboCache limboCache; private LimboCache limboCache;
public void processSyncQuit(Player player) { public void processSyncQuit(Player player) {
LimboPlayer limbo = limboCache.getLimboPlayer(player.getName().toLowerCase()); PlayerData limbo = limboCache.getPlayerData(player.getName().toLowerCase());
if (limbo != null) { // it mean player is not authenticated if (limbo != null) { // it mean player is not authenticated
// Only delete if we don't need player's last location // Only delete if we don't need player's last location
if (service.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)) { if (service.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)) {
limboCache.removeLimboPlayer(player); limboCache.removePlayerData(player);
} else { } else {
// Restore data if its about to delete LimboPlayer // Restore data if its about to delete PlayerData
if (!StringUtils.isEmpty(limbo.getGroup())) { if (!StringUtils.isEmpty(limbo.getGroup())) {
Utils.addNormal(player, limbo.getGroup()); Utils.addNormal(player, limbo.getGroup());
} }
player.setOp(limbo.isOperator()); player.setOp(limbo.isOperator());
player.setAllowFlight(limbo.isCanFly()); player.setAllowFlight(limbo.isCanFly());
player.setWalkSpeed(limbo.getWalkSpeed()); player.setWalkSpeed(limbo.getWalkSpeed());
limboCache.deleteLimboPlayer(player); limboCache.deletePlayerData(player);
} }
} else { } else {
// Write player's location, so we could retrieve it later on player next join // Write player's location, so we could retrieve it later on player next join
if (service.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)) { if (service.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)) {
if (!jsonCache.doesCacheExist(player)) { if (!playerDataStorage.hasData(player)) {
jsonCache.writeCache(player); playerDataStorage.saveData(player);
} }
} }
} }

View File

@ -7,7 +7,7 @@ import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.process.SynchronousProcess; import fr.xephi.authme.process.SynchronousProcess;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.SecuritySettings; import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.task.LimboPlayerTaskManager; import fr.xephi.authme.task.PlayerDataTaskManager;
import fr.xephi.authme.util.Utils; import fr.xephi.authme.util.Utils;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -20,7 +20,7 @@ public class ProcessSyncEmailRegister implements SynchronousProcess {
private ProcessService service; private ProcessService service;
@Inject @Inject
private LimboPlayerTaskManager limboPlayerTaskManager; private PlayerDataTaskManager playerDataTaskManager;
ProcessSyncEmailRegister() { } ProcessSyncEmailRegister() { }
@ -32,8 +32,8 @@ public class ProcessSyncEmailRegister implements SynchronousProcess {
} }
service.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED); service.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED);
limboPlayerTaskManager.registerTimeoutTask(player); playerDataTaskManager.registerTimeoutTask(player);
limboPlayerTaskManager.registerMessageTask(name, true); playerDataTaskManager.registerMessageTask(name, true);
player.saveData(); player.saveData();
if (!service.getProperty(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE)) { if (!service.getProperty(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE)) {

View File

@ -5,7 +5,7 @@ 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.LimboPlayer; 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;
@ -18,7 +18,7 @@ import fr.xephi.authme.settings.properties.EmailSettings;
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.SecuritySettings; import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.task.LimboPlayerTaskManager; import fr.xephi.authme.task.PlayerDataTaskManager;
import fr.xephi.authme.util.BukkitService; import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.Utils; import fr.xephi.authme.util.Utils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -49,7 +49,7 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
private LimboCache limboCache; private LimboCache limboCache;
@Inject @Inject
private LimboPlayerTaskManager limboPlayerTaskManager; private PlayerDataTaskManager playerDataTaskManager;
ProcessSyncPasswordRegister() { } ProcessSyncPasswordRegister() { }
@ -82,9 +82,9 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
final String name = player.getName().toLowerCase(); final String name = player.getName().toLowerCase();
Utils.teleportToSpawn(player); Utils.teleportToSpawn(player);
limboCache.updateLimboPlayer(player); limboCache.updatePlayerData(player);
limboPlayerTaskManager.registerTimeoutTask(player); playerDataTaskManager.registerTimeoutTask(player);
limboPlayerTaskManager.registerMessageTask(name, true); playerDataTaskManager.registerMessageTask(name, true);
if (player.isInsideVehicle() && player.getVehicle() != null) { if (player.isInsideVehicle() && player.getVehicle() != null) {
player.getVehicle().eject(); player.getVehicle().eject();
@ -93,7 +93,7 @@ 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();
LimboPlayer limbo = limboCache.getLimboPlayer(name); PlayerData limbo = limboCache.getPlayerData(name);
if (limbo != null) { if (limbo != null) {
Utils.teleportToSpawn(player); Utils.teleportToSpawn(player);
@ -105,7 +105,7 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
} }
} }
limboCache.deleteLimboPlayer(player); limboCache.deletePlayerData(player);
} }
if (!Settings.getRegisteredGroup.isEmpty()) { if (!Settings.getRegisteredGroup.isEmpty()) {

View File

@ -13,7 +13,7 @@ import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
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.settings.properties.RestrictionSettings;
import fr.xephi.authme.task.LimboPlayerTaskManager; import fr.xephi.authme.task.PlayerDataTaskManager;
import fr.xephi.authme.util.Utils; import fr.xephi.authme.util.Utils;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
@ -41,7 +41,7 @@ public class AsynchronousUnregister implements AsynchronousProcess {
private LimboCache limboCache; private LimboCache limboCache;
@Inject @Inject
private LimboPlayerTaskManager limboPlayerTaskManager; private PlayerDataTaskManager playerDataTaskManager;
AsynchronousUnregister() { } AsynchronousUnregister() { }
@ -62,9 +62,9 @@ public class AsynchronousUnregister implements AsynchronousProcess {
if (!Settings.getRegisteredGroup.isEmpty()) { if (!Settings.getRegisteredGroup.isEmpty()) {
service.setGroup(player, AuthGroupType.UNREGISTERED); service.setGroup(player, AuthGroupType.UNREGISTERED);
} }
limboCache.addLimboPlayer(player); limboCache.addPlayerData(player);
limboPlayerTaskManager.registerTimeoutTask(player); playerDataTaskManager.registerTimeoutTask(player);
limboPlayerTaskManager.registerMessageTask(name, false); playerDataTaskManager.registerMessageTask(name, false);
service.send(player, MessageKey.UNREGISTERED_SUCCESS); service.send(player, MessageKey.UNREGISTERED_SUCCESS);
ConsoleLogger.info(player.getDisplayName() + " unregistered himself"); ConsoleLogger.info(player.getDisplayName() + " unregistered himself");

View File

@ -19,8 +19,6 @@ public final class Settings {
public static boolean isPermissionCheckEnabled; public static boolean isPermissionCheckEnabled;
public static boolean isTeleportToSpawnEnabled; public static boolean isTeleportToSpawnEnabled;
public static boolean isAllowRestrictedIp; public static boolean isAllowRestrictedIp;
public static boolean isSaveQuitLocationEnabled;
public static boolean protectInventoryBeforeLogInEnabled;
public static boolean isStopEnabled; public static boolean isStopEnabled;
public static boolean reloadSupport; public static boolean reloadSupport;
public static boolean noTeleport; public static boolean noTeleport;
@ -45,8 +43,6 @@ public final class Settings {
isPermissionCheckEnabled = load(PluginSettings.ENABLE_PERMISSION_CHECK); isPermissionCheckEnabled = load(PluginSettings.ENABLE_PERMISSION_CHECK);
isTeleportToSpawnEnabled = load(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN); isTeleportToSpawnEnabled = load(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN);
isAllowRestrictedIp = load(RestrictionSettings.ENABLE_RESTRICTED_USERS); isAllowRestrictedIp = load(RestrictionSettings.ENABLE_RESTRICTED_USERS);
isSaveQuitLocationEnabled = load(RestrictionSettings.SAVE_QUIT_LOCATION);
isRemoveSpeedEnabled = load(RestrictionSettings.REMOVE_SPEED);
getUnloggedinGroup = load(SecuritySettings.UNLOGGEDIN_GROUP); getUnloggedinGroup = load(SecuritySettings.UNLOGGEDIN_GROUP);
getNonActivatedGroup = configFile.getInt("ExternalBoardOptions.nonActivedUserGroup", -1); getNonActivatedGroup = configFile.getInt("ExternalBoardOptions.nonActivedUserGroup", -1);
unRegisteredGroup = configFile.getString("GroupOptions.UnregisteredPlayerGroup", ""); unRegisteredGroup = configFile.getString("GroupOptions.UnregisteredPlayerGroup", "");

View File

@ -43,9 +43,9 @@ public class SpawnLoader implements Reloadable {
* Constructor. * Constructor.
* *
* @param pluginFolder The AuthMe data folder * @param pluginFolder The AuthMe data folder
* @param settings The setting instance * @param settings The setting instance
* @param pluginHooks The plugin hooks instance * @param pluginHooks The plugin hooks instance
* @param dataSource The plugin auth database instance * @param dataSource The plugin auth database instance
*/ */
@Inject @Inject
public SpawnLoader(@DataFolder File pluginFolder, NewSetting settings, PluginHooks pluginHooks, public SpawnLoader(@DataFolder File pluginFolder, NewSetting settings, PluginHooks pluginHooks,
@ -83,6 +83,7 @@ public class SpawnLoader implements Reloadable {
* Set the AuthMe spawn point. * Set the AuthMe spawn point.
* *
* @param location The location to use * @param location The location to use
*
* @return True upon success, false otherwise * @return True upon success, false otherwise
*/ */
public boolean setSpawn(Location location) { public boolean setSpawn(Location location) {
@ -102,6 +103,7 @@ public class SpawnLoader implements Reloadable {
* Set the AuthMe first spawn location. * Set the AuthMe first spawn location.
* *
* @param location The location to use * @param location The location to use
*
* @return True upon success, false otherwise * @return True upon success, false otherwise
*/ */
public boolean setFirstSpawn(Location location) { public boolean setFirstSpawn(Location location) {
@ -140,7 +142,9 @@ public class SpawnLoader implements Reloadable {
* depending on the spawn priority setting. * depending on the spawn priority setting.
* *
* @param player The player to retrieve the spawn point for * @param player The player to retrieve the spawn point for
*
* @return The spawn location, or the default spawn location upon failure * @return The spawn location, or the default spawn location upon failure
*
* @see RestrictionSettings#SPAWN_PRIORITY * @see RestrictionSettings#SPAWN_PRIORITY
*/ */
public Location getSpawnLocation(Player player) { public Location getSpawnLocation(Player player) {
@ -187,8 +191,9 @@ public class SpawnLoader implements Reloadable {
/** /**
* Save the location under the given prefix. * Save the location under the given prefix.
* *
* @param prefix The prefix to save the spawn under * @param prefix The prefix to save the spawn under
* @param location The location to persist * @param location The location to persist
*
* @return True upon success, false otherwise * @return True upon success, false otherwise
*/ */
private boolean setLocation(String prefix, Location location) { private boolean setLocation(String prefix, Location location) {
@ -214,11 +219,26 @@ public class SpawnLoader implements Reloadable {
return false; return false;
} }
/**
* Return player's location if player is alive, or player's spawn location if dead.
*
* @param player player to retrieve
*
* @return location of the given player if alive, spawn location if dead.
*/
public Location getPlayerLocationOrSpawn(Player player) {
if (player.isOnline() && player.isDead()) {
return getSpawnLocation(player);
}
return player.getLocation();
}
/** /**
* Build a {@link Location} object from the given path in the file configuration. * Build a {@link Location} object from the given path in the file configuration.
* *
* @param configuration The file configuration to read from * @param configuration The file configuration to read from
* @param pathPrefix The path to get the spawn point from * @param pathPrefix The path to get the spawn point from
*
* @return Location corresponding to the values in the path * @return Location corresponding to the values in the path
*/ */
private static Location getLocationFromConfiguration(FileConfiguration configuration, String pathPrefix) { private static Location getLocationFromConfiguration(FileConfiguration configuration, String pathPrefix) {
@ -240,7 +260,8 @@ public class SpawnLoader implements Reloadable {
* under the given path. * under the given path.
* *
* @param configuration The file configuration to use * @param configuration The file configuration to use
* @param pathPrefix The path to verify * @param pathPrefix The path to verify
*
* @return True if all spawn fields are present, false otherwise * @return True if all spawn fields are present, false otherwise
*/ */
private static boolean containsAllSpawnFields(FileConfiguration configuration, String pathPrefix) { private static boolean containsAllSpawnFields(FileConfiguration configuration, String pathPrefix) {
@ -257,7 +278,8 @@ public class SpawnLoader implements Reloadable {
* Retrieve a property as a float from the given file configuration. * Retrieve a property as a float from the given file configuration.
* *
* @param configuration The file configuration to use * @param configuration The file configuration to use
* @param path The path of the property to retrieve * @param path The path of the property to retrieve
*
* @return The float * @return The float
*/ */
private static float getFloat(FileConfiguration configuration, String path) { private static float getFloat(FileConfiguration configuration, String path) {

View File

@ -45,8 +45,8 @@ public class MessageTask implements Runnable {
player.sendMessage(ms); player.sendMessage(ms);
} }
BukkitTask nextTask = bukkitService.runTaskLater(this, interval * TICKS_PER_SECOND); BukkitTask nextTask = bukkitService.runTaskLater(this, interval * TICKS_PER_SECOND);
if (limboCache.hasLimboPlayer(name)) { if (limboCache.hasPlayerData(name)) {
limboCache.getLimboPlayer(name).setMessageTask(nextTask); limboCache.getPlayerData(name).setMessageTask(nextTask);
} }
return; return;
} }

View File

@ -3,7 +3,7 @@ package fr.xephi.authme.task;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.cache.limbo.LimboPlayer; import fr.xephi.authme.cache.limbo.PlayerData;
import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages; import fr.xephi.authme.output.Messages;
import fr.xephi.authme.settings.NewSetting; import fr.xephi.authme.settings.NewSetting;
@ -18,9 +18,9 @@ import javax.inject.Inject;
import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND; import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND;
/** /**
* Registers tasks associated with a LimboPlayer. * Registers tasks associated with a PlayerData.
*/ */
public class LimboPlayerTaskManager { public class PlayerDataTaskManager {
@Inject @Inject
private Messages messages; private Messages messages;
@ -37,7 +37,8 @@ public class LimboPlayerTaskManager {
@Inject @Inject
private PlayerCache playerCache; private PlayerCache playerCache;
LimboPlayerTaskManager() { } PlayerDataTaskManager() {
}
/** /**
@ -51,14 +52,14 @@ public class LimboPlayerTaskManager {
final int interval = settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL); final int interval = settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
final MessageKey key = getMessageKey(isRegistered); final MessageKey key = getMessageKey(isRegistered);
if (interval > 0) { if (interval > 0) {
final LimboPlayer limboPlayer = limboCache.getLimboPlayer(name); final PlayerData playerData = limboCache.getPlayerData(name);
if (limboPlayer == null) { if (playerData == null) {
ConsoleLogger.info("LimboPlayer for '" + name + "' is not available"); ConsoleLogger.info("PlayerData for '" + name + "' is not available");
} else { } else {
cancelTask(limboPlayer.getMessageTask()); cancelTask(playerData.getMessageTask());
BukkitTask messageTask = bukkitService.runTask(new MessageTask(name, messages.retrieve(key), BukkitTask messageTask = bukkitService.runTask(new MessageTask(name, messages.retrieve(key),
interval, bukkitService, limboCache, playerCache)); interval, bukkitService, limboCache, playerCache));
limboPlayer.setMessageTask(messageTask); playerData.setMessageTask(messageTask);
} }
} }
} }
@ -71,14 +72,14 @@ public class LimboPlayerTaskManager {
public void registerTimeoutTask(Player player) { public void registerTimeoutTask(Player player) {
final int timeout = settings.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND; final int timeout = settings.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
if (timeout > 0) { if (timeout > 0) {
final LimboPlayer limboPlayer = limboCache.getLimboPlayer(player.getName()); final PlayerData playerData = limboCache.getPlayerData(player.getName());
if (limboPlayer == null) { if (playerData == null) {
ConsoleLogger.info("LimboPlayer for '" + player.getName() + "' is not available"); ConsoleLogger.info("PlayerData for '" + player.getName() + "' is not available");
} else { } else {
cancelTask(limboPlayer.getTimeoutTask()); cancelTask(playerData.getTimeoutTask());
String message = messages.retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR); String message = messages.retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR);
BukkitTask task = bukkitService.runTaskLater(new TimeoutTask(player, message, playerCache), timeout); BukkitTask task = bukkitService.runTaskLater(new TimeoutTask(player, message, playerCache), timeout);
limboPlayer.setTimeoutTask(task); playerData.setTimeoutTask(task);
} }
} }
} }

View File

@ -2,7 +2,7 @@ package fr.xephi.authme.util;
import fr.xephi.authme.cache.auth.PlayerAuth; 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.limbo.LimboPlayer; import fr.xephi.authme.cache.limbo.PlayerData;
import fr.xephi.authme.events.AbstractTeleportEvent; import fr.xephi.authme.events.AbstractTeleportEvent;
import fr.xephi.authme.events.AuthMeTeleportEvent; import fr.xephi.authme.events.AuthMeTeleportEvent;
import fr.xephi.authme.events.FirstSpawnTeleportEvent; import fr.xephi.authme.events.FirstSpawnTeleportEvent;
@ -94,14 +94,14 @@ public class TeleportationService implements Reloadable {
* *
* @param player the player * @param player the player
* @param auth corresponding PlayerAuth object * @param auth corresponding PlayerAuth object
* @param limbo corresponding LimboPlayer object * @param limbo corresponding PlayerData object
*/ */
public void teleportOnLogin(final Player player, PlayerAuth auth, LimboPlayer limbo) { public void teleportOnLogin(final Player player, PlayerAuth auth, PlayerData limbo) {
if (settings.getProperty(RestrictionSettings.NO_TELEPORT)) { if (settings.getProperty(RestrictionSettings.NO_TELEPORT)) {
return; return;
} }
// The world in LimboPlayer 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.getLoc().getWorld().getName();
if (mustForceSpawnAfterLogin(worldName)) { if (mustForceSpawnAfterLogin(worldName)) {
teleportToSpawn(player, true); teleportToSpawn(player, true);

View File

@ -72,7 +72,16 @@ public final class Utils {
} }
} }
/**
* Get player's UUID if can, name otherwise.
*
* @param player Player to retrieve
*
* @return player's UUID or Name in String.
*/
public static String getUUIDorName(OfflinePlayer player) { public static String getUUIDorName(OfflinePlayer player) {
// We may made this configurable in future
// so we can have uuid support.
try { try {
return player.getUniqueId().toString(); return player.getUniqueId().toString();
} catch (Exception ignore) { } catch (Exception ignore) {
@ -80,6 +89,13 @@ public final class Utils {
} }
} }
/**
* Compile Pattern sneaky without throwing Exception.
*
* @param pattern pattern string to compile
*
* @return the given regex compiled into Pattern object.
*/
public static Pattern safePatternCompile(String pattern) { public static Pattern safePatternCompile(String pattern) {
try { try {
return Pattern.compile(pattern); return Pattern.compile(pattern);

View File

@ -3,7 +3,7 @@ package fr.xephi.authme.task;
import fr.xephi.authme.TestHelper; import fr.xephi.authme.TestHelper;
import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.cache.limbo.LimboPlayer; import fr.xephi.authme.cache.limbo.PlayerData;
import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages; import fr.xephi.authme.output.Messages;
import fr.xephi.authme.settings.NewSetting; import fr.xephi.authme.settings.NewSetting;
@ -28,13 +28,13 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.verifyZeroInteractions;
/** /**
* Test for {@link LimboPlayerTaskManager}. * Test for {@link PlayerDataTaskManager}.
*/ */
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public class LimboPlayerTaskManagerTest { public class PlayerDataTaskManagerTest {
@InjectMocks @InjectMocks
private LimboPlayerTaskManager limboPlayerTaskManager; private PlayerDataTaskManager playerDataTaskManager;
@Mock @Mock
private Messages messages; private Messages messages;
@ -60,8 +60,8 @@ public class LimboPlayerTaskManagerTest {
public void shouldRegisterMessageTask() { public void shouldRegisterMessageTask() {
// given // given
String name = "bobby"; String name = "bobby";
LimboPlayer limboPlayer = mock(LimboPlayer.class); PlayerData playerData = mock(PlayerData.class);
given(limboCache.getLimboPlayer(name)).willReturn(limboPlayer); given(limboCache.getPlayerData(name)).willReturn(playerData);
MessageKey key = MessageKey.REGISTER_EMAIL_MESSAGE; MessageKey key = MessageKey.REGISTER_EMAIL_MESSAGE;
given(messages.retrieve(key)).willReturn(new String[]{"Please register!"}); given(messages.retrieve(key)).willReturn(new String[]{"Please register!"});
BukkitTask bukkiTask = mock(BukkitTask.class); BukkitTask bukkiTask = mock(BukkitTask.class);
@ -70,10 +70,10 @@ public class LimboPlayerTaskManagerTest {
given(settings.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true); given(settings.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
// when // when
limboPlayerTaskManager.registerMessageTask(name, false); playerDataTaskManager.registerMessageTask(name, false);
// then // then
verify(limboPlayer).setMessageTask(bukkiTask); verify(playerData).setMessageTask(bukkiTask);
verify(messages).retrieve(key); verify(messages).retrieve(key);
} }
@ -81,14 +81,14 @@ public class LimboPlayerTaskManagerTest {
public void shouldNotScheduleTaskForMissingLimboPlayer() { public void shouldNotScheduleTaskForMissingLimboPlayer() {
// given // given
String name = "ghost"; String name = "ghost";
given(limboCache.getLimboPlayer(name)).willReturn(null); given(limboCache.getPlayerData(name)).willReturn(null);
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(5); given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(5);
// when // when
limboPlayerTaskManager.registerMessageTask(name, true); playerDataTaskManager.registerMessageTask(name, true);
// then // then
verify(limboCache).getLimboPlayer(name); verify(limboCache).getPlayerData(name);
verifyZeroInteractions(bukkitService); verifyZeroInteractions(bukkitService);
verifyZeroInteractions(messages); verifyZeroInteractions(messages);
} }
@ -97,28 +97,28 @@ public class LimboPlayerTaskManagerTest {
public void shouldNotScheduleTaskForZeroAsInterval() { public void shouldNotScheduleTaskForZeroAsInterval() {
// given // given
String name = "Tester1"; String name = "Tester1";
LimboPlayer limboPlayer = mock(LimboPlayer.class); PlayerData playerData = mock(PlayerData.class);
given(limboCache.getLimboPlayer(name)).willReturn(limboPlayer); given(limboCache.getPlayerData(name)).willReturn(playerData);
BukkitTask bukkiTask = mock(BukkitTask.class); BukkitTask bukkiTask = mock(BukkitTask.class);
given(bukkitService.runTask(any(MessageTask.class))).willReturn(bukkiTask); given(bukkitService.runTask(any(MessageTask.class))).willReturn(bukkiTask);
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(0); given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(0);
// when // when
limboPlayerTaskManager.registerMessageTask(name, true); playerDataTaskManager.registerMessageTask(name, true);
// then // then
verifyZeroInteractions(limboPlayer, bukkitService); verifyZeroInteractions(playerData, bukkitService);
} }
@Test @Test
public void shouldCancelExistingMessageTask() { public void shouldCancelExistingMessageTask() {
// given // given
LimboPlayer limboPlayer = mock(LimboPlayer.class); PlayerData playerData = mock(PlayerData.class);
BukkitTask existingMessageTask = mock(BukkitTask.class); BukkitTask existingMessageTask = mock(BukkitTask.class);
given(limboPlayer.getMessageTask()).willReturn(existingMessageTask); given(playerData.getMessageTask()).willReturn(existingMessageTask);
String name = "bobby"; String name = "bobby";
given(limboCache.getLimboPlayer(name)).willReturn(limboPlayer); given(limboCache.getPlayerData(name)).willReturn(playerData);
given(messages.retrieve(MessageKey.REGISTER_EMAIL_MESSAGE)) given(messages.retrieve(MessageKey.REGISTER_EMAIL_MESSAGE))
.willReturn(new String[]{"Please register", "Use /register"}); .willReturn(new String[]{"Please register", "Use /register"});
@ -128,10 +128,10 @@ public class LimboPlayerTaskManagerTest {
given(settings.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true); given(settings.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
// when // when
limboPlayerTaskManager.registerMessageTask(name, false); playerDataTaskManager.registerMessageTask(name, false);
// then // then
verify(limboPlayer).setMessageTask(bukkiTask); verify(playerData).setMessageTask(bukkiTask);
verify(messages).retrieve(MessageKey.REGISTER_EMAIL_MESSAGE); verify(messages).retrieve(MessageKey.REGISTER_EMAIL_MESSAGE);
verify(existingMessageTask).cancel(); verify(existingMessageTask).cancel();
} }
@ -142,17 +142,17 @@ public class LimboPlayerTaskManagerTest {
String name = "l33tPlayer"; String name = "l33tPlayer";
Player player = mock(Player.class); Player player = mock(Player.class);
given(player.getName()).willReturn(name); given(player.getName()).willReturn(name);
LimboPlayer limboPlayer = mock(LimboPlayer.class); PlayerData playerData = mock(PlayerData.class);
given(limboCache.getLimboPlayer(name)).willReturn(limboPlayer); given(limboCache.getPlayerData(name)).willReturn(playerData);
given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(30); given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(30);
BukkitTask bukkitTask = mock(BukkitTask.class); BukkitTask bukkitTask = mock(BukkitTask.class);
given(bukkitService.runTaskLater(any(TimeoutTask.class), anyLong())).willReturn(bukkitTask); given(bukkitService.runTaskLater(any(TimeoutTask.class), anyLong())).willReturn(bukkitTask);
// when // when
limboPlayerTaskManager.registerTimeoutTask(player); playerDataTaskManager.registerTimeoutTask(player);
// then // then
verify(limboPlayer).setTimeoutTask(bukkitTask); verify(playerData).setTimeoutTask(bukkitTask);
verify(bukkitService).runTaskLater(any(TimeoutTask.class), eq(600L)); // 30 * TICKS_PER_SECOND verify(bukkitService).runTaskLater(any(TimeoutTask.class), eq(600L)); // 30 * TICKS_PER_SECOND
verify(messages).retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR); verify(messages).retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR);
} }
@ -163,11 +163,11 @@ public class LimboPlayerTaskManagerTest {
String name = "Phantom_"; String name = "Phantom_";
Player player = mock(Player.class); Player player = mock(Player.class);
given(player.getName()).willReturn(name); given(player.getName()).willReturn(name);
given(limboCache.getLimboPlayer(name)).willReturn(null); given(limboCache.getPlayerData(name)).willReturn(null);
given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(27); given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(27);
// when // when
limboPlayerTaskManager.registerTimeoutTask(player); playerDataTaskManager.registerTimeoutTask(player);
// then // then
verifyZeroInteractions(bukkitService, messages); verifyZeroInteractions(bukkitService, messages);
@ -179,15 +179,15 @@ public class LimboPlayerTaskManagerTest {
String name = "snail"; String name = "snail";
Player player = mock(Player.class); Player player = mock(Player.class);
given(player.getName()).willReturn(name); given(player.getName()).willReturn(name);
LimboPlayer limboPlayer = mock(LimboPlayer.class); PlayerData playerData = mock(PlayerData.class);
given(limboCache.getLimboPlayer(name)).willReturn(limboPlayer); given(limboCache.getPlayerData(name)).willReturn(playerData);
given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(0); given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(0);
// when // when
limboPlayerTaskManager.registerTimeoutTask(player); playerDataTaskManager.registerTimeoutTask(player);
// then // then
verifyZeroInteractions(limboPlayer, bukkitService); verifyZeroInteractions(playerData, bukkitService);
} }
@Test @Test
@ -196,20 +196,20 @@ public class LimboPlayerTaskManagerTest {
String name = "l33tPlayer"; String name = "l33tPlayer";
Player player = mock(Player.class); Player player = mock(Player.class);
given(player.getName()).willReturn(name); given(player.getName()).willReturn(name);
LimboPlayer limboPlayer = mock(LimboPlayer.class); PlayerData playerData = mock(PlayerData.class);
BukkitTask existingTask = mock(BukkitTask.class); BukkitTask existingTask = mock(BukkitTask.class);
given(limboPlayer.getTimeoutTask()).willReturn(existingTask); given(playerData.getTimeoutTask()).willReturn(existingTask);
given(limboCache.getLimboPlayer(name)).willReturn(limboPlayer); given(limboCache.getPlayerData(name)).willReturn(playerData);
given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(18); given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(18);
BukkitTask bukkitTask = mock(BukkitTask.class); BukkitTask bukkitTask = mock(BukkitTask.class);
given(bukkitService.runTaskLater(any(TimeoutTask.class), anyLong())).willReturn(bukkitTask); given(bukkitService.runTaskLater(any(TimeoutTask.class), anyLong())).willReturn(bukkitTask);
// when // when
limboPlayerTaskManager.registerTimeoutTask(player); playerDataTaskManager.registerTimeoutTask(player);
// then // then
verify(existingTask).cancel(); verify(existingTask).cancel();
verify(limboPlayer).setTimeoutTask(bukkitTask); verify(playerData).setTimeoutTask(bukkitTask);
verify(bukkitService).runTaskLater(any(TimeoutTask.class), eq(360L)); // 18 * TICKS_PER_SECOND verify(bukkitService).runTaskLater(any(TimeoutTask.class), eq(360L)); // 18 * TICKS_PER_SECOND
verify(messages).retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR); verify(messages).retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR);
} }

View File

@ -2,7 +2,7 @@ package fr.xephi.authme.util;
import fr.xephi.authme.cache.auth.PlayerAuth; 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.limbo.LimboPlayer; import fr.xephi.authme.cache.limbo.PlayerData;
import fr.xephi.authme.events.FirstSpawnTeleportEvent; import fr.xephi.authme.events.FirstSpawnTeleportEvent;
import fr.xephi.authme.events.SpawnTeleportEvent; import fr.xephi.authme.events.SpawnTeleportEvent;
import fr.xephi.authme.settings.NewSetting; import fr.xephi.authme.settings.NewSetting;
@ -259,7 +259,7 @@ public class TeleportationServiceTest {
given(settings.getProperty(RestrictionSettings.NO_TELEPORT)).willReturn(true); given(settings.getProperty(RestrictionSettings.NO_TELEPORT)).willReturn(true);
Player player = mock(Player.class); Player player = mock(Player.class);
PlayerAuth auth = mock(PlayerAuth.class); PlayerAuth auth = mock(PlayerAuth.class);
LimboPlayer limbo = mock(LimboPlayer.class); PlayerData limbo = mock(PlayerData.class);
// when // when
teleportationService.teleportOnLogin(player, auth, limbo); teleportationService.teleportOnLogin(player, auth, limbo);
@ -277,7 +277,7 @@ public class TeleportationServiceTest {
Location spawn = mockLocation(); Location spawn = mockLocation();
given(spawnLoader.getSpawnLocation(player)).willReturn(spawn); given(spawnLoader.getSpawnLocation(player)).willReturn(spawn);
PlayerAuth auth = mock(PlayerAuth.class); PlayerAuth auth = mock(PlayerAuth.class);
LimboPlayer limbo = mock(LimboPlayer.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.getLoc()).willReturn(limboLocation);
@ -301,7 +301,7 @@ public class TeleportationServiceTest {
Location spawn = mockLocation(); Location spawn = mockLocation();
given(spawnLoader.getSpawnLocation(player)).willReturn(spawn); given(spawnLoader.getSpawnLocation(player)).willReturn(spawn);
PlayerAuth auth = mock(PlayerAuth.class); PlayerAuth auth = mock(PlayerAuth.class);
LimboPlayer limbo = mock(LimboPlayer.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.getLoc()).willReturn(limboLocation);
@ -328,7 +328,7 @@ public class TeleportationServiceTest {
Player player = mock(Player.class); Player player = mock(Player.class);
given(player.isOnline()).willReturn(true); given(player.isOnline()).willReturn(true);
LimboPlayer limbo = mock(LimboPlayer.class); PlayerData limbo = mock(PlayerData.class);
Location limboLocation = mockLocation(); Location limboLocation = mockLocation();
given(limbo.getLoc()).willReturn(limboLocation); given(limbo.getLoc()).willReturn(limboLocation);
@ -357,7 +357,7 @@ public class TeleportationServiceTest {
given(player.isOnline()).willReturn(true); given(player.isOnline()).willReturn(true);
World world = mock(World.class); World world = mock(World.class);
given(player.getWorld()).willReturn(world); given(player.getWorld()).willReturn(world);
LimboPlayer limbo = mock(LimboPlayer.class); PlayerData limbo = mock(PlayerData.class);
Location limboLocation = mockLocation(); Location limboLocation = mockLocation();
given(limbo.getLoc()).willReturn(limboLocation); given(limbo.getLoc()).willReturn(limboLocation);
@ -385,7 +385,7 @@ public class TeleportationServiceTest {
given(player.isOnline()).willReturn(true); given(player.isOnline()).willReturn(true);
World world = mock(World.class); World world = mock(World.class);
given(player.getWorld()).willReturn(world); given(player.getWorld()).willReturn(world);
LimboPlayer limbo = mock(LimboPlayer.class); PlayerData limbo = mock(PlayerData.class);
Location location = mockLocation(); Location location = mockLocation();
given(limbo.getLoc()).willReturn(location); given(limbo.getLoc()).willReturn(location);
@ -410,7 +410,7 @@ public class TeleportationServiceTest {
given(player.isOnline()).willReturn(true); given(player.isOnline()).willReturn(true);
World world = mock(World.class); World world = mock(World.class);
given(player.getWorld()).willReturn(world); given(player.getWorld()).willReturn(world);
LimboPlayer limbo = mock(LimboPlayer.class); PlayerData limbo = mock(PlayerData.class);
Location location = mockLocation(); Location location = mockLocation();
given(limbo.getLoc()).willReturn(location); given(limbo.getLoc()).willReturn(location);