Skip to content

Commit 8017313

Browse files
committed
stuff probably
1 parent fd7a2ac commit 8017313

File tree

7 files changed

+60
-68
lines changed

7 files changed

+60
-68
lines changed

src/main/kotlin/com/github/subat0m1c/hatecheaters/HateCheaters.kt

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import me.odinmain.features.ModuleManager
1717
import net.minecraft.client.gui.GuiScreen
1818
import net.minecraftforge.common.MinecraftForge
1919
import net.minecraftforge.fml.common.Mod
20-
import net.minecraftforge.event.world.WorldEvent
2120
import net.minecraftforge.fml.common.event.FMLInitializationEvent
2221
import net.minecraftforge.fml.common.event.FMLLoadCompleteEvent
2322
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -37,22 +36,6 @@ class HateCheaters {
3736
).forEach { MinecraftForge.EVENT_BUS.register(it) }
3837
}
3938

40-
private var isUpdateCheckInProgress = false
41-
private var timesCheckedForUpdate = 0
42-
43-
@SubscribeEvent
44-
fun onWorldLoad(event: WorldEvent.Load) {
45-
if (timesCheckedForUpdate > 1 || isUpdateCheckInProgress) return
46-
47-
isUpdateCheckInProgress = true
48-
launch {
49-
CheckUpdate.lookForUpdates()
50-
isUpdateCheckInProgress = false
51-
}
52-
53-
timesCheckedForUpdate++
54-
}
55-
5639
@SubscribeEvent
5740
fun onTick(event: ClientTickEvent){
5841
if (screen == null) return

src/main/kotlin/com/github/subat0m1c/hatecheaters/modules/HateCheatersModule.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package com.github.subat0m1c.hatecheaters.modules
22

3+
import com.github.subat0m1c.hatecheaters.HateCheaters.Companion.launch
4+
import com.github.subat0m1c.hatecheaters.utils.CheckUpdate
35
import me.odinmain.features.Category
46
import me.odinmain.features.Module
57
import me.odinmain.features.settings.AlwaysActive
68
import me.odinmain.features.settings.impl.BooleanSetting
79
import me.odinmain.features.settings.impl.StringSetting
10+
import me.odinmain.utils.skyblock.LocationUtils
811

912
@AlwaysActive
1013
object HateCheatersModule : Module(
@@ -16,4 +19,17 @@ object HateCheatersModule : Module(
1619
val debugMessages: Boolean by BooleanSetting("Debug messages", default = false, description = "Prints debug messages in your chat instead of needing to open logs.")
1720
val checkUpdates: Boolean by BooleanSetting("Update Checker", default = true, description = "Checks GitHub for latest HateCheaters releases and notifies you if you are on an old version!")
1821
val server: String by StringSetting("Api Server", default = "default", hidden = false, description = "Server to be used to connect to the api. set to \"default\" to use the default. Only change if you know what you're doing. format: \"subdomain.domain.tld\"")
22+
23+
private var checkedForUpdate = false
24+
25+
init {
26+
execute(250) {
27+
if (checkedForUpdate || !checkUpdates) destroyExecutor()
28+
if (!LocationUtils.isInSkyblock) return@execute
29+
checkedForUpdate = true
30+
launch {
31+
CheckUpdate.lookForUpdates()
32+
}
33+
}
34+
}
1935
}

src/main/kotlin/com/github/subat0m1c/hatecheaters/pvgui/v2/pages/Inventory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ object Inventory: Pages.PVPage("Inventory") {
207207
private val buttons: ButtonDSL<Int> by profileLazy {
208208
buttons(
209209
Box(mainX, startY, mainWidth, buttonHeight), lineY, ot, default = 1,
210-
profile.inventory.backpackContents.keys.mapNotNull { it.toIntOrNull()?.plus(1) }.sorted(), 2, // adding and subtracting so the display matches the game menu.
210+
profile.inventory.backpackContents.keys.mapNotNull { it.toIntOrNull()?.plus(1) }.sorted(), 2, // adding and subtracting so the display matches the game menu instead of index.
211211
ct.button, ct.selected, ct.roundness, 1f,
212212
) {
213213
onSelect {

src/main/kotlin/com/github/subat0m1c/hatecheaters/utils/ChatUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ object ChatUtils {
5959

6060
val message get() = chat
6161

62-
fun print() = runOnMCThread { mc.thePlayer.addChatMessage(chat) }
62+
fun print() = runOnMCThread { mc.thePlayer?.addChatMessage(chat) }
6363
}
6464

6565
fun ChatStyle.setHover(text: List<String>): ChatStyle =
Lines changed: 39 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
package com.github.subat0m1c.hatecheaters.utils
22

3-
import com.github.subat0m1c.hatecheaters.utils.ChatUtils
43
import com.github.subat0m1c.hatecheaters.utils.LogHandler.Logger
5-
import com.github.subat0m1c.hatecheaters.utils.WebUtils
64
import me.odinmain.utils.skyblock.getChatBreak
75
import com.github.subat0m1c.hatecheaters.utils.OdinCheck.compareVersions
8-
import com.github.subat0m1c.hatecheaters.modules.HateCheatersModule.checkUpdates
96
import com.github.subat0m1c.hatecheaters.HateCheaters
7+
import com.github.subat0m1c.hatecheaters.HateCheaters.Companion.launch
8+
import com.github.subat0m1c.hatecheaters.utils.ChatUtils.modMessage
109
import net.minecraft.event.ClickEvent
1110
import kotlinx.serialization.*
1211
import kotlinx.serialization.json.*
13-
import kotlinx.coroutines.*
14-
import java.net.HttpURLConnection
15-
import java.net.URL
12+
import me.odinmain.utils.runIn
1613

1714
val json = Json {
1815
isLenient = true
@@ -21,60 +18,55 @@ val json = Json {
2118

2219
@Serializable
2320
data class ReleaseInfo(
24-
val tag_name: String
21+
@SerialName("tag_name")
22+
val tagName: String
2523
)
2624

2725
object CheckUpdate {
28-
private const val githubAPIURL = "https://api.github.com/repos/subat0m1c/HateCheaters/releases/latest"
26+
private const val GITHUBAPIURL = "https://api.github.com/repos/subat0m1c/HateCheaters/releases/latest"
2927
private inline val currentVersion: String get() = HateCheaters.version
3028

31-
fun lookForUpdates() {
32-
if (!checkUpdates) {
33-
return
34-
}
35-
36-
HateCheaters.scope.launch {
37-
try {
38-
Logger.info("Currently on HateCheaters $currentVersion")
39-
val jsonResponse = WebUtils.getInputStream(githubAPIURL).getOrElse {
40-
return@launch Logger.warning("Failed to fetch data from GitHub API: ${it.message}")
41-
}
42-
val jsonString = jsonResponse.bufferedReader().use { it.readText() }
43-
checkVersion(jsonString)
44-
} catch (e: Exception) {
45-
Logger.warning("Error while checking for updates: ${e.message}")
46-
}
29+
fun lookForUpdates() = launch {
30+
try {
31+
Logger.info("Currently on HateCheaters $currentVersion")
32+
val jsonResponse = WebUtils.getInputStream(GITHUBAPIURL).getOrElse { return@launch }
33+
val jsonString = jsonResponse.bufferedReader().use { it.readText() }
34+
checkVersion(jsonString)
35+
} catch (e: Exception) {
36+
Logger.warning("Error while checking for updates: ${e.message}")
4737
}
4838
}
4939

5040

51-
private suspend fun checkVersion(jsonResponse: String) {
41+
private fun checkVersion(jsonResponse: String) {
5242
val releaseInfo = json.decodeFromString<ReleaseInfo>(jsonResponse)
53-
val latestVersion = releaseInfo.tag_name
43+
val latestVersion = releaseInfo.tagName
5444

5545
val isNewVersionAvailable = compareVersions(latestVersion, currentVersion)
56-
if (isNewVersionAvailable < 0) {
57-
delay(2000)
58-
ChatUtils.modMessage("You are on a development build! Hi!")
59-
Logger.info("HC > Development Build Detected!")
60-
} else if (isNewVersionAvailable > 0) {
61-
val releaseLink = "https://github.com/SubAt0m1c/HateCheaters/releases/tag/$latestVersion"
62-
delay(2000)
63-
ChatUtils.chatConstructor {
64-
displayText(getChatBreak())
65-
displayText("§bH§3C §8»§r Update available! ($currentVersion$latestVersion) ")
66-
clickText(
67-
"Click here to open the latest release link!",
68-
releaseLink,
69-
listOf("Click to open the release link."),
70-
ClickEvent.Action.OPEN_URL
71-
)
72-
displayText(getChatBreak())
73-
}.print()
46+
runIn(40) {
47+
when {
48+
isNewVersionAvailable < 0 -> {
49+
Logger.info("HC > Development Build Detected!")
50+
modMessage("You are on a development build! Hi!")
51+
}
52+
isNewVersionAvailable > 0 -> {
53+
ChatUtils.chatConstructor {
54+
displayText(getChatBreak())
55+
displayText("§bH§3C §8»§r Update available! ($currentVersion$latestVersion) ")
56+
clickText(
57+
"Click here to open the latest release link!",
58+
"https://github.com/SubAt0m1c/HateCheaters/releases/tag/$latestVersion",
59+
listOf("Click to open the release link."),
60+
ClickEvent.Action.OPEN_URL
61+
)
62+
displayText(getChatBreak())
63+
}.print()
7464

75-
Logger.info("HC > Update available.")
76-
} else {
77-
Logger.info("HC > No update needed.")
65+
Logger.info("HC > Update available.")
66+
} else -> {
67+
Logger.info("HC > No update needed.")
68+
}
69+
}
7870
}
7971
}
8072
}

src/main/kotlin/com/github/subat0m1c/hatecheaters/utils/OdinCheck.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,11 @@ object OdinCheck {
116116
private val versionRegex = Regex("(\\d)\\.(\\d)\\.(\\d)(?:\\.(\\d))?(?:\\.beta(\\d+))?")
117117

118118
/**
119-
* @return -1 if version1 is older, 1 if version1 is newer, 0 if they're the same.
120119
* UPDATE: it now generally compares versions between the 2 args, might be good idk
120+
*
121121
* I think this code is bad but i cant be bothered fixing it. also can return lower than -1.
122+
*
123+
* @return -1 if version1 is older, 1 if version1 is newer, 0 if they're the same.
122124
*/
123125
fun compareVersions(version1: String, version2: String): Int {
124126
val v1 = versionRegex.find(version1)?.groupValues?.drop(1)?.map { it.toIntOrNull() } ?: return -2

src/main/kotlin/com/github/subat0m1c/hatecheaters/utils/apiutils/ParseUtils.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import com.github.subat0m1c.hatecheaters.utils.LogHandler.Logger
66
import com.github.subat0m1c.hatecheaters.utils.WebUtils.Server
77
import com.github.subat0m1c.hatecheaters.utils.WebUtils.getInputStream
88
import com.github.subat0m1c.hatecheaters.utils.WebUtils.getUUIDbyName
9-
import com.github.subat0m1c.hatecheaters.utils.apiutils.ApiUtils.memberData
109
import com.github.subat0m1c.hatecheaters.utils.apiutils.HypixelData.PlayerInfo
1110
import com.github.subat0m1c.hatecheaters.utils.apiutils.SkyCryptData.skyCryptToHypixel
1211
import kotlinx.coroutines.Dispatchers

0 commit comments

Comments
 (0)