Use JsonCache correctly, couldn't list all changes.

This commit is contained in:
DNx5 2016-06-28 21:36:58 +07:00
parent 874869cef8
commit 145747505f
17 changed files with 185 additions and 152 deletions

View File

@ -580,11 +580,12 @@ public class AuthMe extends JavaPlugin {
if (!Settings.noTeleport) { if (!Settings.noTeleport) {
player.teleport(limbo.getLoc()); player.teleport(limbo.getLoc());
} }
Utils.addNormal(player, limbo.getGroup()); Utils.addNormal(player, limbo.getGroup());
player.setOp(limbo.isOperator()); player.setOp(limbo.isOperator());
limbo.getTimeoutTask().cancel(); player.setAllowFlight(limbo.isCanFly());
limboCache.deleteLimboPlayer(name); player.setWalkSpeed(limbo.getWalkSpeed());
limbo.clearTasks();
limboCache.deleteLimboPlayer(player);
} }
PlayerCache.getInstance().removePlayer(name); PlayerCache.getInstance().removePlayer(name);
} }

View File

@ -12,8 +12,17 @@ import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer; import com.google.gson.JsonSerializer;
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.LimboPlayer;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.settings.SpawnLoader;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.FileUtils;
import fr.xephi.authme.util.Utils;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import javax.inject.Inject;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@ -22,110 +31,145 @@ public class JsonCache {
private final Gson gson; private final Gson gson;
private final File cacheDir; private final File cacheDir;
@Inject
private AuthMe plugin;
@Inject
private PermissionsManager permissionsManager;
@Inject
private SpawnLoader spawnLoader;
@Inject
private BukkitService bukkitService;
public JsonCache() { public JsonCache() {
cacheDir = new File(AuthMe.getInstance().getDataFolder(), "cache"); cacheDir = new File(plugin.getDataFolder(), "cache");
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 cache directory.");
} }
gson = new GsonBuilder() gson = new GsonBuilder()
.registerTypeAdapter(PlayerData.class, new PlayerDataSerializer()) .registerTypeAdapter(LimboPlayer.class, new LimboPlayerSerializer())
.registerTypeAdapter(PlayerData.class, new PlayerDataDeserializer()) .registerTypeAdapter(LimboPlayer.class, new LimboPlayerDeserializer())
.setPrettyPrinting() .setPrettyPrinting()
.create(); .create();
} }
public PlayerData readCache(Player player) { public LimboPlayer readCache(Player player) {
String name = player.getName().toLowerCase(); String id = Utils.getUUIDorName(player);
File file = new File(cacheDir, name + File.separator + "cache.json"); File file = new File(cacheDir, id + File.separator + "cache.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, PlayerData.class); return gson.fromJson(str, LimboPlayer.class);
} catch (IOException e) { } catch (IOException e) {
ConsoleLogger.writeStackTrace(e); ConsoleLogger.writeStackTrace(e);
return null; return null;
} }
} }
public void removeCache(Player player) { public void writeCache(Player player) {
String id = Utils.getUUIDorName(player);
String name = player.getName().toLowerCase(); String name = player.getName().toLowerCase();
File file = new File(cacheDir, name); Location location = player.isDead() ? spawnLoader.getSpawnLocation(player) : player.getLocation();
String group = permissionsManager.getPrimaryGroup(player);
boolean operator = player.isOp();
boolean canFly = player.getAllowFlight();
float walkSpeed = player.getWalkSpeed();
LimboPlayer limboPlayer = new LimboPlayer(name, location, operator, group, canFly, walkSpeed);
try {
File file = new File(cacheDir, id + File.separator + "cache.json");
Files.write(gson.toJson(limboPlayer), file, Charsets.UTF_8);
} catch (IOException e) {
ConsoleLogger.logException("Failed to write " + player.getName() + " cache.", e);
}
}
public void removeCache(Player player) {
String id = Utils.getUUIDorName(player);
File file = new File(cacheDir, id);
if (file.exists()) { if (file.exists()) {
purgeDirectory(file); FileUtils.purgeDirectory(file);
if (!file.delete()) { if (!file.delete()) {
ConsoleLogger.showError("Failed to remove" + player.getName() + "cache."); ConsoleLogger.showError("Failed to remove " + player.getName() + " cache.");
} }
} }
} }
public boolean doesCacheExist(Player player) { public boolean doesCacheExist(Player player) {
String name = player.getName().toLowerCase(); String id = Utils.getUUIDorName(player);
File file = new File(cacheDir, name + File.separator + "cache.json"); File file = new File(cacheDir, id + File.separator + "cache.json");
return file.exists(); return file.exists();
} }
private class PlayerDataDeserializer implements JsonDeserializer<PlayerData> { private class LimboPlayerDeserializer implements JsonDeserializer<LimboPlayer> {
@Override @Override
public PlayerData deserialize(JsonElement jsonElement, Type type, public LimboPlayer 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;
} }
String group = null;
Location loc = null;
String group = "";
boolean operator = false; boolean operator = false;
boolean fly = false; boolean canFly = false;
float walkSpeed = 0.2f;
JsonElement e; JsonElement e;
if ((e = jsonObject.getAsJsonObject("location")) != null) {
JsonObject obj = e.getAsJsonObject();
World world = bukkitService.getWorld(obj.get("world").getAsString());
if (world != null) {
double x = obj.get("x").getAsDouble();
double y = obj.get("y").getAsDouble();
double z = obj.get("z").getAsDouble();
float yaw = obj.get("yaw").getAsFloat();
float pitch = obj.get("pitch").getAsFloat();
loc = new Location(world, x, y, z, yaw, pitch);
}
}
if ((e = jsonObject.get("group")) != null) { if ((e = jsonObject.get("group")) != null) {
group = e.getAsString(); group = e.getAsString();
} }
if ((e = jsonObject.get("operator")) != null) { if ((e = jsonObject.get("operator")) != null) {
operator = e.getAsBoolean(); operator = e.getAsBoolean();
} }
if ((e = jsonObject.get("fly")) != null) { if ((e = jsonObject.get("can-fly")) != null) {
fly = e.getAsBoolean(); canFly = e.getAsBoolean();
}
if ((e = jsonObject.get("walk-speed")) != null) {
walkSpeed = e.getAsFloat();
} }
return new PlayerData(group, operator, fly); return new LimboPlayer("", loc, operator, group, canFly, walkSpeed);
} }
} }
private class PlayerDataSerializer implements JsonSerializer<PlayerData> { private class LimboPlayerSerializer implements JsonSerializer<LimboPlayer> {
@Override @Override
public JsonElement serialize(PlayerData playerData, Type type, public JsonElement serialize(LimboPlayer limboPlayer, Type type,
JsonSerializationContext context) { JsonSerializationContext context) {
JsonObject jsonObject = new JsonObject(); JsonObject obj = new JsonObject();
jsonObject.addProperty("group", playerData.getGroup()); obj.addProperty("group", limboPlayer.getGroup());
jsonObject.addProperty("operator", playerData.getOperator());
jsonObject.addProperty("fly", playerData.isFlyEnabled()); Location loc = limboPlayer.getLoc();
return jsonObject; JsonObject obj2 = new JsonObject();
obj2.addProperty("world", loc.getWorld().getName());
obj2.addProperty("x", loc.getX());
obj2.addProperty("y", loc.getY());
obj2.addProperty("z", loc.getZ());
obj2.addProperty("yaw", loc.getYaw());
obj2.addProperty("pitch", loc.getPitch());
obj.add("location", obj2);
obj.addProperty("operator", limboPlayer.isOperator());
obj.addProperty("can-fly", limboPlayer.isCanFly());
obj.addProperty("walk-speed", limboPlayer.getWalkSpeed());
return obj;
} }
} }
/**
* Delete a given directory and all its content.
*
* @param directory The directory to remove
*/
private static void purgeDirectory(File directory) {
if (!directory.isDirectory()) {
return;
}
File[] files = directory.listFiles();
if (files == null) {
return;
}
for (File target : files) {
if (target.isDirectory()) {
purgeDirectory(target);
}
target.delete();
}
}
} }

View File

@ -1,26 +0,0 @@
package fr.xephi.authme.cache.backup;
public class PlayerData {
private final String group;
private final boolean operator;
private final boolean flyEnabled;
public PlayerData(String group, boolean operator, boolean flyEnabled) {
this.group = group;
this.operator = operator;
this.flyEnabled = flyEnabled;
}
public String getGroup() {
return group;
}
public boolean getOperator() {
return operator;
}
public boolean isFlyEnabled() {
return flyEnabled;
}
}

View File

@ -1,7 +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.JsonCache;
import fr.xephi.authme.cache.backup.PlayerData;
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;
@ -41,36 +40,40 @@ public class LimboCache {
Location location = player.isDead() ? spawnLoader.getSpawnLocation(player) : player.getLocation(); Location location = player.isDead() ? spawnLoader.getSpawnLocation(player) : player.getLocation();
boolean operator = player.isOp(); boolean operator = player.isOp();
boolean flyEnabled = player.getAllowFlight(); boolean flyEnabled = player.getAllowFlight();
float walkSpeed = player.getWalkSpeed();
String playerGroup = ""; String playerGroup = "";
if (permissionsManager.hasGroupSupport()) { if (permissionsManager.hasGroupSupport()) {
playerGroup = permissionsManager.getPrimaryGroup(player); playerGroup = permissionsManager.getPrimaryGroup(player);
} }
if (jsonCache.doesCacheExist(player)) { if (jsonCache.doesCacheExist(player)) {
PlayerData cache = jsonCache.readCache(player); LimboPlayer cache = jsonCache.readCache(player);
if (cache != null) { if (cache != null) {
location = cache.getLoc();
playerGroup = cache.getGroup(); playerGroup = cache.getGroup();
operator = cache.getOperator(); operator = cache.isOperator();
flyEnabled = cache.isFlyEnabled(); flyEnabled = cache.isCanFly();
walkSpeed = cache.getWalkSpeed();
} }
} else {
jsonCache.writeCache(player);
} }
cache.put(name, new LimboPlayer(name, location, operator, playerGroup, flyEnabled, walkSpeed));
cache.put(name, new LimboPlayer(name, location, operator, playerGroup, flyEnabled));
} }
/** /**
* Method deleteLimboPlayer. * Method deleteLimboPlayer.
* *
* @param name String * @param player Player player to remove.
*/ */
public void deleteLimboPlayer(String name) { public void deleteLimboPlayer(Player player) {
checkNotNull(name); String name = player.getName().toLowerCase();
name = name.toLowerCase();
LimboPlayer cachedPlayer = cache.remove(name); LimboPlayer cachedPlayer = cache.remove(name);
if (cachedPlayer != null) { if (cachedPlayer != null) {
cachedPlayer.clearTasks(); cachedPlayer.clearTasks();
} }
jsonCache.removeCache(player);
} }
/** /**
@ -104,7 +107,7 @@ public class LimboCache {
*/ */
public void updateLimboPlayer(Player player) { public void updateLimboPlayer(Player player) {
checkNotNull(player); checkNotNull(player);
deleteLimboPlayer(player.getName().toLowerCase()); deleteLimboPlayer(player);
addLimboPlayer(player); addLimboPlayer(player);
} }

View File

@ -10,20 +10,22 @@ import org.bukkit.scheduler.BukkitTask;
public class LimboPlayer { public class LimboPlayer {
private final String name; private final String name;
private final boolean fly; 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 BukkitTask timeoutTask = null; private BukkitTask timeoutTask = null;
private BukkitTask messageTask = null; private BukkitTask messageTask = null;
public LimboPlayer(String name, Location loc, boolean operator, public LimboPlayer(String name, Location loc, boolean operator,
String group, boolean fly) { String group, boolean fly, float walkSpeed) {
this.name = name; this.name = name;
this.loc = loc; this.loc = loc;
this.operator = operator; this.operator = operator;
this.group = group; this.group = group;
this.fly = fly; this.canFly = fly;
this.walkSpeed = walkSpeed;
} }
/** /**
@ -62,8 +64,12 @@ public class LimboPlayer {
return group; return group;
} }
public boolean isFly() { public boolean isCanFly() {
return fly; return canFly;
}
public float getWalkSpeed() {
return walkSpeed;
} }
/** /**

View File

@ -73,10 +73,6 @@ public class AuthMeInventoryPacketAdapter extends PacketAdapter {
ProtocolLibrary.getProtocolManager().removePacketListener(this); ProtocolLibrary.getProtocolManager().removePacketListener(this);
} }
public void sendInventoryPacket(Player player) {
player.updateInventory();
}
public void sendBlankInventoryPacket(Player player) { public void sendBlankInventoryPacket(Player player) {
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
PacketContainer inventoryPacket = protocolManager.createPacket(PacketType.Play.Server.WINDOW_ITEMS); PacketContainer inventoryPacket = protocolManager.createPacket(PacketType.Play.Server.WINDOW_ITEMS);

View File

@ -98,19 +98,6 @@ public class ProtocolLibService implements SettingsDependent {
} }
} }
/**
* Send a packet to the player to give them an inventory.
*
* @param player The player to send the packet to.
*/
public void sendInventoryPacket(Player player) {
if (!isEnabled || inventoryPacketAdapter == null) {
return;
}
inventoryPacketAdapter.sendInventoryPacket(player);
}
/** /**
* Send a packet to the player to give them a blank inventory. * Send a packet to the player to give them a blank inventory.
* *

View File

@ -67,14 +67,17 @@ 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()); LimboPlayer limbo = limboCache.getLimboPlayer(player.getName().toLowerCase());
if (limbo == null) if (limbo == null) {
return false; return false;
}
// Get the players group // Get the players group
String realGroup = limbo.getGroup(); String realGroup = limbo.getGroup();
// Remove the other group types groups, set the real group // Remove the other group types groups, set the real group
permissionsManager.removeGroups(player, Arrays.asList(Settings.unRegisteredGroup, Settings.getRegisteredGroup, Settings.getUnloggedinGroup)); permissionsManager.removeGroups(player,
Arrays.asList(Settings.unRegisteredGroup, Settings.getRegisteredGroup, Settings.getUnloggedinGroup)
);
return permissionsManager.addGroup(player, realGroup); return permissionsManager.addGroup(player, realGroup);
default: default:
return false; return false;

View File

@ -71,11 +71,11 @@ public class SyncProcessManager {
}); });
} }
public void processSyncPlayerQuit(final Player player, final boolean isOp, final boolean needToChange) { public void processSyncPlayerQuit(final Player player) {
runTask(new Runnable() { runTask(new Runnable() {
@Override @Override
public void run() { public void run() {
processSyncronousPlayerQuit.processSyncQuit(player, isOp, needToChange); processSyncronousPlayerQuit.processSyncQuit(player);
} }
}); });
} }

View File

@ -134,7 +134,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
ProtectInventoryEvent ev = new ProtectInventoryEvent(player); ProtectInventoryEvent ev = new ProtectInventoryEvent(player);
bukkitService.callEvent(ev); bukkitService.callEvent(ev);
if (ev.isCancelled()) { if (ev.isCancelled()) {
protocolLibService.sendInventoryPacket(player); player.updateInventory();
if (!service.getProperty(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE)) { if (!service.getProperty(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE)) {
ConsoleLogger.info("ProtectInventoryEvent has been cancelled for " + player.getName() + "..."); ConsoleLogger.info("ProtectInventoryEvent has been cancelled for " + player.getName() + "...");
} }

View File

@ -199,12 +199,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
// processed in other order. // processed in other order.
LimboPlayer limboPlayer = limboCache.getLimboPlayer(name); LimboPlayer limboPlayer = limboCache.getLimboPlayer(name);
if (limboPlayer != null) { if (limboPlayer != null) {
if (limboPlayer.getTimeoutTask() != null) { limboPlayer.clearTasks();
limboPlayer.getTimeoutTask().cancel();
}
if (limboPlayer.getMessageTask() != null) {
limboPlayer.getMessageTask().cancel();
}
} }
syncProcessManager.processSyncPlayerLogin(player); syncProcessManager.processSyncPlayerLogin(player);
} else if (player.isOnline()) { } else if (player.isOnline()) {

View File

@ -2,7 +2,6 @@ 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.auth.PlayerAuth;
import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboCache;
@ -20,7 +19,6 @@ 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.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;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@ -77,7 +75,7 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
RestoreInventoryEvent event = new RestoreInventoryEvent(player); RestoreInventoryEvent event = new RestoreInventoryEvent(player);
pluginManager.callEvent(event); pluginManager.callEvent(event);
if (!event.isCancelled()) { if (!event.isCancelled()) {
protocolLibService.sendInventoryPacket(player); player.updateInventory();
} }
} }
@ -99,8 +97,13 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
if (limbo != null) { if (limbo != null) {
// Restore Op state and Permission Group // Restore Op state and Permission Group
restoreOpState(player, limbo); player.setOp(limbo.isOperator());
// Restore primary group
service.setGroup(player, AuthGroupType.LOGGED_IN); service.setGroup(player, AuthGroupType.LOGGED_IN);
// Restore can-fly state
player.setAllowFlight(limbo.isCanFly());
// Restore walk speed
player.setWalkSpeed(limbo.getWalkSpeed());
teleportationService.teleportOnLogin(player, auth, limbo); teleportationService.teleportOnLogin(player, auth, limbo);
@ -117,7 +120,7 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
} }
// Clean up no longer used temporary data // Clean up no longer used temporary data
limboCache.deleteLimboPlayer(name); limboCache.deleteLimboPlayer(player);
} }
// We can now display the join message (if delayed) // We can now display the join message (if delayed)
@ -142,6 +145,7 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
bukkitService.callEvent(new LoginEvent(player)); bukkitService.callEvent(new LoginEvent(player));
player.saveData(); player.saveData();
sendBungeeMessage(player); sendBungeeMessage(player);
// Login is done, display welcome message // Login is done, display welcome message
if (service.getProperty(RegistrationSettings.USE_WELCOME_MESSAGE)) { if (service.getProperty(RegistrationSettings.USE_WELCOME_MESSAGE)) {
if (service.getProperty(RegistrationSettings.BROADCAST_WELCOME_MESSAGE)) { if (service.getProperty(RegistrationSettings.BROADCAST_WELCOME_MESSAGE)) {
@ -161,10 +165,6 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
sendTo(player); sendTo(player);
} }
private void restoreOpState(Player player, LimboPlayer limboPlayer) {
player.setOp(limboPlayer.isOperator());
}
private void sendTo(Player player) { private void sendTo(Player player) {
if(!service.getProperty(HooksSettings.BUNGEECORD)) { if(!service.getProperty(HooksSettings.BUNGEECORD)) {
return; return;

View File

@ -60,7 +60,7 @@ public class AsynchronousLogout implements AsynchronousProcess {
} }
}); });
if (limboCache.hasLimboPlayer(name)) { if (limboCache.hasLimboPlayer(name)) {
limboCache.deleteLimboPlayer(name); limboCache.deleteLimboPlayer(player);
} }
limboCache.addLimboPlayer(player); limboCache.addLimboPlayer(player);
service.setGroup(player, AuthGroupType.NOT_LOGGED_IN); service.setGroup(player, AuthGroupType.NOT_LOGGED_IN);

View File

@ -5,7 +5,6 @@ import fr.xephi.authme.cache.SessionManager;
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.datasource.CacheDataSource; import fr.xephi.authme.datasource.CacheDataSource;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.process.AsynchronousProcess; import fr.xephi.authme.process.AsynchronousProcess;
@ -13,7 +12,6 @@ import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.process.SyncProcessManager; import fr.xephi.authme.process.SyncProcessManager;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.util.StringUtils;
import fr.xephi.authme.util.Utils; import fr.xephi.authme.util.Utils;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -74,18 +72,6 @@ public class AsynchronousQuit implements AsynchronousProcess {
database.updateSession(auth); database.updateSession(auth);
} }
boolean needToChange = false;
boolean isOp = false;
LimboPlayer limbo = limboCache.getLimboPlayer(name);
if (limbo != null) {
if (!StringUtils.isEmpty(limbo.getGroup())) {
Utils.addNormal(player, limbo.getGroup());
}
needToChange = true;
isOp = limbo.isOperator();
limboCache.deleteLimboPlayer(name);
}
if (!isKick) { if (!isKick) {
if (plugin.isEnabled()) { if (plugin.isEnabled()) {
BukkitTask task = plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() { BukkitTask task = plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@ -108,7 +94,7 @@ public class AsynchronousQuit implements AsynchronousProcess {
} }
if (plugin.isEnabled()) { if (plugin.isEnabled()) {
syncProcessManager.processSyncPlayerQuit(player, isOp, needToChange); syncProcessManager.processSyncPlayerQuit(player);
} }
// remove player from cache // remove player from cache
if (database instanceof CacheDataSource) { if (database instanceof CacheDataSource) {

View File

@ -1,14 +1,30 @@
package fr.xephi.authme.process.quit; package fr.xephi.authme.process.quit;
import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.cache.limbo.LimboPlayer;
import fr.xephi.authme.process.SynchronousProcess; import fr.xephi.authme.process.SynchronousProcess;
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;
public class ProcessSyncronousPlayerQuit implements SynchronousProcess { public class ProcessSyncronousPlayerQuit implements SynchronousProcess {
public void processSyncQuit(Player player, boolean isOp, boolean needToChange) { @Inject
if (needToChange) { private LimboCache limboCache;
player.setOp(isOp);
public void processSyncQuit(Player player) {
LimboPlayer limbo = limboCache.getLimboPlayer(player.getName().toLowerCase());
if (limbo != null) {
if (!StringUtils.isEmpty(limbo.getGroup())) {
Utils.addNormal(player, limbo.getGroup());
}
player.setOp(limbo.isOperator());
player.setAllowFlight(limbo.isCanFly());
player.setWalkSpeed(limbo.getWalkSpeed());
limboCache.deleteLimboPlayer(player);
} }
player.leaveVehicle(); player.leaveVehicle();
} }

View File

@ -106,11 +106,11 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
RestoreInventoryEvent event = new RestoreInventoryEvent(player); RestoreInventoryEvent event = new RestoreInventoryEvent(player);
bukkitService.callEvent(event); bukkitService.callEvent(event);
if (!event.isCancelled()) { if (!event.isCancelled()) {
protocolLibService.sendInventoryPacket(player); player.updateInventory();
} }
} }
limboCache.deleteLimboPlayer(name); limboCache.deleteLimboPlayer(player);
} }
if (!Settings.getRegisteredGroup.isEmpty()) { if (!Settings.getRegisteredGroup.isEmpty()) {

View File

@ -22,7 +22,8 @@ public class FileUtils {
* Copy a resource file (from the JAR) to the given file if it doesn't exist. * Copy a resource file (from the JAR) to the given file if it doesn't exist.
* *
* @param destinationFile The file to check and copy to (outside of JAR) * @param destinationFile The file to check and copy to (outside of JAR)
* @param resourcePath Absolute path to the resource file (path to file within JAR) * @param resourcePath Absolute path to the resource file (path to file within JAR)
*
* @return False if the file does not exist and could not be copied, true otherwise * @return False if the file does not exist and could not be copied, true otherwise
*/ */
public static boolean copyFileFromResource(File destinationFile, String resourcePath) { public static boolean copyFileFromResource(File destinationFile, String resourcePath) {
@ -49,4 +50,25 @@ public class FileUtils {
} }
return false; return false;
} }
/**
* Delete a given directory and all its content.
*
* @param directory The directory to remove
*/
public static void purgeDirectory(File directory) {
if (!directory.isDirectory()) {
return;
}
File[] files = directory.listFiles();
if (files == null) {
return;
}
for (File target : files) {
if (target.isDirectory()) {
purgeDirectory(target);
}
target.delete();
}
}
} }