-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
70e006a
commit cc5ec0a
Showing
6 changed files
with
81 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/kotlin/gg/obsidian/discoursegroupsync/UUIDHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package gg.obsidian.discoursegroupsync | ||
|
||
import com.mashape.unirest.http.HttpResponse | ||
import com.mashape.unirest.http.JsonNode | ||
import com.mashape.unirest.http.Unirest | ||
import java.util.* | ||
|
||
object UUIDHelper { | ||
val PROFILE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/" | ||
|
||
fun uuidToUsername(uuid: UUID): String { | ||
val url = PROFILE_URL + uuid.toString().replace("-", "") | ||
val jsonResponse: HttpResponse<JsonNode> = Unirest.get(url).asJson() | ||
val body = jsonResponse.body.`object` | ||
|
||
if (body.has("error")) { | ||
return "" | ||
} | ||
|
||
return body.getString("name") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
package gg.obsidian.discoursegroupsync | ||
|
||
data class User(val username: String, val minecraftGroups: Set<String>) | ||
import java.util.* | ||
|
||
data class User(val username: String = "", val minecraftGroups: Set<String> = HashSet(), val exists: Boolean = true) |
43 changes: 43 additions & 0 deletions
43
src/main/kotlin/gg/obsidian/discoursegroupsync/UserManger.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package gg.obsidian.discoursegroupsync | ||
|
||
import com.mashape.unirest.http.HttpResponse | ||
import com.mashape.unirest.http.JsonNode | ||
import com.mashape.unirest.http.Unirest | ||
import org.bukkit.entity.Player | ||
import java.util.* | ||
|
||
class UserManager(val plugin: DiscourseGroupSync) { | ||
|
||
fun getDiscourseUser(username: String): User { | ||
val url = plugin.config.DISCOURSE_URL + "/users/" + username + ".json" | ||
val jsonResponse: HttpResponse<JsonNode> = Unirest.get(url).asJson() | ||
|
||
if (jsonResponse.status != 200) { | ||
return User(exists = false) | ||
} | ||
|
||
val body = jsonResponse.body.`object` | ||
|
||
val minecraftGroups = HashSet<String>() | ||
|
||
val customGroups = body.getJSONArray("custom_groups") | ||
|
||
for (i in (0..customGroups.length() - 1)) { | ||
val group = customGroups.get(i) as JsonNode | ||
val groupId = group.getObject().getInt("id") | ||
|
||
if (plugin.config.GROUPS.containsKey(groupId)) { | ||
minecraftGroups.add(plugin.config.GROUPS[groupId].minecraftGroup) | ||
} | ||
} | ||
|
||
return User(username = username, minecraftGroups = HashSet<String>()) | ||
} | ||
|
||
fun syncGroups(player: Player) { | ||
val username = UUIDHelper.uuidToUsername(player.uniqueId) | ||
if (username == "") return | ||
|
||
val discourseUser = getDiscourseUser(username) | ||
} | ||
} |