use of org.spongepowered.api.scoreboard.Score in project LanternServer by LanternPowered.
the class JsonTextScoreSerializer method deserialize.
@Override
public ScoreText deserialize(JsonElement element, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
final JsonObject obj = element.getAsJsonObject();
final Text name = LanternTexts.fromLegacy(obj.get(SCORE_NAME).getAsString());
// Try to parse the value
int value = 0;
try {
value = Integer.parseInt(obj.get(SCORE_VALUE).getAsString());
} catch (NumberFormatException ignored) {
}
final String baseObjective = obj.get(SCORE_MAIN_OBJECTIVE).getAsString();
final Set<Objective> objectives = new HashSet<>();
if (!baseObjective.isEmpty()) {
this.tryAddObjective(baseObjective, objectives);
}
if ((element = obj.get(SCORE_EXTRA_OBJECTIVES)) != null) {
final JsonArray array = element.getAsJsonArray();
for (JsonElement jsonElement : array) {
this.tryAddObjective(jsonElement.getAsString(), objectives);
}
}
String override = null;
if ((element = obj.get(SCORE_OVERRIDE)) != null) {
override = element.getAsString();
}
final Score score = new LanternScore(name);
// TODO: How to handle the objectives?
// We cannot add them to the score without attaching the
// score to the objective
score.setScore(value);
final ScoreText.Builder builder = Text.builder(score).override(override);
deserialize(obj, builder, context);
return builder.build();
}
Aggregations