Try avoid issues with preferences.json
This commit is contained in:
parent
5f09d6d910
commit
4f0be27f0a
@ -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()) {
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user