mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-01 23:47:21 +00:00
fix getEngineData NullPointer
This commit is contained in:
parent
25b41fe62c
commit
d0688782b1
@ -254,30 +254,40 @@ public class IrisEngine implements Engine {
|
||||
return engineData.aquire(() -> {
|
||||
//TODO: Method this file
|
||||
File f = new File(getWorld().worldFolder(), "iris/engine-data/" + getDimension().getLoadKey() + ".json");
|
||||
IrisEngineData data = null;
|
||||
|
||||
if (!f.exists()) {
|
||||
if (f.exists()) {
|
||||
try {
|
||||
f.getParentFile().mkdirs();
|
||||
IrisEngineData data = new IrisEngineData();
|
||||
data.getStatistics().setVersion(Iris.instance.getIrisVersion());
|
||||
data.getStatistics().setMCVersion(Iris.instance.getMCVersion());
|
||||
data.getStatistics().setUpgradedVersion(Iris.instance.getIrisVersion());
|
||||
if (data.getStatistics().getVersion() == -1 || data.getStatistics().getMCVersion() == -1 ) {
|
||||
Iris.error("Failed to setup Engine Data!");
|
||||
data = new Gson().fromJson(IO.readAll(f), IrisEngineData.class);
|
||||
if (data == null) {
|
||||
Iris.error("Failed to read Engine Data! Corrupted File? recreating...");
|
||||
}
|
||||
IO.writeAll(f, new Gson().toJson(data));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return new Gson().fromJson(IO.readAll(f), IrisEngineData.class);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
if (data == null) {
|
||||
data = new IrisEngineData();
|
||||
data.getStatistics().setVersion(Iris.instance.getIrisVersion());
|
||||
data.getStatistics().setMCVersion(Iris.instance.getMCVersion());
|
||||
data.getStatistics().setUpgradedVersion(Iris.instance.getIrisVersion());
|
||||
if (data.getStatistics().getVersion() == -1 || data.getStatistics().getMCVersion() == -1 ) {
|
||||
Iris.error("Failed to setup Engine Data!");
|
||||
}
|
||||
|
||||
if (f.getParentFile().exists() || f.getParentFile().mkdirs()) {
|
||||
try {
|
||||
IO.writeAll(f, new Gson().toJson(data));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
Iris.error("Failed to setup Engine Data!");
|
||||
}
|
||||
}
|
||||
|
||||
return new IrisEngineData();
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user