mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2025-12-16 11:30:19 -07:00
cleanup
This commit is contained in:
parent
9cb152a3c1
commit
f0de95ad06
1 changed files with 8 additions and 6 deletions
|
|
@ -99,6 +99,8 @@ class plugin : Plugin() {
|
||||||
|
|
||||||
private fun replace() {
|
private fun replace() {
|
||||||
if (component != null && component?.id == TARGET_COMPONENT_ID) {
|
if (component != null && component?.id == TARGET_COMPONENT_ID) {
|
||||||
|
// Unmodified login name is used here to display it however the user types it
|
||||||
|
// caps and spaces respected.
|
||||||
val modifiedStr = replaceUsernameInBytes(component!!.text.chars, Player.usernameInput.toString())
|
val modifiedStr = replaceUsernameInBytes(component!!.text.chars, Player.usernameInput.toString())
|
||||||
component?.text = JagString.parse(modifiedStr)
|
component?.text = JagString.parse(modifiedStr)
|
||||||
}
|
}
|
||||||
|
|
@ -124,11 +126,11 @@ class plugin : Plugin() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// No match found, check the hiscores (live server)
|
// No match found, check the hiscores (live server)
|
||||||
fetchAccountTypeFromAPI(cleanUsername)
|
fetchAccountTypeFromAPI(lowercaseUsername)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fetchAccountTypeFromAPI(username : String){
|
private fun fetchAccountTypeFromAPI(lowercaseUsername : String){
|
||||||
val apiUrl = "http://api.2009scape.org:3000/hiscores/playerSkills/1/${username.toLowerCase()}"
|
val apiUrl = "http://api.2009scape.org:3000/hiscores/playerSkills/1/${lowercaseUsername}"
|
||||||
Thread {
|
Thread {
|
||||||
try {
|
try {
|
||||||
val url = URL(apiUrl)
|
val url = URL(apiUrl)
|
||||||
|
|
@ -144,16 +146,16 @@ class plugin : Plugin() {
|
||||||
val reader = BufferedReader(InputStreamReader(connection.inputStream))
|
val reader = BufferedReader(InputStreamReader(connection.inputStream))
|
||||||
val response = reader.use { it.readText() }
|
val response = reader.use { it.readText() }
|
||||||
reader.close()
|
reader.close()
|
||||||
updatePlayerData(response, username)
|
updatePlayerData(response, lowercaseUsername)
|
||||||
}
|
}
|
||||||
} catch (_: Exception) { }
|
} catch (_: Exception) { }
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updatePlayerData(jsonResponse: String, username: String) {
|
private fun updatePlayerData(jsonResponse: String, lowercaseUsername: String) {
|
||||||
val hiscoresResponse = gson.fromJson(jsonResponse, HiscoresResponse::class.java)
|
val hiscoresResponse = gson.fromJson(jsonResponse, HiscoresResponse::class.java)
|
||||||
ACCOUNT_TYPE = hiscoresResponse.info.iron_mode.toInt()
|
ACCOUNT_TYPE = hiscoresResponse.info.iron_mode.toInt()
|
||||||
usernameMatches[username.toLowerCase()] = ACCOUNT_TYPE
|
usernameMatches[lowercaseUsername] = ACCOUNT_TYPE
|
||||||
storeData()
|
storeData()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue