Skip to content

Commit

Permalink
Use correct JSON library
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobwgillespie committed Dec 14, 2015
1 parent 0637f6e commit a6d6c45
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
<version>1.5</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20151123</version>
</dependency>
</dependencies>

<build>
Expand Down
9 changes: 4 additions & 5 deletions src/main/kotlin/gg/obsidian/discoursegroupsync/UUIDHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package gg.obsidian.discoursegroupsync

import com.squareup.okhttp.OkHttpClient
import com.squareup.okhttp.Request
import org.json.simple.JSONObject
import org.json.simple.JSONValue
import org.json.JSONObject
import java.util.*

object UUIDHelper {
Expand All @@ -15,12 +14,12 @@ object UUIDHelper {
val url = PROFILE_URL + uuid.toString().replace("-", "")
val request = Request.Builder().url(url).get().build();
val response = httpClient.newCall(request).execute()
val body = JSONValue.parse(response.body().string()) as JSONObject
val body = JSONObject(response.body().string())

if (body.containsKeyRaw("error")) {
if (body.has("error")) {
return ""
}

return body.get("name") as String
return body.getString("name")
}
}
14 changes: 6 additions & 8 deletions src/main/kotlin/gg/obsidian/discoursegroupsync/UserManger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package gg.obsidian.discoursegroupsync
import com.squareup.okhttp.OkHttpClient
import com.squareup.okhttp.Request
import org.bukkit.entity.Player
import org.json.simple.JSONArray
import org.json.simple.JSONObject
import org.json.simple.JSONValue
import org.json.JSONObject
import java.util.*

class UserManager(val plugin: DiscourseGroupSync) {
Expand All @@ -32,19 +30,19 @@ class UserManager(val plugin: DiscourseGroupSync) {
}

val bodyString = response.body().string()
val body = JSONValue.parse(bodyString) as JSONObject
val user = body.getRaw("user") as JSONObject
val customGroups = user.getRaw("custom_groups") as JSONArray
val body = JSONObject(bodyString)
val user = body.getJSONObject("user")
val customGroups = user.getJSONArray("custom_groups")

val discourseGroups = HashSet<Int>()

for (g in customGroups) {
val group = g as JSONObject
val id = group.getRaw("id") as Long
val id = group.getLong("id")
discourseGroups.add(id.toInt())
}

if (customGroups.size == 0) {
if (customGroups.length() == 0) {
discourseGroups.add(0)
}

Expand Down

0 comments on commit a6d6c45

Please sign in to comment.