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

View File

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