mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2025-12-09 16:45:46 -07:00
Group overrides together, change somem comments
This commit is contained in:
parent
57ca3365d1
commit
0392204f03
1 changed files with 50 additions and 62 deletions
|
|
@ -28,15 +28,13 @@ class plugin : Plugin() {
|
||||||
3 to "<img=6>", // UIM
|
3 to "<img=6>", // UIM
|
||||||
)
|
)
|
||||||
|
|
||||||
// Local storage for username matches to avoid API calls
|
|
||||||
@Exposed(description = "Username to account type mappings (0=Normal, 1=IM, 2=HCIM, 3=UIM)")
|
@Exposed(description = "Username to account type mappings (0=Normal, 1=IM, 2=HCIM, 3=UIM)")
|
||||||
private var usernameMatches = HashMap<String, Int>()
|
private var usernameMatches = HashMap<String, Int>()
|
||||||
|
|
||||||
private var ACCOUNT_TYPE = 0
|
private var ACCOUNT_TYPE = 0
|
||||||
|
|
||||||
private var component: Component? = null
|
private var component: Component? = null
|
||||||
|
|
||||||
// See JagString.java parse(), There is special encoding
|
// See JagString.java parse() in the client, There is special encoding
|
||||||
// and this correctly resolves specials.
|
// and this correctly resolves specials.
|
||||||
val SPECIAL_ESCAPES: Map<Char, String> = hashMapOf(
|
val SPECIAL_ESCAPES: Map<Char, String> = hashMapOf(
|
||||||
' ' to "(P",
|
' ' to "(P",
|
||||||
|
|
@ -245,38 +243,18 @@ class plugin : Plugin() {
|
||||||
HashMap()
|
HashMap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> {
|
else -> HashMap()
|
||||||
// No data or unexpected format
|
|
||||||
HashMap()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun OnKondoValueUpdated() {
|
|
||||||
println("OnKondoValueUpdated called - current usernameMatches: $usernameMatches")
|
|
||||||
StoreData()
|
|
||||||
OnPluginsReloaded() //refresh the ui
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getCleanUserName(): String {
|
|
||||||
return Player.usernameInput.toString().replace(" ", "_")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun OnPluginsReloaded(): Boolean {
|
override fun OnPluginsReloaded(): Boolean {
|
||||||
grabConfig()
|
grabConfig()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun StoreData() {
|
|
||||||
val jsonString = gson.toJson(usernameMatches)
|
|
||||||
println("Storing ${jsonString}")
|
|
||||||
API.StoreData(SETTINGS_KEY, jsonString)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun Draw(timeDelta: Long) {
|
override fun Draw(timeDelta: Long) {
|
||||||
if (component != null && component?.id == TARGET_COMPONENT_ID) {
|
if (component != null && component?.id == TARGET_COMPONENT_ID) {
|
||||||
val username = Player.usernameInput.toString().toLowerCase()
|
val modifiedStr = replaceUsernameInBytes(component!!.text.chars, Player.usernameInput.toString())
|
||||||
val modifiedStr = replaceUsernameInBytes(component!!.text.chars, username)
|
|
||||||
component?.text = JagString.parse(modifiedStr)
|
component?.text = JagString.parse(modifiedStr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -287,8 +265,48 @@ class plugin : Plugin() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun OnLogin() {
|
||||||
|
grabConfig()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allow setting from the chatbox
|
||||||
|
override fun ProcessCommand(commandStr: String?, args: Array<out String>?) {
|
||||||
|
super.ProcessCommand(commandStr, args)
|
||||||
|
when(commandStr) {
|
||||||
|
"::chathelm" -> {
|
||||||
|
if (args != null) {
|
||||||
|
if(args.isEmpty()) return
|
||||||
|
val type = args[0].toIntOrNull() ?: return
|
||||||
|
ACCOUNT_TYPE = type
|
||||||
|
usernameMatches[getCleanUserName()] = ACCOUNT_TYPE
|
||||||
|
storeData()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun OnKondoValueUpdated() {
|
||||||
|
storeData()
|
||||||
|
OnPluginsReloaded() //refresh the ui
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getCleanUserName(): String {
|
||||||
|
return Player.usernameInput.toString().replace(" ", "_")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun grabConfig() {
|
||||||
|
// Check if we already have the account type for this user
|
||||||
|
val cleanUsername = getCleanUserName()
|
||||||
|
if (usernameMatches.containsKey(cleanUsername.toLowerCase())) {
|
||||||
|
ACCOUNT_TYPE = usernameMatches[cleanUsername]!!
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// No match found, check the hiscores (live server)
|
||||||
|
fetchAccountTypeFromAPI()
|
||||||
|
}
|
||||||
|
|
||||||
private fun fetchAccountTypeFromAPI(){
|
private fun fetchAccountTypeFromAPI(){
|
||||||
println("Fetching Iron status from API...")
|
|
||||||
val cleanUsername = getCleanUserName()
|
val cleanUsername = getCleanUserName()
|
||||||
val apiUrl = "http://api.2009scape.org:3000/hiscores/playerSkills/1/${cleanUsername.toLowerCase()}"
|
val apiUrl = "http://api.2009scape.org:3000/hiscores/playerSkills/1/${cleanUsername.toLowerCase()}"
|
||||||
Thread {
|
Thread {
|
||||||
|
|
@ -315,45 +333,10 @@ class plugin : Plugin() {
|
||||||
private fun updatePlayerData(jsonResponse: String, username: String) {
|
private fun updatePlayerData(jsonResponse: String, username: 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()
|
||||||
println("Resolved you are account type: $ACCOUNT_TYPE")
|
|
||||||
|
|
||||||
// Store the result in our local cache
|
// Store the result in our local cache
|
||||||
usernameMatches[username] = ACCOUNT_TYPE
|
usernameMatches[username] = ACCOUNT_TYPE
|
||||||
StoreData()
|
storeData()
|
||||||
}
|
|
||||||
|
|
||||||
override fun OnLogin() {
|
|
||||||
grabConfig()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun grabConfig() {
|
|
||||||
// Check if we already have the account type for this user
|
|
||||||
val cleanUsername = getCleanUserName()
|
|
||||||
if (usernameMatches.containsKey(cleanUsername.toLowerCase())) {
|
|
||||||
ACCOUNT_TYPE = usernameMatches[cleanUsername]!!
|
|
||||||
println("Using cached account type: $ACCOUNT_TYPE for $cleanUsername")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// The game server doesn't tell us what account type we are.
|
|
||||||
// Requesting from API is the easier way to tell.
|
|
||||||
fetchAccountTypeFromAPI()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allow setting from the chatbox
|
|
||||||
override fun ProcessCommand(commandStr: String?, args: Array<out String>?) {
|
|
||||||
super.ProcessCommand(commandStr, args)
|
|
||||||
when(commandStr) {
|
|
||||||
"::chathelm" -> {
|
|
||||||
if (args != null) {
|
|
||||||
if(args.isEmpty()) return
|
|
||||||
val type = args[0].toIntOrNull() ?: return
|
|
||||||
ACCOUNT_TYPE = type
|
|
||||||
usernameMatches[getCleanUserName()] = ACCOUNT_TYPE
|
|
||||||
StoreData()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun replaceUsernameInBytes(bytes: ByteArray, username: String): String {
|
private fun replaceUsernameInBytes(bytes: ByteArray, username: String): String {
|
||||||
|
|
@ -369,6 +352,11 @@ class plugin : Plugin() {
|
||||||
return encodeToJagStr(text)
|
return encodeToJagStr(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun storeData() {
|
||||||
|
val jsonString = gson.toJson(usernameMatches)
|
||||||
|
API.StoreData(SETTINGS_KEY, jsonString)
|
||||||
|
}
|
||||||
|
|
||||||
private fun encodeToJagStr(str: String): String {
|
private fun encodeToJagStr(str: String): String {
|
||||||
val result = StringBuilder()
|
val result = StringBuilder()
|
||||||
for (char in str) {
|
for (char in str) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue