mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-12-25 01:58:41 +01:00
Errors loading conf.json are handled better now, allowing Factions to continue loading the board instead of losing it
Also, the bad conf.json file is backed up to conf.json_bad so it can potentially be recovered
This commit is contained in:
parent
8b5a724c03
commit
64f47b01fb
@ -86,6 +86,13 @@ public class Persist {
|
|||||||
if (loaded == null)
|
if (loaded == null)
|
||||||
{
|
{
|
||||||
p.log(Level.WARNING, "Using default as I failed to load: "+file);
|
p.log(Level.WARNING, "Using default as I failed to load: "+file);
|
||||||
|
|
||||||
|
// backup bad file, so user can attempt to recover their changes from it
|
||||||
|
File backup = new File(file.getPath()+"_bad");
|
||||||
|
if (backup.exists()) backup.delete();
|
||||||
|
p.log(Level.WARNING, "Backing up copy of bad file to: "+backup);
|
||||||
|
file.renameTo(backup);
|
||||||
|
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,9 +136,17 @@ public class Persist {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
T instance = p.gson.fromJson(content, clazz);
|
try
|
||||||
|
{
|
||||||
|
T instance = p.gson.fromJson(content, clazz);
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{ // output the error message rather than full stack trace; error parsing the file, most likely
|
||||||
|
p.log(Level.WARNING, ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
return instance;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user