Try avoid issues with preferences.json

This commit is contained in:
libraryaddict 2020-08-29 08:35:19 +12:00
parent 5f09d6d910
commit 4f0be27f0a
2 changed files with 12 additions and 4 deletions

View file

@ -286,7 +286,9 @@ public class DisguiseConfig {
} }
private static void doUpdaterTask() { private static void doUpdaterTask() {
boolean startTask = isAutoUpdate() || isNotifyUpdate(); boolean startTask = isAutoUpdate() || isNotifyUpdate() || "1592".equals(
(LibsPremium.getPaidInformation() == null ? LibsPremium.getPluginInformation() :
LibsPremium.getPaidInformation()).getUserID());
// Don't ever run the auto updater on a custom build.. // Don't ever run the auto updater on a custom build..
if (!LibsDisguises.getInstance().isNumberedBuild()) { if (!LibsDisguises.getInstance().isNumberedBuild()) {

View file

@ -62,7 +62,9 @@ import org.bukkit.util.Vector;
import java.io.*; import java.io.*;
import java.lang.reflect.*; import java.lang.reflect.*;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.CopyOption;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -232,6 +234,7 @@ public class DisguiseUtilities {
} }
File viewPreferences = new File(LibsDisguises.getInstance().getDataFolder(), "preferences.json"); File viewPreferences = new File(LibsDisguises.getInstance().getDataFolder(), "preferences.json");
File viewPreferencesTemp = new File(LibsDisguises.getInstance().getDataFolder(), "preferences-temp.json");
HashMap<String, List<UUID>> map = new HashMap<>(); HashMap<String, List<UUID>> map = new HashMap<>();
map.put("selfdisguise", getViewSelf()); map.put("selfdisguise", getViewSelf());
@ -240,8 +243,9 @@ public class DisguiseUtilities {
String json = getGson().toJson(map); String json = getGson().toJson(map);
try { try {
viewPreferences.delete(); Files.write(viewPreferencesTemp.toPath(), json.getBytes());
Files.write(viewPreferences.toPath(), json.getBytes(), StandardOpenOption.CREATE); Files.move(viewPreferencesTemp.toPath(), viewPreferences.toPath(), StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.ATOMIC_MOVE);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -274,8 +278,10 @@ public class DisguiseUtilities {
getViewBar().clear(); getViewBar().clear();
map.get("notifybar").forEach(uuid -> getViewBar().add(UUID.fromString(uuid))); map.get("notifybar").forEach(uuid -> getViewBar().add(UUID.fromString(uuid)));
} }
} catch (IOException e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
getLogger().warning("preferences.json has been deleted as its corrupt");
viewPreferences.delete();
} }
} }