use of com.massivecraft.massivecore.xlib.gson.JsonSyntaxException in project MassiveCore by MassiveCraft.
the class Coll method loadFromRemoteFixed.
@Override
public synchronized void loadFromRemoteFixed(String id, Entry<JsonObject, Long> remoteEntry) {
if (id == null)
throw new NullPointerException("id");
this.removeIdentifiedModificationFixed(id);
if (remoteEntry == null) {
try {
remoteEntry = this.getDb().load(this, id);
} catch (Exception e) {
logLoadError(id, e.getMessage());
return;
}
}
if (!this.remoteEntryIsOk(id, remoteEntry))
return;
JsonObject raw = remoteEntry.getKey();
Long mtime = remoteEntry.getValue();
int version = MigratorUtil.getVersion(raw);
if (version > MigratorUtil.getTargetVersion(this.getEntityClass())) {
logLoadError(id, String.format("Cannot load entity of entity version %d", version));
return;
}
// Migrate if another version is wanted
boolean migrated = MigratorUtil.migrate(this.getEntityClass(), raw);
// Calculate temp but handle raw cases.
E temp;
try {
temp = this.getGson().fromJson(raw, this.getEntityClass());
} catch (JsonSyntaxException ex) {
logLoadError(id, ex.getMessage());
return;
}
E entity = this.getFixed(id, false);
if (entity != null) {
// It did already exist
this.copy(temp, entity);
} else {
// Create first (or load from registry)
// The registry is used by MassiveMagic
Map<String, E> tempRegistry = this.getTempRegistry();
if (tempRegistry != null)
entity = tempRegistry.get(id);
if (entity == null)
entity = this.createNewInstance();
if (tempRegistry != null)
tempRegistry.remove(id);
// Copy over data first
this.copy(temp, entity);
// Then attach!
this.attach(entity, id, false);
// On creation it might be modified by addition or removal of new/old fields.
// So we must do a check for that.
// this.putIdentifiedModificationFixed(id, Modification.UNKNOWN);
}
entity.setLastRaw(raw);
entity.setLastMtime(mtime);
entity.setLastDefault(false);
// Now the loading is done. If it was migrated we will have to save it to remote again.
if (migrated)
this.putIdentifiedModificationFixed(id, Modification.LOCAL_ALTER);
}
Aggregations