parent
a00deb0e0f
commit
4ec548cb8d
@ -34,9 +34,7 @@ public class NewAPI {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook into AuthMe
|
* Hook into AuthMe
|
||||||
*
|
*
|
||||||
* @return
|
|
||||||
*
|
|
||||||
* @return AuthMe plugin
|
* @return AuthMe plugin
|
||||||
*/
|
*/
|
||||||
public static NewAPI getInstance() {
|
public static NewAPI getInstance() {
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
package fr.xephi.authme.cache.backup;
|
package fr.xephi.authme.cache.backup;
|
||||||
|
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.io.BaseEncoding;
|
import com.google.common.io.BaseEncoding;
|
||||||
|
import com.google.common.io.Files;
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
@ -18,7 +20,6 @@ import java.io.ByteArrayOutputStream;
|
|||||||
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;
|
||||||
import java.nio.file.Files;
|
|
||||||
|
|
||||||
public class JsonCache {
|
public class JsonCache {
|
||||||
|
|
||||||
@ -61,7 +62,8 @@ public class JsonCache {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
String data = gson.toJson(playerData);
|
String data = gson.toJson(playerData);
|
||||||
Files.write(file.toPath(), data.getBytes());
|
Files.touch(file);
|
||||||
|
Files.write(data, file, Charsets.UTF_8);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -76,9 +78,12 @@ public class JsonCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
File file = new File(cacheDir, path + File.separator + "cache.json");
|
File file = new File(cacheDir, path + File.separator + "cache.json");
|
||||||
|
if (!file.exists()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
byte[] bytes = Files.readAllBytes(file.toPath());
|
String str = Files.toString(file, Charsets.UTF_8);
|
||||||
String str = new String(bytes);
|
|
||||||
return gson.fromJson(str, DataFileCache.class);
|
return gson.fromJson(str, DataFileCache.class);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -142,17 +147,37 @@ public class JsonCache {
|
|||||||
@Override
|
@Override
|
||||||
public DataFileCache deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
public DataFileCache deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
||||||
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
||||||
String group = jsonObject.get("group").getAsString();
|
if (jsonObject == null) {
|
||||||
boolean operator = jsonObject.get("operator").getAsBoolean();
|
return null;
|
||||||
boolean flying = jsonObject.get("flying").getAsBoolean();
|
}
|
||||||
|
JsonElement e;
|
||||||
|
String group = null;
|
||||||
|
boolean operator = false;
|
||||||
|
boolean flying = false;
|
||||||
|
|
||||||
|
if ((e = jsonObject.get("group")) != null) {
|
||||||
|
group = e.getAsString();
|
||||||
|
}
|
||||||
|
if ((e = jsonObject.get("operator")) != null) {
|
||||||
|
operator = e.getAsBoolean();
|
||||||
|
}
|
||||||
|
if ((e = jsonObject.get("flying")) != null) {
|
||||||
|
flying = e.getAsBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
JsonArray arr;
|
JsonArray arr;
|
||||||
|
ItemStack[] inv = null;
|
||||||
|
ItemStack[] armour = null;
|
||||||
|
|
||||||
arr = jsonObject.get("inventory").getAsJsonArray();
|
if (jsonObject.has("inventory")) {
|
||||||
ItemStack[] inv = getItems(arr);
|
arr = jsonObject.get("inventory").getAsJsonArray();
|
||||||
|
inv = getItems(arr);
|
||||||
|
}
|
||||||
|
|
||||||
arr = jsonObject.get("armour").getAsJsonArray();
|
if (jsonObject.has("armour")) {
|
||||||
ItemStack[] armour = getItems(arr);
|
arr = jsonObject.get("armour").getAsJsonArray();
|
||||||
|
armour = getItems(arr);
|
||||||
|
}
|
||||||
|
|
||||||
return new DataFileCache(inv, armour, group, operator, flying);
|
return new DataFileCache(inv, armour, group, operator, flying);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -195,7 +195,8 @@ public class AsyncronousJoin {
|
|||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (NullPointerException ex) {
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String[] msg;
|
String[] msg;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user