use of com.massivecraft.massivecore.xlib.gson.JsonElement 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.JsonElement in project MassiveCore by MassiveCraft.
the class MigratorUtil method migrateFields.
public static boolean migrateFields(Type type, JsonObject object) {
if (type == null)
throw new NullPointerException("entityClass");
if (object == null)
throw new NullPointerException("object");
Class<?> entityClass = getClassType(type);
// because their "fields" are dynamically made and can't be looked up with reflection
if (Map.class.isAssignableFrom(entityClass))
return false;
boolean migrated = false;
for (Entry<String, JsonElement> entry : object.entrySet()) {
String name = entry.getKey();
JsonElement element = entry.getValue();
// It might be defined in a superclass, so find the defining class
Class<?> superClass = ReflectionUtil.getSuperclassDeclaringField(entityClass, true, name);
// Try find field if it has a different serialisation name
if (superClass == null) {
Field field = tryFindField(entityClass, name);
if (field != null) {
name = field.getName();
superClass = entityClass;
}
}
Type elementType = ReflectionUtil.getField(superClass, name).getGenericType();
migrated = migrate(elementType, element) | migrated;
}
return migrated;
}
Aggregations