remove uuid, only use player's name.
This commit is contained in:
parent
4e011f437a
commit
3d90d478c2
@ -8,7 +8,6 @@ import com.google.gson.JsonDeserializationContext;
|
|||||||
import com.google.gson.JsonDeserializer;
|
import com.google.gson.JsonDeserializer;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParseException;
|
|
||||||
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;
|
||||||
@ -41,14 +40,8 @@ public class JsonCache {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String path;
|
String name = player.getName().toLowerCase();
|
||||||
try {
|
File file = new File(cacheDir, name + File.separator + "cache.json");
|
||||||
path = player.getUniqueId().toString();
|
|
||||||
} catch (Exception | Error e) {
|
|
||||||
path = player.getName().toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
File file = new File(cacheDir, path + File.separator + "cache.json");
|
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -61,19 +54,13 @@ public class JsonCache {
|
|||||||
Files.touch(file);
|
Files.touch(file);
|
||||||
Files.write(data, file, Charsets.UTF_8);
|
Files.write(data, file, Charsets.UTF_8);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
ConsoleLogger.writeStackTrace(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerData readCache(Player player) {
|
public PlayerData readCache(Player player) {
|
||||||
String path;
|
String name = player.getName().toLowerCase();
|
||||||
try {
|
File file = new File(cacheDir, name + File.separator + "cache.json");
|
||||||
path = player.getUniqueId().toString();
|
|
||||||
} catch (Exception | Error e) {
|
|
||||||
path = player.getName().toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
File file = new File(cacheDir, path + File.separator + "cache.json");
|
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -81,20 +68,15 @@ public class JsonCache {
|
|||||||
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, PlayerData.class);
|
||||||
} catch (Exception e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
ConsoleLogger.writeStackTrace(e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeCache(Player player) {
|
public void removeCache(Player player) {
|
||||||
String path;
|
String name = player.getName().toLowerCase();
|
||||||
try {
|
File file = new File(cacheDir, name);
|
||||||
path = player.getUniqueId().toString();
|
|
||||||
} catch (Exception | Error e) {
|
|
||||||
path = player.getName().toLowerCase();
|
|
||||||
}
|
|
||||||
File file = new File(cacheDir, path);
|
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
purgeDirectory(file);
|
purgeDirectory(file);
|
||||||
if (!file.delete()) {
|
if (!file.delete()) {
|
||||||
@ -104,19 +86,15 @@ public class JsonCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean doesCacheExist(Player player) {
|
public boolean doesCacheExist(Player player) {
|
||||||
String path;
|
String name = player.getName().toLowerCase();
|
||||||
try {
|
File file = new File(cacheDir, name + File.separator + "cache.json");
|
||||||
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();
|
return file.exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PlayerDataDeserializer implements JsonDeserializer<PlayerData> {
|
private class PlayerDataDeserializer implements JsonDeserializer<PlayerData> {
|
||||||
@Override
|
@Override
|
||||||
public PlayerData deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
public PlayerData deserialize(JsonElement jsonElement, Type type,
|
||||||
|
JsonDeserializationContext context) {
|
||||||
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
||||||
if (jsonObject == null) {
|
if (jsonObject == null) {
|
||||||
return null;
|
return null;
|
||||||
@ -143,7 +121,7 @@ public class JsonCache {
|
|||||||
private class PlayerDataSerializer implements JsonSerializer<PlayerData> {
|
private class PlayerDataSerializer implements JsonSerializer<PlayerData> {
|
||||||
@Override
|
@Override
|
||||||
public JsonElement serialize(PlayerData playerData, Type type,
|
public JsonElement serialize(PlayerData playerData, Type type,
|
||||||
JsonSerializationContext jsonSerializationContext) {
|
JsonSerializationContext context) {
|
||||||
JsonObject jsonObject = new JsonObject();
|
JsonObject jsonObject = new JsonObject();
|
||||||
jsonObject.addProperty("group", playerData.getGroup());
|
jsonObject.addProperty("group", playerData.getGroup());
|
||||||
jsonObject.addProperty("operator", playerData.getOperator());
|
jsonObject.addProperty("operator", playerData.getOperator());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user