Stuff from the common floobits workspace

Author:    AuthMe-Team <AuthMeTeam@123NoEmail.com>
This commit is contained in:
AuthMe-Team
2015-11-23 20:20:42 +01:00
committed by Gabriele C
parent 69a09aec17
commit 9ec2d6d059
169 changed files with 5161 additions and 4806 deletions
@@ -10,9 +10,10 @@ public class DataFileCache {
/**
* Constructor for DataFileCache.
* @param group String
*
* @param group String
* @param operator boolean
* @param flying boolean
* @param flying boolean
*/
public DataFileCache(String group, boolean operator, boolean flying) {
this.group = group;
@@ -22,24 +23,27 @@ public class DataFileCache {
/**
* Method getGroup.
* @return String */
*
* @return String
*/
public String getGroup() {
return group;
}
/**
* Method getOperator.
* @return boolean */
*
* @return boolean
*/
public boolean getOperator() {
return operator;
}
/**
* Method isFlying.
* @return boolean */
*
* @return boolean
*/
public boolean isFlying() {
return flying;
}
+67 -73
View File
@@ -1,27 +1,17 @@
package fr.xephi.authme.cache.backup;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.google.gson.*;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.Utils;
import org.bukkit.entity.Player;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Type;
import org.bukkit.entity.Player;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.Utils;
/**
*/
public class JsonCache {
@@ -43,7 +33,8 @@ public class JsonCache {
/**
* Method createCache.
* @param player Player
*
* @param player Player
* @param playerData DataFileCache
*/
public void createCache(Player player, DataFileCache playerData) {
@@ -77,9 +68,10 @@ public class JsonCache {
/**
* Method readCache.
*
* @param player Player
* @return DataFileCache */
* @return DataFileCache
*/
public DataFileCache readCache(Player player) {
String path;
try {
@@ -103,24 +95,41 @@ public class JsonCache {
}
/**
* Method removeCache.
*
* @param player Player
*/
private class PlayerDataSerializer implements JsonSerializer<DataFileCache> {
/**
* Method serialize.
* @param dataFileCache DataFileCache
* @param type Type
* @param jsonSerializationContext JsonSerializationContext
* @return JsonElement */
@Override
public JsonElement serialize(DataFileCache dataFileCache, Type type, JsonSerializationContext jsonSerializationContext) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("group", dataFileCache.getGroup());
jsonObject.addProperty("operator", dataFileCache.getOperator());
jsonObject.addProperty("flying", dataFileCache.isFlying());
return jsonObject;
public void removeCache(Player player) {
String path;
try {
path = player.getUniqueId().toString();
} catch (Exception | Error e) {
path = player.getName().toLowerCase();
}
File file = new File(cacheDir, path);
if (file.exists()) {
Utils.purgeDirectory(file);
if (!file.delete()) {
ConsoleLogger.showError("Failed to remove" + player.getName() + "cache.");
}
}
}
/**
* Method doesCacheExist.
*
* @param player Player
* @return boolean
*/
public boolean doesCacheExist(Player player) {
String path;
try {
path = player.getUniqueId().toString();
} catch (Exception | Error e) {
path = player.getName().toLowerCase();
}
File file = new File(cacheDir, path + File.separator + "cache.json");
return file.exists();
}
/**
@@ -128,13 +137,12 @@ public class JsonCache {
private static class PlayerDataDeserializer implements JsonDeserializer<DataFileCache> {
/**
* Method deserialize.
* @param jsonElement JsonElement
* @param type Type
*
* @param jsonElement JsonElement
* @param type Type
* @param jsonDeserializationContext JsonDeserializationContext
* @return DataFileCache * @throws JsonParseException * @see com.google.gson.JsonDeserializer#deserialize(JsonElement, Type, JsonDeserializationContext) */
* @return DataFileCache * @throws JsonParseException * @see com.google.gson.JsonDeserializer#deserialize(JsonElement, Type, JsonDeserializationContext)
*/
@Override
public DataFileCache deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
JsonObject jsonObject = jsonElement.getAsJsonObject();
@@ -161,39 +169,25 @@ public class JsonCache {
}
/**
* Method removeCache.
* @param player Player
*/
public void removeCache(Player player) {
String path;
try {
path = player.getUniqueId().toString();
} catch (Exception | Error e) {
path = player.getName().toLowerCase();
}
File file = new File(cacheDir, path);
if (file.exists()) {
Utils.purgeDirectory(file);
if (!file.delete()) {
ConsoleLogger.showError("Failed to remove" + player.getName() + "cache.");
}
}
}
private class PlayerDataSerializer implements JsonSerializer<DataFileCache> {
/**
* Method serialize.
*
* @param dataFileCache DataFileCache
* @param type Type
* @param jsonSerializationContext JsonSerializationContext
* @return JsonElement
*/
@Override
public JsonElement serialize(DataFileCache dataFileCache, Type type, JsonSerializationContext jsonSerializationContext) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("group", dataFileCache.getGroup());
jsonObject.addProperty("operator", dataFileCache.getOperator());
jsonObject.addProperty("flying", dataFileCache.isFlying());
/**
* Method doesCacheExist.
* @param player Player
* @return boolean */
public boolean doesCacheExist(Player player) {
String path;
try {
path = player.getUniqueId().toString();
} catch (Exception | Error e) {
path = player.getName().toLowerCase();
return jsonObject;
}
File file = new File(cacheDir, path + File.separator + "cache.json");
return file.exists();
}
}