use of com.massivecraft.massivecore.xlib.gson.JsonObject in project MassiveCore by MassiveCraft.
the class DriverFlatfile method loadFile.
public Entry<JsonObject, Long> loadFile(File file) {
long mtime = file.lastModified();
JsonObject raw = loadFileJson(file);
return new SimpleEntry<>(raw, mtime);
}
use of com.massivecraft.massivecore.xlib.gson.JsonObject in project MassiveCore by MassiveCraft.
the class DriverMongo method loadAll.
@Override
public Map<String, Entry<JsonObject, Long>> loadAll(Coll<?> coll) {
// Declare Ret
Map<String, Entry<JsonObject, Long>> ret = null;
// Fix Coll
DBCollection dbcoll = fixColl(coll);
// Find All
DBCursor cursor = dbcoll.find();
try {
// Create Ret
ret = new MassiveMap<>(cursor.count());
// For Each Found
while (cursor.hasNext()) {
BasicDBObject raw = (BasicDBObject) cursor.next();
// Get ID
Object rawId = raw.removeField(ID_FIELD);
if (rawId == null)
continue;
String id = rawId.toString();
// Get Entry
Entry<JsonObject, Long> entry = loadRaw(raw);
// NOTE: The entry can be a failed one with null and 0.
// NOTE: We add it anyways since it's an informative failure.
// NOTE: This is supported by our defined specification.
// Add
ret.put(id, entry);
}
} finally {
cursor.close();
}
// Return Ret
return ret;
}
use of com.massivecraft.massivecore.xlib.gson.JsonObject in project MassiveCore by MassiveCraft.
the class PS method valueOf.
public static PS valueOf(final JsonElement jsonElement) {
if (jsonElement == null)
return null;
if (jsonElement.isJsonNull())
return null;
final JsonObject jsonObject = jsonElement.getAsJsonObject();
final PSBuilder builder = new PSBuilder();
if (jsonObject.has("world") && jsonObject.has("yaw")) {
// Old Faction LazyLocation
for (Entry<String, JsonElement> entry : jsonObject.entrySet()) {
final String key = entry.getKey();
final JsonElement value = entry.getValue();
if (key.equals("world")) {
builder.world(value.getAsString());
} else if (key.equals("x")) {
builder.locationX(value.getAsDouble());
} else if (key.equals("y")) {
builder.locationY(value.getAsDouble());
} else if (key.equals("z")) {
builder.locationZ(value.getAsDouble());
} else if (key.equals("pitch")) {
builder.pitch(value.getAsFloat());
} else if (key.equals("yaw")) {
builder.yaw(value.getAsFloat());
}
}
} else {
// The Standard Format
for (Entry<String, JsonElement> entry : jsonObject.entrySet()) {
final String key = entry.getKey();
final JsonElement value = entry.getValue();
if (key.equals(NAME_SERIALIZED_WORLD)) {
builder.world(value.getAsString());
} else if (key.equals(NAME_SERIALIZED_BLOCKX)) {
builder.blockX(value.getAsInt());
} else if (key.equals(NAME_SERIALIZED_BLOCKY)) {
builder.blockY(value.getAsInt());
} else if (key.equals(NAME_SERIALIZED_BLOCKZ)) {
builder.blockZ(value.getAsInt());
} else if (key.equals(NAME_SERIALIZED_LOCATIONX)) {
builder.locationX(value.getAsDouble());
} else if (key.equals(NAME_SERIALIZED_LOCATIONY)) {
builder.locationY(value.getAsDouble());
} else if (key.equals(NAME_SERIALIZED_LOCATIONZ)) {
builder.locationZ(value.getAsDouble());
} else if (key.equals(NAME_SERIALIZED_CHUNKX)) {
builder.chunkX(value.getAsInt());
} else if (key.equals(NAME_SERIALIZED_CHUNKZ)) {
builder.chunkZ(value.getAsInt());
} else if (key.equals(NAME_SERIALIZED_PITCH)) {
builder.pitch(value.getAsFloat());
} else if (key.equals(NAME_SERIALIZED_YAW)) {
builder.yaw(value.getAsFloat());
} else if (key.equals(NAME_SERIALIZED_VELOCITYX)) {
builder.velocityX(value.getAsDouble());
} else if (key.equals(NAME_SERIALIZED_VELOCITYY)) {
builder.velocityY(value.getAsDouble());
} else if (key.equals(NAME_SERIALIZED_VELOCITYZ)) {
builder.velocityZ(value.getAsDouble());
}
}
}
return builder.build();
}
use of com.massivecraft.massivecore.xlib.gson.JsonObject in project MassiveCore by MassiveCraft.
the class Coll method examineHasLocalAlterFixed.
protected boolean examineHasLocalAlterFixed(String id, E entity) {
JsonObject lastRaw = entity.getLastRaw();
JsonObject currentRaw = null;
try {
currentRaw = this.getGson().toJsonTree(entity, this.getEntityClass()).getAsJsonObject();
} catch (Exception e) {
MassiveCore.get().log(Txt.parse("<b>Database examineHasLocalAlter failed convert current entity to JSON tree."));
MassiveCore.get().log(Txt.parse("<k>Error: <v>%s", e.getMessage()));
MassiveCore.get().log(Txt.parse("<k>Entity: <v>%s", id));
MassiveCore.get().log(Txt.parse("<k>Collection: <v>%s", this.getName()));
throw new RuntimeException(e);
}
return !MStore.equal(lastRaw, currentRaw);
}
use of com.massivecraft.massivecore.xlib.gson.JsonObject in project MassiveCore by MassiveCraft.
the class Coll method remoteEntryIsOk.
public boolean remoteEntryIsOk(String id, Entry<JsonObject, Long> remoteEntry) {
Long mtime = remoteEntry.getValue();
if (mtime == null) {
this.logLoadError(id, "Last modification time (mtime) was null. The file might not be readable or simply not exist.");
return false;
}
if (mtime == 0) {
this.logLoadError(id, "Last modification time (mtime) was 0. The file might not be readable or simply not exist.");
return false;
}
JsonObject raw = remoteEntry.getKey();
if (raw == null) {
this.logLoadError(id, "Raw data was null. Is the file completely empty?");
return false;
}
if (raw.isJsonNull()) {
this.logLoadError(id, "Raw data was JSON null. It seems you have a file containing just the word \"null\". Why would you do this?");
return false;
}
return true;
}
Aggregations