Skip to content

Commit

Permalink
Fix UnsupportedOperationException in SqlUserLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
Archy-X committed Jul 28, 2024
1 parent cc6af2c commit abe0ff0
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private void processResultSet(ResultSet rs, User user) throws SQLException {
for (JsonElement skillLevelElement : skillLevels) {
JsonObject skillLevelObj = skillLevelElement.getAsJsonObject();

String name = skillLevelObj.get("name").getAsString();
String name = getString(skillLevelObj, "name");
int level = skillLevelObj.get("level").getAsInt();
double xp = skillLevelObj.get("xp").getAsDouble();

Expand All @@ -109,14 +109,14 @@ private void processResultSet(ResultSet rs, User user) throws SQLException {

// Load key values
JsonArray keyValues = getJsonArray("key_values", rs);
if (keyValues != null) {
if (keyValues != null && !keyValues.isJsonNull()) {
for (JsonElement keyValueElement : keyValues) {
JsonObject keyValueObj = keyValueElement.getAsJsonObject();

int dataId = keyValueObj.get("data_id").getAsInt();
String categoryId = keyValueObj.get("category_id").getAsString();
String keyName = keyValueObj.get("key_name").getAsString();
String value = keyValueObj.get("value").getAsString();
String categoryId = getString(keyValueObj, "category_id");
String keyName = getString(keyValueObj, "key_name");
String value = getString(keyValueObj, "value");

switch (dataId) {
case STAT_MODIFIER_ID -> applyStatModifier(user, categoryId, keyName, value);
Expand All @@ -133,6 +133,14 @@ private void processResultSet(ResultSet rs, User user) throws SQLException {
user.clearInvalidItems();
}

private String getString(JsonObject parent, String key) {
JsonElement element = parent.get(key);
if (element != null && !element.isJsonNull() && element.isJsonPrimitive()) {
return element.getAsString();
}
return "";
}

private void applyStatModifier(User user, String categoryId, String keyName, String valueStr) {
try {
double valueDouble = Double.parseDouble(valueStr);
Expand Down

0 comments on commit abe0ff0

Please sign in to comment.