use of com.massivecraft.massivecore.xlib.gson.JsonObject in project MassiveCore by MassiveCraft.
the class GsonMongoConverter method gson2MongoObject.
public static BasicDBObject gson2MongoObject(JsonElement inElement, BasicDBObject out) {
JsonObject in = inElement.getAsJsonObject();
for (Entry<String, JsonElement> entry : in.entrySet()) {
String key = gson2MongoKey(entry.getKey());
JsonElement val = entry.getValue();
if (val.isJsonArray()) {
out.put(key, gson2MongoArray(val));
} else if (val.isJsonObject()) {
out.put(key, gson2MongoObject(val));
} else {
out.put(key, gson2MongoPrimitive(val));
}
}
return out;
}
use of com.massivecraft.massivecore.xlib.gson.JsonObject in project MassiveCore by MassiveCraft.
the class AdapterPolymorphic method deserialize.
@Override
public T deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
if (!json.isJsonObject()) {
throw new JsonParseException("A polymorph must be an object.");
}
JsonObject jsonObject = json.getAsJsonObject();
if (!jsonObject.has(TYPE)) {
throw new JsonParseException("A polymorph must be have a \"" + TYPE + "\" field.");
}
if (!jsonObject.has(VALUE)) {
throw new JsonParseException("A polymorph must be have a \"+VALUE+\" field.");
}
String type = ((JsonPrimitive) jsonObject.get(TYPE)).getAsString();
Class<?> typeClass = null;
try {
typeClass = Class.forName(type);
} catch (ClassNotFoundException e) {
e.printStackTrace();
throw new JsonParseException(e.getMessage());
}
return context.deserialize(jsonObject.get(VALUE), typeClass);
}
use of com.massivecraft.massivecore.xlib.gson.JsonObject in project MassiveCore by MassiveCraft.
the class EngineMassiveCoreDatabase method massiveStoreLoginSync.
// Can not be cancelled.
@EventHandler(priority = EventPriority.LOWEST)
public void massiveStoreLoginSync(PlayerLoginEvent event) {
// Get player id ...
Player player = event.getPlayer();
if (MUtil.isntPlayer(player))
return;
final String playerId = player.getUniqueId().toString();
// ... get remote entries ...
Map<SenderColl<?>, Entry<JsonObject, Long>> remoteEntries = getRemoteEntries(playerId);
// ... and sync each of them.
for (Entry<SenderColl<?>, Entry<JsonObject, Long>> entry : remoteEntries.entrySet()) {
SenderColl<?> coll = entry.getKey();
Entry<JsonObject, Long> remoteEntry = entry.getValue();
coll.syncId(playerId, null, remoteEntry);
}
}
use of com.massivecraft.massivecore.xlib.gson.JsonObject in project MassiveCore by MassiveCraft.
the class MigratorInventory001StringId method updateField.
public void updateField(JsonObject json, String name) {
JsonElement element = json.get(name);
if (element == null)
return;
if (!element.isJsonObject())
return;
JsonObject object = element.getAsJsonObject();
MigratorUtil.migrate(DataItemStack.class, object);
}
use of com.massivecraft.massivecore.xlib.gson.JsonObject in project MassiveCore by MassiveCraft.
the class DriverFlatfile method loadAll.
@Override
public Map<String, Entry<JsonObject, Long>> loadAll(Coll<?> coll) {
// Create Ret
Map<String, Entry<JsonObject, Long>> ret = null;
// Get Directory
File directory = getDirectory(coll);
if (!directory.isDirectory())
return ret;
// Find All
File[] files = directory.listFiles(JsonFileFilter.get());
// Create Ret
ret = new MassiveMap<>(files.length);
// For Each Found
for (File file : files) {
// Get ID
String id = idFromFile(file);
// Get Entry
Entry<JsonObject, Long> entry = loadFile(file);
// 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);
}
// Return Ret
return ret;
}
Aggregations