Skip to content

Commit

Permalink
fix getEngineData NullPointer
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyDev05 committed Aug 15, 2024
1 parent 25b41fe commit d068878
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions core/src/main/java/com/volmit/iris/engine/IrisEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,30 +254,40 @@ public IrisEngineData getEngineData() {
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;
});
}

Expand Down

0 comments on commit d068878

Please sign in to comment.