Make the files for disguises/gameprofiles if needed

This commit is contained in:
libraryaddict 2017-06-10 02:29:28 +12:00
parent 87e810c608
commit 3d78b493bc
2 changed files with 26 additions and 8 deletions

View file

@ -135,6 +135,9 @@ public class DisguiseUtilities {
if (!LibsPremium.isPremium())
return;
if (!savedDisguises.exists())
savedDisguises.mkdirs();
try {
File disguiseFile = new File(savedDisguises, owningEntity.toString());
@ -174,6 +177,9 @@ public class DisguiseUtilities {
if (!isSavedDisguise(entityUUID) || !LibsPremium.isPremium())
return new Disguise[0];
if (!savedDisguises.exists())
savedDisguises.mkdirs();
File disguiseFile = new File(savedDisguises, entityUUID.toString());
if (!disguiseFile.exists()) {
@ -204,6 +210,9 @@ public class DisguiseUtilities {
if (!savedDisguiseList.remove(entityUUID))
return;
if (!savedDisguises.exists())
savedDisguises.mkdirs();
File disguiseFile = new File(savedDisguises, entityUUID.toString());
disguiseFile.delete();
@ -283,6 +292,9 @@ public class DisguiseUtilities {
public static void addGameProfile(String string, WrappedGameProfile gameProfile) {
try {
if (!profileCache.exists())
profileCache.mkdirs();
File file = new File(profileCache, string.toLowerCase());
PrintWriter writer = new PrintWriter(file);
writer.write(gson.toJson(gameProfile));
@ -551,6 +563,9 @@ public class DisguiseUtilities {
if (!cachedNames.contains(playerName.toLowerCase()))
return null;
if (!profileCache.exists())
profileCache.mkdirs();
File file = new File(profileCache, playerName.toLowerCase());
if (!file.exists()) {
@ -785,12 +800,6 @@ public class DisguiseUtilities {
gson = gsonBuilder.create();
if (!profileCache.exists())
profileCache.mkdirs();
if (!savedDisguises.exists())
savedDisguises.mkdirs();
try {
Object server = ReflectionManager.getNmsMethod("MinecraftServer", "getServer").invoke(null);
Object world = ((List) server.getClass().getField("worlds").get(server)).get(0);
@ -839,6 +848,12 @@ public class DisguiseUtilities {
ex.printStackTrace();
}
if (!profileCache.exists())
profileCache.mkdirs();
if (!savedDisguises.exists())
savedDisguises.mkdirs();
cachedNames.addAll(Arrays.asList(profileCache.list()));
for (String key : savedDisguises.list()) {
@ -1099,6 +1114,9 @@ public class DisguiseUtilities {
public static void removeGameProfile(String string) {
cachedNames.remove(string.toLowerCase());
if (!profileCache.exists())
profileCache.mkdirs();
File file = new File(profileCache, string.toLowerCase());
file.delete();

View file

@ -120,7 +120,7 @@ public class ReflectionManager {
Object playerinteractmanager = getNmsClass("PlayerInteractManager").getDeclaredConstructor(
getNmsClass("World")).newInstance(world);
WrappedGameProfile gameProfile = getGameProfile(null, "Steve");
WrappedGameProfile gameProfile = getGameProfile(new UUID(0, 0), "Steve");
entityObject = entityClass.getDeclaredConstructor(getNmsClass("MinecraftServer"),
getNmsClass("WorldServer"), gameProfile.getHandleType(),
@ -847,7 +847,7 @@ public class ReflectionManager {
} else if (value instanceof Double)
return ((Double) value).floatValue();
else if (value instanceof NbtCompound)
return ((NbtWrapper)value).getHandle();
return ((NbtWrapper) value).getHandle();
return value;
}